Skip to content

Commit b700454

Browse files
authored
Merge branch 'main' into danirabbit/preferences-rmthumbnails
2 parents 84e19ed + 138b905 commit b700454

File tree

2 files changed

+75
-104
lines changed

2 files changed

+75
-104
lines changed
Lines changed: 66 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,77 @@
1-
/***
2-
ViewSwicher.cs
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2026 elementary, Inc. (https://elementary.io)
4+
* 2010 mathijshenquet
5+
*/
36

4-
Authors:
5-
mathijshenquet <mathijs.henquet@gmail.com>
6-
ammonkey <am.monkeyd@gmail.com>
7+
public class Files.View.Chrome.ViewSwitcher : Gtk.Box {
8+
public GLib.SimpleAction action { get; construct; }
79

8-
Copyright (c) 2010 mathijshenquet
9-
10-
This program is free software: you can redistribute it and/or modify
11-
it under the terms of the GNU General Public License as published by
12-
the Free Software Foundation, either version 3 of the License, or
13-
(at your option) any later version.
14-
15-
This program is distributed in the hope that it will be useful,
16-
but WITHOUT ANY WARRANTY; without even the implied warranty of
17-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-
GNU General Public License for more details.
19-
20-
You should have received a copy of the GNU General Public License
21-
along with this program. If not, see <http://www.gnu.org/licenses/>.
22-
***/
23-
24-
namespace Files.View.Chrome {
25-
public class ViewSwitcher : Gtk.Box {
26-
public GLib.SimpleAction action { get; construct; }
27-
28-
public ViewSwitcher (GLib.SimpleAction view_mode_action) {
29-
Object (action: view_mode_action);
30-
}
31-
32-
construct {
33-
get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED);
34-
35-
/* Grid View item */
36-
var id = (uint32)ViewMode.ICON;
37-
var grid_view_btn = new Gtk.RadioButton (null) {
38-
image = new Gtk.Image.from_icon_name ("view-grid-symbolic", Gtk.IconSize.BUTTON),
39-
tooltip_markup = get_tooltip_for_id (id, _("View as Grid"))
40-
};
41-
grid_view_btn.set_mode (false);
42-
grid_view_btn.toggled.connect (on_mode_changed);
43-
grid_view_btn.set_data<uint32> ("id", id);
44-
45-
/* List View */
46-
id = (uint32)ViewMode.LIST;
47-
var list_view_btn = new Gtk.RadioButton.from_widget (grid_view_btn) {
48-
image = new Gtk.Image.from_icon_name ("view-list-symbolic", Gtk.IconSize.BUTTON),
49-
tooltip_markup = get_tooltip_for_id (id, _("View as List"))
50-
};
51-
list_view_btn.set_mode (false);
52-
list_view_btn.toggled.connect (on_mode_changed);
53-
list_view_btn.set_data<uint32> ("id", id);
10+
public ViewSwitcher (GLib.SimpleAction view_mode_action) {
11+
Object (action: view_mode_action);
12+
}
5413

14+
construct {
15+
get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED);
16+
17+
/* Grid View item */
18+
var id = (uint32)ViewMode.ICON;
19+
var grid_view_btn = new Gtk.RadioButton (null) {
20+
image = new Gtk.Image.from_icon_name ("view-grid-symbolic", Gtk.IconSize.BUTTON),
21+
tooltip_markup = get_tooltip_for_id (id, _("View as Grid"))
22+
};
23+
grid_view_btn.set_mode (false);
24+
grid_view_btn.toggled.connect (on_mode_changed);
25+
grid_view_btn.set_data<uint32> ("id", id);
26+
27+
/* List View */
28+
id = (uint32)ViewMode.LIST;
29+
var list_view_btn = new Gtk.RadioButton.from_widget (grid_view_btn) {
30+
image = new Gtk.Image.from_icon_name ("view-list-symbolic", Gtk.IconSize.BUTTON),
31+
tooltip_markup = get_tooltip_for_id (id, _("View as List"))
32+
};
33+
list_view_btn.set_mode (false);
34+
list_view_btn.toggled.connect (on_mode_changed);
35+
list_view_btn.set_data<uint32> ("id", id);
36+
37+
38+
/* Item 2 */
39+
id = (uint32)ViewMode.MILLER_COLUMNS;
40+
var column_view_btn = new Gtk.RadioButton.from_widget (grid_view_btn) {
41+
image = new Gtk.Image.from_icon_name ("view-column-symbolic", Gtk.IconSize.BUTTON),
42+
tooltip_markup = get_tooltip_for_id (id, _("View in Columns"))
43+
};
44+
column_view_btn.set_mode (false);
45+
column_view_btn.toggled.connect (on_mode_changed);
46+
column_view_btn.set_data<ViewMode> ("id", ViewMode.MILLER_COLUMNS);
47+
48+
valign = Gtk.Align.CENTER;
49+
add (grid_view_btn);
50+
add (list_view_btn);
51+
add (column_view_btn);
52+
}
5553

56-
/* Item 2 */
57-
id = (uint32)ViewMode.MILLER_COLUMNS;
58-
var column_view_btn = new Gtk.RadioButton.from_widget (grid_view_btn) {
59-
image = new Gtk.Image.from_icon_name ("view-column-symbolic", Gtk.IconSize.BUTTON),
60-
tooltip_markup = get_tooltip_for_id (id, _("View in Columns"))
61-
};
62-
column_view_btn.set_mode (false);
63-
column_view_btn.toggled.connect (on_mode_changed);
64-
column_view_btn.set_data<ViewMode> ("id", ViewMode.MILLER_COLUMNS);
54+
private string get_tooltip_for_id (uint32 id, string description) {
55+
var app = (Gtk.Application)Application.get_default ();
56+
var detailed_name = Action.print_detailed_name ("win." + action.name, new Variant.uint32 (id));
57+
var accels = app.get_accels_for_action (detailed_name);
58+
return Granite.markup_accel_tooltip (accels, description);
59+
}
6560

66-
valign = Gtk.Align.CENTER;
67-
add (grid_view_btn);
68-
add (list_view_btn);
69-
add (column_view_btn);
61+
private void on_mode_changed (Gtk.ToggleButton source) {
62+
if (!source.active) {
63+
return;
7064
}
7165

72-
private string get_tooltip_for_id (uint32 id, string description) {
73-
var app = (Gtk.Application)Application.get_default ();
74-
var detailed_name = Action.print_detailed_name ("win." + action.name, new Variant.uint32 (id));
75-
var accels = app.get_accels_for_action (detailed_name);
76-
return Granite.markup_accel_tooltip (accels, description);
77-
}
66+
action.activate (source.get_data<uint32> ("id"));
67+
}
7868

79-
private void on_mode_changed (Gtk.ToggleButton source) {
80-
if (!source.active) {
81-
return;
69+
public void set_mode (uint32 mode) {
70+
this.@foreach ((child) => {
71+
if (child.get_data<uint32> ("id") == mode) {
72+
((Gtk.RadioButton)child).active = true;
73+
action.activate (child.get_data<uint32> ("id"));
8274
}
83-
84-
action.activate (source.get_data<uint32> ("id"));
85-
}
86-
87-
public void set_mode (uint32 mode) {
88-
this.@foreach ((child) => {
89-
if (child.get_data<uint32> ("id") == mode) {
90-
((Gtk.RadioButton)child).active = true;
91-
action.activate (child.get_data<uint32> ("id"));
92-
}
93-
});
94-
}
75+
});
9576
}
9677
}

src/View/Window.vala

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ public class Files.View.Window : Hdy.ApplicationWindow {
4747
}
4848
}
4949

50-
public ViewMode default_mode {
51-
get {
52-
return ViewMode.PREFERRED;
53-
}
54-
}
55-
5650
public GLib.File default_location {
5751
owned get {
5852
return GLib.File.new_for_path (PF.UserUtils.get_real_user_home ());
@@ -414,7 +408,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
414408
tab_view.close_page_finish (page, true);
415409

416410
if (tab_view.n_pages == 0) {
417-
add_tab.begin (default_location, default_mode, false);
411+
add_tab.begin (default_location, PREFERRED, false);
418412
}
419413

420414
return Gdk.EVENT_STOP;
@@ -497,10 +491,6 @@ public class Files.View.Window : Hdy.ApplicationWindow {
497491
});
498492
}
499493

500-
public new void set_title (string title) {
501-
this.title = title;
502-
}
503-
504494
private void change_tab () {
505495
//Ignore if some restored tabs still loading
506496
if (restoring_tabs > 0) {
@@ -515,7 +505,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
515505

516506
public async void open_tabs (
517507
owned GLib.File[]? files,
518-
ViewMode mode = default_mode,
508+
ViewMode mode = PREFERRED,
519509
bool ignore_duplicate
520510
) {
521511
// Always try to restore tabs
@@ -540,7 +530,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
540530
}
541531
}
542532

543-
private async bool add_tab_by_uri (string uri, ViewMode mode = default_mode) {
533+
private async bool add_tab_by_uri (string uri, ViewMode mode = PREFERRED) {
544534
var file = get_file_from_uri (uri);
545535
if (file != null) {
546536
return yield add_tab (file, mode, false);
@@ -551,7 +541,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
551541

552542
private async bool add_tab (
553543
GLib.File _location = default_location,
554-
ViewMode mode = default_mode,
544+
ViewMode mode = PREFERRED,
555545
bool ignore_duplicate
556546
) {
557547
// Do not try to restore locations that we cannot determine the filetype. This will
@@ -786,7 +776,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
786776
}
787777
}
788778

789-
private void add_window (GLib.File location = default_location, ViewMode mode = default_mode) {
779+
private void add_window (GLib.File location = default_location, ViewMode mode = PREFERRED) {
790780
var new_window = new Window (marlin_app);
791781
new_window.add_tab.begin (location, real_mode (mode), false);
792782
new_window.present ();
@@ -959,7 +949,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
959949
private void action_tab (GLib.SimpleAction action, GLib.Variant? param) {
960950
switch (param.get_string ()) {
961951
case "NEW":
962-
add_tab.begin (default_location, default_mode, false);
952+
add_tab.begin (default_location, PREFERRED, false);
963953
break;
964954

965955
case "CLOSE":
@@ -1029,7 +1019,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
10291019
update_undo_actions ();
10301020
}
10311021

1032-
public void after_undo_redo () {
1022+
private void after_undo_redo () {
10331023
if (current_container.slot.directory.is_recent) {
10341024
get_action_group ("win").activate_action ("refresh", null);
10351025
}
@@ -1062,7 +1052,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
10621052
}
10631053

10641054

1065-
public GLib.SimpleAction? get_action (string action_name) {
1055+
private GLib.SimpleAction? get_action (string action_name) {
10661056
return (GLib.SimpleAction?)(lookup_action (action_name));
10671057
}
10681058

@@ -1361,7 +1351,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
13611351

13621352
private void update_labels (string uri) {
13631353
if (current_container != null) { /* Can happen during restore */
1364-
set_title (current_container.tab_name); /* Not actually visible on elementaryos */
1354+
title = current_container.tab_name; /* Not actually visible on elementaryos */
13651355
update_location_bar (uri);
13661356
sidebar.sync_uri (uri);
13671357
}

0 commit comments

Comments
 (0)