[libdazzle] prefs: allow toggling use of sidebar
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] prefs: allow toggling use of sidebar
- Date: Tue, 12 Jun 2018 07:08:42 +0000 (UTC)
commit a1f2ff6b902dd0d74317cd75eebc3401bda7fa5d
Author: Christian Hergert <chergert redhat com>
Date: Tue Jun 12 00:04:46 2018 -0700
prefs: allow toggling use of sidebar
When disabling the sidebar, we lose the search entry. But it does seem to
be a useful option for some cases.
data/themes/shared/shared-preferences.css | 4 ++
src/prefs/dzl-preferences-view.c | 98 ++++++++++++++++++++++++++++++-
src/prefs/dzl-preferences-view.h | 19 +++---
src/prefs/dzl-preferences-view.ui | 45 +++++++++-----
tests/test-preferences.c | 15 +++++
5 files changed, 154 insertions(+), 27 deletions(-)
---
diff --git a/data/themes/shared/shared-preferences.css b/data/themes/shared/shared-preferences.css
index 0b3079c..12ecd08 100644
--- a/data/themes/shared/shared-preferences.css
+++ b/data/themes/shared/shared-preferences.css
@@ -40,3 +40,7 @@ dzlpreferencesview dzlpreferencesgroup list entry {
background: none;
min-height: 0px;
}
+
+dzlpreferencesview stackswitcher {
+ margin: 12px;
+}
diff --git a/src/prefs/dzl-preferences-view.c b/src/prefs/dzl-preferences-view.c
index 683e762..8afacad 100644
--- a/src/prefs/dzl-preferences-view.c
+++ b/src/prefs/dzl-preferences-view.c
@@ -39,11 +39,15 @@ typedef struct
GtkScrolledWindow *scroller;
GtkStack *page_stack;
- GtkStackSwitcher *page_stack_sidebar;
+ GtkStackSidebar *page_stack_sidebar;
GtkSearchEntry *search_entry;
GtkStack *subpage_stack;
+ GtkBox *sidebar;
+ GtkStackSwitcher *top_stack_switcher;
guint last_widget_id;
+
+ guint use_sidebar : 1;
} DzlPreferencesViewPrivate;
typedef struct
@@ -59,6 +63,14 @@ G_DEFINE_TYPE_WITH_CODE (DzlPreferencesView, dzl_preferences_view, GTK_TYPE_BIN,
G_ADD_PRIVATE (DzlPreferencesView)
G_IMPLEMENT_INTERFACE (DZL_TYPE_PREFERENCES, dzl_preferences_iface_init))
+enum {
+ PROP_0,
+ PROP_USE_SIDEBAR,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
static void
tracked_widget_free (gpointer data)
{
@@ -216,6 +228,44 @@ dzl_preferences_view_finalize (GObject *object)
G_OBJECT_CLASS (dzl_preferences_view_parent_class)->finalize (object);
}
+static void
+dzl_preferences_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ DzlPreferencesView *self = DZL_PREFERENCES_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_USE_SIDEBAR:
+ g_value_set_boolean (value, dzl_preferences_view_get_use_sidebar (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+dzl_preferences_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DzlPreferencesView *self = DZL_PREFERENCES_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_USE_SIDEBAR:
+ dzl_preferences_view_set_use_sidebar (self, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
static void
dzl_preferences_view_class_init (DzlPreferencesViewClass *klass)
{
@@ -223,6 +273,8 @@ dzl_preferences_view_class_init (DzlPreferencesViewClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = dzl_preferences_view_finalize;
+ object_class->get_property = dzl_preferences_view_get_property;
+ object_class->set_property = dzl_preferences_view_set_property;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/dazzle/ui/dzl-preferences-view.ui");
gtk_widget_class_set_css_name (widget_class, "dzlpreferencesview");
@@ -230,7 +282,18 @@ dzl_preferences_view_class_init (DzlPreferencesViewClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, DzlPreferencesView, page_stack_sidebar);
gtk_widget_class_bind_template_child_private (widget_class, DzlPreferencesView, scroller);
gtk_widget_class_bind_template_child_private (widget_class, DzlPreferencesView, search_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, DzlPreferencesView, sidebar);
gtk_widget_class_bind_template_child_private (widget_class, DzlPreferencesView, subpage_stack);
+ gtk_widget_class_bind_template_child_private (widget_class, DzlPreferencesView, top_stack_switcher);
+
+ properties [PROP_USE_SIDEBAR] =
+ g_param_spec_boolean ("use-sidebar",
+ "Use Sidebar",
+ "Use Sidebar",
+ FALSE,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
@@ -299,6 +362,8 @@ dzl_preferences_view_init (DzlPreferencesView *self)
{ "go-back", go_back_activate },
};
+ priv->use_sidebar = TRUE;
+
gtk_widget_init_template (GTK_WIDGET (self));
g_signal_connect_object (priv->search_entry,
@@ -963,3 +1028,34 @@ dzl_preferences_view_new (void)
{
return g_object_new (DZL_TYPE_PREFERENCES_VIEW, NULL);
}
+
+gboolean
+dzl_preferences_view_get_use_sidebar (DzlPreferencesView *self)
+{
+ DzlPreferencesViewPrivate *priv = dzl_preferences_view_get_instance_private (self);
+
+ g_return_val_if_fail (DZL_IS_PREFERENCES_VIEW (self), FALSE);
+
+ return priv->use_sidebar;
+}
+
+void
+dzl_preferences_view_set_use_sidebar (DzlPreferencesView *self,
+ gboolean use_sidebar)
+{
+ DzlPreferencesViewPrivate *priv = dzl_preferences_view_get_instance_private (self);
+
+ g_return_if_fail (DZL_IS_PREFERENCES_VIEW (self));
+
+ use_sidebar = !!use_sidebar;
+
+ if (priv->use_sidebar != use_sidebar)
+ {
+ priv->use_sidebar = use_sidebar;
+
+ gtk_widget_set_visible (GTK_WIDGET (priv->sidebar), use_sidebar);
+ gtk_widget_set_visible (GTK_WIDGET (priv->top_stack_switcher), !use_sidebar);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_USE_SIDEBAR]);
+ }
+}
diff --git a/src/prefs/dzl-preferences-view.h b/src/prefs/dzl-preferences-view.h
index 417a50e..f3a282c 100644
--- a/src/prefs/dzl-preferences-view.h
+++ b/src/prefs/dzl-preferences-view.h
@@ -36,20 +36,19 @@ struct _DzlPreferencesViewClass
{
GtkBinClass parent_class;
- gpointer _reserved1;
- gpointer _reserved2;
- gpointer _reserved3;
- gpointer _reserved4;
- gpointer _reserved5;
- gpointer _reserved6;
- gpointer _reserved7;
- gpointer _reserved8;
+ /*< private >*/
+ gpointer _reserved[8];
};
DZL_AVAILABLE_IN_3_28
-GtkWidget *dzl_preferences_view_new (void);
+GtkWidget *dzl_preferences_view_new (void);
DZL_AVAILABLE_IN_ALL
-void dzl_preferences_view_reapply_filter (DzlPreferencesView *self);
+void dzl_preferences_view_reapply_filter (DzlPreferencesView *self);
+DZL_AVAILABLE_IN_3_30
+gboolean dzl_preferences_view_get_use_sidebar (DzlPreferencesView *self);
+DZL_AVAILABLE_IN_3_30
+void dzl_preferences_view_set_use_sidebar (DzlPreferencesView *self,
+ gboolean use_sidebar);
G_END_DECLS
diff --git a/src/prefs/dzl-preferences-view.ui b/src/prefs/dzl-preferences-view.ui
index 25bb738..c7aac68 100644
--- a/src/prefs/dzl-preferences-view.ui
+++ b/src/prefs/dzl-preferences-view.ui
@@ -7,7 +7,7 @@
<property name="orientation">horizontal</property>
<property name="visible">true</property>
<child>
- <object class="GtkBox">
+ <object class="GtkBox" id="sidebar">
<property name="orientation">vertical</property>
<property name="visible">true</property>
<child>
@@ -35,32 +35,45 @@
<property name="visible">true</property>
<child>
<object class="GtkBox">
- <property name="orientation">horizontal</property>
+ <property name="orientation">vertical</property>
<property name="visible">true</property>
<child>
- <object class="GtkStack" id="page_stack">
- <property name="margin">24</property>
- <property name="homogeneous">false</property>
- <property name="transition-duration">333</property>
- <property name="transition-type">crossfade</property>
- <property name="visible">true</property>
+ <object class="GtkStackSwitcher" id="top_stack_switcher">
+ <property name="stack">page_stack</property>
+ <property name="visible">false</property>
</object>
</child>
<child>
<object class="GtkBox">
- <property name="hexpand">true</property>
+ <property name="orientation">horizontal</property>
+ <property name="expand">true</property>
<property name="visible">true</property>
<child>
- <object class="GtkStack" id="subpage_stack">
- <property name="margin-start">0</property>
- <property name="margin-end">24</property>
- <property name="margin-top">24</property>
- <property name="margin-bottom">24</property>
- <property name="halign">start</property>
- <property name="hexpand">false</property>
+ <object class="GtkStack" id="page_stack">
+ <property name="margin">24</property>
<property name="homogeneous">false</property>
<property name="transition-duration">333</property>
<property name="transition-type">crossfade</property>
+ <property name="visible">true</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="hexpand">true</property>
+ <property name="visible">true</property>
+ <child>
+ <object class="GtkStack" id="subpage_stack">
+ <property name="margin-start">0</property>
+ <property name="margin-end">24</property>
+ <property name="margin-top">24</property>
+ <property name="margin-bottom">24</property>
+ <property name="halign">start</property>
+ <property name="hexpand">false</property>
+ <property name="homogeneous">false</property>
+ <property name="transition-duration">333</property>
+ <property name="transition-type">crossfade</property>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/tests/test-preferences.c b/tests/test-preferences.c
index 550f016..5ae50c7 100644
--- a/tests/test-preferences.c
+++ b/tests/test-preferences.c
@@ -65,6 +65,8 @@ main (gint argc,
gchar *argv[])
{
GtkWidget *window;
+ GtkWidget *headerbar;
+ GtkWidget *toggle;
GtkWidget *view;
gtk_init (&argc, &argv);
@@ -77,11 +79,24 @@ main (gint argc,
"default-height", 600,
NULL);
+ headerbar = g_object_new (GTK_TYPE_HEADER_BAR,
+ "show-close-button", TRUE,
+ "visible", TRUE,
+ NULL);
+ gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);
+
view = g_object_new (DZL_TYPE_PREFERENCES_VIEW,
"visible", TRUE,
NULL);
gtk_container_add (GTK_CONTAINER (window), view);
+ toggle = g_object_new (GTK_TYPE_SWITCH,
+ "visible", TRUE,
+ NULL);
+ g_object_bind_property (view, "use-sidebar", toggle, "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+ gtk_container_add (GTK_CONTAINER (headerbar), toggle);
+
add_preferences (DZL_PREFERENCES (view));
g_signal_connect (window, "delete-event", gtk_main_quit, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]