[gnome-builder] stack splits



commit 2823e3acb649613856cba83202987c25e10236fa
Author: Christian Hergert <christian hergert me>
Date:   Wed Mar 18 18:25:43 2015 -0700

    stack splits

 src/views/gb-view-grid.c          |   78 +++++++++++++++++++++++++++++++++++++
 src/views/gb-view-grid.h          |   12 +++++-
 src/views/gb-view-stack-actions.c |   15 +++++++
 src/views/gb-view-stack.c         |   14 +++++++
 4 files changed, 118 insertions(+), 1 deletions(-)
---
diff --git a/src/views/gb-view-grid.c b/src/views/gb-view-grid.c
index 5c9e09b..27a5600 100644
--- a/src/views/gb-view-grid.c
+++ b/src/views/gb-view-grid.c
@@ -231,6 +231,56 @@ cleanup:
   g_list_free (stacks);
 }
 
+static void
+gb_view_grid_stack_split (GbViewGrid      *self,
+                          GbView          *view,
+                          GbViewGridSplit  split,
+                          GbViewStack     *stack)
+{
+  GbDocument *document;
+  GtkWidget *target;
+  GtkWidget *new_view;
+
+  g_assert (GB_IS_VIEW (view));
+  g_assert (GB_IS_VIEW_GRID (self));
+  g_assert (GB_IS_VIEW_STACK (stack));
+
+  document = gb_view_get_document (view);
+  if (document == NULL)
+    return;
+
+  switch (split)
+    {
+    case GB_VIEW_GRID_SPLIT_LEFT:
+      target = gb_view_grid_get_stack_before (self, stack);
+      if (target == NULL)
+        target = gb_view_grid_add_stack_before (self, stack);
+      new_view = gb_document_create_view (document);
+      if (new_view == NULL)
+        return;
+      gb_view_stack_focus_document (GB_VIEW_STACK (target), document);
+      break;
+
+    case GB_VIEW_GRID_SPLIT_RIGHT:
+      target = gb_view_grid_get_stack_after (self, stack);
+      if (target == NULL)
+        target = gb_view_grid_add_stack_after (self, stack);
+      new_view = gb_document_create_view (document);
+      if (new_view == NULL)
+        return;
+      gb_view_stack_focus_document (GB_VIEW_STACK (target), document);
+      break;
+
+    case GB_VIEW_GRID_MOVE_RIGHT:
+    case GB_VIEW_GRID_MOVE_LEFT:
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+}
+
 static GtkPaned *
 gb_view_grid_create_paned (GbViewGrid *self)
 {
@@ -257,6 +307,12 @@ gb_view_grid_create_stack (GbViewGrid *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  g_signal_connect_object (stack,
+                           "split",
+                           G_CALLBACK (gb_view_grid_stack_split),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   return stack;
 }
 
@@ -629,3 +685,25 @@ gb_view_grid_init (GbViewGrid *self)
 
   gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (paned));
 }
+
+GType
+gb_view_grid_split_get_type (void)
+{
+  static gsize type_id;
+
+  if (g_once_init_enter (&type_id))
+    {
+      static const GEnumValue values[] = {
+        { GB_VIEW_GRID_SPLIT_LEFT, "GB_VIEW_GRID_SPLIT_LEFT", "split-left" },
+        { GB_VIEW_GRID_SPLIT_RIGHT, "GB_VIEW_GRID_SPLIT_RIGHT", "split-right" },
+        { GB_VIEW_GRID_MOVE_LEFT, "GB_VIEW_GRID_MOVE_LEFT", "move-left" },
+        { GB_VIEW_GRID_MOVE_RIGHT, "GB_VIEW_GRID_MOVE_RIGHT", "move-right" },
+      };
+      gsize _type_id;
+
+      _type_id = g_enum_register_static ("GbViewGridSplit", values);
+      g_once_init_leave (&type_id, _type_id);
+    }
+
+  return type_id;
+}
diff --git a/src/views/gb-view-grid.h b/src/views/gb-view-grid.h
index acf915c..0873e11 100644
--- a/src/views/gb-view-grid.h
+++ b/src/views/gb-view-grid.h
@@ -26,10 +26,20 @@
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_VIEW_GRID (gb_view_grid_get_type())
+#define GB_TYPE_VIEW_GRID       (gb_view_grid_get_type())
+#define GB_TYPE_VIEW_GRID_SPLIT (gb_view_grid_split_get_type())
 
 G_DECLARE_FINAL_TYPE (GbViewGrid, gb_view_grid, GB, VIEW_GRID, GtkBin)
 
+typedef enum
+{
+  GB_VIEW_GRID_SPLIT_LEFT,
+  GB_VIEW_GRID_SPLIT_RIGHT,
+  GB_VIEW_GRID_MOVE_LEFT,
+  GB_VIEW_GRID_MOVE_RIGHT,
+} GbViewGridSplit;
+
+GType      gb_view_grid_split_get_type       (void);
 GtkWidget *gb_view_grid_new                  (void);
 GtkWidget *gb_view_grid_add_stack_after      (GbViewGrid  *grid,
                                               GbViewStack *stack);
diff --git a/src/views/gb-view-stack-actions.c b/src/views/gb-view-stack-actions.c
index da8fac5..2433da1 100644
--- a/src/views/gb-view-stack-actions.c
+++ b/src/views/gb-view-stack-actions.c
@@ -19,6 +19,7 @@
 #define G_LOG_DOMAIN "gb-view-stack"
 
 #include "gb-view.h"
+#include "gb-view-grid.h"
 #include "gb-view-stack.h"
 #include "gb-view-stack-actions.h"
 #include "gb-view-stack-private.h"
@@ -100,8 +101,15 @@ gb_view_stack_actions_split_left (GSimpleAction *action,
                                   gpointer       user_data)
 {
   GbViewStack *self = user_data;
+  GtkWidget *active_view;
 
   g_assert (GB_IS_VIEW_STACK (self));
+
+  active_view = gb_view_stack_get_active_view (self);
+  if (active_view == NULL || !GB_IS_VIEW (active_view))
+    return;
+
+  g_signal_emit_by_name (self, "split", active_view, GB_VIEW_GRID_SPLIT_LEFT);
 }
 
 static void
@@ -110,8 +118,15 @@ gb_view_stack_actions_split_right (GSimpleAction *action,
                                    gpointer       user_data)
 {
   GbViewStack *self = user_data;
+  GtkWidget *active_view;
 
   g_assert (GB_IS_VIEW_STACK (self));
+
+  active_view = gb_view_stack_get_active_view (self);
+  if (active_view == NULL || !GB_IS_VIEW (active_view))
+    return;
+
+  g_signal_emit_by_name (self, "split", active_view, GB_VIEW_GRID_SPLIT_RIGHT);
 }
 
 static const GActionEntry gGbViewStackActions[] = {
diff --git a/src/views/gb-view-stack.c b/src/views/gb-view-stack.c
index e78cc25..8901b3b 100644
--- a/src/views/gb-view-stack.c
+++ b/src/views/gb-view-stack.c
@@ -20,6 +20,7 @@
 #include <ide.h>
 
 #include "gb-view.h"
+#include "gb-view-grid.h"
 #include "gb-view-stack.h"
 #include "gb-view-stack-actions.h"
 #include "gb-view-stack-private.h"
@@ -35,6 +36,7 @@ enum {
 
 enum {
   EMPTY,
+  SPLIT,
   LAST_SIGNAL
 };
 
@@ -256,6 +258,17 @@ gb_view_stack_class_init (GbViewStackClass *klass)
                                    G_TYPE_NONE,
                                    0);
 
+  gSignals [SPLIT] = g_signal_new ("split",
+                                   G_TYPE_FROM_CLASS (klass),
+                                   G_SIGNAL_RUN_LAST,
+                                   0,
+                                   NULL, NULL,
+                                   g_cclosure_marshal_generic,
+                                   G_TYPE_NONE,
+                                   2,
+                                   GB_TYPE_VIEW,
+                                   GB_TYPE_VIEW_GRID_SPLIT);
+
   GB_WIDGET_CLASS_TEMPLATE (klass, "gb-view-stack.ui");
   GB_WIDGET_CLASS_BIND (klass, GbViewStack, controls_stack);
   GB_WIDGET_CLASS_BIND (klass, GbViewStack, go_backward);
@@ -384,6 +397,7 @@ gb_view_stack_focus_document (GbViewStack *self,
   if (view != NULL && GB_IS_VIEW (view))
     {
       gb_view_stack_set_active_view (self, view);
+      gtk_widget_grab_focus (view);
       return;
     }
 


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