|
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 | + */ |
3 | 6 |
|
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; } |
7 | 9 |
|
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 | + } |
54 | 13 |
|
| 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 | + } |
55 | 53 |
|
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 | + } |
65 | 60 |
|
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; |
70 | 64 | } |
71 | 65 |
|
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 | + } |
78 | 68 |
|
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")); |
82 | 74 | } |
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 | + }); |
95 | 76 | } |
96 | 77 | } |
0 commit comments