[gnome-control-center/gbsneto/panel-widget-in-sidebar: 9/14] window: Add panel's sidebar widget to sidebar
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gbsneto/panel-widget-in-sidebar: 9/14] window: Add panel's sidebar widget to sidebar
- Date: Fri, 16 Nov 2018 17:21:04 +0000 (UTC)
commit a5487e4d4abc63864462cc8a788e811db401ed12
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Nov 16 14:28:53 2018 -0200
window: Add panel's sidebar widget to sidebar
When opening a panel, add its sidebar widget to the sidebar.
shell/cc-panel-list.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++----
shell/cc-panel-list.h | 4 ++++
shell/cc-window.c | 4 ++++
3 files changed, 70 insertions(+), 4 deletions(-)
---
diff --git a/shell/cc-panel-list.c b/shell/cc-panel-list.c
index 7796dae32..ed4b89a75 100644
--- a/shell/cc-panel-list.c
+++ b/shell/cc-panel-list.c
@@ -107,6 +107,9 @@ get_widget_from_view (CcPanelList *self,
case CC_PANEL_LIST_SEARCH:
return self->search_listbox;
+ case CC_PANEL_LIST_WIDGET:
+ return gtk_stack_get_child_by_name (GTK_STACK (self), "custom-widget");
+
default:
return NULL;
}
@@ -202,8 +205,12 @@ switch_to_view (CcPanelList *self,
/* For non-search views, make sure the displayed panel matches the
* newly selected row
*/
- if (self->autoselect_panel && view != CC_PANEL_LIST_SEARCH)
- cc_panel_list_activate (self);
+ if (self->autoselect_panel &&
+ view != CC_PANEL_LIST_SEARCH &&
+ self->previous_view != CC_PANEL_LIST_WIDGET)
+ {
+ cc_panel_list_activate (self);
+ }
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VIEW]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SEARCH_MODE]);
@@ -602,6 +609,15 @@ row_activated_cb (GtkWidget *listbox,
data = g_object_get_data (G_OBJECT (row), "data");
+ /* If the activated row is relative to the current panel, and it has
+ * a custom widget, show the custom widget again.
+ */
+ if (g_strcmp0 (data->id, self->current_panel_id) == 0 &&
+ gtk_stack_get_child_by_name (GTK_STACK (self), "custom-widget") != NULL)
+ {
+ switch_to_view (self, CC_PANEL_LIST_WIDGET);
+ }
+
g_signal_emit (self, signals[SHOW_PANEL], 0, data->id);
out:
@@ -866,6 +882,8 @@ cc_panel_list_activate (CcPanelList *self)
g_return_val_if_fail (CC_IS_PANEL_LIST (self), FALSE);
listbox = get_widget_from_view (self, self->view);
+ if (!GTK_IS_LIST_BOX (listbox))
+ CC_RETURN (FALSE);
/* Select the first visible row */
do
@@ -923,9 +941,28 @@ cc_panel_list_get_view (CcPanelList *self)
void
cc_panel_list_go_previous (CcPanelList *self)
{
+ CcPanelListView previous_view;
+
g_return_if_fail (CC_IS_PANEL_LIST (self));
- switch_to_view (self, self->previous_view);
+ previous_view = self->previous_view;
+
+ /* The back button is only visible and clickable outside the main view. If
+ * the previous view is the widget view itself, it means we went from:
+ *
+ * Main → Details or Devices → Widget
+ *
+ * to
+ * Main → Details or Devices
+ *
+ * To avoid a loop (Details or Devices → Widget → Details or Devices → ...),
+ * make sure to go back to the main view when the current view is details or
+ * devices.
+ */
+ if (previous_view == CC_PANEL_LIST_WIDGET)
+ previous_view = CC_PANEL_LIST_MAIN;
+
+ switch_to_view (self, previous_view);
}
void
@@ -1023,7 +1060,8 @@ cc_panel_list_set_active_panel (CcPanelList *self,
*/
self->autoselect_panel = FALSE;
- g_signal_emit_by_name (data->row, "activate");
+ if (self->view != CC_PANEL_LIST_WIDGET)
+ g_signal_emit_by_name (data->row, "activate");
/* Store the current panel id */
g_clear_pointer (&self->current_panel_id, g_free);
@@ -1067,3 +1105,23 @@ cc_panel_list_set_panel_visibility (CcPanelList *self,
gtk_widget_set_visible (data->row, visibility == CC_PANEL_VISIBLE);
gtk_widget_set_visible (search_data->row, visibility =! CC_PANEL_HIDDEN);
}
+
+void
+cc_panel_list_add_sidebar_widget (CcPanelList *self,
+ GtkWidget *widget)
+{
+ g_return_if_fail (CC_IS_PANEL_LIST (self));
+
+ if (widget)
+ {
+ gtk_stack_add_named (GTK_STACK (self), widget, "custom-widget");
+ switch_to_view (self, CC_PANEL_LIST_WIDGET);
+ }
+ else
+ {
+ widget = get_widget_from_view (self, CC_PANEL_LIST_WIDGET);
+
+ if (widget)
+ gtk_container_remove (GTK_CONTAINER (self), widget);
+ }
+}
diff --git a/shell/cc-panel-list.h b/shell/cc-panel-list.h
index 343de0bcc..525734ea5 100644
--- a/shell/cc-panel-list.h
+++ b/shell/cc-panel-list.h
@@ -33,6 +33,7 @@ typedef enum
CC_PANEL_LIST_MAIN,
CC_PANEL_LIST_DETAILS,
CC_PANEL_LIST_DEVICES,
+ CC_PANEL_LIST_WIDGET,
CC_PANEL_LIST_SEARCH
} CcPanelListView;
@@ -69,6 +70,9 @@ void cc_panel_list_set_panel_visibility (CcPanelList
const gchar *id,
CcPanelVisibility visibility);
+void cc_panel_list_add_sidebar_widget (CcPanelList *self,
+ GtkWidget *widget);
+
G_END_DECLS
#endif /* CC_PANEL_LIST_H */
diff --git a/shell/cc-window.c b/shell/cc-window.c
index 532b80626..f145e9cf9 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -161,6 +161,7 @@ activate_panel (CcWindow *self,
CcPanelVisibility visibility)
{
g_autoptr (GTimer) timer = NULL;
+ GtkWidget *sidebar_widget;
GtkWidget *title_widget;
gdouble ellapsed_time;
@@ -197,6 +198,9 @@ activate_panel (CcWindow *self,
title_widget = cc_panel_get_title_widget (CC_PANEL (self->current_panel));
gtk_header_bar_set_custom_title (GTK_HEADER_BAR (self->panel_headerbar), title_widget);
+ sidebar_widget = cc_panel_get_sidebar_widget (CC_PANEL (self->current_panel));
+ cc_panel_list_add_sidebar_widget (CC_PANEL_LIST (self->panel_list), sidebar_widget);
+
/* Finish profiling */
g_timer_stop (timer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]