[gnome-builder] gb-editor-view: track focus on horizontal split views



commit 8611f1b01981ce55dd47944d68e5f5cec1579c50
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Tue Sep 29 18:15:53 2015 +0200

    gb-editor-view: track focus on horizontal split views
    
    immediate effects of this:
    
    - when you click on a symbol in the symbol panel,
      the right part of the split view is scrolling
      ( only the top before the patch )
    
    - when showing documentation's view, then closing it,
      or when selecting a file in the files list popover,
      the right part of the split view is re-focused again.

 src/editor/gb-editor-view-private.h |    1 +
 src/editor/gb-editor-view.c         |   60 ++++++++++++++++++++++++++++++++---
 2 files changed, 56 insertions(+), 5 deletions(-)
---
diff --git a/src/editor/gb-editor-view-private.h b/src/editor/gb-editor-view-private.h
index 596bdb2..ee90953 100644
--- a/src/editor/gb-editor-view-private.h
+++ b/src/editor/gb-editor-view-private.h
@@ -42,6 +42,7 @@ struct _GbEditorView
   GtkLabel            *cursor_label;
   GbEditorFrame       *frame1;
   GbEditorFrame       *frame2;
+  GbEditorFrame       *last_focused_frame;
   GtkButton           *modified_cancel_button;
   GtkRevealer         *modified_revealer;
   GtkPaned            *paned;
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index e6d8061..00a5b24 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -61,8 +61,9 @@ gb_editor_view_get_document (GbView *view)
 static GbEditorFrame *
 gb_editor_view_get_last_focused (GbEditorView *self)
 {
-  /* TODO: track focus */
-  return self->frame1;
+  g_assert (self->last_focused_frame != NULL);
+
+  return self->last_focused_frame;
 }
 
 static void
@@ -422,10 +423,9 @@ gb_editor_view_grab_focus (GtkWidget *widget)
   GbEditorView *self = (GbEditorView *)widget;
 
   g_assert (GB_IS_EDITOR_VIEW (self));
+  g_assert (GB_IS_EDITOR_FRAME (self->last_focused_frame));
 
-  /* todo: track last focus frame */
-
-  gtk_widget_grab_focus (GTK_WIDGET (self->frame1->source_view));
+  gtk_widget_grab_focus (GTK_WIDGET (self->last_focused_frame->source_view));
 }
 
 static void
@@ -450,6 +450,42 @@ gb_editor_view_request_documentation (GbEditorView  *self,
 }
 
 static void
+gb_editor_view__focused_frame_weak_notify (gpointer  data,
+                                           GObject  *object)
+{
+  GbEditorView  *self = data;
+
+  g_assert (GB_IS_EDITOR_VIEW (self));
+
+  self->last_focused_frame = self->frame1;
+}
+
+static gboolean
+gb_editor_view__focus_in_event (GbEditorView  *self,
+                                GdkEvent      *event,
+                                IdeSourceView *source_view)
+{
+  g_assert (GB_IS_EDITOR_VIEW (self));
+  g_assert (IDE_IS_SOURCE_VIEW (source_view));
+
+  if (self->last_focused_frame && self->last_focused_frame->source_view == source_view)
+      return FALSE;
+
+  if (self->frame2 && self->frame2->source_view == source_view)
+    {
+      self->last_focused_frame = self->frame2;
+      g_object_weak_ref (G_OBJECT (self->frame2), gb_editor_view__focused_frame_weak_notify, self);
+    }
+  else
+    {
+      g_object_weak_unref (G_OBJECT (self->frame2), gb_editor_view__focused_frame_weak_notify, self);
+      self->last_focused_frame = self->frame1;
+    }
+
+  return FALSE;
+}
+
+static void
 gb_editor_view_set_split_view (GbView   *view,
                                gboolean  split_view)
 {
@@ -475,6 +511,13 @@ gb_editor_view_set_split_view (GbView   *view,
                                G_CALLBACK (gb_editor_view_request_documentation),
                                self,
                                G_CONNECT_SWAPPED);
+
+      g_signal_connect_object (self->frame2->source_view,
+                               "focus-in-event",
+                               G_CALLBACK (gb_editor_view__focus_in_event),
+                               self,
+                               G_CONNECT_SWAPPED);
+
       gtk_container_add_with_properties (GTK_CONTAINER (self->paned), GTK_WIDGET (self->frame2),
                                          "shrink", FALSE,
                                          "resize", TRUE,
@@ -829,6 +872,7 @@ gb_editor_view_init (GbEditorView *self)
   gtk_widget_init_template (GTK_WIDGET (self));
 
   self->settings = g_settings_new ("org.gnome.builder.editor");
+  self->last_focused_frame = self->frame1;
 
   gb_editor_view_actions_init (self);
 
@@ -854,6 +898,12 @@ gb_editor_view_init (GbEditorView *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  g_signal_connect_object (self->frame1->source_view,
+                           "focus-in-event",
+                           G_CALLBACK (gb_editor_view__focus_in_event),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   g_signal_connect_object (self->goto_line_popover,
                            "activate",
                            G_CALLBACK (gb_editor_view_goto_line_activate),


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