From 8f61afaf5834c28ac660b79ee209c6fdcf460bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 18 Mar 2024 12:03:10 -0700 Subject: [PATCH 01/13] DefaultPlug: use Switchboard.SettingsPage --- src/Defaults/DefaultPlug.vala | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Defaults/DefaultPlug.vala b/src/Defaults/DefaultPlug.vala index 47a8027c..cddb8427 100644 --- a/src/Defaults/DefaultPlug.vala +++ b/src/Defaults/DefaultPlug.vala @@ -6,7 +6,14 @@ * Chris Triantafillis */ -public class Defaults.Plug : Gtk.Box { +public class Defaults.Plug : Switchboard.SettingsPage { + public Plug () { + Object ( + title: _("Defaults"), + icon: new ThemedIcon ("preferences-desktop") + ); + } + construct { var browser_setting = new SettingsChild ( _("Web Browser"), @@ -65,19 +72,7 @@ public class Defaults.Plug : Gtk.Box { flowbox.append (videos_setting); flowbox.append (files_setting); - var clamp = new Adw.Clamp () { - child = flowbox, - margin_end = 12, - margin_bottom = 12, - margin_start = 12 - }; - - var scrolled_window = new Gtk.ScrolledWindow () { - child = clamp - }; - - append (scrolled_window); - + child = flowbox; } private class SettingsChild : Gtk.FlowBoxChild { From 7163dccee1fd8968ed2a00370e299df046025c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 18 Mar 2024 12:25:07 -0700 Subject: [PATCH 02/13] PermissionsPlug: use Switchboard.SettingsPage --- src/Permissions/Backend/App.vala | 8 +++++++ src/Permissions/PermissionsPlug.vala | 12 +++++------ src/Permissions/Widgets/AppSettingsView.vala | 22 ++++++-------------- src/Permissions/Widgets/SidebarRow.vala | 12 +++-------- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/Permissions/Backend/App.vala b/src/Permissions/Backend/App.vala index 51bd1cf8..38e7b683 100644 --- a/src/Permissions/Backend/App.vala +++ b/src/Permissions/Backend/App.vala @@ -25,6 +25,7 @@ public class Permissions.Backend.App : GLib.Object { public Flatpak.InstalledRef installed_ref { get; construct; } public string id { get; private set; } public string name { get; private set; } + public Icon icon { get; private set; } public GenericArray settings; private const string GROUP = "Context"; @@ -37,6 +38,13 @@ public class Permissions.Backend.App : GLib.Object { id = installed_ref.get_name (); name = installed_ref.get_appdata_name () ?? id; + var appinfo = new GLib.DesktopAppInfo (id + ".desktop"); + if (appinfo != null && appinfo.get_icon () != null) { + icon = appinfo.get_icon (); + } else { + icon = new ThemedIcon ("application-default-icon"); + } + settings = new GenericArray (); var permissions = new GenericArray (); diff --git a/src/Permissions/PermissionsPlug.vala b/src/Permissions/PermissionsPlug.vala index d89abc39..c7eafad3 100644 --- a/src/Permissions/PermissionsPlug.vala +++ b/src/Permissions/PermissionsPlug.vala @@ -73,7 +73,10 @@ public class Permissions.Plug : Gtk.Box { child = scrolled_window }; - var sidebar = new Gtk.Box (VERTICAL, 12); + var sidebar = new Gtk.Box (VERTICAL, 12) { + margin_bottom = 12, + margin_start = 12 + }; sidebar.append (search_entry); sidebar.append (frame); @@ -94,12 +97,7 @@ public class Permissions.Plug : Gtk.Box { show_row (row); } - var grid = new Gtk.Grid () { - margin_end = 12, - margin_bottom = 12, - margin_start = 12, - column_spacing = 12 - }; + var grid = new Gtk.Grid (); grid.attach (sidebar, 0, 0, 1, 1); grid.attach (app_settings_view, 1, 0, 2, 1); diff --git a/src/Permissions/Widgets/AppSettingsView.vala b/src/Permissions/Widgets/AppSettingsView.vala index 0e8fdc16..96d2aa7b 100644 --- a/src/Permissions/Widgets/AppSettingsView.vala +++ b/src/Permissions/Widgets/AppSettingsView.vala @@ -19,7 +19,7 @@ * Authored by: Marius Meisenzahl */ -public class Permissions.Widgets.AppSettingsView : Gtk.Grid { +public class Permissions.Widgets.AppSettingsView : Switchboard.SettingsPage { public Backend.App? selected_app { get; set; default = null; } private Gtk.ListBox list_box; @@ -97,23 +97,11 @@ public class Permissions.Widgets.AppSettingsView : Gtk.Grid { list_box.append (printing_widget); list_box.append (ssh_widget); list_box.append (gpu_widget); + list_box.add_css_class (Granite.STYLE_CLASS_BACKGROUND); - var scrolled_window = new Gtk.ScrolledWindow () { - child = list_box - }; - - var frame = new Gtk.Frame (null) { - child = scrolled_window - }; - frame.add_css_class (Granite.STYLE_CLASS_VIEW); - - reset_button = new Gtk.Button.with_label (_("Reset to Defaults")) { - halign = Gtk.Align.END - }; + child = list_box; - row_spacing = 24; - attach (frame, 0, 0); - attach (reset_button, 0, 1); + reset_button = add_button (_("Reset to Defaults")); update_view (); @@ -180,6 +168,8 @@ public class Permissions.Widgets.AppSettingsView : Gtk.Grid { }); update_property (Gtk.AccessibleProperty.LABEL, _("%s permissions").printf (selected_app.name), -1); + title = selected_app.name; + icon = selected_app.icon; } private void change_permission_settings (Backend.PermissionSettings settings) { diff --git a/src/Permissions/Widgets/SidebarRow.vala b/src/Permissions/Widgets/SidebarRow.vala index 134f4c3a..5aa183d2 100644 --- a/src/Permissions/Widgets/SidebarRow.vala +++ b/src/Permissions/Widgets/SidebarRow.vala @@ -30,16 +30,10 @@ public class Permissions.SidebarRow : Gtk.ListBoxRow { construct { hexpand = true; - var appinfo = new GLib.DesktopAppInfo (app.id + ".desktop"); - Gtk.Image image; - if (appinfo != null && appinfo.get_icon () != null) { - image = new Gtk.Image.from_gicon (appinfo.get_icon ()); - } else { - image = new Gtk.Image.from_icon_name ("application-default-icon"); - } - - image.pixel_size = 32; + var image = new Gtk.Image.from_gicon (app.icon) { + pixel_size = 32 + }; var title_label = new Gtk.Label (app.name) { ellipsize = Pango.EllipsizeMode.END, From 50ec581a6866c7865210d39cc35ce4ccfe46414f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 18 Mar 2024 12:36:45 -0700 Subject: [PATCH 03/13] Startup: use Granite.SettingsPage --- src/Startup/Startup.vala | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Startup/Startup.vala b/src/Startup/Startup.vala index f930e281..7a6e93a0 100644 --- a/src/Startup/Startup.vala +++ b/src/Startup/Startup.vala @@ -6,17 +6,23 @@ * Julien Spautz */ -public class Startup.Plug : Gtk.Box { +public class Startup.Plug : Switchboard.SettingsPage { private Controller controller; private Gtk.ListBox list; private Widgets.AppChooser app_chooser; + public Plug () { + Object ( + title: _("Startup"), + icon: new ThemedIcon ("system-restart") + ); + } + construct { Backend.KeyFileFactory.init (); var empty_alert = new Granite.Placeholder (_("Launch Apps on Startup")) { - description = _("Add apps to the Startup list by clicking the icon in the toolbar below."), - icon = new ThemedIcon ("system-restart") + description = _("Add apps to the Startup list by clicking the icon in the toolbar below.") }; list = new Gtk.ListBox () { @@ -57,14 +63,7 @@ public class Startup.Plug : Gtk.Box { child = box }; - var clamp = new Adw.Clamp () { - child = frame, - margin_end = 12, - margin_bottom = 12, - margin_start = 12 - }; - - append (clamp); + child = frame; app_chooser = new Widgets.AppChooser () { modal = true From 2995c337ac30d2f18a79e88fe0956cfac0959038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 21:53:15 -0700 Subject: [PATCH 04/13] Move permission_names to app --- src/Permissions/Backend/App.vala | 16 +++++++++++++++- src/Permissions/PermissionsPlug.vala | 14 -------------- src/Permissions/Widgets/AppSettingsView.vala | 2 +- src/Permissions/Widgets/SidebarRow.vala | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Permissions/Backend/App.vala b/src/Permissions/Backend/App.vala index 85d0f31b..e44649a7 100644 --- a/src/Permissions/Backend/App.vala +++ b/src/Permissions/Backend/App.vala @@ -28,12 +28,26 @@ public class Permissions.Backend.App : GLib.Object { public Icon icon { get; private set; } public GenericArray settings; + public static GLib.HashTable permission_names { get; private set; } + private const string GROUP = "Context"; public App (Flatpak.InstalledRef installed_ref) { Object (installed_ref: installed_ref); } + static construct { + permission_names = new GLib.HashTable (str_hash, str_equal); + permission_names["filesystems=home"] = _("Home Folder"); + permission_names["filesystems=host"] = _("System Folders"); + permission_names["devices=all"] = _("Devices"); + permission_names["shared=network"] = _("Network"); + permission_names["features=bluetooth"] = _("Bluetooth"); + permission_names["sockets=cups"] = _("Printing"); + permission_names["sockets=ssh-auth"] = _("Secure Shell Agent"); + permission_names["devices=dri"] = _("GPU Acceleration"); + } + construct { id = installed_ref.get_name (); @@ -97,7 +111,7 @@ public class Permissions.Backend.App : GLib.Object { current_permissions.add (permission); } - Plug.permission_names.foreach ((key) => { + permission_names.foreach ((key) => { bool standard = false; bool enabled = false; diff --git a/src/Permissions/PermissionsPlug.vala b/src/Permissions/PermissionsPlug.vala index c7eafad3..d47fdd62 100644 --- a/src/Permissions/PermissionsPlug.vala +++ b/src/Permissions/PermissionsPlug.vala @@ -20,24 +20,10 @@ */ public class Permissions.Plug : Gtk.Box { - public static GLib.HashTable permission_names { get; private set; } - private Gtk.SearchEntry search_entry; private Gtk.ListBox app_list; private Widgets.AppSettingsView app_settings_view; - static construct { - permission_names = new GLib.HashTable (str_hash, str_equal); - permission_names["filesystems=home"] = _("Home Folder"); - permission_names["filesystems=host"] = _("System Folders"); - permission_names["devices=all"] = _("Devices"); - permission_names["shared=network"] = _("Network"); - permission_names["features=bluetooth"] = _("Bluetooth"); - permission_names["sockets=cups"] = _("Printing"); - permission_names["sockets=ssh-auth"] = _("Secure Shell Agent"); - permission_names["devices=dri"] = _("GPU Acceleration"); - } - construct { var placeholder = new Granite.Placeholder (_("No Flatpak apps installed")) { icon = new ThemedIcon ("dialog-information"), diff --git a/src/Permissions/Widgets/AppSettingsView.vala b/src/Permissions/Widgets/AppSettingsView.vala index 9b27c4b2..ec6d05b8 100644 --- a/src/Permissions/Widgets/AppSettingsView.vala +++ b/src/Permissions/Widgets/AppSettingsView.vala @@ -99,7 +99,7 @@ public class Permissions.Widgets.AppSettingsView : Switchboard.SettingsPage { } var override_row = new PermissionSettingsWidget ( - Plug.permission_names[settings.context], + Backend.App.permission_names[settings.context], description, icon_name ); diff --git a/src/Permissions/Widgets/SidebarRow.vala b/src/Permissions/Widgets/SidebarRow.vala index 5aa183d2..81c3e8b1 100644 --- a/src/Permissions/Widgets/SidebarRow.vala +++ b/src/Permissions/Widgets/SidebarRow.vala @@ -74,7 +74,7 @@ public class Permissions.SidebarRow : Gtk.ListBoxRow { for (var i = 0; i < app.settings.length; i++) { var settings = app.settings.get (i); if (settings.enabled) { - current_permissions.add (Plug.permission_names[settings.context]); + current_permissions.add (Backend.App.permission_names[settings.context]); } } From 1e9f841355d76cfcd80be58421a3112d40bfd191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 22:03:29 -0700 Subject: [PATCH 05/13] Make it work --- src/Defaults/DefaultPlug.vala | 1 + src/Permissions/PermissionsPlug.vala | 134 ------------------- src/Permissions/Widgets/AppSettingsView.vala | 1 + src/Plug.vala | 118 +++++++++++++--- src/Startup/Startup.vala | 1 + src/meson.build | 4 +- 6 files changed, 103 insertions(+), 156 deletions(-) delete mode 100644 src/Permissions/PermissionsPlug.vala diff --git a/src/Defaults/DefaultPlug.vala b/src/Defaults/DefaultPlug.vala index cddb8427..3601e74a 100644 --- a/src/Defaults/DefaultPlug.vala +++ b/src/Defaults/DefaultPlug.vala @@ -73,6 +73,7 @@ public class Defaults.Plug : Switchboard.SettingsPage { flowbox.append (files_setting); child = flowbox; + show_end_title_buttons = true; } private class SettingsChild : Gtk.FlowBoxChild { diff --git a/src/Permissions/PermissionsPlug.vala b/src/Permissions/PermissionsPlug.vala deleted file mode 100644 index d47fdd62..00000000 --- a/src/Permissions/PermissionsPlug.vala +++ /dev/null @@ -1,134 +0,0 @@ -/* -* Copyright 2020 elementary, Inc. (https://elementary.io) -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public -* License as published by the Free Software Foundation; either -* version 3 of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -* Boston, MA 02110-1301 USA -* -* Authored by: Marius Meisenzahl -*/ - -public class Permissions.Plug : Gtk.Box { - private Gtk.SearchEntry search_entry; - private Gtk.ListBox app_list; - private Widgets.AppSettingsView app_settings_view; - - construct { - var placeholder = new Granite.Placeholder (_("No Flatpak apps installed")) { - icon = new ThemedIcon ("dialog-information"), - description = _("Apps whose permissions can be adjusted will automatically appear here when installed") - }; - placeholder.add_css_class (Granite.STYLE_CLASS_BACKGROUND); - - search_entry = new Gtk.SearchEntry () { - placeholder_text = _("Search Applications") - }; - - var alert_view = new Granite.Placeholder ("") { - icon = new ThemedIcon ("edit-find-symbolic"), - description = _("Try changing search terms.") - }; - - app_list = new Gtk.ListBox () { - vexpand = true, - selection_mode = Gtk.SelectionMode.SINGLE - }; - app_list.add_css_class (Granite.STYLE_CLASS_RICH_LIST); - app_list.set_placeholder (alert_view); - app_list.set_filter_func ((Gtk.ListBoxFilterFunc) filter_func); - app_list.set_sort_func ((Gtk.ListBoxSortFunc) sort_func); - app_list.update_property (Gtk.AccessibleProperty.LABEL, _("Applications"), -1); - - - var scrolled_window = new Gtk.ScrolledWindow () { - child = app_list - }; - - var frame = new Gtk.Frame (null) { - child = scrolled_window - }; - - var sidebar = new Gtk.Box (VERTICAL, 12) { - margin_bottom = 12, - margin_start = 12 - }; - sidebar.append (search_entry); - sidebar.append (frame); - - var app_manager = Permissions.Backend.AppManager.get_default (); - - app_manager.apps.foreach ((id, app) => { - var app_entry = new Permissions.SidebarRow (app); - app_list.append (app_entry); - }); - - app_settings_view = new Widgets.AppSettingsView (); - - var first_child = app_list.get_first_child (); - if (first_child != null && first_child is Gtk.ListBoxRow) { - var row = (Gtk.ListBoxRow) first_child; - - app_list.select_row (row); - show_row (row); - } - - var grid = new Gtk.Grid (); - grid.attach (sidebar, 0, 0, 1, 1); - grid.attach (app_settings_view, 1, 0, 2, 1); - - var placeholder_stack = new Gtk.Stack (); - placeholder_stack.add_child (placeholder); - placeholder_stack.add_child (grid); - - append (placeholder_stack); - - if (app_manager.apps.length > 0) { - placeholder_stack.set_visible_child (grid); - } else { - placeholder_stack.set_visible_child (placeholder); - } - - map.connect (() => search_entry.grab_focus ()); - search_entry.search_changed.connect (() => { - app_list.invalidate_filter (); - alert_view.title = _("No Results for ā€œ%sā€").printf (search_entry.text); - }); - - app_list.row_selected.connect (show_row); - } - - [CCode (instance_pos = -1)] - private bool filter_func (SidebarRow row) { - var should_show = search_entry.text.down ().strip () in row.app.name.down (); - - if (!should_show && app_list.get_selected_row () == row) { - app_list.select_row (null); - } - - return should_show; - } - - [CCode (instance_pos = -1)] - private int sort_func (SidebarRow row1, SidebarRow row2) { - return row1.app.name.collate (row2.app.name); - } - - private void show_row (Gtk.ListBoxRow? row) { - if (row == null || !(row is Permissions.SidebarRow)) { - app_settings_view.selected_app = null; - } else { - app_settings_view.selected_app = ((Permissions.SidebarRow)row).app; - } - } -} diff --git a/src/Permissions/Widgets/AppSettingsView.vala b/src/Permissions/Widgets/AppSettingsView.vala index ec6d05b8..735d856d 100644 --- a/src/Permissions/Widgets/AppSettingsView.vala +++ b/src/Permissions/Widgets/AppSettingsView.vala @@ -37,6 +37,7 @@ public class Permissions.Widgets.AppSettingsView : Switchboard.SettingsPage { list_box.add_css_class (Granite.STYLE_CLASS_RICH_LIST); child = list_box; + show_end_title_buttons = true; reset_button = add_button (_("Reset to Defaults")); diff --git a/src/Plug.vala b/src/Plug.vala index e5c1db39..2ed1b04c 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -50,36 +50,73 @@ public class ApplicationsPlug : Switchboard.Plug { public override Gtk.Widget get_widget () { if (grid == null) { + var app_settings_view = new Permissions.Widgets.AppSettingsView (); + stack = new Gtk.Stack () { hexpand = true, vexpand = true }; - stack.add_titled (new Defaults.Plug (), DEFAULTS, _("Defaults")); - stack.add_titled (new Startup.Plug (), STARTUP, _("Startup")); - stack.add_titled (new Permissions.Plug (), PERMISSIONS, _("Permissions")); + stack.add_named (new Defaults.Plug (), DEFAULTS); + stack.add_named (new Startup.Plug (), STARTUP); + stack.add_named (app_settings_view, PERMISSIONS); - var stack_switcher = new Gtk.StackSwitcher () { - halign = Gtk.Align.CENTER, - stack = stack - }; + var defaults_row = new SimpleSidebarRow ( + _("Defaults"), "preferences-desktop-defaults" + ); - var size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL); - var widget = stack_switcher.get_first_child (); - while (widget != null) { - size_group.add_widget (widget); - widget = widget.get_next_sibling (); - } + var startup_row = new SimpleSidebarRow ( + _("Startup"), "preferences-desktop-startup" + ); - var headerbar = new Adw.HeaderBar () { - title_widget = stack_switcher + var sidebar = new Gtk.ListBox () { + vexpand = true, + selection_mode = Gtk.SelectionMode.SINGLE + }; + sidebar.add_css_class (Granite.STYLE_CLASS_SIDEBAR); + sidebar.set_sort_func ((Gtk.ListBoxSortFunc) sort_func); + sidebar.append (defaults_row); + sidebar.append (startup_row); + + Permissions.Backend.AppManager.get_default ().apps.foreach ((id, app) => { + var app_entry = new Permissions.SidebarRow (app); + sidebar.append (app_entry); + }); + + var scrolled_window = new Gtk.ScrolledWindow () { + child = sidebar, + vexpand = true, + hscrollbar_policy = NEVER }; - headerbar.add_css_class (Granite.STYLE_CLASS_FLAT); - grid = new Gtk.Grid () { - row_spacing = 24 + var paned = new Gtk.Paned (HORIZONTAL) { + position = 200, + start_child = scrolled_window, + end_child = stack, + shrink_start_child = false, + shrink_end_child = false, + resize_start_child = false }; - grid.attach (headerbar, 0, 0); - grid.attach (stack, 0, 1); + + grid = new Gtk.Grid (); + grid.attach (paned, 0, 0); + + sidebar.row_selected.connect ((row) => { + if (row == null) { + return; + } + + if (row is Permissions.SidebarRow) { + stack.visible_child = app_settings_view; + app_settings_view.selected_app = ((Permissions.SidebarRow)row).app; + } else if (row is SimpleSidebarRow) { + if (((SimpleSidebarRow) row).icon_name == "preferences-desktop-defaults") { + stack.visible_child_name = DEFAULTS; + } else if (((SimpleSidebarRow) row).icon_name == "preferences-desktop-startup") { + stack.visible_child_name = STARTUP; + } + + } + }); } return grid; @@ -125,6 +162,47 @@ public class ApplicationsPlug : Switchboard.Plug { return search_results; } + [CCode (instance_pos = -1)] + private int sort_func (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) { + if (row1 is Permissions.SidebarRow && row2 is Permissions.SidebarRow) { + return ((Permissions.SidebarRow) row1).app.name.collate (((Permissions.SidebarRow) row2).app.name); + } + + return 0; + } + + private class SimpleSidebarRow : Gtk.ListBoxRow { + public string label { get; construct; } + public string icon_name { get; construct; } + + public SimpleSidebarRow (string label, string icon_name) { + Object ( + label: label, + icon_name: icon_name + ); + } + + construct { + var image = new Gtk.Image.from_icon_name ("application-default-icon") { + icon_size = LARGE + }; + + var title_label = new Gtk.Label (label) { + ellipsize = END, + xalign = 0 + }; + title_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL); + + var grid = new Gtk.Grid () { + column_spacing = 6 + }; + grid.attach (image, 0, 0); + grid.attach (title_label, 1, 0); + + hexpand = true; + child = grid; + } + } } public Switchboard.Plug get_plug (Module module) { diff --git a/src/Startup/Startup.vala b/src/Startup/Startup.vala index 7a6e93a0..95403d6d 100644 --- a/src/Startup/Startup.vala +++ b/src/Startup/Startup.vala @@ -64,6 +64,7 @@ public class Startup.Plug : Switchboard.SettingsPage { }; child = frame; + show_end_title_buttons = true; app_chooser = new Widgets.AppChooser () { modal = true diff --git a/src/meson.build b/src/meson.build index 2a5f6e5e..1778dbc1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -18,8 +18,8 @@ plug_files = files( 'Permissions/Backend/PermissionSettings.vala', 'Permissions/Widgets/AppSettingsView.vala', 'Permissions/Widgets/PermissionSettingsWidget.vala', - 'Permissions/Widgets/SidebarRow.vala', - 'Permissions/PermissionsPlug.vala' + 'Permissions/Widgets/SidebarRow.vala' + # 'Permissions/PermissionsPlug.vala' ) switchboard_dep = dependency('switchboard-3') From 8bb6fd41d7ddf1888e3ab26db987dd36ee8c8123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 28 Mar 2024 22:07:36 -0700 Subject: [PATCH 06/13] Sidebar header --- src/Plug.vala | 54 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/Plug.vala b/src/Plug.vala index 2ed1b04c..3f161268 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -68,29 +68,37 @@ public class ApplicationsPlug : Switchboard.Plug { _("Startup"), "preferences-desktop-startup" ); - var sidebar = new Gtk.ListBox () { - vexpand = true, - selection_mode = Gtk.SelectionMode.SINGLE + var headerbar = new Adw.HeaderBar () { + show_end_title_buttons = false, + show_title = false }; - sidebar.add_css_class (Granite.STYLE_CLASS_SIDEBAR); - sidebar.set_sort_func ((Gtk.ListBoxSortFunc) sort_func); - sidebar.append (defaults_row); - sidebar.append (startup_row); - Permissions.Backend.AppManager.get_default ().apps.foreach ((id, app) => { - var app_entry = new Permissions.SidebarRow (app); - sidebar.append (app_entry); - }); + var listbox = new Gtk.ListBox () { + vexpand = true, + selection_mode = BROWSE + }; + listbox.add_css_class (Granite.STYLE_CLASS_SIDEBAR); + listbox.set_sort_func ((Gtk.ListBoxSortFunc) sort_func); + listbox.append (defaults_row); + listbox.append (startup_row); var scrolled_window = new Gtk.ScrolledWindow () { - child = sidebar, - vexpand = true, + child = listbox, hscrollbar_policy = NEVER }; + var toolbarview = new Adw.ToolbarView () { + content = scrolled_window, + top_bar_style = FLAT, + }; + toolbarview.add_top_bar (headerbar); + + var sidebar = new Sidebar (); + sidebar.append (toolbarview); + var paned = new Gtk.Paned (HORIZONTAL) { position = 200, - start_child = scrolled_window, + start_child = sidebar, end_child = stack, shrink_start_child = false, shrink_end_child = false, @@ -100,7 +108,12 @@ public class ApplicationsPlug : Switchboard.Plug { grid = new Gtk.Grid (); grid.attach (paned, 0, 0); - sidebar.row_selected.connect ((row) => { + Permissions.Backend.AppManager.get_default ().apps.foreach ((id, app) => { + var app_entry = new Permissions.SidebarRow (app); + listbox.append (app_entry); + }); + + listbox.row_selected.connect ((row) => { if (row == null) { return; } @@ -203,6 +216,17 @@ public class ApplicationsPlug : Switchboard.Plug { child = grid; } } + + // Workaround to set styles + private class Sidebar : Gtk.Box { + class construct { + set_css_name ("settingssidebar"); + } + + construct { + add_css_class (Granite.STYLE_CLASS_SIDEBAR); + } + } } public Switchboard.Plug get_plug (Module module) { From 999b22d3fd7720a9ecf71120bdfcfb0ba402e092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 29 Mar 2024 09:02:57 -0700 Subject: [PATCH 07/13] header func --- src/Plug.vala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Plug.vala b/src/Plug.vala index 3f161268..1d336b49 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -79,6 +79,19 @@ public class ApplicationsPlug : Switchboard.Plug { }; listbox.add_css_class (Granite.STYLE_CLASS_SIDEBAR); listbox.set_sort_func ((Gtk.ListBoxSortFunc) sort_func); + listbox.set_header_func ((row, before) => { + if (row is SimpleSidebarRow && !(before is SimpleSidebarRow)) { + row.set_header (new Granite.HeaderLabel (_("System"))); + return; + } + + if (row is Permissions.SidebarRow && !(before is Permissions.SidebarRow)) { + row.set_header (new Granite.HeaderLabel (_("Apps"))); + return; + } + + row.set_header (null); + }); listbox.append (defaults_row); listbox.append (startup_row); From 79fc07a36841cd02324cac125f6abd7342928388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 29 Mar 2024 09:10:07 -0700 Subject: [PATCH 08/13] search --- src/Plug.vala | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/Plug.vala b/src/Plug.vala index 1d336b49..d528302a 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -26,6 +26,7 @@ public class ApplicationsPlug : Switchboard.Plug { private const string PERMISSIONS = "permissions"; private Gtk.Grid grid; + private Gtk.SearchEntry search_entry; private Gtk.Stack stack; public ApplicationsPlug () { @@ -68,10 +69,29 @@ public class ApplicationsPlug : Switchboard.Plug { _("Startup"), "preferences-desktop-startup" ); + search_entry = new Gtk.SearchEntry () { + placeholder_text = _("Search Apps"), + margin_top = 6, + margin_bottom = 6, + margin_start = 6, + margin_end = 6, + hexpand = true + }; + + var search_revealer = new Gtk.Revealer () { + child = search_entry + }; + + var search_toggle = new Gtk.ToggleButton () { + icon_name = "edit-find-symbolic", + tooltip_text = _("Search Apps") + }; + var headerbar = new Adw.HeaderBar () { show_end_title_buttons = false, show_title = false }; + headerbar.pack_end (search_toggle); var listbox = new Gtk.ListBox () { vexpand = true, @@ -85,13 +105,14 @@ public class ApplicationsPlug : Switchboard.Plug { return; } - if (row is Permissions.SidebarRow && !(before is Permissions.SidebarRow)) { + if (row is Permissions.SidebarRow && before is SimpleSidebarRow) { row.set_header (new Granite.HeaderLabel (_("Apps"))); return; } row.set_header (null); }); + listbox.set_filter_func (filter_function); listbox.append (defaults_row); listbox.append (startup_row); @@ -105,6 +126,7 @@ public class ApplicationsPlug : Switchboard.Plug { top_bar_style = FLAT, }; toolbarview.add_top_bar (headerbar); + toolbarview.add_top_bar (search_revealer); var sidebar = new Sidebar (); sidebar.append (toolbarview); @@ -143,6 +165,20 @@ public class ApplicationsPlug : Switchboard.Plug { } }); + + search_entry.search_changed.connect (() => { + listbox.invalidate_filter (); + }); + + search_toggle.bind_property ("active", search_revealer, "reveal-child"); + + search_revealer.notify["child-revealed"].connect (() => { + if (search_revealer.child_revealed) { + search_entry.grab_focus (); + } else { + search_entry.text = ""; + } + }); } return grid; @@ -188,6 +224,21 @@ public class ApplicationsPlug : Switchboard.Plug { return search_results; } + private bool filter_function (Gtk.ListBoxRow row) { + if (search_entry.text != "") { + if (row is SimpleSidebarRow) { + return false; + } + + var search_term = search_entry.text.down (); + var row_name = ((Permissions.SidebarRow) row).app.name.down (); + + return search_term in row_name; + } + + return true; + } + [CCode (instance_pos = -1)] private int sort_func (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) { if (row1 is Permissions.SidebarRow && row2 is Permissions.SidebarRow) { From ba44438421aa82411a0ffea8a0406c653ebc4206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 29 Mar 2024 10:46:38 -0700 Subject: [PATCH 09/13] Icons --- src/Defaults/DefaultPlug.vala | 2 +- src/Plug.vala | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Defaults/DefaultPlug.vala b/src/Defaults/DefaultPlug.vala index 3601e74a..88043058 100644 --- a/src/Defaults/DefaultPlug.vala +++ b/src/Defaults/DefaultPlug.vala @@ -10,7 +10,7 @@ public class Defaults.Plug : Switchboard.SettingsPage { public Plug () { Object ( title: _("Defaults"), - icon: new ThemedIcon ("preferences-desktop") + icon: new ThemedIcon ("preferences-system") ); } diff --git a/src/Plug.vala b/src/Plug.vala index d528302a..4580f43b 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -21,8 +21,8 @@ */ public class ApplicationsPlug : Switchboard.Plug { - private const string DEFAULTS = "defaults"; - private const string STARTUP = "startup"; + private const string DEFAULTS = "preferences-system"; + private const string STARTUP = "system-restart"; private const string PERMISSIONS = "permissions"; private Gtk.Grid grid; @@ -62,11 +62,11 @@ public class ApplicationsPlug : Switchboard.Plug { stack.add_named (app_settings_view, PERMISSIONS); var defaults_row = new SimpleSidebarRow ( - _("Defaults"), "preferences-desktop-defaults" + _("Defaults"), DEFAULTS ); var startup_row = new SimpleSidebarRow ( - _("Startup"), "preferences-desktop-startup" + _("Startup"), STARTUP ); search_entry = new Gtk.SearchEntry () { @@ -157,9 +157,9 @@ public class ApplicationsPlug : Switchboard.Plug { stack.visible_child = app_settings_view; app_settings_view.selected_app = ((Permissions.SidebarRow)row).app; } else if (row is SimpleSidebarRow) { - if (((SimpleSidebarRow) row).icon_name == "preferences-desktop-defaults") { + if (((SimpleSidebarRow) row).icon_name == DEFAULTS) { stack.visible_child_name = DEFAULTS; - } else if (((SimpleSidebarRow) row).icon_name == "preferences-desktop-startup") { + } else if (((SimpleSidebarRow) row).icon_name == STARTUP) { stack.visible_child_name = STARTUP; } @@ -260,7 +260,7 @@ public class ApplicationsPlug : Switchboard.Plug { } construct { - var image = new Gtk.Image.from_icon_name ("application-default-icon") { + var image = new Gtk.Image.from_icon_name (icon_name) { icon_size = LARGE }; From 1e6605570a1e0ed3c05ba2097d5d852c46091eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 29 Mar 2024 10:56:28 -0700 Subject: [PATCH 10/13] Make startup icons --- data/applications.gresource.xml | 4 + data/startup-32.svg | 184 ++++++++++++++++++++++++++ data/startup-48.svg | 228 ++++++++++++++++++++++++++++++++ src/Plug.vala | 2 +- src/Startup/Startup.vala | 2 +- 5 files changed, 418 insertions(+), 2 deletions(-) create mode 100644 data/startup-32.svg create mode 100644 data/startup-48.svg diff --git a/data/applications.gresource.xml b/data/applications.gresource.xml index 067e48d6..ce573071 100644 --- a/data/applications.gresource.xml +++ b/data/applications.gresource.xml @@ -2,5 +2,9 @@ background.svg + startup-32.svg + startup-32.svg + startup-48.svg + startup-48.svg diff --git a/data/startup-32.svg b/data/startup-32.svg new file mode 100644 index 00000000..036380f7 --- /dev/null +++ b/data/startup-32.svg @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/data/startup-48.svg b/data/startup-48.svg new file mode 100644 index 00000000..6c0afdb1 --- /dev/null +++ b/data/startup-48.svg @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/Plug.vala b/src/Plug.vala index 4580f43b..950ec082 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -22,7 +22,7 @@ public class ApplicationsPlug : Switchboard.Plug { private const string DEFAULTS = "preferences-system"; - private const string STARTUP = "system-restart"; + private const string STARTUP = "preferences-desktop-startup"; private const string PERMISSIONS = "permissions"; private Gtk.Grid grid; diff --git a/src/Startup/Startup.vala b/src/Startup/Startup.vala index 95403d6d..55973111 100644 --- a/src/Startup/Startup.vala +++ b/src/Startup/Startup.vala @@ -14,7 +14,7 @@ public class Startup.Plug : Switchboard.SettingsPage { public Plug () { Object ( title: _("Startup"), - icon: new ThemedIcon ("system-restart") + icon: new ThemedIcon ("preferences-desktop-startup") ); } From e30cae85a7943a76aed7443b267ddd93900b0925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 1 Apr 2024 10:01:55 -0700 Subject: [PATCH 11/13] Move sidebar to its own class --- po/POTFILES | 2 +- src/Plug.vala | 194 ++--------------------------------------------- src/Sidebar.vala | 180 +++++++++++++++++++++++++++++++++++++++++++ src/meson.build | 2 +- 4 files changed, 190 insertions(+), 188 deletions(-) create mode 100644 src/Sidebar.vala diff --git a/po/POTFILES b/po/POTFILES index ce3b6cc1..b99b6599 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,5 +1,5 @@ src/Plug.vala -src/Permissions/PermissionsPlug.vala +src/Sidebar.vala src/Permissions/Widgets/AppSettingsView.vala src/Permissions/Widgets/SidebarRow.vala src/Startup/Utils.vala diff --git a/src/Plug.vala b/src/Plug.vala index 950ec082..1cb7c4d9 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -20,16 +20,15 @@ * Marius Meisenzahl */ -public class ApplicationsPlug : Switchboard.Plug { - private const string DEFAULTS = "preferences-system"; - private const string STARTUP = "preferences-desktop-startup"; - private const string PERMISSIONS = "permissions"; +public class Applications.Plug : Switchboard.Plug { + public const string DEFAULTS = "preferences-system"; + public const string STARTUP = "preferences-desktop-startup"; + public const string PERMISSIONS = "permissions"; private Gtk.Grid grid; - private Gtk.SearchEntry search_entry; private Gtk.Stack stack; - public ApplicationsPlug () { + public Plug () { GLib.Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); GLib.Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); @@ -53,86 +52,14 @@ public class ApplicationsPlug : Switchboard.Plug { if (grid == null) { var app_settings_view = new Permissions.Widgets.AppSettingsView (); - stack = new Gtk.Stack () { - hexpand = true, - vexpand = true - }; + stack = new Gtk.Stack (); stack.add_named (new Defaults.Plug (), DEFAULTS); stack.add_named (new Startup.Plug (), STARTUP); stack.add_named (app_settings_view, PERMISSIONS); - var defaults_row = new SimpleSidebarRow ( - _("Defaults"), DEFAULTS - ); - - var startup_row = new SimpleSidebarRow ( - _("Startup"), STARTUP - ); - - search_entry = new Gtk.SearchEntry () { - placeholder_text = _("Search Apps"), - margin_top = 6, - margin_bottom = 6, - margin_start = 6, - margin_end = 6, - hexpand = true - }; - - var search_revealer = new Gtk.Revealer () { - child = search_entry - }; - - var search_toggle = new Gtk.ToggleButton () { - icon_name = "edit-find-symbolic", - tooltip_text = _("Search Apps") - }; - - var headerbar = new Adw.HeaderBar () { - show_end_title_buttons = false, - show_title = false - }; - headerbar.pack_end (search_toggle); - - var listbox = new Gtk.ListBox () { - vexpand = true, - selection_mode = BROWSE - }; - listbox.add_css_class (Granite.STYLE_CLASS_SIDEBAR); - listbox.set_sort_func ((Gtk.ListBoxSortFunc) sort_func); - listbox.set_header_func ((row, before) => { - if (row is SimpleSidebarRow && !(before is SimpleSidebarRow)) { - row.set_header (new Granite.HeaderLabel (_("System"))); - return; - } - - if (row is Permissions.SidebarRow && before is SimpleSidebarRow) { - row.set_header (new Granite.HeaderLabel (_("Apps"))); - return; - } - - row.set_header (null); - }); - listbox.set_filter_func (filter_function); - listbox.append (defaults_row); - listbox.append (startup_row); - - var scrolled_window = new Gtk.ScrolledWindow () { - child = listbox, - hscrollbar_policy = NEVER - }; - - var toolbarview = new Adw.ToolbarView () { - content = scrolled_window, - top_bar_style = FLAT, - }; - toolbarview.add_top_bar (headerbar); - toolbarview.add_top_bar (search_revealer); - - var sidebar = new Sidebar (); - sidebar.append (toolbarview); + var sidebar = new Sidebar (stack); var paned = new Gtk.Paned (HORIZONTAL) { - position = 200, start_child = sidebar, end_child = stack, shrink_start_child = false, @@ -142,43 +69,6 @@ public class ApplicationsPlug : Switchboard.Plug { grid = new Gtk.Grid (); grid.attach (paned, 0, 0); - - Permissions.Backend.AppManager.get_default ().apps.foreach ((id, app) => { - var app_entry = new Permissions.SidebarRow (app); - listbox.append (app_entry); - }); - - listbox.row_selected.connect ((row) => { - if (row == null) { - return; - } - - if (row is Permissions.SidebarRow) { - stack.visible_child = app_settings_view; - app_settings_view.selected_app = ((Permissions.SidebarRow)row).app; - } else if (row is SimpleSidebarRow) { - if (((SimpleSidebarRow) row).icon_name == DEFAULTS) { - stack.visible_child_name = DEFAULTS; - } else if (((SimpleSidebarRow) row).icon_name == STARTUP) { - stack.visible_child_name = STARTUP; - } - - } - }); - - search_entry.search_changed.connect (() => { - listbox.invalidate_filter (); - }); - - search_toggle.bind_property ("active", search_revealer, "reveal-child"); - - search_revealer.notify["child-revealed"].connect (() => { - if (search_revealer.child_revealed) { - search_entry.grab_focus (); - } else { - search_entry.text = ""; - } - }); } return grid; @@ -223,76 +113,8 @@ public class ApplicationsPlug : Switchboard.Plug { search_results.set ("%s ā†’ %s ā†’ %s".printf (display_name, _("Default"), _("File Browser")), DEFAULTS); return search_results; } - - private bool filter_function (Gtk.ListBoxRow row) { - if (search_entry.text != "") { - if (row is SimpleSidebarRow) { - return false; - } - - var search_term = search_entry.text.down (); - var row_name = ((Permissions.SidebarRow) row).app.name.down (); - - return search_term in row_name; - } - - return true; - } - - [CCode (instance_pos = -1)] - private int sort_func (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) { - if (row1 is Permissions.SidebarRow && row2 is Permissions.SidebarRow) { - return ((Permissions.SidebarRow) row1).app.name.collate (((Permissions.SidebarRow) row2).app.name); - } - - return 0; - } - - private class SimpleSidebarRow : Gtk.ListBoxRow { - public string label { get; construct; } - public string icon_name { get; construct; } - - public SimpleSidebarRow (string label, string icon_name) { - Object ( - label: label, - icon_name: icon_name - ); - } - - construct { - var image = new Gtk.Image.from_icon_name (icon_name) { - icon_size = LARGE - }; - - var title_label = new Gtk.Label (label) { - ellipsize = END, - xalign = 0 - }; - title_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL); - - var grid = new Gtk.Grid () { - column_spacing = 6 - }; - grid.attach (image, 0, 0); - grid.attach (title_label, 1, 0); - - hexpand = true; - child = grid; - } - } - - // Workaround to set styles - private class Sidebar : Gtk.Box { - class construct { - set_css_name ("settingssidebar"); - } - - construct { - add_css_class (Granite.STYLE_CLASS_SIDEBAR); - } - } } public Switchboard.Plug get_plug (Module module) { - return new ApplicationsPlug (); + return new Applications.Plug (); } diff --git a/src/Sidebar.vala b/src/Sidebar.vala new file mode 100644 index 00000000..93ac9322 --- /dev/null +++ b/src/Sidebar.vala @@ -0,0 +1,180 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2011-2024 elementary, Inc. (https://elementary.io) + */ + +public class Applications.Sidebar : Gtk.Box { + public Gtk.Stack stack { get; construct; } + + private Gtk.SearchEntry search_entry; + + class construct { + set_css_name ("settingssidebar"); + } + + public Sidebar (Gtk.Stack stack) { + Object (stack: stack); + } + + construct { + add_css_class (Granite.STYLE_CLASS_SIDEBAR); + + var defaults_row = new SimpleSidebarRow ( + _("Defaults"), Plug.DEFAULTS + ); + + var startup_row = new SimpleSidebarRow ( + _("Startup"), Plug.STARTUP + ); + + search_entry = new Gtk.SearchEntry () { + placeholder_text = _("Search Apps"), + margin_top = 6, + margin_bottom = 6, + margin_start = 6, + margin_end = 6, + hexpand = true + }; + + var search_revealer = new Gtk.Revealer () { + child = search_entry + }; + + var search_toggle = new Gtk.ToggleButton () { + icon_name = "edit-find-symbolic", + tooltip_text = _("Search Apps") + }; + + var headerbar = new Adw.HeaderBar () { + show_end_title_buttons = false, + show_title = false + }; + headerbar.pack_end (search_toggle); + + var listbox = new Gtk.ListBox () { + vexpand = true, + selection_mode = BROWSE + }; + listbox.set_filter_func (filter_function); + listbox.set_header_func (header_func); + listbox.set_sort_func (sort_func); + listbox.append (defaults_row); + listbox.append (startup_row); + + var scrolled_window = new Gtk.ScrolledWindow () { + child = listbox, + hscrollbar_policy = NEVER + }; + + var toolbarview = new Adw.ToolbarView () { + content = scrolled_window, + top_bar_style = FLAT, + }; + toolbarview.add_top_bar (headerbar); + toolbarview.add_top_bar (search_revealer); + + append (toolbarview); + + Permissions.Backend.AppManager.get_default ().apps.foreach ((id, app) => { + var app_entry = new Permissions.SidebarRow (app); + listbox.append (app_entry); + }); + + listbox.row_selected.connect ((row) => { + if (row == null) { + return; + } + + if (row is Permissions.SidebarRow) { + stack.visible_child_name = Plug.PERMISSIONS; + ((Permissions.Widgets.AppSettingsView) stack.visible_child).selected_app = ((Permissions.SidebarRow)row).app; + } else if (row is SimpleSidebarRow) { + stack.visible_child_name = ((SimpleSidebarRow) row).icon_name; + } + }); + + search_entry.search_changed.connect (() => { + listbox.invalidate_filter (); + }); + + search_toggle.bind_property ("active", search_revealer, "reveal-child"); + + search_revealer.notify["child-revealed"].connect (() => { + if (search_revealer.child_revealed) { + search_entry.grab_focus (); + } else { + search_entry.text = ""; + } + }); + } + + private bool filter_function (Gtk.ListBoxRow row) { + if (search_entry.text != "") { + if (row is SimpleSidebarRow) { + return false; + } + + var search_term = search_entry.text.down (); + var row_name = ((Permissions.SidebarRow) row).app.name.down (); + + return search_term in row_name; + } + + return true; + } + + private void header_func (Gtk.ListBoxRow row, Gtk.ListBoxRow? before) { + if (row is SimpleSidebarRow && !(before is SimpleSidebarRow)) { + row.set_header (new Granite.HeaderLabel (_("System"))); + return; + } + + if (row is Permissions.SidebarRow && before is SimpleSidebarRow) { + row.set_header (new Granite.HeaderLabel (_("Apps"))); + return; + } + + row.set_header (null); + } + + private int sort_func (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) { + if (row1 is Permissions.SidebarRow && row2 is Permissions.SidebarRow) { + return ((Permissions.SidebarRow) row1).app.name.collate (((Permissions.SidebarRow) row2).app.name); + } + + return 0; + } + + private class SimpleSidebarRow : Gtk.ListBoxRow { + public string label { get; construct; } + public string icon_name { get; construct; } + + public SimpleSidebarRow (string label, string icon_name) { + Object ( + label: label, + icon_name: icon_name + ); + } + + construct { + var image = new Gtk.Image.from_icon_name (icon_name) { + icon_size = LARGE + }; + + var title_label = new Gtk.Label (label) { + ellipsize = END, + xalign = 0 + }; + title_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL); + + var grid = new Gtk.Grid () { + column_spacing = 6 + }; + grid.attach (image, 0, 0); + grid.attach (title_label, 1, 0); + + hexpand = true; + child = grid; + } + } +} diff --git a/src/meson.build b/src/meson.build index 50adc46d..1dca946b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,5 +1,6 @@ plug_files = files( 'Plug.vala', + 'Sidebar.vala', 'Startup/Utils.vala', 'Startup/Startup.vala', 'Startup/Controller.vala', @@ -20,7 +21,6 @@ plug_files = files( 'Permissions/Widgets/AppSettingsView.vala', 'Permissions/Widgets/PermissionSettingsWidget.vala', 'Permissions/Widgets/SidebarRow.vala' - # 'Permissions/PermissionsPlug.vala' ) switchboard_dep = dependency('switchboard-3') From 84ac88850db7cbf27ae129718d5f606aa1ea22e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 1 Apr 2024 10:09:22 -0700 Subject: [PATCH 12/13] Clean up extra grid --- src/Plug.vala | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Plug.vala b/src/Plug.vala index 1cb7c4d9..fa814005 100644 --- a/src/Plug.vala +++ b/src/Plug.vala @@ -25,7 +25,7 @@ public class Applications.Plug : Switchboard.Plug { public const string STARTUP = "preferences-desktop-startup"; public const string PERMISSIONS = "permissions"; - private Gtk.Grid grid; + private Gtk.Paned paned; private Gtk.Stack stack; public Plug () { @@ -49,7 +49,7 @@ public class Applications.Plug : Switchboard.Plug { } public override Gtk.Widget get_widget () { - if (grid == null) { + if (paned == null) { var app_settings_view = new Permissions.Widgets.AppSettingsView (); stack = new Gtk.Stack (); @@ -59,19 +59,16 @@ public class Applications.Plug : Switchboard.Plug { var sidebar = new Sidebar (stack); - var paned = new Gtk.Paned (HORIZONTAL) { + paned = new Gtk.Paned (HORIZONTAL) { start_child = sidebar, end_child = stack, shrink_start_child = false, shrink_end_child = false, resize_start_child = false }; - - grid = new Gtk.Grid (); - grid.attach (paned, 0, 0); } - return grid; + return paned; } public override void shown () { From 565df9c146b28713e062e3b0fae0ba2d9b0c34d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 1 Apr 2024 10:13:19 -0700 Subject: [PATCH 13/13] grid to box --- src/Sidebar.vala | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Sidebar.vala b/src/Sidebar.vala index 93ac9322..0682da45 100644 --- a/src/Sidebar.vala +++ b/src/Sidebar.vala @@ -1,6 +1,6 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2011-2024 elementary, Inc. (https://elementary.io) + * SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io) */ public class Applications.Sidebar : Gtk.Box { @@ -17,8 +17,6 @@ public class Applications.Sidebar : Gtk.Box { } construct { - add_css_class (Granite.STYLE_CLASS_SIDEBAR); - var defaults_row = new SimpleSidebarRow ( _("Defaults"), Plug.DEFAULTS ); @@ -74,6 +72,7 @@ public class Applications.Sidebar : Gtk.Box { toolbarview.add_top_bar (search_revealer); append (toolbarview); + add_css_class (Granite.STYLE_CLASS_SIDEBAR); Permissions.Backend.AppManager.get_default ().apps.foreach ((id, app) => { var app_entry = new Permissions.SidebarRow (app); @@ -167,14 +166,11 @@ public class Applications.Sidebar : Gtk.Box { }; title_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL); - var grid = new Gtk.Grid () { - column_spacing = 6 - }; - grid.attach (image, 0, 0); - grid.attach (title_label, 1, 0); + var box = new Gtk.Box (HORIZONTAL, 6); + box.append (image); + box.append (title_label); - hexpand = true; - child = grid; + child = box; } } }