[gnome-builder/wip/libide-merge: 11/35] vertical splits



commit 798d86631a9f04ea15bd75078016cbc78f4dcdd3
Author: Christian Hergert <christian hergert me>
Date:   Wed Mar 18 16:13:08 2015 -0700

    vertical splits

 data/ui/gb-editor-view.ui            |    5 ++++
 src/editor/gb-editor-frame-private.h |    4 ++-
 src/editor/gb-editor-frame.c         |   36 +++++++++++++++++++++++++++++---
 src/editor/gb-editor-view.c          |   37 ++++++++++++++++++++++++++++++++++
 src/views/gb-view-stack-actions.c    |   16 +++++++++++++-
 src/views/gb-view.c                  |   17 +++++++++++++++
 src/views/gb-view.h                  |   22 ++++++++++++--------
 7 files changed, 122 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/gb-editor-view.ui b/data/ui/gb-editor-view.ui
index d62ab1b..14cd987 100644
--- a/data/ui/gb-editor-view.ui
+++ b/data/ui/gb-editor-view.ui
@@ -19,11 +19,16 @@
         <child>
           <object class="GtkPaned" id="paned">
             <property name="expand">true</property>
+            <property name="orientation">vertical</property>
             <property name="visible">true</property>
             <child>
               <object class="GbEditorFrame" id="frame1">
                 <property name="visible">true</property>
               </object>
+              <packing>
+                <property name="resize">true</property>
+                <property name="shrink">false</property>
+              </packing>
             </child>
           </object>
         </child>
diff --git a/src/editor/gb-editor-frame-private.h b/src/editor/gb-editor-frame-private.h
index 41957d6..65fe097 100644
--- a/src/editor/gb-editor-frame-private.h
+++ b/src/editor/gb-editor-frame-private.h
@@ -29,13 +29,15 @@ G_BEGIN_DECLS
 
 struct _GbEditorFrame
 {
-  GtkBin             parent_instance;
+  GtkBin               parent_instance;
 
   NautilusFloatingBar *floating_bar;
   GtkScrolledWindow   *scrolled_window;
   GtkRevealer         *search_revealer;
   GdTaggedEntry       *search_entry;
   IdeSourceView       *source_view;
+
+  gulong               cursor_moved_handler;
 };
 
 G_END_DECLS
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index a2976d3..9658ecd 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -85,12 +85,19 @@ void
 gb_editor_frame_set_document (GbEditorFrame    *self,
                               GbEditorDocument *document)
 {
+  GtkTextMark *mark;
+  GtkTextIter iter;
+
   g_return_if_fail (GB_IS_EDITOR_FRAME (self));
   g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
 
   gtk_text_view_set_buffer (GTK_TEXT_VIEW (self->source_view), GTK_TEXT_BUFFER (document));
-  g_signal_connect (document, "cursor-moved", G_CALLBACK (on_cursor_moved), self);
+  self->cursor_moved_handler = g_signal_connect (document, "cursor-moved", G_CALLBACK (on_cursor_moved), 
self);
   g_object_bind_property (document, "busy", self->floating_bar, "show-spinner", G_BINDING_SYNC_CREATE);
+
+  mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (document));
+  gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (document), &iter, mark);
+  on_cursor_moved (document, &iter, self);
 }
 
 static gboolean
@@ -118,9 +125,27 @@ keybindings_changed (GSettings     *settings,
 }
 
 static void
-gb_editor_frame_finalize (GObject *object)
+gb_editor_frame_grab_focus (GtkWidget *widget)
 {
-  G_OBJECT_CLASS (gb_editor_frame_parent_class)->finalize (object);
+  GbEditorFrame *self = (GbEditorFrame *)widget;
+
+  gtk_widget_grab_focus (GTK_WIDGET (self->source_view));
+}
+
+static void
+gb_editor_frame_dispose (GObject *object)
+{
+  GbEditorFrame *self = (GbEditorFrame *)object;
+
+  if (self->source_view && self->cursor_moved_handler)
+    {
+      GtkTextBuffer *buffer;
+
+      buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view));
+      ide_clear_signal_handler (buffer, &self->cursor_moved_handler);
+    }
+
+  G_OBJECT_CLASS (gb_editor_frame_parent_class)->dispose (object);
 }
 
 static void
@@ -165,11 +190,14 @@ static void
 gb_editor_frame_class_init (GbEditorFrameClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  object_class->finalize = gb_editor_frame_finalize;
+  object_class->dispose = gb_editor_frame_dispose;
   object_class->get_property = gb_editor_frame_get_property;
   object_class->set_property = gb_editor_frame_set_property;
 
+  widget_class->grab_focus = gb_editor_frame_grab_focus;
+
   gParamSpecs [PROP_DOCUMENT] =
     g_param_spec_object ("document",
                          _("Document"),
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index 99358a3..fc50394 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -117,6 +117,42 @@ gb_editor_view_grab_focus (GtkWidget *widget)
 }
 
 static void
+gb_editor_view_set_split_view (GbView   *view,
+                               gboolean  split_view)
+{
+  GbEditorView *self = (GbEditorView *)view;
+
+  g_assert (GB_IS_EDITOR_VIEW (self));
+
+  if (split_view && (self->frame2 != NULL))
+    return;
+
+  if (!split_view && (self->frame2 == NULL))
+    return;
+
+  if (split_view)
+    {
+      self->frame2 = g_object_new (GB_TYPE_EDITOR_FRAME,
+                                   "document", self->document,
+                                   "visible", TRUE,
+                                   NULL);
+      gtk_container_add_with_properties (GTK_CONTAINER (self->paned), GTK_WIDGET (self->frame2),
+                                         "shrink", FALSE,
+                                         "resize", TRUE,
+                                         NULL);
+      gtk_widget_grab_focus (GTK_WIDGET (self->frame2));
+    }
+  else
+    {
+      GtkWidget *copy = GTK_WIDGET (self->frame2);
+
+      self->frame2 = NULL;
+      gtk_container_remove (GTK_CONTAINER (self->paned), copy);
+      gtk_widget_grab_focus (GTK_WIDGET (self->frame1));
+    }
+}
+
+static void
 gb_editor_view_finalize (GObject *object)
 {
   GbEditorView *self = (GbEditorView *)object;
@@ -180,6 +216,7 @@ gb_editor_view_class_init (GbEditorViewClass *klass)
 
   view_class->create_split = gb_editor_view_create_split;
   view_class->get_document = gb_editor_view_get_document;
+  view_class->set_split_view = gb_editor_view_set_split_view;
 
   gParamSpecs [PROP_DOCUMENT] =
     g_param_spec_object ("document",
diff --git a/src/views/gb-view-stack-actions.c b/src/views/gb-view-stack-actions.c
index 6426426..da8fac5 100644
--- a/src/views/gb-view-stack-actions.c
+++ b/src/views/gb-view-stack-actions.c
@@ -16,6 +16,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define G_LOG_DOMAIN "gb-view-stack"
+
+#include "gb-view.h"
 #include "gb-view-stack.h"
 #include "gb-view-stack-actions.h"
 #include "gb-view-stack-private.h"
@@ -76,8 +79,19 @@ gb_view_stack_actions_split_down (GSimpleAction *action,
                                   gpointer       user_data)
 {
   GbViewStack *self = user_data;
+  GtkWidget *active_view;
+  gboolean split_view;
 
   g_assert (GB_IS_VIEW_STACK (self));
+
+  active_view = gb_view_stack_get_active_view (self);
+  if (!GB_IS_VIEW (active_view))
+    return;
+
+  split_view = g_variant_get_boolean (param);
+  gb_view_set_split_view (GB_VIEW (active_view), split_view);
+
+  g_simple_action_set_state (action, param);
 }
 
 static void
@@ -106,7 +120,7 @@ static const GActionEntry gGbViewStackActions[] = {
   { "move-right",  gb_view_stack_actions_move_right },
   { "save",        gb_view_stack_actions_save },
   { "save-as",     gb_view_stack_actions_save_as },
-  { "split-down",  gb_view_stack_actions_split_down },
+  { "split-down",  NULL, NULL, "false", gb_view_stack_actions_split_down },
   { "split-left",  gb_view_stack_actions_split_left },
   { "split-right", gb_view_stack_actions_split_right },
 };
diff --git a/src/views/gb-view.c b/src/views/gb-view.c
index 963e184..5420855 100644
--- a/src/views/gb-view.c
+++ b/src/views/gb-view.c
@@ -81,6 +81,23 @@ gb_view_create_split (GbView *self)
 }
 
 /**
+ * gb_view_set_split_view:
+ * @self: A #GbView.
+ * @split_view: if the split should be enabled.
+ *
+ * Set a split view using GtkPaned style split with %GTK_ORIENTATION_VERTICAL.
+ */
+void
+gb_view_set_split_view (GbView   *self,
+                        gboolean  split_view)
+{
+  g_return_if_fail (GB_IS_VIEW (self));
+
+  if (GB_VIEW_GET_CLASS (self)->set_split_view)
+    GB_VIEW_GET_CLASS (self)->set_split_view (self, split_view);
+}
+
+/**
  * gb_view_get_controls:
  * @self: A #GbView.
  *
diff --git a/src/views/gb-view.h b/src/views/gb-view.h
index 86b9019..2442b9a 100644
--- a/src/views/gb-view.h
+++ b/src/views/gb-view.h
@@ -33,17 +33,21 @@ struct _GbViewClass
 {
   GtkBinClass parent;
 
-  gboolean     (*get_can_split) (GbView *self);
-  GbDocument  *(*get_document)  (GbView *self);
-  const gchar *(*get_title)     (GbView *self);
-  GbView      *(*create_split)  (GbView *self);
+  gboolean     (*get_can_split)   (GbView *self);
+  GbDocument  *(*get_document)    (GbView *self);
+  const gchar *(*get_title)       (GbView *self);
+  GbView      *(*create_split)    (GbView *self);
+  void         (*set_split_view)  (GbView   *self,
+                                   gboolean  split_view);
 };
 
-GbView      *gb_view_create_split  (GbView *self);
-gboolean     gb_view_get_can_split (GbView *self);
-GbDocument  *gb_view_get_document  (GbView *self);
-const gchar *gb_view_get_title     (GbView *self);
-GtkWidget   *gb_view_get_controls  (GbView *self);
+GbView      *gb_view_create_split   (GbView   *self);
+gboolean     gb_view_get_can_split  (GbView   *self);
+GbDocument  *gb_view_get_document   (GbView   *self);
+const gchar *gb_view_get_title      (GbView   *self);
+GtkWidget   *gb_view_get_controls   (GbView   *self);
+void         gb_view_set_split_view (GbView   *self,
+                                     gboolean  split_view);
 
 G_END_DECLS
 


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