From 661df1b6830dea73f267334b5f5bc102e411ebd5 Mon Sep 17 00:00:00 2001 From: Mohammed Sadiq Date: Thu, 25 Jul 2019 21:48:35 +0530 Subject: [PATCH] window: Disable selection when panel list is folded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the panel list is folded, either the panel items list or the panel itself is shown, not both. And when the list is shown it doesn’t mean anything for an item to be marked as selected. --- shell/cc-panel-list.c | 23 +++++++++++++++++++++++ shell/cc-panel-list.h | 3 +++ shell/cc-window.c | 16 ++++++++++++++++ shell/cc-window.ui | 1 + 4 files changed, 43 insertions(+) diff --git a/shell/cc-panel-list.c b/shell/cc-panel-list.c index 67a0ac77f..e5134ac6b 100644 --- a/shell/cc-panel-list.c +++ b/shell/cc-panel-list.c @@ -1137,3 +1137,26 @@ cc_panel_list_add_sidebar_widget (CcPanelList *self, gtk_container_remove (GTK_CONTAINER (self), widget); } } + +void +cc_panel_list_set_selection_mode (CcPanelList *self, + GtkSelectionMode selection_mode) +{ + g_return_if_fail (CC_IS_PANEL_LIST (self)); + + gtk_list_box_set_selection_mode (GTK_LIST_BOX (self->main_listbox), selection_mode); + gtk_list_box_set_selection_mode (GTK_LIST_BOX (self->devices_listbox), selection_mode); + gtk_list_box_set_selection_mode (GTK_LIST_BOX (self->details_listbox), selection_mode); + + /* When selection mode changed, selection will be lost. So reselect */ + if (selection_mode == GTK_SELECTION_SINGLE && self->current_panel_id) + { + GtkWidget *listbox; + RowData *data; + + data = g_hash_table_lookup (self->id_to_data, self->current_panel_id); + listbox = gtk_widget_get_parent (data->row); + gtk_list_box_select_row (GTK_LIST_BOX (listbox), GTK_LIST_BOX_ROW (data->row)); + } +} + diff --git a/shell/cc-panel-list.h b/shell/cc-panel-list.h index 525734ea5..76995c2b8 100644 --- a/shell/cc-panel-list.h +++ b/shell/cc-panel-list.h @@ -73,6 +73,9 @@ void cc_panel_list_set_panel_visibility (CcPanelList void cc_panel_list_add_sidebar_widget (CcPanelList *self, GtkWidget *widget); +void cc_panel_list_set_selection_mode (CcPanelList *self, + GtkSelectionMode selection_mode); + G_END_DECLS #endif /* CC_PANEL_LIST_H */ diff --git a/shell/cc-window.c b/shell/cc-window.c index 6cbe22c71..8a6c6eeeb 100644 --- a/shell/cc-window.c +++ b/shell/cc-window.c @@ -536,6 +536,21 @@ notify_fold_cb (HdyLeaflet *leaflet, update_fold_state (shell); } +static void +on_main_leaflet_fold_changed_cb (CcWindow *self) +{ + GtkSelectionMode selection_mode; + + g_assert (CC_IS_WINDOW (self)); + + selection_mode = GTK_SELECTION_SINGLE; + + if (hdy_leaflet_get_fold (HDY_LEAFLET (self->main_leaflet)) == HDY_FOLD_FOLDED) + selection_mode = GTK_SELECTION_NONE; + + cc_panel_list_set_selection_mode (CC_PANEL_LIST (self->panel_list), selection_mode); +} + static void show_panel_cb (CcPanelList *panel_list, const gchar *panel_id, @@ -917,6 +932,7 @@ cc_window_class_init (CcWindowClass *klass) gtk_widget_class_bind_template_callback (widget_class, gdk_window_set_cb); gtk_widget_class_bind_template_callback (widget_class, notify_header_visible_child_cb); gtk_widget_class_bind_template_callback (widget_class, notify_fold_cb); + gtk_widget_class_bind_template_callback (widget_class, on_main_leaflet_fold_changed_cb); gtk_widget_class_bind_template_callback (widget_class, on_development_warning_dialog_responded_cb); gtk_widget_class_bind_template_callback (widget_class, previous_button_clicked_cb); gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb); diff --git a/shell/cc-window.ui b/shell/cc-window.ui index 45f9182f1..e7b2a5d89 100644 --- a/shell/cc-window.ui +++ b/shell/cc-window.ui @@ -15,6 +15,7 @@ False slide slide + True