Merge lp:~jeremywootten/pantheon-files/fix-1592068-viewmode-buttons-do-not-update into lp:~elementary-apps/pantheon-files/trunk

Proposed by Jeremy Wootten
Status: Merged
Approved by: Adam Bieńkowski
Approved revision: 2199
Merged at revision: 2199
Proposed branch: lp:~jeremywootten/pantheon-files/fix-1592068-viewmode-buttons-do-not-update
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 185 lines (+42/-33)
2 files modified
src/View/ViewContainer.vala (+23/-12)
src/View/Window.vala (+19/-21)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-files/fix-1592068-viewmode-buttons-do-not-update
Reviewer Review Type Date Requested Status
Adam Bieńkowski (community) code / testing Approve
Review via email: mp+297750@code.launchpad.net

Commit message

* Fix bug #1592068: "View buttons don't update".

Description of the change

This branch ensures that the viewmode switch is updated when required and also that it is made insensitive when appropriate (that is when the view is showing an error message or when a connect server dialog is showing).

The opportunity is taken to reduce the extent to which the widget "ViewContainer" directly calls functions in its controller "Window". It is made more modular by introducing a new signal to which Window listens, causing the topmenu to update. Further work is required in this area which will be the subject of a further branch.

To post a comment you must log in.
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

I can confirm that this is much more cleaner solution and it fixes the problems with navigation buttons and view mode switcher as well.

Only one thing: update_view_method is no longer needed as this is done already in update_top_menu, even the compiler points this out, we should remove it.

review: Needs Fixing (code / testing)
Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

r2199 overwritten with redundant function removed.

Revision history for this message
Adam Bieńkowski (donadigo) wrote :

Looks great now! Thanks, approve.

review: Approve (code / testing)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/View/ViewContainer.vala'
2--- src/View/ViewContainer.vala 2016-06-04 18:58:03 +0000
3+++ src/View/ViewContainer.vala 2016-06-17 14:06:30 +0000
4@@ -28,7 +28,7 @@
5 public class ViewContainer : Gtk.Overlay {
6
7 public Gtk.Widget? content_item;
8- public bool can_show_folder = true;
9+ public bool can_show_folder = false;
10 public string label = "";
11 public Marlin.View.Window window;
12 public GOF.AbstractSlot? view = null;
13@@ -58,6 +58,18 @@
14 }
15 }
16
17+ public bool can_go_back {
18+ get {
19+ return browser.get_can_go_back ();
20+ }
21+ }
22+
23+ public bool can_go_forward {
24+ get {
25+ return browser.get_can_go_forward ();
26+ }
27+ }
28+
29 public OverlayBar overlay_statusbar;
30 private Browser browser;
31 private GLib.List<GLib.File>? selected_locations = null;
32@@ -66,6 +78,7 @@
33 public signal void loading (bool is_loading);
34 /* To maintain compatibility with existing plugins */
35 public signal void path_changed (File file);
36+ public signal void active ();
37
38 /* Initial location now set by Window.make_tab after connecting signals */
39 public ViewContainer (Marlin.View.Window win) {
40@@ -264,10 +277,12 @@
41 }
42
43 private void directory_is_loading (GLib.File loc) {
44- loading (true);
45 overlay_statusbar.cancel ();
46 overlay_statusbar.halign = Gtk.Align.END;
47 refresh_slot_info (loc);
48+
49+ can_show_folder = false;
50+ loading (true);
51 }
52
53 public void plugin_directory_loaded () {
54@@ -284,7 +299,7 @@
55 plugins.directory_loaded ((void*) data);
56 }
57
58- public void refresh_slot_info (GLib.File loc) {
59+ private void refresh_slot_info (GLib.File loc) {
60 update_tab_name (loc);
61 window.loading_uri (loc.get_uri ());
62 window.update_labels (loc.get_parse_name (), tab_name);
63@@ -327,12 +342,10 @@
64 }
65
66 public void directory_done_loading (GOF.AbstractSlot slot) {
67- loading (false);
68- can_show_folder = true;
69+ can_show_folder = slot.directory.can_load;
70
71 /* First deal with all cases where directory could not be loaded */
72- if (!slot.directory.can_load) {
73- can_show_folder = false;
74+ if (!can_show_folder) {
75 if (!slot.directory.file.exists) {
76 if (slot.can_create)
77 content = new DirectoryNotFound (slot.directory, this);
78@@ -369,16 +382,13 @@
79 content = view.get_content_box ();
80 /* Only record valid folders (will also log Zeitgeist event) */
81 browser.record_uri (slot.uri); /* will ignore null changes i.e reloading*/
82- window.set_can_go_forward (browser.get_can_go_forward ());
83 plugin_directory_loaded ();
84 } else {
85 /* Save previous uri but do not record current one */
86 browser.record_uri (null);
87- /* Inactivate the forward button but do not lose existing forward stack */
88- window.set_can_go_forward (false);
89 }
90- window.set_can_go_back (browser.get_can_go_back ());
91- window.update_top_menu ();
92+
93+ loading (false); /* Will cause topmenu to update */
94 overlay_statusbar.update_hovered (null); /* Prevent empty statusbar showing */
95 }
96
97@@ -403,6 +413,7 @@
98 if (aslot != null) {
99 /* Since async loading it may not have been determined whether slot is loadable */
100 aslot.set_active_state (is_active);
101+ active ();
102 }
103 }
104
105
106=== modified file 'src/View/Window.vala'
107--- src/View/Window.vala 2016-06-09 08:48:35 +0000
108+++ src/View/Window.vala 2016-06-17 14:06:30 +0000
109@@ -63,12 +63,6 @@
110 public ViewContainer? current_tab = null;
111 public uint window_number;
112
113- public void set_can_go_forward (bool can) {
114- top_menu.set_can_go_forward (can);
115- }
116- public void set_can_go_back (bool can) {
117- top_menu.set_can_go_back (can);
118- }
119 public bool is_first_window {get; private set;}
120 private bool tabs_restored = false;
121 private bool freeze_view_changes = false;
122@@ -449,7 +443,6 @@
123 public void add_tab (File location = File.new_for_commandline_arg (Environment.get_home_dir ()),
124 Marlin.ViewMode mode = Marlin.ViewMode.PREFERRED) {
125 mode = real_mode (mode);
126- update_view_mode (mode);
127
128 var content = new View.ViewContainer (this);
129 var tab = new Granite.Widgets.Tab ("", null, content);
130@@ -460,6 +453,11 @@
131
132 content.loading.connect ((is_loading) => {
133 tab.working = is_loading;
134+ update_top_menu ();
135+ });
136+
137+ content.active.connect (() => {
138+ update_top_menu ();
139 });
140
141 content.update_tab_name (location);
142@@ -831,13 +829,6 @@
143 }
144 }
145
146- private void update_view_mode (Marlin.ViewMode mode) { /* Called via update topmenu */
147- GLib.SimpleAction action = get_action ("view_mode");
148- action.set_state (mode_strings [(int)mode]);
149- view_switcher.mode = mode;
150- Preferences.settings.set_enum ("default-viewmode", mode);
151- }
152-
153 public void quit () {
154 top_menu.destroy (); /* stop unwanted signals if quit while pathbar in focus */
155
156@@ -1011,15 +1002,22 @@
157 }
158 }
159
160- public void update_top_menu () {
161- if (freeze_view_changes)
162+ private void update_top_menu () {
163+ if (freeze_view_changes || current_tab == null)
164 return;
165
166- if (current_tab != null) {
167- top_menu.set_back_menu (current_tab.get_go_back_path_list ());
168- top_menu.set_forward_menu (current_tab.get_go_forward_path_list ());
169- update_view_mode (current_tab.view_mode);
170- }
171+ /* Update browser buttons */
172+ top_menu.set_back_menu (current_tab.get_go_back_path_list ());
173+ top_menu.set_forward_menu (current_tab.get_go_forward_path_list ());
174+ top_menu.set_can_go_back (current_tab.can_go_back);
175+ top_menu.set_can_go_forward (current_tab.can_show_folder && current_tab.can_go_forward);
176+
177+ /* Update viewmode switch, action state and settings */
178+ var mode = current_tab.view_mode;
179+ view_switcher.mode = mode;
180+ view_switcher.sensitive = current_tab.can_show_folder;
181+ get_action ("view_mode").set_state (mode_strings [(int)mode]);
182+ Preferences.settings.set_enum ("default-viewmode", mode);
183 }
184
185 public void update_labels (string new_path, string tab_name) {

Subscribers

People subscribed via source and target branches

to all changes: