Skip to content

Commit 37d9b41

Browse files
danirabbitjeremypw
andauthored
AppMenu: handle view mode changed internally (#2731)
Co-authored-by: Jeremy Wootten <jeremywootten@gmail.com>
1 parent 8f2e5de commit 37d9b41

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

src/View/Widgets/AppMenu.vala

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ public class Files.AppMenu : Gtk.Popover {
1313
private string[] undo_accels;
1414
private unowned UndoManager undo_manager;
1515

16+
private static Settings column_view_settings;
17+
private static Settings icon_view_settings;
18+
private static Settings list_view_settings;
19+
20+
static construct {
21+
column_view_settings = new Settings ("io.elementary.files.column-view");
22+
icon_view_settings = new Settings ("io.elementary.files.icon-view");
23+
list_view_settings = new Settings ("io.elementary.files.list-view");
24+
}
25+
1626
construct {
1727
var app_instance = (Gtk.Application)(GLib.Application.get_default ());
1828

@@ -161,14 +171,13 @@ public class Files.AppMenu : Gtk.Popover {
161171

162172
// Connect to all view settings rather than try to connect and disconnect
163173
// continuously to current view mode setting.
164-
var icon_view_settings = new Settings ("io.elementary.files.icon-view");
165-
var list_view_settings = new Settings ("io.elementary.files.list-view");
166-
var column_view_settings = new Settings ("io.elementary.files.column-view");
167174
icon_view_settings.changed["zoom-level"].connect (on_zoom_setting_changed);
168175
list_view_settings.changed["zoom-level"].connect (on_zoom_setting_changed);
169176
column_view_settings.changed["zoom-level"].connect (on_zoom_setting_changed);
170177

171178
var app_settings = new Settings ("io.elementary.files.preferences");
179+
app_settings.changed["default-viewmode"].connect (on_zoom_setting_changed);
180+
172181
// Initialize and connect dateformat buttons
173182
switch (app_settings.get_enum ("date-format")) {
174183
case DateFormatMode.ISO:
@@ -228,7 +237,20 @@ public class Files.AppMenu : Gtk.Popover {
228237
);
229238
}
230239

231-
public void on_zoom_setting_changed (Settings settings, string key) {
240+
private void on_zoom_setting_changed () {
241+
Settings settings = null;
242+
switch (app_settings.get_string ("default-viewmode")) {
243+
case "icon":
244+
settings = icon_view_settings;
245+
break;
246+
case "list":
247+
settings = list_view_settings;
248+
break;
249+
case "miller_columns":
250+
settings = column_view_settings;
251+
break;
252+
}
253+
232254
if (settings == null) {
233255
critical ("Zoom string from settinggs: Null settings");
234256
zoom_default_button.label = "";

src/View/Window.vala

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -286,28 +286,6 @@ public class Files.View.Window : Hdy.ApplicationWindow {
286286
get_action ("folders-before-files").set_state (prefs.sort_directories_first);
287287
get_action ("restore-tabs-on-startup").set_state (app_settings.get_boolean ("restore-tabs"));
288288

289-
/*/
290-
/* Connect and abstract signals to local ones
291-
/*/
292-
view_switcher.action.activate.connect ((id) => {
293-
switch ((ViewMode)(id.get_uint32 ())) {
294-
case ViewMode.ICON:
295-
app_menu.on_zoom_setting_changed (Files.icon_view_settings, "zoom-level");
296-
break;
297-
case ViewMode.LIST:
298-
app_menu.on_zoom_setting_changed (Files.list_view_settings, "zoom-level");
299-
break;
300-
case ViewMode.MILLER_COLUMNS:
301-
app_menu.on_zoom_setting_changed (Files.column_view_settings, "zoom-level");
302-
break;
303-
case ViewMode.PREFERRED:
304-
case ViewMode.CURRENT:
305-
case ViewMode.INVALID:
306-
assert_not_reached (); //The switcher should not generate these modes
307-
}
308-
});
309-
310-
311289
button_forward.slow_press.connect (() => {
312290
get_action_group ("win").activate_action ("forward", new Variant.int32 (1));
313291
});

0 commit comments

Comments
 (0)