[gnome-builder] beautifier plugin: move to Editor addin



commit b19c52b0ead6c950dac9544e621a7d4eeacffa5a
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Thu Aug 10 23:01:58 2017 +0200

    beautifier plugin: move to Editor addin
    
    Instead of the Workbench addin, we now use the Editor addin
    to use the views tracking feature.

 meson_options.txt                                  |    2 +-
 plugins/beautifier/gb-beautifier-config.c          |   60 ++++----
 plugins/beautifier/gb-beautifier-config.h          |    4 +-
 ...kbench-addin.c => gb-beautifier-editor-addin.c} |  162 +++++++++-----------
 ...kbench-addin.h => gb-beautifier-editor-addin.h} |   12 +-
 plugins/beautifier/gb-beautifier-helper.c          |   40 +++---
 plugins/beautifier/gb-beautifier-helper.h          |   28 ++--
 plugins/beautifier/gb-beautifier-plugin.c          |    6 +-
 plugins/beautifier/gb-beautifier-private.h         |    5 +-
 plugins/beautifier/gb-beautifier-process.c         |   78 +++++-----
 plugins/beautifier/gb-beautifier-process.h         |   24 ++--
 plugins/beautifier/meson.build                     |    4 +-
 12 files changed, 208 insertions(+), 217 deletions(-)
---
diff --git a/meson_options.txt b/meson_options.txt
index b3ca444..6b4f214 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -23,7 +23,7 @@ option('with_docs', type: 'boolean')
 #   https://github.com/mesonbuild/meson/issues/707
 option('with_autotools', type: 'boolean')
 option('with_autotools_templates', type: 'boolean')
-option('with_beautifier', type: 'boolean', value: false)
+option('with_beautifier', type: 'boolean')
 option('with_c_pack', type: 'boolean')
 option('with_cargo', type: 'boolean')
 option('with_clang', type: 'boolean')
diff --git a/plugins/beautifier/gb-beautifier-config.c b/plugins/beautifier/gb-beautifier-config.c
index f0db858..1ea446b 100644
--- a/plugins/beautifier/gb-beautifier-config.c
+++ b/plugins/beautifier/gb-beautifier-config.c
@@ -67,12 +67,12 @@ map_entry_clear_func (gpointer data)
 }
 
 static gboolean
-gb_beautifier_config_check_duplicates (GbBeautifierWorkbenchAddin *self,
-                                       GArray                     *entries,
-                                       const gchar                *lang_id,
-                                       const gchar                *display_name)
+gb_beautifier_config_check_duplicates (GbBeautifierEditorAddin *self,
+                                       GArray                  *entries,
+                                       const gchar             *lang_id,
+                                       const gchar             *display_name)
 {
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (entries != NULL);
   g_assert (!ide_str_empty0 (lang_id));
   g_assert (!ide_str_empty0 (display_name));
@@ -94,11 +94,11 @@ gb_beautifier_config_check_duplicates (GbBeautifierWorkbenchAddin *self,
 }
 
 static gboolean
-gb_beautifier_map_check_duplicates (GbBeautifierWorkbenchAddin *self,
-                                    GArray                     *map,
-                                    const gchar                *lang_id)
+gb_beautifier_map_check_duplicates (GbBeautifierEditorAddin *self,
+                                    GArray                  *map,
+                                    const gchar             *lang_id)
 {
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (map != NULL);
   g_assert (!ide_str_empty0 (lang_id));
 
@@ -118,13 +118,13 @@ gb_beautifier_map_check_duplicates (GbBeautifierWorkbenchAddin *self,
 }
 
 static gboolean
-add_entries_from_config_ini_file (GbBeautifierWorkbenchAddin *self,
-                                  const gchar                *base_path,
-                                  const gchar                *lang_id,
-                                  const gchar                *real_lang_id,
-                                  GArray                     *entries,
-                                  const gchar                *map_default,
-                                  gboolean                    is_from_map)
+add_entries_from_config_ini_file (GbBeautifierEditorAddin *self,
+                                  const gchar             *base_path,
+                                  const gchar             *lang_id,
+                                  const gchar             *real_lang_id,
+                                  GArray                  *entries,
+                                  const gchar             *map_default,
+                                  gboolean                 is_from_map)
 {
   g_autoptr(GKeyFile) key_file = NULL;
   g_autofree gchar *ini_path = NULL;
@@ -134,7 +134,7 @@ add_entries_from_config_ini_file (GbBeautifierWorkbenchAddin *self,
   gsize nb_profiles;
   GError *error = NULL;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (!ide_str_empty0 (base_path));
   g_assert (!ide_str_empty0 (lang_id));
   g_assert (!ide_str_empty0 (real_lang_id));
@@ -279,8 +279,8 @@ fail:
 }
 
 static gboolean
-is_a_lang_id (GbBeautifierWorkbenchAddin *self,
-              const gchar                *lang_id)
+is_a_lang_id (GbBeautifierEditorAddin *self,
+              const gchar             *lang_id)
 {
   GtkSourceLanguageManager *lang_manager;
   const gchar * const * lang_ids = NULL;
@@ -292,10 +292,10 @@ is_a_lang_id (GbBeautifierWorkbenchAddin *self,
 }
 
 static gboolean
-add_entries_from_base_path (GbBeautifierWorkbenchAddin *self,
-                            const gchar                *base_path,
-                            GArray                     *entries,
-                            GArray                     *map)
+add_entries_from_base_path (GbBeautifierEditorAddin *self,
+                            const gchar             *base_path,
+                            GArray                  *entries,
+                            GArray                  *map)
 {
   g_autoptr(GFileEnumerator) enumerator = NULL;
   g_autoptr(GFile) parent_file = NULL;
@@ -303,7 +303,7 @@ add_entries_from_base_path (GbBeautifierWorkbenchAddin *self,
   GError *error = NULL;
   gboolean ret = FALSE;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (!ide_str_empty0 (base_path));
   g_assert (entries != NULL);
   g_assert (map != NULL);
@@ -364,8 +364,8 @@ add_entries_from_base_path (GbBeautifierWorkbenchAddin *self,
 }
 
 static GArray *
-gb_beautifier_config_get_map (GbBeautifierWorkbenchAddin *self,
-                              const gchar                *path)
+gb_beautifier_config_get_map (GbBeautifierEditorAddin *self,
+                              const gchar             *path)
 {
   GArray *map;
   g_autofree gchar *file_name = NULL;
@@ -374,7 +374,7 @@ gb_beautifier_config_get_map (GbBeautifierWorkbenchAddin *self,
   gsize nb_lang_ids;
   GError *error = NULL;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (!ide_str_empty0 (path));
 
   map = g_array_new (TRUE, TRUE, sizeof (GbBeautifierMapEntry));
@@ -420,7 +420,7 @@ gb_beautifier_config_get_map (GbBeautifierWorkbenchAddin *self,
 }
 
 GArray *
-gb_beautifier_config_get_entries (GbBeautifierWorkbenchAddin *self)
+gb_beautifier_config_get_entries (GbBeautifierEditorAddin *self)
 {
   IdeContext *context;
   IdeVcs *vcs;
@@ -431,7 +431,7 @@ gb_beautifier_config_get_entries (GbBeautifierWorkbenchAddin *self)
   const gchar *datadir;
   g_autofree gchar *configdir = NULL;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
 
   entries = g_array_new (TRUE, TRUE, sizeof (GbBeautifierConfigEntry));
   g_array_set_clear_func (entries, config_entry_clear_func);
@@ -447,7 +447,7 @@ gb_beautifier_config_get_entries (GbBeautifierWorkbenchAddin *self)
     g_array_free (map, TRUE);
 
   /* Project wide config */
-  if (NULL != (context = ide_workbench_get_context (self->workbench)) &&
+  if (NULL != (context = self->context) &&
       NULL != (vcs = ide_context_get_vcs (context)))
     {
       GFile *workdir;
diff --git a/plugins/beautifier/gb-beautifier-config.h b/plugins/beautifier/gb-beautifier-config.h
index 4d01c67..cdb74a8 100644
--- a/plugins/beautifier/gb-beautifier-config.h
+++ b/plugins/beautifier/gb-beautifier-config.h
@@ -21,7 +21,7 @@
 
 #include <glib.h>
 
-#include "gb-beautifier-workbench-addin.h"
+#include "gb-beautifier-editor-addin.h"
 
 G_BEGIN_DECLS
 
@@ -48,7 +48,7 @@ typedef struct
   gchar *default_profile;
 } GbBeautifierMapEntry;
 
-GArray *gb_beautifier_config_get_entries (GbBeautifierWorkbenchAddin *self);
+GArray *gb_beautifier_config_get_entries (GbBeautifierEditorAddin *self);
 
 G_END_DECLS
 
diff --git a/plugins/beautifier/gb-beautifier-workbench-addin.c 
b/plugins/beautifier/gb-beautifier-editor-addin.c
similarity index 68%
rename from plugins/beautifier/gb-beautifier-workbench-addin.c
rename to plugins/beautifier/gb-beautifier-editor-addin.c
index ebe90e9..33f15f6 100644
--- a/plugins/beautifier/gb-beautifier-workbench-addin.c
+++ b/plugins/beautifier/gb-beautifier-editor-addin.c
@@ -1,4 +1,4 @@
-/* gb-beautifier-workbench_addin.c
+/* gb-beautifier-editor-addin.c
  *
  * Copyright (C) 2016 sebastien lafargue <slafargue gnome org>
  *
@@ -25,22 +25,22 @@
 #include "gb-beautifier-helper.h"
 #include "gb-beautifier-process.h"
 
-#include "gb-beautifier-workbench-addin.h"
+#include "gb-beautifier-editor-addin.h"
 
-static void workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface);
+static void editor_addin_iface_init (IdeEditorAddinInterface *iface);
 
-G_DEFINE_TYPE_EXTENDED (GbBeautifierWorkbenchAddin, gb_beautifier_workbench_addin, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
+G_DEFINE_TYPE_EXTENDED (GbBeautifierEditorAddin, gb_beautifier_editor_addin, G_TYPE_OBJECT, 0,
+                        G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_ADDIN, editor_addin_iface_init))
 
 static void
 process_launch_async_cb (GObject      *object,
                          GAsyncResult *result,
                          gpointer      user_data)
 {
-  GbBeautifierWorkbenchAddin *self = (GbBeautifierWorkbenchAddin *)object;
+  GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)object;
   g_autoptr(GError) error = NULL;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (G_IS_ASYNC_RESULT (result));
 
   if (!gb_beautifier_process_launch_finish (self, result, &error))
@@ -52,7 +52,7 @@ view_activate_beautify_action_cb (GSimpleAction *action,
                                   GVariant      *variant,
                                   gpointer       user_data)
 {
-  GbBeautifierWorkbenchAddin *self = (GbBeautifierWorkbenchAddin *)user_data;
+  GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)user_data;
   IdeEditorView *view;
   IdeSourceView *source_view;
   GtkTextBuffer *buffer;
@@ -63,11 +63,11 @@ view_activate_beautify_action_cb (GSimpleAction *action,
   GtkTextIter end;
   guint64 index;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING));
   g_assert (G_IS_SIMPLE_ACTION (action));
 
-  view = g_object_get_data (G_OBJECT (action), "gb-beautifier-workbench-addin");
+  view = g_object_get_data (G_OBJECT (action), "gb-beautifier-editor-addin");
   if (view == NULL || !IDE_IS_EDITOR_VIEW (view))
     return;
 
@@ -109,10 +109,10 @@ view_activate_beautify_action_cb (GSimpleAction *action,
 }
 
 static void
-view_populate_submenu (GbBeautifierWorkbenchAddin *self,
-                       IdeSourceView              *view,
-                       GMenu                      *submenu,
-                       GArray                     *entries)
+view_populate_submenu (GbBeautifierEditorAddin *self,
+                       IdeSourceView           *view,
+                       GMenu                   *submenu,
+                       GArray                  *entries)
 {
   const gchar *lang_id;
   GtkApplication *app;
@@ -121,7 +121,7 @@ view_populate_submenu (GbBeautifierWorkbenchAddin *self,
   gboolean has_entries = FALSE;
   gboolean default_set = FALSE;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (IDE_IS_SOURCE_VIEW (view));
   g_assert (G_IS_MENU (submenu));
   g_assert (entries != NULL);
@@ -199,13 +199,13 @@ view_populate_submenu (GbBeautifierWorkbenchAddin *self,
 }
 
 static void
-view_populate_popup (GbBeautifierWorkbenchAddin *self,
-                     GtkWidget                  *popup,
-                     IdeSourceView              *source_view)
+view_populate_popup (GbBeautifierEditorAddin *self,
+                     GtkWidget               *popup,
+                     IdeSourceView           *source_view)
 {
   GMenu *submenu;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (GTK_IS_WIDGET (popup));
   g_assert (IDE_IS_SOURCE_VIEW (source_view));
 
@@ -220,15 +220,15 @@ static GActionEntry GbBeautifierActions [] = {
 };
 
 static void
-setup_view_cb (GtkWidget                  *widget,
-               GbBeautifierWorkbenchAddin *self)
+setup_view_cb (GtkWidget               *widget,
+               GbBeautifierEditorAddin *self)
 {
   IdeEditorView *view = (IdeEditorView *)widget;
   IdeSourceView *source_view;
   GActionGroup *actions;
   GAction *action;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (IDE_IS_EDITOR_VIEW (view));
 
   actions = gtk_widget_get_action_group (GTK_WIDGET (view), "view");
@@ -238,11 +238,11 @@ setup_view_cb (GtkWidget                  *widget,
                                    self);
 
   action = g_action_map_lookup_action (G_ACTION_MAP (actions), "beautify");
-  g_object_set_data (G_OBJECT (action), "gb-beautifier-workbench-addin", view);
+  g_object_set_data (G_OBJECT (action), "gb-beautifier-editor-addin", view);
   action = g_action_map_lookup_action (G_ACTION_MAP (actions), "beautify-default");
-  g_object_set_data (G_OBJECT (action), "gb-beautifier-workbench-addin", view);
+  g_object_set_data (G_OBJECT (action), "gb-beautifier-editor-addin", view);
 
-  g_object_set_data (G_OBJECT (view), "gb-beautifier-workbench-addin", self);
+  g_object_set_data (G_OBJECT (view), "gb-beautifier-editor-addin", self);
 
   source_view = ide_editor_view_get_view (view);
   g_signal_connect_object (source_view,
@@ -253,15 +253,15 @@ setup_view_cb (GtkWidget                  *widget,
 }
 
 static void
-cleanup_view_cb (GtkWidget                  *widget,
-                 GbBeautifierWorkbenchAddin *self)
+cleanup_view_cb (GtkWidget               *widget,
+                 GbBeautifierEditorAddin *self)
 {
   IdeEditorView *view = (IdeEditorView *)widget;
   GActionGroup *actions;
   GtkApplication *app;
   gchar *default_action_name;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (IDE_IS_EDITOR_VIEW (view));
 
   app = GTK_APPLICATION (g_application_get_default ());
@@ -272,7 +272,7 @@ cleanup_view_cb (GtkWidget                  *widget,
       g_action_map_remove_action (G_ACTION_MAP (actions), "beautify-default");
     }
 
-  g_object_set_data (G_OBJECT (view), "gb-beautifier-workbench-addin", NULL);
+  g_object_set_data (G_OBJECT (view), "gb-beautifier-editor-addin", NULL);
   if (NULL != (default_action_name = g_object_get_data (G_OBJECT (view), "gb-beautifier-default-action")))
     {
       gtk_application_set_accels_for_action (app, default_action_name, (const gchar*[]) {NULL});
@@ -281,94 +281,84 @@ cleanup_view_cb (GtkWidget                  *widget,
 }
 
 static void
-view_added_cb (GbBeautifierWorkbenchAddin *self,
-               GtkWidget                  *widget)
+gb_beautifier_editor_addin_load (IdeEditorAddin       *addin,
+                                 IdeEditorPerspective *editor)
 {
-  IdeLayoutView *view = (IdeLayoutView *)widget;
+  GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
+  IdeWorkbench *workbench;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
-  g_assert (IDE_IS_LAYOUT_VIEW (view));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
 
-  if (!IDE_IS_EDITOR_VIEW (view))
-    return;
+  ide_set_weak_pointer (&self->editor, editor);
+  workbench = ide_widget_get_workbench (GTK_WIDGET (editor));
+  self->context = ide_workbench_get_context (workbench);
+  self->entries = gb_beautifier_config_get_entries (self);
 
-  setup_view_cb (GTK_WIDGET (view), self);
+  ide_perspective_views_foreach (IDE_PERSPECTIVE (self->editor), (GtkCallback)setup_view_cb, self);
 }
 
 static void
-view_removed_cb (GbBeautifierWorkbenchAddin *self,
-                 GtkWidget                  *widget)
+gb_beautifier_editor_addin_unload (IdeEditorAddin       *addin,
+                                   IdeEditorPerspective *editor)
 {
-  IdeLayoutView *view = (IdeLayoutView *)widget;
+  GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
-  g_assert (IDE_IS_LAYOUT_VIEW (view));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
+  g_assert (IDE_IS_EDITOR_PERSPECTIVE (editor));
 
-  if (!IDE_IS_EDITOR_VIEW (view))
-    return;
+  ide_perspective_views_foreach (IDE_PERSPECTIVE (self->editor), (GtkCallback)cleanup_view_cb, self);
+  if (self->entries != NULL)
+    {
+      g_array_free (self->entries, TRUE);
+      self->entries = NULL;
+    }
 
-  cleanup_view_cb (GTK_WIDGET (view), self);
+  ide_clear_weak_pointer (&self->editor);
+  self->context = NULL;
 }
 
 static void
-gb_beautifier_workbench_addin_load (IdeWorkbenchAddin *addin,
-                                    IdeWorkbench      *workbench)
+gb_beautifier_editor_addin_view_set (IdeEditorAddin *addin,
+                                     IdeLayoutView  *view)
 {
-  GbBeautifierWorkbenchAddin *self = (GbBeautifierWorkbenchAddin *)addin;
-
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
-  g_assert (IDE_IS_WORKBENCH (workbench));
-
-  ide_set_weak_pointer (&self->workbench, workbench);
-  self->editor = IDE_EDITOR_PERSPECTIVE (ide_workbench_get_perspective_by_name (workbench, "editor"));
-  self->entries = gb_beautifier_config_get_entries (self);
-
-  ide_perspective_views_foreach (IDE_PERSPECTIVE (self->editor), (GtkCallback)setup_view_cb, self);
-
-  g_signal_connect_object (self->editor,
-                           "view-added",
-                           G_CALLBACK (view_added_cb),
-                           self,
-                           G_CONNECT_SWAPPED);
-  g_signal_connect_object (self->editor,
-                           "view-removed",
-                           G_CALLBACK (view_removed_cb),
-                           self,
-                           G_CONNECT_SWAPPED);
-}
+  GbBeautifierEditorAddin *self = (GbBeautifierEditorAddin *)addin;
 
-static void
-gb_beautifier_workbench_addin_unload (IdeWorkbenchAddin *addin,
-                                      IdeWorkbench      *workbench)
-{
-  GbBeautifierWorkbenchAddin *self = (GbBeautifierWorkbenchAddin *)addin;
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
+  g_assert (!view || IDE_IS_LAYOUT_VIEW (view));
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
-  g_assert (IDE_IS_WORKBENCH (workbench));
+  /* If there is currently a view set, and this is
+   * a new view, then we want to clean it up.
+   */
 
-  ide_perspective_views_foreach (IDE_PERSPECTIVE (self->editor), (GtkCallback)cleanup_view_cb, self);
-  if (self->entries != NULL)
+  if (self->current_view != NULL)
     {
-      g_array_free (self->entries, TRUE);
-      self->entries = NULL;
+      if (view == IDE_LAYOUT_VIEW (self->current_view))
+        return;
+
+      if (view != NULL)
+        cleanup_view_cb (GTK_WIDGET (view), self);
     }
 
-  ide_clear_weak_pointer (&self->workbench);
+  self->current_view = view;
+  if (view != NULL)
+    setup_view_cb (GTK_WIDGET (view), self);
 }
 
 static void
-gb_beautifier_workbench_addin_class_init (GbBeautifierWorkbenchAddinClass *klass)
+gb_beautifier_editor_addin_class_init (GbBeautifierEditorAddinClass *klass)
 {
 }
 
 static void
-gb_beautifier_workbench_addin_init (GbBeautifierWorkbenchAddin *self)
+gb_beautifier_editor_addin_init (GbBeautifierEditorAddin *self)
 {
 }
 
 static void
-workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
+editor_addin_iface_init (IdeEditorAddinInterface *iface)
 {
-  iface->load = gb_beautifier_workbench_addin_load;
-  iface->unload = gb_beautifier_workbench_addin_unload;
+  iface->load = gb_beautifier_editor_addin_load;
+  iface->unload = gb_beautifier_editor_addin_unload;
+  iface->view_set = gb_beautifier_editor_addin_view_set;
 }
diff --git a/plugins/beautifier/gb-beautifier-workbench-addin.h 
b/plugins/beautifier/gb-beautifier-editor-addin.h
similarity index 67%
rename from plugins/beautifier/gb-beautifier-workbench-addin.h
rename to plugins/beautifier/gb-beautifier-editor-addin.h
index ed18209..bb4008f 100644
--- a/plugins/beautifier/gb-beautifier-workbench-addin.h
+++ b/plugins/beautifier/gb-beautifier-editor-addin.h
@@ -1,4 +1,4 @@
-/* gb-beautifier-workbench-addin.h
+/* gb-beautifier-editor-addin.h
  *
  * Copyright (C) 2016 sebastien lafargue <slafargue gnome org>
  *
@@ -16,17 +16,17 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef GB_BEAUTIFIER_WORKBENCH_ADDIN_H
-#define GB_BEAUTIFIER_WORKBENCH_ADDIN_H
+#ifndef GB_BEAUTIFIER_EDITOR_ADDIN_H
+#define GB_BEAUTIFIER_EDITOR_ADDIN_H
 
 #include <glib-object.h>
 
 G_BEGIN_DECLS
 
-#define GB_TYPE_BEAUTIFIER_WORKBENCH_ADDIN (gb_beautifier_workbench_addin_get_type())
+#define GB_TYPE_BEAUTIFIER_EDITOR_ADDIN (gb_beautifier_editor_addin_get_type())
 
-G_DECLARE_FINAL_TYPE (GbBeautifierWorkbenchAddin, gb_beautifier_workbench_addin, GB, 
BEAUTIFIER_WORKBENCH_ADDIN, GObject)
+G_DECLARE_FINAL_TYPE (GbBeautifierEditorAddin, gb_beautifier_editor_addin, GB, BEAUTIFIER_EDITOR_ADDIN, 
GObject)
 
 G_END_DECLS
 
-#endif /* GB_BEAUTIFIER_WORKBENCH_ADDIN_H */
+#endif /* GB_BEAUTIFIER_EDITOR_ADDIN_H */
diff --git a/plugins/beautifier/gb-beautifier-helper.c b/plugins/beautifier/gb-beautifier-helper.c
index aeaf6b5..e4dae2b 100644
--- a/plugins/beautifier/gb-beautifier-helper.c
+++ b/plugins/beautifier/gb-beautifier-helper.c
@@ -24,10 +24,10 @@
 
 typedef struct
 {
-  GbBeautifierWorkbenchAddin *self;
-  GFile                      *file;
-  GFileIOStream              *stream;
-  gsize                       len;
+  GbBeautifierEditorAddin *self;
+  GFile                   *file;
+  GFileIOStream           *stream;
+  gsize                    len;
 } SaveTmpState;
 
 static void
@@ -68,11 +68,11 @@ gb_beautifier_helper_create_tmp_file_cb (GObject      *object,
 }
 
 void
-gb_beautifier_helper_create_tmp_file_async (GbBeautifierWorkbenchAddin *self,
-                                            const gchar                *text,
-                                            GAsyncReadyCallback         callback,
-                                            GCancellable               *cancellable,
-                                            gpointer                    user_data)
+gb_beautifier_helper_create_tmp_file_async (GbBeautifierEditorAddin *self,
+                                            const gchar             *text,
+                                            GAsyncReadyCallback      callback,
+                                            GCancellable            *cancellable,
+                                            gpointer                 user_data)
 {
   SaveTmpState *state;
   GFile *file = NULL;
@@ -81,7 +81,7 @@ gb_beautifier_helper_create_tmp_file_async (GbBeautifierWorkbenchAddin *self,
   g_autoptr(GTask) task = NULL;
   g_autoptr(GError) error = NULL;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (!ide_str_empty0 (text));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
   g_assert (callback != NULL);
@@ -113,35 +113,35 @@ gb_beautifier_helper_create_tmp_file_async (GbBeautifierWorkbenchAddin *self,
 }
 
 GFile *
-gb_beautifier_helper_create_tmp_file_finish (GbBeautifierWorkbenchAddin  *self,
-                                             GAsyncResult                *result,
-                                             GError                     **error)
+gb_beautifier_helper_create_tmp_file_finish (GbBeautifierEditorAddin  *self,
+                                             GAsyncResult             *result,
+                                             GError                  **error)
 {
   GTask *task = (GTask *)result;
 
-  g_return_val_if_fail (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self), NULL);
+  g_return_val_if_fail (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self), NULL);
   g_return_val_if_fail (g_task_is_valid (result, self), NULL);
 
   return g_task_propagate_pointer (task, error);
 }
 
 void
-gb_beautifier_helper_remove_tmp_file (GbBeautifierWorkbenchAddin *self,
-                                      GFile                      *tmp_file)
+gb_beautifier_helper_remove_tmp_file (GbBeautifierEditorAddin *self,
+                                      GFile                   *tmp_file)
 {
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
 
   g_file_delete (tmp_file, NULL, NULL);
 }
 
 const gchar *
-gb_beautifier_helper_get_lang_id (GbBeautifierWorkbenchAddin *self,
-                                  IdeSourceView              *view)
+gb_beautifier_helper_get_lang_id (GbBeautifierEditorAddin *self,
+                                  IdeSourceView           *view)
 {
   GtkTextBuffer *buffer;
   GtkSourceLanguage *lang;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (IDE_IS_SOURCE_VIEW (view));
 
   buffer = GTK_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
diff --git a/plugins/beautifier/gb-beautifier-helper.h b/plugins/beautifier/gb-beautifier-helper.h
index 23cdf92..1ad8059 100644
--- a/plugins/beautifier/gb-beautifier-helper.h
+++ b/plugins/beautifier/gb-beautifier-helper.h
@@ -23,23 +23,23 @@
 
 #include "ide.h"
 
-#include "gb-beautifier-workbench-addin.h"
+#include "gb-beautifier-editor-addin.h"
 
 G_BEGIN_DECLS
 
-void          gb_beautifier_helper_create_tmp_file_async    (GbBeautifierWorkbenchAddin  *self,
-                                                             const gchar                 *text,
-                                                             GAsyncReadyCallback          callback,
-                                                             GCancellable                *cancellable,
-                                                             gpointer                     user_data);
-GFile        *gb_beautifier_helper_create_tmp_file_finish   (GbBeautifierWorkbenchAddin  *self,
-                                                             GAsyncResult                *result,
-                                                             GError                     **error);
-
-const gchar  *gb_beautifier_helper_get_lang_id              (GbBeautifierWorkbenchAddin  *self,
-                                                             IdeSourceView               *view);
-void          gb_beautifier_helper_remove_tmp_file          (GbBeautifierWorkbenchAddin  *self,
-                                                             GFile                       *tmp_file);
+void          gb_beautifier_helper_create_tmp_file_async    (GbBeautifierEditorAddin  *self,
+                                                             const gchar              *text,
+                                                             GAsyncReadyCallback       callback,
+                                                             GCancellable             *cancellable,
+                                                             gpointer                  user_data);
+GFile        *gb_beautifier_helper_create_tmp_file_finish   (GbBeautifierEditorAddin  *self,
+                                                             GAsyncResult             *result,
+                                                             GError                  **error);
+
+const gchar  *gb_beautifier_helper_get_lang_id              (GbBeautifierEditorAddin  *self,
+                                                             IdeSourceView            *view);
+void          gb_beautifier_helper_remove_tmp_file          (GbBeautifierEditorAddin  *self,
+                                                             GFile                    *tmp_file);
 
 G_END_DECLS
 
diff --git a/plugins/beautifier/gb-beautifier-plugin.c b/plugins/beautifier/gb-beautifier-plugin.c
index 2f702c5..8745967 100644
--- a/plugins/beautifier/gb-beautifier-plugin.c
+++ b/plugins/beautifier/gb-beautifier-plugin.c
@@ -19,12 +19,12 @@
 #include <ide.h>
 #include <libpeas/peas.h>
 
-#include "gb-beautifier-workbench-addin.h"
+#include "gb-beautifier-editor-addin.h"
 
 void
 peas_register_types (PeasObjectModule *module)
 {
   peas_object_module_register_extension_type (module,
-                                              IDE_TYPE_WORKBENCH_ADDIN,
-                                              GB_TYPE_BEAUTIFIER_WORKBENCH_ADDIN);
+                                              IDE_TYPE_EDITOR_ADDIN,
+                                              GB_TYPE_BEAUTIFIER_EDITOR_ADDIN);
 }
diff --git a/plugins/beautifier/gb-beautifier-private.h b/plugins/beautifier/gb-beautifier-private.h
index d95e021..8a6f4c7 100644
--- a/plugins/beautifier/gb-beautifier-private.h
+++ b/plugins/beautifier/gb-beautifier-private.h
@@ -25,12 +25,13 @@
 
 G_BEGIN_DECLS
 
-struct _GbBeautifierWorkbenchAddin
+struct _GbBeautifierEditorAddin
 {
   GObject                parent_instance;
 
-  IdeWorkbench          *workbench;
+  IdeContext            *context;
   IdeEditorPerspective  *editor;
+  IdeLayoutView         *current_view;
   GArray                *entries;
 };
 
diff --git a/plugins/beautifier/gb-beautifier-process.c b/plugins/beautifier/gb-beautifier-process.c
index 2c16952..a196d03 100644
--- a/plugins/beautifier/gb-beautifier-process.c
+++ b/plugins/beautifier/gb-beautifier-process.c
@@ -27,19 +27,19 @@
 
 typedef struct
 {
-  GbBeautifierWorkbenchAddin *self;
-  IdeSourceView              *source_view;
-  GtkTextMark                *begin_mark;
-  GtkTextMark                *end_mark;
-  GbBeautifierConfigCommand   command;
-  GPtrArray                  *command_args;
-  GFile                      *src_file;
-  GFile                      *config_file;
-  GFile                      *tmp_workdir_file;
-  GFile                      *tmp_src_file;
-  GFile                      *tmp_config_file;
-  gchar                      *lang_id;
-  gchar                      *text;
+  GbBeautifierEditorAddin   *self;
+  IdeSourceView             *source_view;
+  GtkTextMark               *begin_mark;
+  GtkTextMark               *end_mark;
+  GbBeautifierConfigCommand  command;
+  GPtrArray                 *command_args;
+  GFile                     *src_file;
+  GFile                     *config_file;
+  GFile                     *tmp_workdir_file;
+  GFile                     *tmp_src_file;
+  GFile                     *tmp_config_file;
+  gchar                     *lang_id;
+  gchar                     *text;
 } ProcessState;
 
 static void
@@ -112,9 +112,9 @@ match_and_replace (const gchar *str,
 }
 
 static void
-command_args_expand (GbBeautifierWorkbenchAddin *self,
-                     GPtrArray                  *args,
-                     ProcessState               *state)
+command_args_expand (GbBeautifierEditorAddin *self,
+                     GPtrArray               *args,
+                     ProcessState            *state)
 {
   g_autofree gchar *src_path = NULL;
   g_autofree gchar *config_path = NULL;
@@ -146,14 +146,14 @@ command_args_expand (GbBeautifierWorkbenchAddin *self,
 }
 
 static GSubprocess *
-gb_beautifier_process_create_generic (GbBeautifierWorkbenchAddin *self,
-                                      ProcessState               *state,
-                                      GError                     *error)
+gb_beautifier_process_create_generic (GbBeautifierEditorAddin *self,
+                                      ProcessState            *state,
+                                      GError                  *error)
 {
   GSubprocess *subprocess = NULL;
   g_autofree gchar *src_path = NULL;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (state != NULL);
 
   src_path = g_file_get_path (state->src_file);
@@ -171,9 +171,9 @@ gb_beautifier_process_create_generic (GbBeautifierWorkbenchAddin *self,
 }
 
 static GSubprocess *
-gb_beautifier_process_create_for_clang_format (GbBeautifierWorkbenchAddin *self,
-                                               ProcessState               *state,
-                                               GError                     *error)
+gb_beautifier_process_create_for_clang_format (GbBeautifierEditorAddin *self,
+                                               ProcessState            *state,
+                                               GError                  *error)
 {
   g_autoptr(GSubprocessLauncher) launcher = NULL;
   GSubprocess *subprocess = NULL;
@@ -184,7 +184,7 @@ gb_beautifier_process_create_for_clang_format (GbBeautifierWorkbenchAddin *self,
   g_autofree gchar *tmp_config_path = NULL;
   g_autofree gchar *tmp_src_path = NULL;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (state != NULL);
 
   config_path = g_file_get_path (state->config_file);
@@ -312,14 +312,14 @@ create_tmp_file_cb (GObject      *object,
                     GAsyncResult *result,
                     gpointer      user_data)
 {
-  GbBeautifierWorkbenchAddin  *self = (GbBeautifierWorkbenchAddin  *)object;
+  GbBeautifierEditorAddin  *self = (GbBeautifierEditorAddin  *)object;
   g_autoptr (GTask) task = (GTask *)user_data;
   g_autoptr(GError) error = NULL;
   ProcessState *state;
   GSubprocess *process;
   GCancellable *cancellable;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (G_IS_ASYNC_RESULT (result));
   g_assert (G_IS_TASK (task));
 
@@ -371,21 +371,21 @@ command_args_copy (GPtrArray *args)
 }
 
 void
-gb_beautifier_process_launch_async (GbBeautifierWorkbenchAddin  *self,
-                                    IdeSourceView               *source_view,
-                                    GtkTextIter                 *begin,
-                                    GtkTextIter                 *end,
-                                    GbBeautifierConfigEntry     *entry,
-                                    GAsyncReadyCallback          callback,
-                                    GCancellable                *cancellable,
-                                    gpointer                     user_data)
+gb_beautifier_process_launch_async (GbBeautifierEditorAddin  *self,
+                                    IdeSourceView            *source_view,
+                                    GtkTextIter              *begin,
+                                    GtkTextIter              *end,
+                                    GbBeautifierConfigEntry  *entry,
+                                    GAsyncReadyCallback       callback,
+                                    GCancellable             *cancellable,
+                                    gpointer                  user_data)
 {
   GtkTextBuffer *buffer;
   ProcessState *state;
   g_autoptr(GTask) task = NULL;
   const gchar *lang_id;
 
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (IDE_IS_SOURCE_VIEW (source_view));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
   g_assert (entry != NULL);
@@ -431,11 +431,11 @@ gb_beautifier_process_launch_async (GbBeautifierWorkbenchAddin  *self,
 }
 
 gboolean
-gb_beautifier_process_launch_finish (GbBeautifierWorkbenchAddin  *self,
-                                     GAsyncResult                *result,
-                                     GError                     **error)
+gb_beautifier_process_launch_finish (GbBeautifierEditorAddin  *self,
+                                     GAsyncResult             *result,
+                                     GError                  **error)
 {
-  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
+  g_assert (GB_IS_BEAUTIFIER_EDITOR_ADDIN (self));
   g_assert (g_task_is_valid (result, self));
 
   return g_task_propagate_boolean (G_TASK (result), error);
diff --git a/plugins/beautifier/gb-beautifier-process.h b/plugins/beautifier/gb-beautifier-process.h
index 5fc2cfd..fddeae1 100644
--- a/plugins/beautifier/gb-beautifier-process.h
+++ b/plugins/beautifier/gb-beautifier-process.h
@@ -22,21 +22,21 @@
 #include <glib-object.h>
 
 #include "gb-beautifier-config.h"
-#include "gb-beautifier-workbench-addin.h"
+#include "gb-beautifier-editor-addin.h"
 
 G_BEGIN_DECLS
 
-void          gb_beautifier_process_launch_async      (GbBeautifierWorkbenchAddin  *self,
-                                                       IdeSourceView               *source_view,
-                                                       GtkTextIter                 *begin,
-                                                       GtkTextIter                 *end,
-                                                       GbBeautifierConfigEntry     *entry,
-                                                       GAsyncReadyCallback          callback,
-                                                       GCancellable                *cancellable,
-                                                       gpointer                     user_data);
-gboolean      gb_beautifier_process_launch_finish     (GbBeautifierWorkbenchAddin  *self,
-                                                       GAsyncResult                *result,
-                                                       GError                     **error);
+void          gb_beautifier_process_launch_async      (GbBeautifierEditorAddin  *self,
+                                                       IdeSourceView            *source_view,
+                                                       GtkTextIter              *begin,
+                                                       GtkTextIter              *end,
+                                                       GbBeautifierConfigEntry  *entry,
+                                                       GAsyncReadyCallback       callback,
+                                                       GCancellable             *cancellable,
+                                                       gpointer                  user_data);
+gboolean      gb_beautifier_process_launch_finish     (GbBeautifierEditorAddin  *self,
+                                                       GAsyncResult             *result,
+                                                       GError                  **error);
 
 G_END_DECLS
 
diff --git a/plugins/beautifier/meson.build b/plugins/beautifier/meson.build
index 9de245b..6667b0a 100644
--- a/plugins/beautifier/meson.build
+++ b/plugins/beautifier/meson.build
@@ -16,8 +16,8 @@ beautifier_sources = [
   'gb-beautifier-private.h',
   'gb-beautifier-process.c',
   'gb-beautifier-process.h',
-  'gb-beautifier-workbench-addin.c',
-  'gb-beautifier-workbench-addin.h',
+  'gb-beautifier-editor-addin.c',
+  'gb-beautifier-editor-addin.h',
 ]
 
 beautifier_datadir = join_paths(get_option('prefix'), plugindatadir, 'beautifier')



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