[gnome-builder] editor: lazily track sidebar toggle state to gsettings



commit 51c2c9b958cf7bbfc726b732acd24b85b36a99ff
Author: Christian Hergert <christian hergert me>
Date:   Thu Apr 9 15:21:27 2015 -0700

    editor: lazily track sidebar toggle state to gsettings

 .../org.gnome.builder.editor.gschema.xml.in        |    5 +++
 src/editor/gb-editor-workspace-actions.c           |   28 ++++++++++++++++++++
 src/editor/gb-editor-workspace-private.h           |    1 +
 src/editor/gb-editor-workspace.c                   |    7 +++++
 4 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.editor.gschema.xml.in 
b/data/gsettings/org.gnome.builder.editor.gschema.xml.in
index 8565165..97e6fa3 100644
--- a/data/gsettings/org.gnome.builder.editor.gschema.xml.in
+++ b/data/gsettings/org.gnome.builder.editor.gschema.xml.in
@@ -63,5 +63,10 @@
       <range min="0" max="999"/>
       <default>0</default>
     </key>
+    <key name="show-sidebar" type="b">
+      <default>false</default>
+      <summary>Show Project Sidebar</summary>
+      <description>If enabled, the sidebar will be visible in the editor workspace.</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/editor/gb-editor-workspace-actions.c b/src/editor/gb-editor-workspace-actions.c
index f10f3f0..95a3dc7 100644
--- a/src/editor/gb-editor-workspace-actions.c
+++ b/src/editor/gb-editor-workspace-actions.c
@@ -89,6 +89,17 @@ gb_editor_workspace_actions_toggle_sidebar (GSimpleAction *action,
   g_variant_unref (state);
 }
 
+static void
+gb_editor_workspace_actions__show_sidebar_notify_state (GbEditorWorkspace *self,
+                                                        GParamSpec        *pspec,
+                                                        GAction           *action)
+{
+  g_autoptr(GVariant) state = NULL;
+
+  state = g_action_get_state (action);
+  g_settings_set_boolean (self->editor_settings, "show-sidebar", g_variant_get_boolean (state));
+}
+
 static const GActionEntry GbEditorWorkspaceActions[] = {
   { "show-sidebar", NULL, NULL, "false", gb_editor_workspace_actions_show_sidebar },
   { "toggle-sidebar", gb_editor_workspace_actions_toggle_sidebar },
@@ -98,9 +109,26 @@ void
 gb_editor_workspace_actions_init (GbEditorWorkspace *self)
 {
   g_autoptr(GSimpleActionGroup) group = NULL;
+  GAction *action;
 
   group = g_simple_action_group_new ();
   g_action_map_add_action_entries (G_ACTION_MAP (group), GbEditorWorkspaceActions,
                                    G_N_ELEMENTS (GbEditorWorkspaceActions), self);
   gtk_widget_insert_action_group (GTK_WIDGET (self), "workspace", G_ACTION_GROUP (group));
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (group), "show-sidebar");
+  g_assert (G_IS_SIMPLE_ACTION (action));
+
+  if (g_settings_get_boolean (self->editor_settings, "show-sidebar"))
+    {
+      g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (TRUE));
+      gtk_paned_set_position (self->project_paned, self->sidebar_position);
+      gtk_widget_show (GTK_WIDGET (self->project_sidebar));
+    }
+
+  g_signal_connect_object (action,
+                           "notify::state",
+                           G_CALLBACK (gb_editor_workspace_actions__show_sidebar_notify_state),
+                           self,
+                           G_CONNECT_SWAPPED);
 }
diff --git a/src/editor/gb-editor-workspace-private.h b/src/editor/gb-editor-workspace-private.h
index e849799..9d650c8 100644
--- a/src/editor/gb-editor-workspace-private.h
+++ b/src/editor/gb-editor-workspace-private.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
 struct _GbEditorWorkspace
 {
   GbWorkspace    parent_instance;
+  GSettings     *editor_settings;
 
   GtkPaned      *project_paned;
   GtkBox        *project_sidebar;
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index e50eebd..1d7b7df 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -154,6 +154,7 @@ gb_editor_workspace_constructed (GObject *object)
 
   G_OBJECT_CLASS (gb_editor_workspace_parent_class)->constructed (object);
 
+  self->editor_settings = g_settings_new ("org.gnome.builder.editor");
   self->sidebar_position = gtk_paned_get_position (self->project_paned) ?: SIDEBAR_POSITION;
 
   gb_editor_workspace_actions_init (self);
@@ -165,8 +166,14 @@ gb_editor_workspace_constructed (GObject *object)
 static void
 gb_editor_workspace_finalize (GObject *object)
 {
+  GbEditorWorkspace *self = (GbEditorWorkspace *)object;
+
   IDE_ENTRY;
+
+  g_clear_object (&self->editor_settings);
+
   G_OBJECT_CLASS (gb_editor_workspace_parent_class)->finalize (object);
+
   IDE_EXIT;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]