Merge lp:~junrrein/granite/fixed-tabs into lp:~elementary-pantheon/granite/granite

Proposed by Julián Unrrein
Status: Rejected
Rejected by: David Gomes
Proposed branch: lp:~junrrein/granite/fixed-tabs
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 141 lines (+48/-6)
1 file modified
lib/Widgets/DynamicNotebook.vala (+48/-6)
To merge this branch: bzr merge lp:~junrrein/granite/fixed-tabs
Reviewer Review Type Date Requested Status
David Gomes (community) Disapprove
Review via email: mp+172408@code.launchpad.net

Commit message

[Dynamic Notebook] Fix the logic of fixed tabs. Set the width of fixed tabs. Don't let fixed tabs be closed or detached.

Description of the change

Fix the logic of fixed tabs. Set the width of fixed tabs. Don't let fixed tabs be closed or detached.

I assumed that tabs shouldn't be able to be closed if they are fixed. They can still be closed with "remove_tab_force".

To post a comment you must log in.
lp:~junrrein/granite/fixed-tabs updated
602. By Julián Unrrein

Revert changes to granite-demo.

Revision history for this message
Julián Unrrein (junrrein) wrote :

In short words, the size of fixed tabs should be handled correctly, and they shouldn't be able to be closed now.

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

Newline 52, putting some curly braces would really help readibility.

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

I mean, diff line 52*.

lp:~junrrein/granite/fixed-tabs updated
603. By Julián Unrrein

Improve the coding style.

Revision history for this message
Julián Unrrein (junrrein) wrote :

Hi David. I applied your suggestion but I also changed that particular section a bit.

lp:~junrrein/granite/fixed-tabs updated
604. By Julián Unrrein

[DynamicNotebook] Moved a couple of responsibilites from DynamicNotebook to Tab.

605. By Julián Unrrein

Set tab properties correctly when moving them to other notebooks.

606. By Julián Unrrein

Merge from trunk.

Revision history for this message
Julián Unrrein (junrrein) wrote :

It would be nice to disconnect the "on_tab_fixed_set" method when a page is removed from the internal notebook. But I couldn't find a way to retrieve which tab that page belongs to, since it isn't in the notebook anymore. Not having this doesn't seem to cause any bugs.

lp:~junrrein/granite/fixed-tabs updated
607. By Julián Unrrein

Remove duplicated operations.

Revision history for this message
Julián Unrrein (junrrein) wrote :

When testing this, you may notice that in a fixed tab, the icon is not centered.

Fixing that should wait until https://code.launchpad.net/~junrrein/granite/fix-1196721/+merge/174846 gets reviewed, since that branch changes the way the tab is layouted.

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

Newline after diff line 118.

lp:~junrrein/granite/fixed-tabs updated
608. By Julián Unrrein

Improve coding style.

Revision history for this message
Julián Unrrein (junrrein) wrote :

Applied David's suggestion.

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

Rejected in favor of https://code.launchpad.net/~gangsterveggies/granite/fix-bug-959553/+merge/180783.

Decided this together with Daniel, Julian and Pedro.

review: Disapprove

Unmerged revisions

608. By Julián Unrrein

Improve coding style.

607. By Julián Unrrein

Remove duplicated operations.

606. By Julián Unrrein

Merge from trunk.

605. By Julián Unrrein

Set tab properties correctly when moving them to other notebooks.

604. By Julián Unrrein

[DynamicNotebook] Moved a couple of responsibilites from DynamicNotebook to Tab.

603. By Julián Unrrein

Improve the coding style.

602. By Julián Unrrein

Revert changes to granite-demo.

601. By Julián Unrrein

[DynamicNotebook] Make the "Close tab" and "Open in a new Window" menuitems non-sensitive for a fixed tab.

600. By Julián Unrrein

[DynamicNotebook] Don't allow fixed tabs to be closed, unless "remove_tab_forced" is used.

599. By Julián Unrrein

Correct the previous commit.

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-07-13 22:40:24 +0000
3+++ lib/Widgets/DynamicNotebook.vala 2013-07-17 21:34:27 +0000
4@@ -84,8 +84,10 @@
5 get { return _fixed; }
6 set {
7 if (value != _fixed) {
8- _label.visible = value;
9- close.visible = value;
10+ _label.visible = !value;
11+ close.visible = !value;
12+ close_m.sensitive = !value;
13+ new_window_m.sensitive = !value;
14 }
15 _fixed = value;
16 }
17@@ -95,6 +97,7 @@
18 public Gtk.Menu menu { get; set; }
19
20 //we need to be able to toggle those from the notebook
21+ internal Gtk.MenuItem close_m;
22 internal Gtk.MenuItem new_window_m;
23 internal Gtk.MenuItem duplicate_m;
24
25@@ -132,12 +135,13 @@
26 this.page = page ?? new Gtk.Label("");
27 page_container.show_all ();
28
29+ fixed = false;
30 restore_data = "";
31
32 this.show_all ();
33
34 menu = new Gtk.Menu ();
35- var close_m = new Gtk.MenuItem.with_label (_("Close Tab"));
36+ close_m = new Gtk.MenuItem.with_label (_("Close Tab"));
37 var close_other_m = new Gtk.MenuItem.with_label ("");
38 new_window_m = new Gtk.MenuItem.with_label (_("Open in a new Window"));
39 duplicate_m = new Gtk.MenuItem.with_label (_("Duplicate"));
40@@ -425,6 +429,7 @@
41
42 private int tab_width = 150;
43 private int max_tab_width = 150;
44+ private int fixed_tab_width = 25;
45
46 public signal void tab_added (Tab tab);
47 public signal bool tab_removed (Tab tab);
48@@ -621,12 +626,14 @@
49 return false;
50 });
51
52+ notebook.page_added.connect (on_page_added);
53 notebook.switch_page.connect (on_switch_page);
54 notebook.page_reordered.connect (on_page_reordered);
55 notebook.create_window.connect (on_create_window);
56 }
57
58 ~Notebook () {
59+ notebook.page_added.disconnect (on_page_added);
60 notebook.switch_page.disconnect (on_switch_page);
61 notebook.page_reordered.disconnect (on_page_reordered);
62 notebook.create_window.disconnect (on_create_window);
63@@ -641,6 +648,11 @@
64 y += button_alloc.y + button_alloc.height + 1;
65 }
66
67+ void on_page_added (Gtk.Widget page, uint pagenum) {
68+ var tab = this.get_tab_by_index ((int) pagenum);
69+ tab.notify["fixed"].connect (on_tab_fixed_set);
70+ }
71+
72 void on_switch_page (Gtk.Widget page, uint pagenum) {
73 var new_tab = notebook.get_tab_label (page) as Tab;
74
75@@ -662,8 +674,22 @@
76 if (n_tabs == 0)
77 return;
78
79+ var fixed_tabs = 0;
80+ foreach (var tab in this.tabs) {
81+ if (tab.fixed)
82+ fixed_tabs++;
83+ }
84+
85+ var fixed_tabs_width_sum = fixed_tabs * fixed_tab_width;
86+
87 var offset = 130;
88- this.tab_width = (this.get_allocated_width () - offset) / this.notebook.get_n_pages ();
89+
90+ if (this.notebook.get_n_pages () > fixed_tabs)
91+ this.tab_width = (this.get_allocated_width () - offset - fixed_tabs_width_sum)
92+ / (this.notebook.get_n_pages () - fixed_tabs);
93+ else
94+ this.tab_width = max_tab_width;
95+
96 if (tab_width > max_tab_width)
97 tab_width = max_tab_width;
98
99@@ -671,7 +697,11 @@
100 tab_width = 0;
101
102 for (var i = 0; i < this.notebook.get_n_pages (); i++) {
103- this.notebook.get_tab_label (this.notebook.get_nth_page (i)).width_request = tab_width;
104+ var tab = this.get_tab_by_index (i);
105+ if (tab.fixed)
106+ this.notebook.get_tab_label (this.notebook.get_nth_page (i)).width_request = fixed_tab_width;
107+ else
108+ this.notebook.get_tab_label (this.notebook.get_nth_page (i)).width_request = tab_width;
109 }
110
111 this.notebook.resize_children ();
112@@ -687,8 +717,20 @@
113 insert_tab (tab, -1);
114 this.tab_restored (tab);
115 }
116+
117+ private void on_tab_fixed_set (Object object, ParamSpec paramspec) {
118+ var tab = object as Tab;
119+
120+ if (this.get_tab_position (tab) != -1) {
121+ notebook.set_tab_detachable (tab.page_container, this.allow_new_window && !tab.fixed);
122+ this.recalc_size ();
123+ }
124+ }
125
126 public void remove_tab (Tab tab) {
127+ if (tab.fixed)
128+ return;
129+
130 if (Signal.has_handler_pending (this, Signal.lookup ("tab-removed", typeof (DynamicNotebook)), 0, true)) {
131 var sure = tab_removed (tab);
132 if (!sure)
133@@ -778,7 +820,7 @@
134 i = this.notebook.insert_page (tab.page_container, tab, index);
135
136 this.notebook.set_tab_reorderable (tab.page_container, this.allow_drag);
137- this.notebook.set_tab_detachable (tab.page_container, this.allow_new_window);
138+ this.notebook.set_tab_detachable (tab.page_container, this.allow_new_window && !tab.fixed);
139
140 tab._icon.visible = show_icons;
141 tab.duplicate_m.visible = allow_duplication;

Subscribers

People subscribed via source and target branches