[gnome-builder] editor: notify editor view addins when stack changes



commit 42f83a53e9ab143e6ab889debcda631207d6fd4e
Author: Christian Hergert <chergert redhat com>
Date:   Sun Sep 3 19:56:03 2017 -0700

    editor: notify editor view addins when stack changes
    
    It can be useful to change things when the stack has changed for the view.

 libide/editor/ide-editor-private.h    |    3 +++
 libide/editor/ide-editor-view-addin.c |   11 +++++++++++
 libide/editor/ide-editor-view-addin.h |    7 ++++++-
 libide/editor/ide-editor-view.c       |   31 +++++++++++++++++++++++++++++++
 4 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/libide/editor/ide-editor-private.h b/libide/editor/ide-editor-private.h
index e05bfd2..5ae5429 100644
--- a/libide/editor/ide-editor-private.h
+++ b/libide/editor/ide-editor-private.h
@@ -80,6 +80,9 @@ struct _IdeEditorView
   GtkRevealer             *modified_revealer;
   GtkButton               *modified_cancel_button;
 
+  /* Raw pointer used to determine when stack changes */
+  IdeLayoutStack          *last_stack_ptr;
+
   guint                    toggle_map_source;
 
   guint                    auto_hide_map : 1;
diff --git a/libide/editor/ide-editor-view-addin.c b/libide/editor/ide-editor-view-addin.c
index dd47c8c..bc8a784 100644
--- a/libide/editor/ide-editor-view-addin.c
+++ b/libide/editor/ide-editor-view-addin.c
@@ -60,6 +60,17 @@ ide_editor_view_addin_language_changed (IdeEditorViewAddin *self,
     IDE_EDITOR_VIEW_ADDIN_GET_IFACE (self)->language_changed (self, language_id);
 }
 
+void
+ide_editor_view_addin_stack_set (IdeEditorViewAddin *self,
+                                 IdeLayoutStack     *stack)
+{
+  g_return_if_fail (IDE_IS_EDITOR_VIEW_ADDIN (self));
+  g_return_if_fail (IDE_IS_LAYOUT_STACK (stack));
+
+  if (IDE_EDITOR_VIEW_ADDIN_GET_IFACE (self)->stack_set)
+    IDE_EDITOR_VIEW_ADDIN_GET_IFACE (self)->stack_set (self, stack);
+}
+
 /**
  * ide_editor_view_addin_find_by_module_name:
  * @view: an #IdeEditorView
diff --git a/libide/editor/ide-editor-view-addin.h b/libide/editor/ide-editor-view-addin.h
index 0a52432..993516e 100644
--- a/libide/editor/ide-editor-view-addin.h
+++ b/libide/editor/ide-editor-view-addin.h
@@ -18,7 +18,8 @@
 
 #pragma once
 
-#include "ide-editor-view.h"
+#include "editor/ide-editor-view.h"
+#include "layout/ide-layout-stack.h"
 
 G_BEGIN_DECLS
 
@@ -36,12 +37,16 @@ struct _IdeEditorViewAddinInterface
                               IdeEditorView      *view);
   void (*language_changed)   (IdeEditorViewAddin *self,
                               const gchar        *language_id);
+  void (*stack_set)          (IdeEditorViewAddin *self,
+                              IdeLayoutStack     *stack);
 };
 
 void                ide_editor_view_addin_load                (IdeEditorViewAddin *self,
                                                                IdeEditorView      *view);
 void                ide_editor_view_addin_unload              (IdeEditorViewAddin *self,
                                                                IdeEditorView      *view);
+void                ide_editor_view_addin_stack_set           (IdeEditorViewAddin *self,
+                                                               IdeLayoutStack     *stack);
 void                ide_editor_view_addin_language_changed    (IdeEditorViewAddin *self,
                                                                const gchar        *language_id);
 IdeEditorViewAddin *ide_editor_view_addin_find_by_module_name (IdeEditorView      *view,
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index f1343a8..bb1c9b5 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -376,6 +376,23 @@ ide_editor_view_create_split_view (IdeLayoutView *view)
 }
 
 static void
+ide_editor_view_notify_stack_set (IdeExtensionSetAdapter *set,
+                                  PeasPluginInfo         *plugin_info,
+                                  PeasExtension          *exten,
+                                  gpointer                user_data)
+{
+  IdeLayoutStack *stack = user_data;
+  IdeEditorViewAddin *addin = (IdeEditorViewAddin *)exten;
+
+  g_assert (IDE_IS_EXTENSION_SET_ADAPTER (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_EDITOR_VIEW_ADDIN (addin));
+  g_assert (IDE_IS_LAYOUT_STACK (stack));
+
+  ide_editor_view_addin_stack_set (addin, stack);
+}
+
+static void
 ide_editor_view_addin_added (IdeExtensionSetAdapter *set,
                              PeasPluginInfo         *plugin_info,
                              PeasExtension          *exten,
@@ -414,6 +431,7 @@ ide_editor_view_hierarchy_changed (GtkWidget *widget,
                                    GtkWidget *old_toplevel)
 {
   IdeEditorView *self = (IdeEditorView *)widget;
+  IdeLayoutStack *stack;
   IdeContext *context;
 
   g_assert (IDE_IS_EDITOR_VIEW (self));
@@ -428,6 +446,7 @@ ide_editor_view_hierarchy_changed (GtkWidget *widget,
     GTK_WIDGET_CLASS (ide_editor_view_parent_class)->hierarchy_changed (widget, old_toplevel);
 
   context = ide_widget_get_context (GTK_WIDGET (self));
+  stack = (IdeLayoutStack *)gtk_widget_get_ancestor (widget, IDE_TYPE_LAYOUT_STACK);
 
   /*
    * We don't want to create addins until the widget has been placed into
@@ -456,6 +475,18 @@ ide_editor_view_hierarchy_changed (GtkWidget *widget,
                                          ide_editor_view_addin_added,
                                          self);
     }
+
+  /*
+   * If we have been moved into a new stack, notify the addins of the
+   * hierarchy change.
+   */
+  if (stack != NULL && stack != self->last_stack_ptr && self->addins != NULL)
+    {
+      self->last_stack_ptr = stack;
+      ide_extension_set_adapter_foreach (self->addins,
+                                         ide_editor_view_notify_stack_set,
+                                         stack);
+    }
 }
 
 static void


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