From f19bb4aa903de5ad3152cb903eb58d36637b409f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 6 Feb 2025 12:07:25 -0800 Subject: [PATCH] Revert "SettingsSideBar: Fix selection of the correct row (#336)" This reverts commit 054ab206a98af06d835192f6ea3249fbed51c4be. --- lib/SettingsSidebar.vala | 26 +++++++++++++++++--------- lib/SettingsSidebarRow.vala | 5 +---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/SettingsSidebar.vala b/lib/SettingsSidebar.vala index 7dc3a6f6..f12b19b9 100644 --- a/lib/SettingsSidebar.vala +++ b/lib/SettingsSidebar.vala @@ -24,24 +24,32 @@ public class Switchboard.SettingsSidebar : Gtk.Widget { public bool show_title_buttons { get; set;} /** - * The name of the currently visible {@link SettingsPage}. - * Beware this is the name of the page as set via {@link Gtk.Stack.add_named} - * and not the title of the page. + * The name of the currently visible Granite.SettingsPage */ public string? visible_child_name { get { - return stack.visible_child_name; + var selected_row = listbox.get_selected_row (); + + if (selected_row == null) { + return null; + } else { + return ((SettingsSidebarRow) selected_row).page.title; + } } set { - for (unowned var child = listbox.get_first_child (); child != null; child = child.get_next_sibling ()) { - if (!(child is SettingsSidebarRow)) { + weak Gtk.Widget listbox_child = listbox.get_first_child (); + while (listbox_child != null) { + if (!(listbox_child is SettingsSidebarRow)) { + listbox_child = listbox_child.get_next_sibling (); continue; } - if (((SettingsSidebarRow) child).page_name == value) { - listbox.select_row ((Gtk.ListBoxRow) child); + if (((SettingsSidebarRow) listbox_child).page.title == value) { + listbox.select_row ((Gtk.ListBoxRow) listbox_child); break; } + + listbox_child = listbox_child.get_next_sibling (); } } } @@ -126,7 +134,7 @@ public class Switchboard.SettingsSidebar : Gtk.Widget { private Gtk.Widget create_widget_func (Object object) { unowned var stack_page = (Gtk.StackPage) object; unowned var page = (SettingsPage) stack_page.child; - var row = new SettingsSidebarRow (stack_page.name, page); + var row = new SettingsSidebarRow (page); return row; } diff --git a/lib/SettingsSidebarRow.vala b/lib/SettingsSidebarRow.vala index 1aa04e7b..b2005404 100644 --- a/lib/SettingsSidebarRow.vala +++ b/lib/SettingsSidebarRow.vala @@ -4,8 +4,6 @@ */ private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow { - public string page_name { get; construct; } - public SettingsPage.StatusType status_type { set { switch (value) { @@ -59,9 +57,8 @@ private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow { private Gtk.Label title_label; private string _title; - public SettingsSidebarRow (string page_name, SettingsPage page) { + public SettingsSidebarRow (SettingsPage page) { Object ( - page_name: page_name, page: page ); }