Skip to content

Commit 054ab20

Browse files
authored
SettingsSideBar: Fix selection of the correct row (#336)
1 parent 740997e commit 054ab20

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

lib/SettingsSidebar.vala

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,24 @@ public class Switchboard.SettingsSidebar : Gtk.Widget {
2424
public bool show_title_buttons { get; set;}
2525

2626
/**
27-
* The name of the currently visible Granite.SettingsPage
27+
* The name of the currently visible {@link SettingsPage}.
28+
* Beware this is the name of the page as set via {@link Gtk.Stack.add_named}
29+
* and not the title of the page.
2830
*/
2931
public string? visible_child_name {
3032
get {
31-
var selected_row = listbox.get_selected_row ();
32-
33-
if (selected_row == null) {
34-
return null;
35-
} else {
36-
return ((SettingsSidebarRow) selected_row).page.title;
37-
}
33+
return stack.visible_child_name;
3834
}
3935
set {
40-
weak Gtk.Widget listbox_child = listbox.get_first_child ();
41-
while (listbox_child != null) {
42-
if (!(listbox_child is SettingsSidebarRow)) {
43-
listbox_child = listbox_child.get_next_sibling ();
36+
for (unowned var child = listbox.get_first_child (); child != null; child = child.get_next_sibling ()) {
37+
if (!(child is SettingsSidebarRow)) {
4438
continue;
4539
}
4640

47-
if (((SettingsSidebarRow) listbox_child).page.title == value) {
48-
listbox.select_row ((Gtk.ListBoxRow) listbox_child);
41+
if (((SettingsSidebarRow) child).page_name == value) {
42+
listbox.select_row ((Gtk.ListBoxRow) child);
4943
break;
5044
}
51-
52-
listbox_child = listbox_child.get_next_sibling ();
5345
}
5446
}
5547
}
@@ -134,7 +126,7 @@ public class Switchboard.SettingsSidebar : Gtk.Widget {
134126
private Gtk.Widget create_widget_func (Object object) {
135127
unowned var stack_page = (Gtk.StackPage) object;
136128
unowned var page = (SettingsPage) stack_page.child;
137-
var row = new SettingsSidebarRow (page);
129+
var row = new SettingsSidebarRow (stack_page.name, page);
138130

139131
return row;
140132
}

lib/SettingsSidebarRow.vala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow {
7+
public string page_name { get; construct; }
8+
79
public SettingsPage.StatusType status_type {
810
set {
911
switch (value) {
@@ -57,8 +59,9 @@ private class Switchboard.SettingsSidebarRow : Gtk.ListBoxRow {
5759
private Gtk.Label title_label;
5860
private string _title;
5961

60-
public SettingsSidebarRow (SettingsPage page) {
62+
public SettingsSidebarRow (string page_name, SettingsPage page) {
6163
Object (
64+
page_name: page_name,
6265
page: page
6366
);
6467
}

0 commit comments

Comments
 (0)