[gedit/libgpe] Adapt GeditPlugin for use with PeasUIConfigurable



commit a2540822cf86dd7af3f13dfba2d60b7b5e5f6808
Author: Steve Frécinaux <code istique net>
Date:   Sun Jan 3 02:05:56 2010 +0100

    Adapt GeditPlugin for use with PeasUIConfigurable

 bindings/python/__init__.py      |    4 +-
 bindings/python/gedit.defs       |   10 +++++++
 gedit/gedit-plugin.c             |   50 ++++++++++++++++++++++++++++++++++++-
 gedit/gedit-plugin.h             |    3 ++
 plugins/time/gedit-time-plugin.c |    5 ++-
 5 files changed, 66 insertions(+), 6 deletions(-)
---
diff --git a/bindings/python/__init__.py b/bindings/python/__init__.py
index 827890e..92c7109 100644
--- a/bindings/python/__init__.py
+++ b/bindings/python/__init__.py
@@ -25,8 +25,8 @@ import gobject
 from gedit import _gedit
 
 def _method_is_overriden(plugin, method_name):
-    child_method = getattr(plugin.__class__, method_name)
-    parent_method = getattr(_gedit.Plugin, method_name)
+    child_method = getattr(plugin.__class__, method_name, None)
+    parent_method = getattr(_gedit.Plugin, method_name, None)
     return child_method != parent_method
 
 def _proxy_plugin_method(method_name):
diff --git a/bindings/python/gedit.defs b/bindings/python/gedit.defs
index ea2eef3..12070ef 100644
--- a/bindings/python/gedit.defs
+++ b/bindings/python/gedit.defs
@@ -42,6 +42,16 @@
   (gtype-id "GEDIT_TYPE_PLUGIN")
 )
 
+(define-virtual is_configurable
+  (of-object "GeditPlugin")
+  (return-type "gboolean")
+)
+
+(define-virtual create_configure_dialog
+  (of-object "GeditPlugin")
+  (return-type "GtkWidget*")
+)
+
 (define-object Statusbar
   (in-module "Gedit")
   (parent "GtkStatusbar")
diff --git a/gedit/gedit-plugin.c b/gedit/gedit-plugin.c
index a24148f..1b97853 100644
--- a/gedit/gedit-plugin.c
+++ b/gedit/gedit-plugin.c
@@ -31,15 +31,61 @@
 #include <config.h>
 #endif
 
+#include <libpeasui/peas-ui-configurable.h>
+
 #include "gedit-plugin.h"
 #include "gedit-dirs.h"
 
-G_DEFINE_TYPE(GeditPlugin, gedit_plugin, PEAS_TYPE_PLUGIN)
+static void peas_ui_configurable_iface_init (PeasUIConfigurableIface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GeditPlugin, gedit_plugin, PEAS_TYPE_PLUGIN, 0,
+                        G_IMPLEMENT_INTERFACE (PEAS_UI_TYPE_CONFIGURABLE,
+                                               peas_ui_configurable_iface_init))
+
+static GtkWidget *
+gedit_plugin_create_configure_dialog_real (GeditPlugin *plugin)
+{
+	return NULL;
+}
+
+static gboolean
+gedit_plugin_is_configurable_real (GeditPlugin *plugin)
+{
+	return GEDIT_PLUGIN_GET_CLASS (plugin)->create_configure_dialog
+	                          != gedit_plugin_create_configure_dialog_real;
+}
 
 static void 
 gedit_plugin_class_init (GeditPluginClass *klass)
 {
-	/* Empty */
+	klass->is_configurable = gedit_plugin_is_configurable_real;
+	klass->create_configure_dialog = gedit_plugin_create_configure_dialog_real;
+}
+
+static gboolean
+gedit_plugin_is_configurable (PeasUIConfigurable *configurable)
+{
+	GeditPlugin *plugin = GEDIT_PLUGIN (configurable);
+	return GEDIT_PLUGIN_GET_CLASS (plugin)->is_configurable (plugin);
+}
+
+/**
+ * We "proxy" the Configurable methods to virtual methods in the
+ * Gedit Plugin's class to make it easier for implementors to provide
+ * an implementation for those (especially from the python side).
+ */
+static GtkWidget *
+gedit_plugin_create_configure_dialog (PeasUIConfigurable *configurable)
+{
+	GeditPlugin *plugin = GEDIT_PLUGIN (configurable);
+	return GEDIT_PLUGIN_GET_CLASS (plugin)->create_configure_dialog (plugin);
+}
+
+static void
+peas_ui_configurable_iface_init (PeasUIConfigurableIface *iface)
+{
+	iface->is_configurable = gedit_plugin_is_configurable;
+	iface->create_configure_dialog = gedit_plugin_create_configure_dialog;
 }
 
 static void
diff --git a/gedit/gedit-plugin.h b/gedit/gedit-plugin.h
index cd4e3ac..2314677 100644
--- a/gedit/gedit-plugin.h
+++ b/gedit/gedit-plugin.h
@@ -34,6 +34,7 @@
 
 #include <glib-object.h>
 #include <gmodule.h>
+#include <gtk/gtk.h>
 #include <libpeas/peas-plugin.h>
 
 G_BEGIN_DECLS
@@ -66,6 +67,8 @@ typedef struct _GeditPluginClass GeditPluginClass;
 struct _GeditPluginClass 
 {
 	PeasPluginClass parent_class;
+	gboolean	 (*is_configurable)		(GeditPlugin *plugin);
+	GtkWidget	*(*create_configure_dialog)	(GeditPlugin *plugin);
 };
 
 /*
diff --git a/plugins/time/gedit-time-plugin.c b/plugins/time/gedit-time-plugin.c
index a88b68c..c2e26a5 100644
--- a/plugins/time/gedit-time-plugin.c
+++ b/plugins/time/gedit-time-plugin.c
@@ -1238,7 +1238,7 @@ configure_dialog_response_cb (GtkWidget           *widget,
 }
 
 static GtkWidget *
-impl_create_configure_dialog (PeasPlugin *plugin)
+impl_create_configure_dialog (GeditPlugin *plugin)
 {
 	TimeConfigureDialog *dialog;
 
@@ -1259,6 +1259,7 @@ gedit_time_plugin_class_init (GeditTimePluginClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	PeasPluginClass *plugin_class = PEAS_PLUGIN_CLASS (klass);
+	GeditPluginClass *gplugin_class = GEDIT_PLUGIN_CLASS (klass);
 
 	object_class->finalize = gedit_time_plugin_finalize;
 
@@ -1266,7 +1267,7 @@ gedit_time_plugin_class_init (GeditTimePluginClass *klass)
 	plugin_class->deactivate = (PeasFunc) impl_deactivate;
 	plugin_class->update_ui = (PeasFunc) impl_update_ui;
 
-	plugin_class->create_configure_dialog = impl_create_configure_dialog;
+	gplugin_class->create_configure_dialog = impl_create_configure_dialog;
 
 	g_type_class_add_private (object_class, sizeof (GeditTimePluginPrivate));
 }



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