[gedit/libpeas: 2/2] Port the modelines plugin to libpeas



commit ff64df6d4ab023b3f84084f04dd7843b1e961a20
Author: Steve Frécinaux <code istique net>
Date:   Sun Jun 13 21:06:28 2010 +0200

    Port the modelines plugin to libpeas
    
    https://bugzilla.gnome.org/show_bug.cgi?id=606363

 Makefile.am                               |    2 +-
 plugins/Makefile.am                       |   50 ++++++++-------
 plugins/modelines/gedit-modeline-plugin.c |   98 ++++++++++++++++++-----------
 plugins/modelines/gedit-modeline-plugin.h |   22 +++++--
 4 files changed, 105 insertions(+), 67 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 9c3bd85..122a88b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = gedit pixmaps po data docs tests win32 osx
+SUBDIRS = gedit pixmaps po plugins data docs tests win32 osx
 
 if !OS_OSX
 SUBDIRS += help
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index ec1df43..ad444fe 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,28 +1,30 @@
-DIST_SUBDIRS =		\
-	changecase 	\
-	checkupdate	\
-	docinfo 	\
-	filebrowser 	\
-	modelines	\
-	sort 		\
-	spell 		\
-	taglist 	\
-	time
+DIST_SUBDIRS = \
+	modelines
 
+#	changecase 	\
+#	checkupdate	\
+#	docinfo 	\
+#	filebrowser 	\
+#	modelines	\
+#	sort 		\
+#	spell 		\
+#	taglist 	\
+#	time
 #	externaltools
 #	pythonconsole
 #	quickopen
 #	snippets
 
-SUBDIRS = 		\
-	changecase	\
-	docinfo		\
-	filebrowser	\
-	modelines	\
-	sort		\
-	taglist		\
-	time
+SUBDIRS = \
+	modelines
 
+#	changecase
+#	docinfo
+#	filebrowser
+#	modelines
+#	sort
+#	taglist
+#	time
 #	pythonconsole
 #	quickopen
 #	snippets
@@ -31,12 +33,12 @@ SUBDIRS = 		\
 #SUBDIRS      += externaltools
 #endif
 
-if ENABLE_ENCHANT
-SUBDIRS      += spell
-endif
+#if ENABLE_ENCHANT
+#SUBDIRS      += spell
+#endif
 
-if ENABLE_UPDATER
-SUBDIRS      += checkupdate
-endif
+#if ENABLE_UPDATER
+#SUBDIRS      += checkupdate
+#endif
 
 -include $(top_srcdir)/git.mk
diff --git a/plugins/modelines/gedit-modeline-plugin.c b/plugins/modelines/gedit-modeline-plugin.c
index b6bd4e3..5ad8003 100644
--- a/plugins/modelines/gedit-modeline-plugin.c
+++ b/plugins/modelines/gedit-modeline-plugin.c
@@ -2,7 +2,7 @@
  * gedit-modeline-plugin.c
  * Emacs, Kate and Vim-style modelines support for gedit.
  * 
- * Copyright (C) 2005-2007 - Steve Frécinaux <code istique net>
+ * Copyright (C) 2005-2010 - Steve Frécinaux <code istique net>
  *
  * 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
@@ -25,20 +25,20 @@
 
 #include <glib/gi18n-lib.h>
 #include <gmodule.h>
+#include <libpeas/peas-activatable.h>
 #include "gedit-modeline-plugin.h"
 #include "modeline-parser.h"
 
 #include <gedit/gedit-debug.h>
+#include <gedit/gedit-window.h>
 #include <gedit/gedit-utils.h>
 
-#define WINDOW_DATA_KEY "GeditModelinePluginWindowData"
 #define DOCUMENT_DATA_KEY "GeditModelinePluginDocumentData"
 
-typedef struct
-{
+struct _GeditModelinePluginPrivate {
 	gulong tab_added_handler_id;
 	gulong tab_removed_handler_id;
-} WindowData;
+};
 
 typedef struct
 {
@@ -46,18 +46,18 @@ typedef struct
 	gulong document_saved_handler_id;
 } DocumentData;
 
-static void	gedit_modeline_plugin_activate (GeditPlugin *plugin, GeditWindow *window);
-static void	gedit_modeline_plugin_deactivate (GeditPlugin *plugin, GeditWindow *window);
+static void	peas_activatable_iface_init (PeasActivatableInterface *iface);
+static void	gedit_modeline_plugin_activate (PeasActivatable *activatable, GObject *object);
+static void	gedit_modeline_plugin_deactivate (PeasActivatable *activatable, GObject *object);
 static GObject	*gedit_modeline_plugin_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_param);
 static void	gedit_modeline_plugin_finalize (GObject *object);
 
-GEDIT_PLUGIN_REGISTER_TYPE(GeditModelinePlugin, gedit_modeline_plugin)
-
-static void
-window_data_free (WindowData *wdata)
-{
-	g_slice_free (WindowData, wdata);
-}
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditModelinePlugin,
+				gedit_modeline_plugin,
+				PEAS_TYPE_EXTENSION_BASE,
+				0,
+				G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
+							       peas_activatable_iface_init))
 
 static void
 document_data_free (DocumentData *ddata)
@@ -69,13 +69,23 @@ static void
 gedit_modeline_plugin_class_init (GeditModelinePluginClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-	GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
 
 	object_class->constructor = gedit_modeline_plugin_constructor;
 	object_class->finalize = gedit_modeline_plugin_finalize;
 
-	plugin_class->activate = gedit_modeline_plugin_activate;
-	plugin_class->deactivate = gedit_modeline_plugin_deactivate;
+	g_type_class_add_private (klass, sizeof (GeditModelinePluginPrivate));
+}
+
+static void
+peas_activatable_iface_init (PeasActivatableInterface *iface)
+{
+	iface->activate = gedit_modeline_plugin_activate;
+	iface->deactivate = gedit_modeline_plugin_deactivate;
+}
+
+static void
+gedit_modeline_plugin_class_finalize (GeditModelinePluginClass *klass)
+{
 }
 
 static GObject *
@@ -90,7 +100,7 @@ gedit_modeline_plugin_constructor (GType                  type,
 										   n_construct_properties,
 										   construct_param);
 
-	data_dir = gedit_plugin_get_data_dir (GEDIT_PLUGIN (object));
+	data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (object));
 
 	modeline_parser_init (data_dir);
 
@@ -103,6 +113,11 @@ static void
 gedit_modeline_plugin_init (GeditModelinePlugin *plugin)
 {
 	gedit_debug_message (DEBUG_PLUGINS, "GeditModelinePlugin initializing");
+
+	plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
+						    GEDIT_TYPE_MODELINE_PLUGIN,
+						    GeditModelinePluginPrivate);
+
 }
 
 static void
@@ -186,15 +201,19 @@ on_window_tab_removed (GeditWindow *window,
 }
 
 static void
-gedit_modeline_plugin_activate (GeditPlugin *plugin,
-				GeditWindow *window)
+gedit_modeline_plugin_activate (PeasActivatable *activatable,
+				GObject         *object)
 {
-	WindowData *wdata;
+	GeditModelinePlugin *plugin;
+	GeditWindow *window;
 	GList *views;
 	GList *l;
 
 	gedit_debug (DEBUG_PLUGINS);
 
+	plugin = GEDIT_MODELINE_PLUGIN (activatable);
+	window = GEDIT_WINDOW (object);
+
 	views = gedit_window_get_views (window);
 	for (l = views; l != NULL; l = l->next)
 	{
@@ -203,36 +222,31 @@ gedit_modeline_plugin_activate (GeditPlugin *plugin,
 	}
 	g_list_free (views);
 
-	wdata = g_slice_new (WindowData);
-
-	wdata->tab_added_handler_id =
+	plugin->priv->tab_added_handler_id =
 		g_signal_connect (window, "tab-added",
 				  G_CALLBACK (on_window_tab_added), NULL);
 
-	wdata->tab_removed_handler_id =
+	plugin->priv->tab_removed_handler_id =
 		g_signal_connect (window, "tab-removed",
 				  G_CALLBACK (on_window_tab_removed), NULL);
-
-	g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY,
-				wdata, (GDestroyNotify) window_data_free);
 }
 
 static void
-gedit_modeline_plugin_deactivate (GeditPlugin *plugin,
-				  GeditWindow *window)
+gedit_modeline_plugin_deactivate (PeasActivatable *activatable,
+				  GObject         *object)
 {
-	WindowData *wdata;
+	GeditModelinePlugin *plugin;
+	GeditWindow *window;
 	GList *views;
 	GList *l;
 
 	gedit_debug (DEBUG_PLUGINS);
 
-	wdata = g_object_steal_data (G_OBJECT (window), WINDOW_DATA_KEY);
-
-	g_signal_handler_disconnect (window, wdata->tab_added_handler_id);
-	g_signal_handler_disconnect (window, wdata->tab_removed_handler_id);
+	plugin = GEDIT_MODELINE_PLUGIN (activatable);
+	window = GEDIT_WINDOW (object);
 
-	window_data_free (wdata);
+	g_signal_handler_disconnect (window, plugin->priv->tab_added_handler_id);
+	g_signal_handler_disconnect (window, plugin->priv->tab_removed_handler_id);
 
 	views = gedit_window_get_views (window);
 
@@ -246,4 +260,14 @@ gedit_modeline_plugin_deactivate (GeditPlugin *plugin,
 	g_list_free (views);
 }
 
-/* ex:ts=8:noet: */
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+	gedit_modeline_plugin_register_type (G_TYPE_MODULE (module));
+
+	peas_object_module_register_extension_type (module,
+						    PEAS_TYPE_ACTIVATABLE,
+						    GEDIT_TYPE_MODELINE_PLUGIN);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/modelines/gedit-modeline-plugin.h b/plugins/modelines/gedit-modeline-plugin.h
index a5ff1da..fedb8ac 100644
--- a/plugins/modelines/gedit-modeline-plugin.h
+++ b/plugins/modelines/gedit-modeline-plugin.h
@@ -24,7 +24,8 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <gedit/gedit-plugin.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
 
 G_BEGIN_DECLS
 
@@ -35,13 +36,24 @@ G_BEGIN_DECLS
 #define GEDIT_IS_MODELINE_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_MODELINE_PLUGIN))
 #define GEDIT_MODELINE_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_MODELINE_PLUGIN, GeditModelinePluginClass))
 
-/* Private structure type */
-typedef GeditPluginClass	GeditModelinePluginClass;
-typedef GeditPlugin		GeditModelinePlugin;
+typedef struct _GeditModelinePlugin		GeditModelinePlugin;
+typedef struct _GeditModelinePluginPrivate	GeditModelinePluginPrivate;
+typedef struct _GeditModelinePluginClass	GeditModelinePluginClass;
+
+struct _GeditModelinePlugin {
+	PeasExtensionBase parent;
+
+	/*< private >*/
+	GeditModelinePluginPrivate *priv;
+};
+
+struct _GeditModelinePluginClass {
+	PeasExtensionBaseClass parent_class;
+};
 
 GType	gedit_modeline_plugin_get_type		(void) G_GNUC_CONST;
 
-G_MODULE_EXPORT GType register_gedit_plugin (GTypeModule *module);
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
 
 G_END_DECLS
 



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