[gedit] Port the modelines plugin to libpeas
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Port the modelines plugin to libpeas
- Date: Fri, 25 Jun 2010 20:27:01 +0000 (UTC)
commit e1df93f3b827131d13178286cec365c8bbc0f075
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 | 126 +++++++++++++++-------------
plugins/modelines/gedit-modeline-plugin.h | 22 ++++-
4 files changed, 111 insertions(+), 89 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..396e502 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
@@ -29,16 +29,16 @@
#include "modeline-parser.h"
#include <gedit/gedit-debug.h>
+#include <gedit/gedit-window.h>
+#include <gedit/gedit-window-activatable.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,14 @@ 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 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 gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
-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 (GEDIT_TYPE_WINDOW_ACTIVATABLE,
+ gedit_window_activatable_iface_init))
static void
document_data_free (DocumentData *ddata)
@@ -66,43 +62,26 @@ document_data_free (DocumentData *ddata)
}
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;
-}
-
-static GObject *
-gedit_modeline_plugin_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_param)
+gedit_modeline_plugin_constructed (GObject *object)
{
- GObject *object;
gchar *data_dir;
- object = G_OBJECT_CLASS (gedit_modeline_plugin_parent_class)->constructor (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);
g_free (data_dir);
-
- return object;
}
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 +165,17 @@ on_window_tab_removed (GeditWindow *window,
}
static void
-gedit_modeline_plugin_activate (GeditPlugin *plugin,
- GeditWindow *window)
+gedit_modeline_plugin_activate (GeditWindowActivatable *activatable,
+ GeditWindow *window)
{
- WindowData *wdata;
+ GeditModelinePlugin *plugin;
GList *views;
GList *l;
gedit_debug (DEBUG_PLUGINS);
+ plugin = GEDIT_MODELINE_PLUGIN (activatable);
+
views = gedit_window_get_views (window);
for (l = views; l != NULL; l = l->next)
{
@@ -203,36 +184,29 @@ 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 (GeditWindowActivatable *activatable,
+ GeditWindow *window)
{
- WindowData *wdata;
+ GeditModelinePlugin *plugin;
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_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 +220,38 @@ gedit_modeline_plugin_deactivate (GeditPlugin *plugin,
g_list_free (views);
}
-/* ex:ts=8:noet: */
+static void
+gedit_modeline_plugin_class_init (GeditModelinePluginClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructed = gedit_modeline_plugin_constructed;
+ object_class->finalize = gedit_modeline_plugin_finalize;
+
+ g_type_class_add_private (klass, sizeof (GeditModelinePluginPrivate));
+}
+
+static void
+gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface)
+{
+ iface->activate = gedit_modeline_plugin_activate;
+ iface->deactivate = gedit_modeline_plugin_deactivate;
+}
+
+static void
+gedit_modeline_plugin_class_finalize (GeditModelinePluginClass *klass)
+{
+}
+
+
+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,
+ GEDIT_TYPE_WINDOW_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]