Merge lp:~victored/granite/static-notebook-fixes into lp:~elementary-pantheon/granite/granite

Proposed by Victor Martinez
Status: Merged
Approved by: xapantu
Approved revision: 165
Merged at revision: 166
Proposed branch: lp:~victored/granite/static-notebook-fixes
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 124 lines (+65/-26)
1 file modified
lib/Widgets/StaticNotebook.vala (+65/-26)
To merge this branch: bzr merge lp:~victored/granite/static-notebook-fixes
Reviewer Review Type Date Requested Status
xapantu Pending
Review via email: mp+89565@code.launchpad.net

Description of the change

[Granite.Widgets.StaticNotebook]
lp:889376
lp:889551

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/StaticNotebook.vala'
2--- lib/Widgets/StaticNotebook.vala 2011-09-06 16:22:53 +0000
3+++ lib/Widgets/StaticNotebook.vala 2012-01-22 03:05:26 +0000
4@@ -19,55 +19,94 @@
5 */
6
7 namespace Granite.Widgets {
8- public class StaticNotebook : Gtk.VBox
9- {
10- Gtk.Notebook notebook;
11- ModeButton switcher;
12-
13- public int page {
14+
15+ public class StaticNotebook : Gtk.Box {
16+
17+ private Gtk.Notebook notebook;
18+ private ModeButton switcher;
19+ private Gtk.Box switcher_box;
20+
21+ /* The page switcher will NEVER be shown if this property is set to true */
22+ private bool switcher_hidden;
23+
24+ public int page {
25 set { switcher.selected = value; notebook.page = value; }
26 get { return notebook.page; }
27 }
28-
29- public signal void page_changed (int index);
30-
31- public StaticNotebook()
32- {
33+
34+ public signal void page_changed(int index);
35+
36+ public StaticNotebook() {
37+
38+ orientation = Gtk.Orientation.VERTICAL;
39+ switcher_hidden = false;
40+
41 notebook = new Gtk.Notebook();
42 notebook.show_tabs = false;
43+
44 switcher = new ModeButton();
45- var hbox = new Gtk.HBox(false, 0);
46- hbox.pack_start(new Gtk.HSeparator(), true, true);
47- hbox.pack_start(switcher, false, false);
48+
49+ switcher_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
50+ var left_separator = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
51+ var right_separator = new Gtk.Separator(Gtk.Orientation.HORIZONTAL);
52+
53+ switcher_box.pack_start(left_separator, true, true);
54+ switcher_box.pack_start(switcher, false, false);
55+ switcher_box.pack_end(right_separator, true, true);
56+
57 switcher.set_margin_top(5);
58 switcher.set_margin_bottom(5);
59- hbox.pack_start(new Gtk.HSeparator(), true, true);
60- pack_start(hbox, false, false);
61+
62+ pack_start(switcher_box, false, false);
63 pack_start(notebook);
64-
65+
66 switcher.mode_changed.connect(on_mode_changed);
67 }
68-
69- public void append_page(Gtk.Widget widget, Gtk.Label label)
70- {
71+
72+ public void set_switcher_visible(bool val) {
73+ switcher_box.set_no_show_all(!val);
74+ switcher_hidden = !val;
75+ update_switcher_visibility();
76+ }
77+
78+ public void append_page(Gtk.Widget widget, Gtk.Label label) {
79 notebook.append_page(widget, null);
80 label.set_margin_right(5);
81 label.set_margin_left(5);
82 switcher.append(label);
83+
84 if(switcher.selected == -1)
85 switcher.selected = 0;
86+
87+ update_switcher_visibility();
88 }
89-
90- void on_mode_changed(Gtk.Widget widget)
91- {
92+
93+ void on_mode_changed(Gtk.Widget widget) {
94 notebook.page = switcher.selected;
95 page_changed(notebook.page);
96 }
97-
98- public void remove_page(int number)
99- {
100+
101+ public void remove_page(int number) {
102 notebook.remove_page(number);
103 switcher.remove(number);
104+ update_switcher_visibility();
105+ }
106+
107+ private void update_switcher_visibility() {
108+ if (switcher_hidden) {
109+ switcher_box.hide();
110+ return;
111+ }
112+
113+ // Don't show tabs if there's only one page
114+ bool switcher_visible = notebook.get_n_pages() > 1;
115+ switcher_box.set_no_show_all (!switcher_visible);
116+
117+ if (switcher_visible)
118+ switcher_box.show_all();
119+ else
120+ switcher_box.hide();
121 }
122 }
123 }
124+

Subscribers

People subscribed via source and target branches