[gnome-builder] libide: hook up panel actions



commit 40407e7a41cf76f4cbbd152d8e7326a9db87fc54
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 13 02:38:43 2015 -0800

    libide: hook up panel actions

 data/ui/ide-editor-perspective.ui      |    3 +
 libide/editor/ide-editor-perspective.c |   44 +++++++++++++++++++++
 libide/ide-layout.c                    |   65 ++++++++++++++++++++++++++++++++
 3 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/ide-editor-perspective.ui b/data/ui/ide-editor-perspective.ui
index d2a3ed4..3e99139 100644
--- a/data/ui/ide-editor-perspective.ui
+++ b/data/ui/ide-editor-perspective.ui
@@ -32,6 +32,7 @@
         </style>
         <child>
           <object class="GtkToggleButton">
+            <property name="action-name">panels.left</property>
             <property name="focus-on-click">false</property>
             <property name="visible">true</property>
             <style>
@@ -47,6 +48,7 @@
         </child>
         <child>
           <object class="GtkToggleButton">
+            <property name="action-name">panels.bottom</property>
             <property name="focus-on-click">false</property>
             <property name="visible">true</property>
             <style>
@@ -62,6 +64,7 @@
         </child>
         <child>
           <object class="GtkToggleButton">
+            <property name="action-name">panels.right</property>
             <property name="focus-on-click">false</property>
             <property name="visible">true</property>
             <style>
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 7334c4c..9b4fb6f 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -43,6 +43,43 @@ enum {
 static GParamSpec *properties [LAST_PROP];
 
 static void
+ide_editor_perspective_restore_panel_state (IdeEditorPerspective *self)
+{
+  g_autoptr(GSettings) settings = NULL;
+  GtkWidget *pane;
+  gboolean reveal;
+  guint position;
+
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (self));
+
+  settings = g_settings_new ("org.gnome.builder.workbench");
+
+  pane = ide_layout_get_left_pane (IDE_LAYOUT (self));
+  reveal = g_settings_get_boolean (settings, "left-visible");
+  position = g_settings_get_int (settings, "left-position");
+  gtk_container_child_set (GTK_CONTAINER (self), pane,
+                           "position", position,
+                           "reveal", reveal,
+                           NULL);
+
+  pane = ide_layout_get_right_pane (IDE_LAYOUT (self));
+  reveal = g_settings_get_boolean (settings, "right-visible");
+  position = g_settings_get_int (settings, "right-position");
+  gtk_container_child_set (GTK_CONTAINER (self), pane,
+                           "position", position,
+                           "reveal", reveal,
+                           NULL);
+
+  pane = ide_layout_get_bottom_pane (IDE_LAYOUT (self));
+  reveal = g_settings_get_boolean (settings, "bottom-visible");
+  position = g_settings_get_int (settings, "bottom-position");
+  gtk_container_child_set (GTK_CONTAINER (self), pane,
+                           "position", position,
+                           "reveal", reveal,
+                           NULL);
+}
+
+static void
 ide_editor_perspective_finalize (GObject *object)
 {
   G_OBJECT_CLASS (ide_editor_perspective_parent_class)->finalize (object);
@@ -91,7 +128,14 @@ ide_editor_perspective_class_init (IdeEditorPerspectiveClass *klass)
 static void
 ide_editor_perspective_init (IdeEditorPerspective *self)
 {
+  GActionGroup *actions;
+
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  actions = gtk_widget_get_action_group (GTK_WIDGET (self), "panels");
+  gtk_widget_insert_action_group (GTK_WIDGET (self->titlebar), "panels", actions);
+
+  ide_editor_perspective_restore_panel_state (self);
 }
 
 static gchar *
diff --git a/libide/ide-layout.c b/libide/ide-layout.c
index cb1feb1..207c190 100644
--- a/libide/ide-layout.c
+++ b/libide/ide-layout.c
@@ -1136,9 +1136,67 @@ ide_layout_class_init (IdeLayoutClass *klass)
 }
 
 static void
+ide_layout_activate_left (GSimpleAction *action,
+                          GVariant      *param,
+                          gpointer       user_data)
+{
+  IdeLayout *self = user_data;
+  GtkWidget *child;
+  gboolean reveal;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_LAYOUT (self));
+
+  child = ide_layout_get_left_pane (self);
+  reveal = ide_layout_child_get_reveal (self, child);
+  gtk_container_child_set (GTK_CONTAINER (self), child, "reveal", !reveal, NULL);
+}
+
+static void
+ide_layout_activate_right (GSimpleAction *action,
+                           GVariant      *param,
+                           gpointer       user_data)
+{
+  IdeLayout *self = user_data;
+  GtkWidget *child;
+  gboolean reveal;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_LAYOUT (self));
+
+  child = ide_layout_get_right_pane (self);
+  reveal = ide_layout_child_get_reveal (self, child);
+  gtk_container_child_set (GTK_CONTAINER (self), child, "reveal", !reveal, NULL);
+}
+
+static void
+ide_layout_activate_bottom (GSimpleAction *action,
+                            GVariant      *param,
+                            gpointer       user_data)
+{
+  IdeLayout *self = user_data;
+  GtkWidget *child;
+  gboolean reveal;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_LAYOUT (self));
+
+  child = ide_layout_get_bottom_pane (self);
+  reveal = ide_layout_child_get_reveal (self, child);
+  gtk_container_child_set (GTK_CONTAINER (self), child, "reveal", !reveal, NULL);
+}
+
+static const GActionEntry action_entries[] = {
+  { "left", ide_layout_activate_left, NULL, "true" },
+  { "right", ide_layout_activate_right, NULL, "false" },
+  { "bottom", ide_layout_activate_bottom, NULL, "false" },
+};
+
+static void
 ide_layout_init (IdeLayout *self)
 {
   IdeLayoutPrivate *priv = ide_layout_get_instance_private (self);
+  g_autoptr(GSimpleActionGroup) actions = NULL;
 
   priv->children [GTK_POS_LEFT].type = GTK_POS_LEFT;
   priv->children [GTK_POS_LEFT].reveal = TRUE;
@@ -1165,6 +1223,13 @@ ide_layout_init (IdeLayout *self)
   priv->pan_gesture = ide_layout_create_pan_gesture (self, GTK_ORIENTATION_HORIZONTAL);
 
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  actions = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (actions),
+                                   action_entries,
+                                   G_N_ELEMENTS (action_entries),
+                                   self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "panels", G_ACTION_GROUP (actions));
 }
 
 GtkWidget *


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