Merge lp:~elementary-apps/granite/tab-bar-visibility into lp:~elementary-pantheon/granite/granite

Proposed by David Gomes
Status: Merged
Approved by: David Gomes
Approved revision: 685
Merged at revision: 686
Proposed branch: lp:~elementary-apps/granite/tab-bar-visibility
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 188 lines (+42/-12)
2 files modified
lib/Widgets/DynamicNotebook.vala (+39/-9)
lib/Widgets/SourceList.vala (+3/-3)
To merge this branch: bzr merge lp:~elementary-apps/granite/tab-bar-visibility
Reviewer Review Type Date Requested Status
Niclas Lockner (community) Approve
elementary Pantheon team Pending
Review via email: mp+202517@code.launchpad.net

Commit message

Moved all the Pantheon Terminal TabBarBehavior code to Granite.DynamicNotebook,
fixing bug #1264565.

Description of the change

Moved all the Pantheon Terminal TabBarBehavior code to Granite.DynamicNotebook,
fixing bug #1264565.

This now allows any app to set their tab bar visibility behavior.

To post a comment you must log in.
Revision history for this message
Niclas Lockner (niclasl) wrote :

Looks good. I have some minor comments though:

If tab_bar_behavior is changed from never to always, the notebook's visibility isn't updated.
_tab_bar_behavior isn't explicitly initialized, but implicitly initialized to 0, which is more of a readability issue.
Line 659-664 are kind of redundant. When they are executed, _tab_bar_behavior will always be 0 = ALWAYS.

I would suggest you to extend update_tabs_visibility to cover all cases, and then initialize tab_bar_behavior to ALWAYS in the constructor. After that the lines 590-591 and 659-664 can be dropped.

review: Needs Fixing
Revision history for this message
Niclas Lockner (niclasl) wrote :

And with lines 590-591 and 659-664 I meant lines 76-77 and 102-108 in the diff.

Revision history for this message
David Gomes (davidgomes) wrote :

>If tab_bar_behavior is changed from never to always, the notebook's visibility isn't updated.
Do you mean while the application is running?

Revision history for this message
Niclas Lockner (niclasl) wrote :

Exactly. If I were to do a dn.tab_bar_behavior = ALWAYS from an application, there's nothing in the set block that changes the show_tabs property. So if it was hidden before, it is not set to shown.

Revision history for this message
David Gomes (davidgomes) wrote :

Pushed according to your suggestions Niclas. Requesting re-review please.

Revision history for this message
Niclas Lockner (niclasl) :
review: Approve
Revision history for this message
RabbitBot (rabbitbot-a) wrote :

The `tree_dir` option for the target branch is not a lightweight checkout. Please ask a project administrator to resolve the issue, and try again.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/DynamicNotebook.vala'
2--- lib/Widgets/DynamicNotebook.vala 2013-12-27 16:31:25 +0000
3+++ lib/Widgets/DynamicNotebook.vala 2014-01-23 12:56:09 +0000
4@@ -1,6 +1,6 @@
5 /***
6 Copyright (C) 2011-2013 Tom Beckmann <tom@elementaryos.org>
7-
8+
9 This program or library is free software; you can redistribute it
10 and/or modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12@@ -43,10 +43,10 @@
13 * This is a standard tab which can be used in a notebook to form a tabbed UI.
14 */
15 public class Tab : Gtk.EventBox {
16-
17 Gtk.Label _label;
18 public string label {
19 get { return _label.label; }
20+
21 set {
22 _label.label = value;
23 _label.set_tooltip_text (value);
24@@ -56,6 +56,7 @@
25 private bool _pinned;
26 public bool pinned {
27 get { return _pinned; }
28+
29 set {
30 if (pinnable) {
31 if (value != _pinned) {
32@@ -64,7 +65,6 @@
33 close_button.visible = false;
34 _icon.margin_left = 1;
35 _working.margin_left = 1;
36-
37 } else {
38 _label.visible = true;
39 _icon.margin_left = 0;
40@@ -191,7 +191,7 @@
41 _icon.set_size_request (16, 16);
42 _working.set_size_request (16, 16);
43 this.visible_window = false;
44-
45+
46 this.add (tab_box);
47
48 page_container = new TabPageContainer (this);
49@@ -398,7 +398,6 @@
50 }
51
52 public class DynamicNotebook : Gtk.EventBox {
53-
54 /**
55 * number of pages
56 */
57@@ -517,7 +516,7 @@
58 set {
59 if (value != _add_button_visible) {
60 if (_add_button_visible) {
61- this.notebook.set_action_widget (null, Gtk.PackType.START);
62+ this.notebook.set_action_widget (null, Gtk.PackType.START);
63 } else {
64 this.notebook.set_action_widget (add_button, Gtk.PackType.START);
65 }
66@@ -574,6 +573,26 @@
67 set { notebook.group_name = value; }
68 }
69
70+ public enum TabBarBehavior {
71+ ALWAYS = 0,
72+ SINGLE = 1,
73+ NEVER = 2
74+ }
75+
76+ /**
77+ * The behavior of the tab bar and its visibility
78+ */
79+ public TabBarBehavior tab_bar_behavior {
80+ set {
81+ _tab_bar_behavior = value;
82+ update_tabs_visibility ();
83+ }
84+
85+ get { return _tab_bar_behavior; }
86+ }
87+
88+ private TabBarBehavior _tab_bar_behavior;
89+
90 /**
91 * The menu appearing when the notebook is clicked on a blank space
92 */
93@@ -621,8 +640,8 @@
94 * Create a new dynamic notebook
95 */
96 public DynamicNotebook () {
97-
98 this.button_fix = new Gtk.CssProvider ();
99+
100 try {
101 this.button_fix.load_from_data (CLOSE_BUTTON_STYLE, -1);
102 } catch (Error e) { warning (e.message); }
103@@ -633,6 +652,7 @@
104
105 this.notebook.scrollable = true;
106 this.notebook.show_border = false;
107+ _tab_bar_behavior = TabBarBehavior.ALWAYS;
108
109 this.draw.connect ( (ctx) => {
110 this.get_style_context ().render_activity (ctx, 0, 0, this.get_allocated_width (), 27);
111@@ -727,7 +747,6 @@
112 });
113
114 this.key_press_event.connect ((e) => {
115-
116 e.state &= MODIFIER_MASK;
117
118 switch (e.keyval) {
119@@ -834,6 +853,7 @@
120
121 insert_callbacks (t);
122 tab_added (t);
123+ update_tabs_visibility ();
124 }
125
126 void on_page_removed (Gtk.Widget page, uint pagenum) {
127@@ -841,6 +861,7 @@
128
129 remove_callbacks (t);
130 tab_removed (t);
131+ update_tabs_visibility ();
132 }
133
134 void on_page_reordered (Gtk.Widget page, uint pagenum) {
135@@ -866,7 +887,7 @@
136 }
137 }
138
139- for (var p = 0; p < pinned_tabs; p++) {
140+ for (var p = 0; p < pinned_tabs; p++) {
141 int sel = p;
142 for (var i = p; i < this.notebook.get_n_pages (); i++) {
143 if ((this.notebook.get_tab_label (this.notebook.get_nth_page (i)) as Tab).pinned) {
144@@ -1092,5 +1113,14 @@
145 private void on_pin_switch (Tab tab) {
146 switch_pin_tab (tab);
147 }
148+
149+ private void update_tabs_visibility () {
150+ if (_tab_bar_behavior == TabBarBehavior.SINGLE)
151+ notebook.show_tabs = n_tabs > 1;
152+ else if (_tab_bar_behavior == TabBarBehavior.NEVER)
153+ notebook.show_tabs = false;
154+ else if (_tab_bar_behavior == TabBarBehavior.ALWAYS)
155+ notebook.show_tabs = true;
156+ }
157 }
158 }
159
160=== modified file 'lib/Widgets/SourceList.vala'
161--- lib/Widgets/SourceList.vala 2013-12-15 12:40:31 +0000
162+++ lib/Widgets/SourceList.vala 2014-01-23 12:56:09 +0000
163@@ -10,7 +10,7 @@
164 but WITHOUT ANY WARRANTY; without even the implied warranty of
165 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
166 Lesser General Public License for more details.
167-
168+
169 You should have received a copy of the GNU Lesser General
170 Public License along with this library; if not, write to the
171 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
172@@ -2206,7 +2206,7 @@
173 if (data_model.iter_previous (ref new_iter))
174 return data_model.get_item (new_iter);
175 }
176-
177+
178 return null;
179 }
180
181@@ -2225,7 +2225,7 @@
182 if (data_model.iter_next (ref new_iter))
183 return data_model.get_item (new_iter);
184 }
185-
186+
187 return null;
188 }
189

Subscribers

People subscribed via source and target branches