[gtranslator] Use libpeas for plugin engine.



commit 93f17d9ee55bfd6dd90c1c10aa17815afa09bf9a
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue Nov 2 11:50:04 2010 +0100

    Use libpeas for plugin engine.

 configure.ac                             |    2 +
 src/Makefile.am                          |   12 +-
 src/dialogs/gtr-preferences-dialog.c     |    4 +-
 src/gtr-plugins-engine.c                 |  152 ++++++
 src/gtr-plugins-engine.h                 |   67 +++
 src/gtr-window-activatable.c             |  127 +++++
 src/gtr-window-activatable.h             |   64 +++
 src/gtr-window.c                         |   77 +++-
 src/plugin-system/Makefile.am            |   51 --
 src/plugin-system/gtr-module.c           |  255 ---------
 src/plugin-system/gtr-module.h           |   88 ---
 src/plugin-system/gtr-plugin-info-priv.h |   72 ---
 src/plugin-system/gtr-plugin-info.c      |  372 -------------
 src/plugin-system/gtr-plugin-info.h      |   61 ---
 src/plugin-system/gtr-plugin-manager.c   |  849 ------------------------------
 src/plugin-system/gtr-plugin-manager.h   |   82 ---
 src/plugin-system/gtr-plugin.c           |  152 ------
 src/plugin-system/gtr-plugin.h           |  233 --------
 src/plugin-system/gtr-plugins-engine.c   |  607 ---------------------
 src/plugin-system/gtr-plugins-engine.h   |  105 ----
 src/update-from-gedit.sh                 |    6 +-
 21 files changed, 493 insertions(+), 2945 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c22cc63..53b4a4b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,6 +106,8 @@ PKG_CHECK_MODULES(GTRANSLATOR, [
 	gdl-3.0 >= $GDL_REQUIRED
 	gsettings-desktop-schemas
 	libgda-4.0 >= 4.2.0
+	libpeas-1.0 >= 0.7.0
+	libpeas-gtk-1.0 >= 0.7.0
 ])
 
 AC_SUBST(GTRANSLATOR_CFLAGS)
diff --git a/src/Makefile.am b/src/Makefile.am
index 3a94830..6d97308 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,17 +4,17 @@
 
 SUBDIRS = toolbareditor \
 	  dialogs \
-	  plugin-system \
 	  translation-memory
 
 noinst_LTLIBRARIES = libgtranslator.la
 
+lib_LTLIBRARIES = libgtranslator-private.la
+
 INCLUDES = \
 	-I$(top_srcdir)						\
 	-I$(includedir)						\
 	-I$(top_srcdir)/src/dialogs				\
 	-I$(top_srcdir)/src/toolbareditor			\
-	-I$(top_srcdir)/src/plugin-system			\
 	-I$(top_srcdir)/src/translation-memory			\
 	-I$(top_srcdir)/src/translation-memory/berkeley		\
 	-DGNOMELOCALEDIR=\""$(prefix)/${DATADIRNAME}/locale"\"	\
@@ -36,7 +36,7 @@ bin_PROGRAMS = \
 
 gtranslator_SOURCES = main.c
 
-gtranslator_LDADD = libgtranslator.la $(GTRANSLATOR_LIBS) $(GTKSPELL_LIBS) $(INTLLIBS) -lgettextpo
+gtranslator_LDADD = libgtranslator.la libgtranslator-private.la $(GTRANSLATOR_LIBS) $(GTKSPELL_LIBS) $(INTLLIBS) -lgettextpo
 
 if PLATFORM_WIN32
 gtranslator_LDFLAGS = -Wl,--export-all-symbols -mwindows -Wl,--out-implib,libgedit-$(GTR_API_VERSION).a
@@ -73,6 +73,7 @@ INST_H_FILES = \
 	gtr-statusbar.h \
 	gtr-tab.h \
 	gtr-view.h \
+	gtr-window-activatable.h \
 	gtr-window.h
 
 NOINST_H_FILES = \
@@ -93,6 +94,9 @@ headerdir = $(prefix)/include/gtranslator- GTR_API_VERSION@/gtranslator
 header_DATA = \
 	$(INST_H_FILES)
 
+libgtranslator_private_la_SOURCES =	\
+	gtr-window-activatable.c
+
 libgtranslator_c_files = \
 	gtr-actions-documents.c \
 	gtr-actions-edit.c \
@@ -112,6 +116,7 @@ libgtranslator_c_files = \
 	gtr-message-table-model.c \
 	gtr-msg.c \
 	gtr-notebook.c \
+	gtr-plugins-engine.c \
 	gtr-po.c \
 	gtr-profile.c \
 	gtr-profile-manager.c \
@@ -134,7 +139,6 @@ libgtranslator_la_LIBADD = \
 	$(GTRANSLATOR_LIBS) \
 	dialogs/libdialogs.la \
 	toolbareditor/libtoolbareditor.la \
-	plugin-system/libpluginsystem.la \
 	translation-memory/libtranslationmemory.la
 
 gtr-enum-types.h: gtr-enum-types.h.template $(INST_H_FILES) $(GLIB_MKENUMS)
diff --git a/src/dialogs/gtr-preferences-dialog.c b/src/dialogs/gtr-preferences-dialog.c
index 504d800..df5c0ea 100644
--- a/src/dialogs/gtr-preferences-dialog.c
+++ b/src/dialogs/gtr-preferences-dialog.c
@@ -32,7 +32,6 @@
 #include "gtr-profile.h"
 #include "gtr-profile-manager.h"
 #include "gtr-utils.h"
-#include "gtr-plugin-manager.h"
 #include "gtr-profile-dialog.h"
 #include "gtr-po.h"
 #include "gtr-utils.h"
@@ -46,6 +45,7 @@
 #include <string.h>
 #include <gtksourceview/gtksourcestyleschememanager.h>
 #include <gdl/gdl.h>
+#include <libpeas-gtk/peas-gtk-plugin-manager.h>
 
 #define GTR_PREFERENCES_DIALOG_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ( \
                                                     (object), \
@@ -934,7 +934,7 @@ setup_plugin_pages (GtrPreferencesDialog * dlg)
   alignment = gtk_alignment_new (0., 0., 1., 1.);
   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 12, 12, 12);
 
-  page_content = gtr_plugin_manager_new ();
+  page_content = peas_gtk_plugin_manager_new ();
   g_return_if_fail (page_content != NULL);
 
   gtk_container_add (GTK_CONTAINER (alignment), page_content);
diff --git a/src/gtr-plugins-engine.c b/src/gtr-plugins-engine.c
new file mode 100644
index 0000000..2b341ed
--- /dev/null
+++ b/src/gtr-plugins-engine.c
@@ -0,0 +1,152 @@
+/*
+ * gtr-plugins-engine.c
+ * This file is part of gtr
+ *
+ * Copyright (C) 2002-2005 Paolo Maggi 
+ * Copyright (C) 2010 Steve Frécinaux
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, 
+ * Boston, MA 02111-1307, USA. 
+ */
+
+/*
+ * Modified by the gtr Team, 2002-2005. See the AUTHORS file for a 
+ * list of people on the gtr Team.  
+ * See the ChangeLog files for a list of changes. 
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <glib/gi18n.h>
+#include <girepository.h>
+
+#include "gtr-plugins-engine.h"
+//#include "gtr-debug.h"
+#include "gtr-application.h"
+#include "gtr-dirs.h"
+#include "gtr-settings.h"
+#include "gtr-utils.h"
+
+G_DEFINE_TYPE (GtrPluginsEngine, gtr_plugins_engine, PEAS_TYPE_ENGINE)
+
+struct _GtrPluginsEnginePrivate
+{
+  GSettings *plugin_settings;
+};
+
+GtrPluginsEngine *default_engine = NULL;
+
+static void
+gtr_plugins_engine_init (GtrPluginsEngine * engine)
+{
+  gchar *typelib_dir;
+  GError *error = NULL;
+
+  engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine,
+                                              GTR_TYPE_PLUGINS_ENGINE,
+                                              GtrPluginsEnginePrivate);
+
+  engine->priv->plugin_settings = g_settings_new ("org.gnome.gtranslator.plugins");
+
+  /* Require gtr's typelib. */
+  typelib_dir = g_build_filename (gtr_dirs_get_gtr_lib_dir (),
+                                  "girepository-1.0", NULL);
+
+  if (!g_irepository_require_private (g_irepository_get_default (),
+                                      typelib_dir, "Gtranslator", "2.0", 0, &error))
+    {
+      g_warning ("Could not load Gtr repository: %s", error->message);
+      g_error_free (error);
+      error = NULL;
+    }
+
+  g_free (typelib_dir);
+
+  /* This should be moved to libpeas */
+  if (!g_irepository_require (g_irepository_get_default (),
+                              "Peas", "1.0", 0, &error))
+    {
+      g_warning ("Could not load Peas repository: %s", error->message);
+      g_error_free (error);
+      error = NULL;
+    }
+
+  if (!g_irepository_require (g_irepository_get_default (),
+                              "PeasGtk", "1.0", 0, &error))
+    {
+      g_warning ("Could not load PeasGtk repository: %s", error->message);
+      g_error_free (error);
+      error = NULL;
+    }
+
+  peas_engine_add_search_path (PEAS_ENGINE (engine),
+                               gtr_dirs_get_user_plugins_dir (),
+                               gtr_dirs_get_user_plugins_dir ());
+
+  peas_engine_add_search_path (PEAS_ENGINE (engine),
+                               gtr_dirs_get_gtr_plugins_dir (),
+                               gtr_dirs_get_gtr_plugins_data_dir ());
+
+  g_settings_bind (engine->priv->plugin_settings,
+                   GTR_SETTINGS_ACTIVE_PLUGINS,
+                   engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT);
+}
+
+static void
+gtr_plugins_engine_dispose (GObject * object)
+{
+  GtrPluginsEngine *engine = GTR_PLUGINS_ENGINE (object);
+
+  if (engine->priv->plugin_settings != NULL)
+    {
+      g_object_unref (engine->priv->plugin_settings);
+      engine->priv->plugin_settings = NULL;
+    }
+
+  G_OBJECT_CLASS (gtr_plugins_engine_parent_class)->dispose (object);
+}
+
+static void
+gtr_plugins_engine_class_init (GtrPluginsEngineClass * klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = gtr_plugins_engine_dispose;
+
+  g_type_class_add_private (klass, sizeof (GtrPluginsEnginePrivate));
+}
+
+GtrPluginsEngine *
+gtr_plugins_engine_get_default (void)
+{
+  if (default_engine == NULL)
+    {
+      default_engine =
+        GTR_PLUGINS_ENGINE (g_object_new (GTR_TYPE_PLUGINS_ENGINE, NULL));
+
+      g_object_add_weak_pointer (G_OBJECT (default_engine),
+                                 (gpointer) & default_engine);
+    }
+
+  return default_engine;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/src/gtr-plugins-engine.h b/src/gtr-plugins-engine.h
new file mode 100644
index 0000000..5cace58
--- /dev/null
+++ b/src/gtr-plugins-engine.h
@@ -0,0 +1,67 @@
+/*
+ * gtr-plugins-engine.h
+ * This file is part of gtr
+ *
+ * Copyright (C) 2002-2005 - Paolo Maggi 
+ * Copyright (C) 2010 - Steve Frécinaux
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, 
+ * Boston, MA 02111-1307, USA. 
+ */
+
+/*
+ * Modified by the gtr Team, 2002-2005. See the AUTHORS file for a 
+ * list of people on the gtr Team.  
+ * See the ChangeLog files for a list of changes. 
+ *
+ * $Id$
+ */
+
+#ifndef __GTR_PLUGINS_ENGINE_H__
+#define __GTR_PLUGINS_ENGINE_H__
+
+#include <glib.h>
+#include <libpeas/peas-engine.h>
+
+G_BEGIN_DECLS
+#define GTR_TYPE_PLUGINS_ENGINE              (gtr_plugins_engine_get_type ())
+#define GTR_PLUGINS_ENGINE(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), GTR_TYPE_PLUGINS_ENGINE, GtrPluginsEngine))
+#define GTR_PLUGINS_ENGINE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), GTR_TYPE_PLUGINS_ENGINE, GtrPluginsEngineClass))
+#define GTR_IS_PLUGINS_ENGINE(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTR_TYPE_PLUGINS_ENGINE))
+#define GTR_IS_PLUGINS_ENGINE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTR_TYPE_PLUGINS_ENGINE))
+#define GTR_PLUGINS_ENGINE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), GTR_TYPE_PLUGINS_ENGINE, GtrPluginsEngineClass))
+typedef struct _GtrPluginsEngine GtrPluginsEngine;
+typedef struct _GtrPluginsEnginePrivate GtrPluginsEnginePrivate;
+
+struct _GtrPluginsEngine
+{
+  PeasEngine parent;
+  GtrPluginsEnginePrivate *priv;
+};
+
+typedef struct _GtrPluginsEngineClass GtrPluginsEngineClass;
+
+struct _GtrPluginsEngineClass
+{
+  PeasEngineClass parent_class;
+};
+
+GType gtr_plugins_engine_get_type (void) G_GNUC_CONST;
+
+GtrPluginsEngine *gtr_plugins_engine_get_default (void);
+
+G_END_DECLS
+#endif /* __GTR_PLUGINS_ENGINE_H__ */
+/* ex:ts=8:noet: */
diff --git a/src/gtr-window-activatable.c b/src/gtr-window-activatable.c
new file mode 100644
index 0000000..b9a9c15
--- /dev/null
+++ b/src/gtr-window-activatable.c
@@ -0,0 +1,127 @@
+/*
+ * gtr-window-activatable.h
+ * This file is part of gtr
+ *
+ * Copyright (C) 2010 Steve Frécinaux
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gtr-window-activatable.h"
+#include "gtr-window.h"
+
+/**
+ * SECTION:gtr-window-activatable
+ * @short_description: Interface for activatable extensions on windows
+ * @see_also: #PeasExtensionSet
+ *
+ * #GtrWindowActivatable is an interface which should be implemented by
+ * extensions that should be activated on a gtr main window.
+ **/
+
+G_DEFINE_INTERFACE (GtrWindowActivatable, gtr_window_activatable,
+                    G_TYPE_OBJECT)
+     void gtr_window_activatable_default_init (GtrWindowActivatableInterface *
+                                               iface)
+{
+  static gboolean initialized = FALSE;
+
+  if (!initialized)
+    {
+                /**
+		 * GtrWindowActivatable:window:
+		 *
+		 * The window property contains the gtr window for this
+		 * #GtrWindowActivatable instance.
+		 */
+      g_object_interface_install_property (iface,
+                                           g_param_spec_object ("window",
+                                                                "Window",
+                                                                "The gtranslator window",
+                                                                GTR_TYPE_WINDOW,
+                                                                G_PARAM_READWRITE
+                                                                |
+                                                                G_PARAM_CONSTRUCT_ONLY
+                                                                |
+                                                                G_PARAM_STATIC_STRINGS));
+
+      initialized = TRUE;
+    }
+}
+
+/**
+ * gtr_window_activatable_activate:
+ * @activatable: A #GtrWindowActivatable.
+ *
+ * Activates the extension on the window property.
+ */
+void
+gtr_window_activatable_activate (GtrWindowActivatable * activatable)
+{
+  GtrWindowActivatableInterface *iface;
+
+  g_return_if_fail (GTR_IS_WINDOW_ACTIVATABLE (activatable));
+
+  iface = GTR_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->activate != NULL)
+    {
+      iface->activate (activatable);
+    }
+}
+
+/**
+ * gtr_window_activatable_deactivate:
+ * @activatable: A #GtrWindowActivatable.
+ *
+ * Deactivates the extension on the window property.
+ */
+void
+gtr_window_activatable_deactivate (GtrWindowActivatable * activatable)
+{
+  GtrWindowActivatableInterface *iface;
+
+  g_return_if_fail (GTR_IS_WINDOW_ACTIVATABLE (activatable));
+
+  iface = GTR_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->deactivate != NULL)
+    {
+      iface->deactivate (activatable);
+    }
+}
+
+/**
+ * gtr_window_activatable_update_state:
+ * @activatable: A #GtrWindowActivatable.
+ *
+ * Triggers an update of the extension internal state to take into account
+ * state changes in the window, due to some event or user action.
+ */
+void
+gtr_window_activatable_update_state (GtrWindowActivatable * activatable)
+{
+  GtrWindowActivatableInterface *iface;
+
+  g_return_if_fail (GTR_IS_WINDOW_ACTIVATABLE (activatable));
+
+  iface = GTR_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+  if (iface->update_state != NULL)
+    {
+      iface->update_state (activatable);
+    }
+}
diff --git a/src/gtr-window-activatable.h b/src/gtr-window-activatable.h
new file mode 100644
index 0000000..70e60c4
--- /dev/null
+++ b/src/gtr-window-activatable.h
@@ -0,0 +1,64 @@
+/*
+ * gtr-window-activatable.h
+ * This file is part of gtr
+ *
+ * Copyright (C) 2010 - Steve Frécinaux
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTR_WINDOW_ACTIVATABLE_H__
+#define __GTR_WINDOW_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*
+ * Type checking and casting macros
+ */
+#define GTR_TYPE_WINDOW_ACTIVATABLE		(gtr_window_activatable_get_type ())
+#define GTR_WINDOW_ACTIVATABLE(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTR_TYPE_WINDOW_ACTIVATABLE, GtrWindowActivatable))
+#define GTR_WINDOW_ACTIVATABLE_IFACE(obj)	(G_TYPE_CHECK_CLASS_CAST ((obj), GTR_TYPE_WINDOW_ACTIVATABLE, GtrWindowActivatableInterface))
+#define GTR_IS_WINDOW_ACTIVATABLE(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTR_TYPE_WINDOW_ACTIVATABLE))
+#define GTR_WINDOW_ACTIVATABLE_GET_IFACE(obj)	(G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTR_TYPE_WINDOW_ACTIVATABLE, GtrWindowActivatableInterface))
+typedef struct _GtrWindowActivatable GtrWindowActivatable;      /* dummy typedef */
+typedef struct _GtrWindowActivatableInterface GtrWindowActivatableInterface;
+
+struct _GtrWindowActivatableInterface
+{
+  GTypeInterface g_iface;
+
+  /* Virtual public methods */
+  void (*activate) (GtrWindowActivatable * activatable);
+  void (*deactivate) (GtrWindowActivatable * activatable);
+  void (*update_state) (GtrWindowActivatable * activatable);
+};
+
+/*
+ * Public methods
+ */
+GType
+gtr_window_activatable_get_type (void)
+  G_GNUC_CONST;
+
+     void gtr_window_activatable_activate (GtrWindowActivatable *
+                                           activatable);
+     void gtr_window_activatable_deactivate (GtrWindowActivatable *
+                                             activatable);
+     void gtr_window_activatable_update_state (GtrWindowActivatable *
+                                               activatable);
+
+G_END_DECLS
+#endif /* __GTR_WINDOW_ACTIVATABLE_H__ */
diff --git a/src/gtr-window.c b/src/gtr-window.c
index ccc237d..a7ddb57 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -26,6 +26,7 @@
 
 #include "gtr-actions.h"
 #include "gtr-application.h"
+#include "gtr-debug.h"
 #include "gtr-dirs.h"
 #include "gtr-header.h"
 #include "gtr-msg.h"
@@ -37,6 +38,7 @@
 #include "gtr-statusbar.h"
 #include "gtr-utils.h"
 #include "gtr-window.h"
+#include "gtr-window-activatable.h"
 #include "gtr-profile-manager.h"
 #include "gtr-status-combo-box.h"
 
@@ -55,6 +57,7 @@
 #include <glib-object.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <libpeas/peas-extension-set.h>
 
 #define GTR_STOCK_FUZZY_NEXT "gtranslator-fuzzy-next"
 #define GTR_STOCK_FUZZY_PREV "gtranslator-fuzzy-prev"
@@ -113,6 +116,8 @@ struct _GtrWindowPrivate
   GtrProfileManager *prof_manager;
   GtkWidget *profile_combo;
 
+  PeasExtensionSet *extensions;
+
   guint destroy_has_run : 1;
   guint dispose_has_run : 1;
 };
@@ -658,6 +663,8 @@ set_sensitive_according_to_tab (GtrWindow * window, GtrTab * tab)
   gtk_action_set_sensitive (action, current_page < pages - 1);
 
   _gtr_window_set_sensitive_according_to_message (window, po);
+
+  peas_extension_set_call (window->priv->extensions, "update_state", window);
 }
 
 static void
@@ -1056,8 +1063,7 @@ notebook_switch_page (GtkNotebook * nb,
   if (action != NULL)
     gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
 
-  gtr_plugins_engine_update_plugins_ui
-    (gtr_plugins_engine_get_default (), window, FALSE);
+  peas_extension_set_call (window->priv->extensions, "update_state", window);
 }
 
 static void
@@ -1078,6 +1084,8 @@ notebook_page_removed (GtkNotebook * notebook,
     gtk_widget_hide (window->priv->profile_combo);
 
   update_documents_list_menu (window);
+
+  peas_engine_garbage_collect (PEAS_ENGINE (gtr_plugins_engine_get_default ()));
 }
 
 static void
@@ -1088,8 +1096,7 @@ notebook_tab_close_request (GtrNotebook * notebook,
    * seems to be ok, but we need to keep an eye on this. */
   gtr_close_tab (tab, window);
 
-  gtr_plugins_engine_update_plugins_ui
-    (gtr_plugins_engine_get_default (), window, FALSE);
+  peas_extension_set_call (window->priv->extensions, "update_state", window);
 }
 
 static void
@@ -1210,8 +1217,7 @@ notebook_tab_added (GtkNotebook * notebook,
 
   update_documents_list_menu (window);
 
-  gtr_plugins_engine_update_plugins_ui (gtr_plugins_engine_get_default (),
-                                        window, FALSE);
+  peas_extension_set_call (window->priv->extensions, "update_state", window);
 }
 
 void
@@ -1769,6 +1775,30 @@ gtr_window_draw (GtrWindow * window)
 }
 
 static void
+extension_added (PeasExtensionSet *extensions,
+                 PeasPluginInfo   *info,
+                 PeasExtension    *exten,
+                 GtrWindow        *window)
+{
+  peas_extension_call (exten, "activate");
+}
+
+static void
+extension_removed (PeasExtensionSet *extensions,
+                   PeasPluginInfo   *info,
+                   PeasExtension    *exten,
+                   GtrWindow        *window)
+{
+  peas_extension_call (exten, "deactivate");
+
+  /* Ensure update of ui manager, because we suspect it does something
+   * with expected static strings in the type module (when unloaded the
+   * strings don't exist anymore, and ui manager updates in an idle
+   * func) */
+  gtk_ui_manager_ensure_update (window->priv->ui_manager);
+}
+
+static void
 gtr_window_init (GtrWindow * window)
 {
   GtkTargetList *tl;
@@ -1832,10 +1862,6 @@ gtr_window_init (GtrWindow * window)
   window->priv->view_menu =
     gtk_menu_item_get_submenu (GTK_MENU_ITEM (view_menu));
 
-  /* Plugins */
-  gtr_plugins_engine_update_plugins_ui
-    (gtr_plugins_engine_get_default (), window, TRUE);
-
   /* Adding notebook to dock */
   add_widget_full (window,
                    window->priv->notebook,
@@ -1849,6 +1875,21 @@ gtr_window_init (GtrWindow * window)
 
   gtr_window_layout_load (window, filename, NULL);
   g_free (filename);
+
+  /* Plugins */
+  window->priv->extensions = peas_extension_set_new (PEAS_ENGINE (gtr_plugins_engine_get_default ()),
+                                                     GTR_TYPE_WINDOW_ACTIVATABLE,
+                                                     "window", window,
+                                                     NULL);
+  g_signal_connect (window->priv->extensions,
+                    "extension-added",
+                    G_CALLBACK (extension_added),
+                    window);
+  g_signal_connect (window->priv->extensions,
+                    "extension-removed",
+                    G_CALLBACK (extension_removed),
+                    window);
+  peas_extension_set_call (window->priv->extensions, "activate");
 }
 
 static void
@@ -1877,9 +1918,23 @@ gtr_window_dispose (GObject * object)
 
   DEBUG_PRINT ("window dispose");
 
+  /* First of all, force collection so that plugins
+   * really drop some of the references.
+   */
+  peas_engine_garbage_collect (PEAS_ENGINE (gtr_plugins_engine_get_default ()));
+
   if (!priv->dispose_has_run)
     {
       save_panes_state (window);
+
+      peas_extension_set_call (priv->extensions,
+                               "deactivate",
+                               window);
+
+      g_object_unref (priv->extensions);
+
+      peas_engine_garbage_collect (PEAS_ENGINE (gtr_plugins_engine_get_default ()));
+
       priv->dispose_has_run = TRUE;
     }
 
@@ -1921,7 +1976,7 @@ gtr_window_dispose (GObject * object)
   /* Now that there have broken some reference loops,
    * force collection again.
    */
-  gtr_plugins_engine_garbage_collect (gtr_plugins_engine_get_default ());
+  peas_engine_garbage_collect (PEAS_ENGINE (gtr_plugins_engine_get_default ()));
 
   G_OBJECT_CLASS (gtr_window_parent_class)->dispose (object);
 }
diff --git a/src/update-from-gedit.sh b/src/update-from-gedit.sh
index 4f85405..dbb62cb 100755
--- a/src/update-from-gedit.sh
+++ b/src/update-from-gedit.sh
@@ -5,7 +5,11 @@ FILES="gedit-history-entry.h \
        gedit-status-combo-box.h \
        gedit-status-combo-box.c \
        gedit-close-button.h \
-       gedit-close-button.c"
+       gedit-close-button.c \
+       gedit-plugins-engine.h \
+       gedit-plugins-engine.c \
+       gedit-window-activatable.h \
+       gedit-window-activatable.c"
 
 sed_it () {
 	sed \



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