diff options
Diffstat (limited to 'plugins')
48 files changed, 1601 insertions, 1028 deletions
diff --git a/plugins/changecase/Makefile.am b/plugins/changecase/Makefile.am index 6b3a1cdd..5cb37347 100644 --- a/plugins/changecase/Makefile.am +++ b/plugins/changecase/Makefile.am @@ -19,11 +19,11 @@ libchangecase_la_LIBADD = $(PLUMA_LIBS) uidir = $(PLUMA_PLUGINS_DATA_DIR)/changecase ui_DATA = -plugin_in_files = changecase.pluma-plugin.desktop.in +plugin_in_files = changecase.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(ui_DATA) $(plugin_in_files) diff --git a/plugins/changecase/changecase.pluma-plugin.desktop.in b/plugins/changecase/changecase.plugin.desktop.in index d8383125..d1539d99 100644 --- a/plugins/changecase/changecase.pluma-plugin.desktop.in +++ b/plugins/changecase/changecase.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=changecase IAge=2 _Name=Change Case diff --git a/plugins/changecase/pluma-changecase-plugin.c b/plugins/changecase/pluma-changecase-plugin.c index 03b86e04..65b938d9 100644 --- a/plugins/changecase/pluma-changecase-plugin.c +++ b/plugins/changecase/pluma-changecase-plugin.c @@ -28,12 +28,36 @@ #include <glib/gi18n-lib.h> #include <gmodule.h> +#include <libpeas/peas-activatable.h> +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> -#define WINDOW_DATA_KEY "PlumaChangecasePluginWindowData" +#define PLUMA_CHANGECASE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + PLUMA_TYPE_CHANGECASE_PLUGIN, \ + PlumaChangecasePluginPrivate)) -PLUMA_PLUGIN_REGISTER_TYPE(PlumaChangecasePlugin, pluma_changecase_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaChangecasePlugin, + pluma_changecase_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) + +struct _PlumaChangecasePluginPrivate +{ + GtkWidget *window; + + GtkActionGroup *action_group; + guint ui_id; +}; + +enum { + PROP_0, + PROP_OBJECT +}; typedef enum { TO_UPPER_CASE, @@ -250,44 +274,88 @@ const gchar submenu[] = " </menubar>" "</ui>"; + static void pluma_changecase_plugin_init (PlumaChangecasePlugin *plugin) { pluma_debug_message (DEBUG_PLUGINS, "PlumaChangecasePlugin initializing"); + + plugin->priv = PLUMA_CHANGECASE_PLUGIN_GET_PRIVATE (plugin); } static void -pluma_changecase_plugin_finalize (GObject *object) +pluma_changecase_plugin_dispose (GObject *object) { - G_OBJECT_CLASS (pluma_changecase_plugin_parent_class)->finalize (object); + PlumaChangecasePlugin *plugin = PLUMA_CHANGECASE_PLUGIN (object); + + pluma_debug_message (DEBUG_PLUGINS, "PlumaChangecasePlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->action_group != NULL) + { + g_object_unref (plugin->priv->action_group); + plugin->priv->action_group = NULL; + } - pluma_debug_message (DEBUG_PLUGINS, "PlumaChangecasePlugin finalizing"); + G_OBJECT_CLASS (pluma_changecase_plugin_parent_class)->dispose (object); } -typedef struct +static void +pluma_changecase_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - GtkActionGroup *action_group; - guint ui_id; -} WindowData; + PlumaChangecasePlugin *plugin = PLUMA_CHANGECASE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} static void -free_window_data (WindowData *data) +pluma_changecase_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - g_return_if_fail (data != NULL); + PlumaChangecasePlugin *plugin = PLUMA_CHANGECASE_PLUGIN (object); - g_slice_free (WindowData, data); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -update_ui_real (PlumaWindow *window, - WindowData *data) +update_ui (PlumaChangecasePluginPrivate *data) { + PlumaWindow *window; GtkTextView *view; GtkAction *action; gboolean sensitive = FALSE; pluma_debug (DEBUG_PLUGINS); + window = PLUMA_WINDOW (data->window); view = GTK_TEXT_VIEW (pluma_window_get_active_view (window)); if (view != NULL) @@ -305,16 +373,17 @@ update_ui_real (PlumaWindow *window, } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_changecase_plugin_activate (PeasActivatable *activatable) { + PlumaChangecasePluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; GError *error = NULL; pluma_debug (DEBUG_PLUGINS); - data = g_slice_new (WindowData); + data = PLUMA_CHANGECASE_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); manager = pluma_window_get_ui_manager (window); @@ -335,61 +404,72 @@ impl_activate (PlumaPlugin *plugin, if (data->ui_id == 0) { g_warning ("%s", error->message); - free_window_data (data); return; } - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - - update_ui_real (window, data); + update_ui (data); } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_changecase_plugin_deactivate (PeasActivatable *activatable) { + PlumaChangecasePluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - manager = pluma_window_get_ui_manager (window); + data = PLUMA_CHANGECASE_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = pluma_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -impl_update_ui (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_changecase_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - pluma_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - update_ui_real (window, data); + update_ui (PLUMA_CHANGECASE_PLUGIN (activatable)->priv); } static void pluma_changecase_plugin_class_init (PlumaChangecasePluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); - object_class->finalize = pluma_changecase_plugin_finalize; + object_class->dispose = pluma_changecase_plugin_dispose; + object_class->set_property = pluma_changecase_plugin_set_property; + object_class->get_property = pluma_changecase_plugin_get_property; + + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (PlumaChangecasePluginPrivate)); +} + +static void +pluma_changecase_plugin_class_finalize (PlumaChangecasePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_changecase_plugin_activate; + iface->deactivate = pluma_changecase_plugin_deactivate; + iface->update_state = pluma_changecase_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_changecase_plugin_register_type (G_TYPE_MODULE (module)); - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_CHANGECASE_PLUGIN); } diff --git a/plugins/changecase/pluma-changecase-plugin.h b/plugins/changecase/pluma-changecase-plugin.h index b3d1016f..f610ac27 100644 --- a/plugins/changecase/pluma-changecase-plugin.h +++ b/plugins/changecase/pluma-changecase-plugin.h @@ -25,7 +25,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -39,6 +40,9 @@ G_BEGIN_DECLS #define PLUMA_IS_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PLUMA_TYPE_CHANGECASE_PLUGIN)) #define PLUMA_CHANGECASE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PLUMA_TYPE_CHANGECASE_PLUGIN, PlumaChangecasePluginClass)) +/* Private structure type */ +typedef struct _PlumaChangecasePluginPrivate PlumaChangecasePluginPrivate; + /* * Main object structure */ @@ -46,7 +50,10 @@ typedef struct _PlumaChangecasePlugin PlumaChangecasePlugin; struct _PlumaChangecasePlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private >*/ + PlumaChangecasePluginPrivate *priv; }; /* @@ -56,7 +63,7 @@ typedef struct _PlumaChangecasePluginClass PlumaChangecasePluginClass; struct _PlumaChangecasePluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -65,7 +72,7 @@ struct _PlumaChangecasePluginClass GType pluma_changecase_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/docinfo/Makefile.am b/plugins/docinfo/Makefile.am index ec9fc410..1e1b48e9 100644 --- a/plugins/docinfo/Makefile.am +++ b/plugins/docinfo/Makefile.am @@ -19,11 +19,11 @@ libdocinfo_la_LIBADD = $(PLUMA_LIBS) uidir = $(PLUMA_PLUGINS_DATA_DIR)/docinfo ui_DATA = docinfo.ui -plugin_in_files = docinfo.pluma-plugin.desktop.in +plugin_in_files = docinfo.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(ui_DATA) $(plugin_in_files) diff --git a/plugins/docinfo/docinfo.pluma-plugin.desktop.in b/plugins/docinfo/docinfo.plugin.desktop.in index 990f2cd6..b4da32b0 100644 --- a/plugins/docinfo/docinfo.pluma-plugin.desktop.in +++ b/plugins/docinfo/docinfo.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=docinfo IAge=2 _Name=Document Statistics diff --git a/plugins/docinfo/pluma-docinfo-plugin.c b/plugins/docinfo/pluma-docinfo-plugin.c index 520274bb..fbe1ea22 100644 --- a/plugins/docinfo/pluma-docinfo-plugin.c +++ b/plugins/docinfo/pluma-docinfo-plugin.c @@ -31,14 +31,26 @@ #include <glib/gi18n-lib.h> #include <pango/pango-break.h> #include <gmodule.h> +#include <libpeas/peas-activatable.h> +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> #include <pluma/pluma-utils.h> -#define WINDOW_DATA_KEY "PlumaDocInfoWindowData" #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_2" -PLUMA_PLUGIN_REGISTER_TYPE(PlumaDocInfoPlugin, pluma_docinfo_plugin) +#define PLUMA_DOCINFO_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + PLUMA_TYPE_DOCINFO_PLUGIN, \ + PlumaDocInfoPluginPrivate)) + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaDocInfoPlugin, + pluma_docinfo_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) typedef struct { @@ -57,23 +69,28 @@ typedef struct GtkWidget *selected_bytes_label; } DocInfoDialog; -typedef struct +struct _PlumaDocInfoPluginPrivate { - PlumaPlugin *plugin; + GtkWidget *window; GtkActionGroup *ui_action_group; guint ui_id; DocInfoDialog *dialog; -} WindowData; +}; + +enum { + PROP_0, + PROP_OBJECT +}; static void docinfo_dialog_response_cb (GtkDialog *widget, gint res_id, - PlumaWindow *window); + PlumaDocInfoPluginPrivate *data); static void docinfo_dialog_destroy_cb (GObject *obj, - WindowData *data) + PlumaDocInfoPluginPrivate *data) { pluma_debug (DEBUG_PLUGINS); @@ -85,9 +102,10 @@ docinfo_dialog_destroy_cb (GObject *obj, } static DocInfoDialog * -get_docinfo_dialog (PlumaWindow *window, - WindowData *data) +get_docinfo_dialog (PlumaDocInfoPlugin *plugin) { + PlumaDocInfoPluginPrivate *data; + PlumaWindow *window; DocInfoDialog *dialog; gchar *data_dir; gchar *ui_file; @@ -97,9 +115,12 @@ get_docinfo_dialog (PlumaWindow *window, pluma_debug (DEBUG_PLUGINS); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); + dialog = g_new (DocInfoDialog, 1); - data_dir = pluma_plugin_get_data_dir (data->plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "docinfo.ui", NULL); ret = pluma_utils_get_ui_objects (ui_file, NULL, @@ -149,7 +170,7 @@ get_docinfo_dialog (PlumaWindow *window, g_signal_connect (dialog->dialog, "response", G_CALLBACK (docinfo_dialog_response_cb), - window); + data); return dialog; } @@ -338,16 +359,16 @@ selectioninfo_real (PlumaDocument *doc, static void docinfo_cb (GtkAction *action, - PlumaWindow *window) + PlumaDocInfoPlugin *plugin) { + PlumaDocInfoPluginPrivate *data; + PlumaWindow *window; PlumaDocument *doc; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - + data = plugin->priv; + window = PLUMA_WINDOW (data->window); doc = pluma_window_get_active_document (window); g_return_if_fail (doc != NULL); @@ -360,7 +381,7 @@ docinfo_cb (GtkAction *action, { DocInfoDialog *dialog; - dialog = get_docinfo_dialog (window, data); + dialog = get_docinfo_dialog (plugin); g_return_if_fail (dialog != NULL); data->dialog = dialog; @@ -377,14 +398,13 @@ docinfo_cb (GtkAction *action, static void docinfo_dialog_response_cb (GtkDialog *widget, gint res_id, - PlumaWindow *window) + PlumaDocInfoPluginPrivate *data) { - WindowData *data; + PlumaWindow *window; pluma_debug (DEBUG_PLUGINS); - - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); + + window = PLUMA_WINDOW (data->window); switch (res_id) { @@ -427,37 +447,19 @@ static const GtkActionEntry action_entries[] = }; static void -free_window_data (WindowData *data) -{ - g_return_if_fail (data != NULL); - - pluma_debug (DEBUG_PLUGINS); - - g_object_unref (data->plugin); - - g_object_unref (data->ui_action_group); - - if (data->dialog != NULL) - { - gtk_widget_destroy (data->dialog->dialog); - } - - g_free (data); -} - -static void -update_ui_real (PlumaWindow *window, - WindowData *data) +update_ui (PlumaDocInfoPluginPrivate *data) { + PlumaWindow *window; PlumaView *view; pluma_debug (DEBUG_PLUGINS); + window = PLUMA_WINDOW (data->window); view = pluma_window_get_active_view (window); gtk_action_group_set_sensitive (data->ui_action_group, (view != NULL)); - + if (data->dialog != NULL) { gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog->dialog), @@ -470,28 +472,86 @@ static void pluma_docinfo_plugin_init (PlumaDocInfoPlugin *plugin) { pluma_debug_message (DEBUG_PLUGINS, "PlumaDocInfoPlugin initializing"); + + plugin->priv = PLUMA_DOCINFO_PLUGIN_GET_PRIVATE (plugin); +} + +static void +pluma_docinfo_plugin_dispose (GObject *object) +{ + PlumaDocInfoPlugin *plugin = PLUMA_DOCINFO_PLUGIN (object); + + pluma_debug_message (DEBUG_PLUGINS, "PlumaDocInfoPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->ui_action_group != NULL) + { + g_object_unref (plugin->priv->ui_action_group); + plugin->priv->ui_action_group = NULL; + } + + G_OBJECT_CLASS (pluma_docinfo_plugin_parent_class)->dispose (object); +} + +static void +pluma_docinfo_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PlumaDocInfoPlugin *plugin = PLUMA_DOCINFO_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -pluma_docinfo_plugin_finalize (GObject *object) +pluma_docinfo_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - pluma_debug_message (DEBUG_PLUGINS, "PlumaDocInfoPlugin finalizing"); + PlumaDocInfoPlugin *plugin = PLUMA_DOCINFO_PLUGIN (object); - G_OBJECT_CLASS (pluma_docinfo_plugin_parent_class)->finalize (object); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_docinfo_plugin_activate (PeasActivatable *activatable) { + PlumaDocInfoPlugin *plugin; + PlumaDocInfoPluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - data = g_new (WindowData, 1); + plugin = PLUMA_DOCINFO_PLUGIN (activatable); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); - data->plugin = g_object_ref (plugin); data->dialog = NULL; data->ui_action_group = gtk_action_group_new ("PlumaDocInfoPluginActions"); @@ -500,7 +560,7 @@ impl_activate (PlumaPlugin *plugin, gtk_action_group_add_actions (data->ui_action_group, action_entries, G_N_ELEMENTS (action_entries), - window); + plugin); manager = pluma_window_get_ui_manager (window); gtk_ui_manager_insert_action_group (manager, @@ -509,11 +569,6 @@ impl_activate (PlumaPlugin *plugin, data->ui_id = gtk_ui_manager_new_merge_id (manager); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, @@ -522,60 +577,71 @@ impl_activate (PlumaPlugin *plugin, GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, - data); + update_ui (data); } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_docinfo_plugin_deactivate (PeasActivatable *activatable) { + PlumaDocInfoPluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - manager = pluma_window_get_ui_manager (window); + data = PLUMA_DOCINFO_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = pluma_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->ui_action_group); - - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - NULL); } static void -impl_update_ui (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_docinfo_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - pluma_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - update_ui_real (window, - data); + update_ui (PLUMA_DOCINFO_PLUGIN (activatable)->priv); } static void pluma_docinfo_plugin_class_init (PlumaDocInfoPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); - object_class->finalize = pluma_docinfo_plugin_finalize; + object_class->dispose = pluma_docinfo_plugin_dispose; + object_class->set_property = pluma_docinfo_plugin_set_property; + object_class->get_property = pluma_docinfo_plugin_get_property; + + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (PlumaDocInfoPluginPrivate)); +} + +static void +pluma_docinfo_plugin_class_finalize (PlumaDocInfoPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_docinfo_plugin_activate; + iface->deactivate = pluma_docinfo_plugin_deactivate; + iface->update_state = pluma_docinfo_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_docinfo_plugin_register_type (G_TYPE_MODULE (module)); - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_DOCINFO_PLUGIN); } diff --git a/plugins/docinfo/pluma-docinfo-plugin.h b/plugins/docinfo/pluma-docinfo-plugin.h index 7b8fe272..5476e4fb 100644 --- a/plugins/docinfo/pluma-docinfo-plugin.h +++ b/plugins/docinfo/pluma-docinfo-plugin.h @@ -25,7 +25,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -49,7 +50,10 @@ typedef struct _PlumaDocInfoPlugin PlumaDocInfoPlugin; struct _PlumaDocInfoPlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private >*/ + PlumaDocInfoPluginPrivate *priv; }; /* @@ -59,7 +63,7 @@ typedef struct _PlumaDocInfoPluginClass PlumaDocInfoPluginClass; struct _PlumaDocInfoPluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -68,7 +72,7 @@ struct _PlumaDocInfoPluginClass GType pluma_docinfo_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py index 039e0a50..09a0cd42 100755 --- a/plugins/externaltools/tools/library.py +++ b/plugins/externaltools/tools/library.py @@ -19,7 +19,6 @@ import os import re import locale -import platform class Singleton(object): _instance = None @@ -39,22 +38,13 @@ class ToolLibrary(Singleton): def set_locations(self, datadir): self.locations = [] - if platform.platform() != 'Windows': - for d in self.get_xdg_data_dirs(): - self.locations.append(os.path.join(d, 'pluma', 'plugins', 'externaltools', 'tools')) + for d in self.get_xdg_data_dirs(): + self.locations.append(os.path.join(d, 'pluma', 'plugins', 'externaltools', 'tools')) self.locations.append(datadir) # self.locations[0] is where we save the custom scripts - if platform.platform() == 'Windows': - toolsdir = os.path.expanduser('~/pluma/tools') - else: - userdir = os.getenv('MATE22_USER_DIR') - if userdir: - toolsdir = os.path.join(userdir, 'pluma/tools') - else: - toolsdir = os.path.expanduser('~/.config/pluma/tools') - + toolsdir = os.path.expanduser('~/.config/pluma/tools') self.locations.insert(0, toolsdir); if not os.path.isdir(self.locations[0]): @@ -78,11 +68,7 @@ class ToolLibrary(Singleton): # storage file. def import_old_xml_store(self): import xml.etree.ElementTree as et - userdir = os.getenv('MATE22_USER_DIR') - if userdir: - filename = os.path.join(userdir, 'pluma/pluma-tools.xml') - else: - filename = os.path.expanduser('~/.config/pluma/pluma-tools.xml') + filename = os.path.expanduser('~/.config/pluma/pluma-tools.xml') if not os.path.isfile(filename): return diff --git a/plugins/filebrowser/Makefile.am b/plugins/filebrowser/Makefile.am index 3b494cdf..faa554ec 100644 --- a/plugins/filebrowser/Makefile.am +++ b/plugins/filebrowser/Makefile.am @@ -44,9 +44,9 @@ libfilebrowser_la_LIBADD = $(PLUMA_LIBS) uidir = $(PLUMA_PLUGINS_DATA_DIR)/filebrowser ui_DATA = pluma-file-browser-widget-ui.xml -plugin_in_files = filebrowser.pluma-plugin.desktop.in +plugin_in_files = filebrowser.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache pluma-file-browser-enum-types.h: pluma-file-browser-enum-types.h.template $(NOINST_H_FILES) $(GLIB_MKENUMS) (cd $(srcdir) && $(GLIB_MKENUMS) --template pluma-file-browser-enum-types.h.template $(NOINST_H_FILES)) > $@ @@ -63,7 +63,7 @@ pluma-file-browser-marshal.c: pluma-file-browser-marshal.list $(GLIB_GENMARSHAL) $(AM_V_GEN) echo "#include \"pluma-file-browser-marshal.h\"" > $@ && \ $(GLIB_GENMARSHAL) $< --body --prefix=pluma_file_browser_marshal >> $@ -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) @INTLTOOL_XML_NOMERGE_RULE@ filebrowser_gschema_in = org.mate.pluma.plugins.filebrowser.gschema.xml.in diff --git a/plugins/filebrowser/filebrowser.pluma-plugin.desktop.in b/plugins/filebrowser/filebrowser.plugin.desktop.in index 02668983..625f2d01 100644 --- a/plugins/filebrowser/filebrowser.pluma-plugin.desktop.in +++ b/plugins/filebrowser/filebrowser.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Loader=C Module=filebrowser IAge=2 diff --git a/plugins/filebrowser/pluma-file-bookmarks-store.c b/plugins/filebrowser/pluma-file-bookmarks-store.c index d1d8b53d..073d6bb3 100644 --- a/plugins/filebrowser/pluma-file-bookmarks-store.c +++ b/plugins/filebrowser/pluma-file-bookmarks-store.c @@ -23,7 +23,6 @@ #include <glib/gi18n.h> #include <gio/gio.h> #include <pluma/pluma-utils.h> -#include <pluma/pluma-plugin.h> #include "pluma-file-bookmarks-store.h" #include "pluma-file-browser-utils.h" @@ -56,7 +55,7 @@ static gboolean find_with_flags (GtkTreeModel * model, guint flags, guint notflags); -PLUMA_PLUGIN_DEFINE_TYPE(PlumaFileBookmarksStore, pluma_file_bookmarks_store, GTK_TYPE_TREE_STORE) +G_DEFINE_DYNAMIC_TYPE (PlumaFileBookmarksStore, pluma_file_bookmarks_store, GTK_TYPE_TREE_STORE) static void pluma_file_bookmarks_store_dispose (GObject * object) @@ -98,6 +97,12 @@ pluma_file_bookmarks_store_class_init (PlumaFileBookmarksStoreClass *klass) } static void +pluma_file_bookmarks_store_class_finalize (PlumaFileBookmarksStoreClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ +} + +static void pluma_file_bookmarks_store_init (PlumaFileBookmarksStore * obj) { obj->priv = PLUMA_FILE_BOOKMARKS_STORE_GET_PRIVATE (obj); @@ -876,4 +881,10 @@ on_bookmarks_file_changed (GFileMonitor * monitor, } } +void +_pluma_file_bookmarks_store_register_type (GTypeModule *type_module) +{ + pluma_file_bookmarks_store_register_type (type_module); +} + // ex:ts=8:noet: diff --git a/plugins/filebrowser/pluma-file-bookmarks-store.h b/plugins/filebrowser/pluma-file-bookmarks-store.h index 6bd9fcf9..4c368db6 100644 --- a/plugins/filebrowser/pluma-file-bookmarks-store.h +++ b/plugins/filebrowser/pluma-file-bookmarks-store.h @@ -77,7 +77,7 @@ struct _PlumaFileBookmarksStoreClass }; GType pluma_file_bookmarks_store_get_type (void) G_GNUC_CONST; -GType pluma_file_bookmarks_store_register_type (GTypeModule * module); +void _pluma_file_bookmarks_store_register_type (GTypeModule * module); PlumaFileBookmarksStore *pluma_file_bookmarks_store_new (void); gchar *pluma_file_bookmarks_store_get_uri (PlumaFileBookmarksStore * model, diff --git a/plugins/filebrowser/pluma-file-browser-plugin.c b/plugins/filebrowser/pluma-file-browser-plugin.c index 750b2be0..b619309e 100644 --- a/plugins/filebrowser/pluma-file-browser-plugin.c +++ b/plugins/filebrowser/pluma-file-browser-plugin.c @@ -28,9 +28,11 @@ #include <pluma/pluma-utils.h> #include <pluma/pluma-app.h> #include <glib/gi18n-lib.h> +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> #include <gio/gio.h> #include <string.h> +#include <libpeas/peas-activatable.h> #include "pluma-file-browser-enum-types.h" #include "pluma-file-browser-plugin.h" @@ -39,8 +41,6 @@ #include "pluma-file-browser-widget.h" #include "pluma-file-browser-messages.h" -#define WINDOW_DATA_KEY "PlumaFileBrowserPluginWindowData" - #define FILE_BROWSER_SCHEMA "org.mate.pluma.plugins.filebrowser" #define FILE_BROWSER_ONLOAD_SCHEMA "org.mate.pluma.plugins.filebrowser.on-load" #define CAJA_SCHEMA "org.mate.caja.preferences" @@ -54,11 +54,8 @@ struct _PlumaFileBrowserPluginPrivate { - gpointer *dummy; -}; + GtkWidget *window; -typedef struct _PlumaFileBrowserPluginData -{ PlumaFileBrowserWidget * tree_widget; gulong merge_id; GtkActionGroup * action_group; @@ -71,7 +68,12 @@ typedef struct _PlumaFileBrowserPluginData GSettings *onload_settings; GSettings *caja_settings; GSettings *terminal_settings; -} PlumaFileBrowserPluginData; +}; + +enum { + PROP_0, + PROP_OBJECT +}; static void on_uri_activated_cb (PlumaFileBrowserWidget * widget, gchar const *uri, @@ -79,67 +81,114 @@ static void on_uri_activated_cb (PlumaFileBrowserWidget * widget, static void on_error_cb (PlumaFileBrowserWidget * widget, guint code, gchar const *message, - PlumaWindow * window); + PlumaFileBrowserPluginPrivate * data); static void on_model_set_cb (PlumaFileBrowserView * widget, GParamSpec *arg1, - PlumaWindow * window); + PlumaFileBrowserPluginPrivate * data); static void on_virtual_root_changed_cb (PlumaFileBrowserStore * model, GParamSpec * param, - PlumaWindow * window); + PlumaFileBrowserPluginPrivate * data); static void on_filter_mode_changed_cb (PlumaFileBrowserStore * model, GParamSpec * param, - PlumaWindow * window); + PlumaFileBrowserPluginPrivate * data); static void on_rename_cb (PlumaFileBrowserStore * model, const gchar * olduri, const gchar * newuri, PlumaWindow * window); static void on_filter_pattern_changed_cb (PlumaFileBrowserWidget * widget, GParamSpec * param, - PlumaWindow * window); + PlumaFileBrowserPluginPrivate * data); static void on_tab_added_cb (PlumaWindow * window, PlumaTab * tab, - PlumaFileBrowserPluginData * data); + PlumaFileBrowserPluginPrivate * data); static gboolean on_confirm_delete_cb (PlumaFileBrowserWidget * widget, PlumaFileBrowserStore * store, GList * rows, - PlumaWindow * window); + PlumaFileBrowserPluginPrivate * data); static gboolean on_confirm_no_trash_cb (PlumaFileBrowserWidget * widget, GList * files, PlumaWindow * window); -PLUMA_PLUGIN_REGISTER_TYPE_WITH_CODE (PlumaFileBrowserPlugin, filetree_plugin, \ - pluma_file_browser_enum_and_flag_register_type (type_module); \ - pluma_file_browser_store_register_type (type_module); \ - pluma_file_bookmarks_store_register_type (type_module); \ - pluma_file_browser_view_register_type (type_module); \ - pluma_file_browser_widget_register_type (type_module); \ +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaFileBrowserPlugin, + pluma_file_browser_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) \ + \ + pluma_file_browser_enum_and_flag_register_type (type_module); \ + _pluma_file_browser_store_register_type (type_module); \ + _pluma_file_bookmarks_store_register_type (type_module); \ + _pluma_file_browser_view_register_type (type_module); \ + _pluma_file_browser_widget_register_type (type_module); \ ) - static void -filetree_plugin_init (PlumaFileBrowserPlugin * plugin) +pluma_file_browser_plugin_init (PlumaFileBrowserPlugin * plugin) { plugin->priv = PLUMA_FILE_BROWSER_PLUGIN_GET_PRIVATE (plugin); } static void -filetree_plugin_finalize (GObject * object) +pluma_file_browser_plugin_dispose (GObject * object) +{ + PlumaFileBrowserPlugin *plugin = PLUMA_FILE_BROWSER_PLUGIN (object); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (pluma_file_browser_plugin_parent_class)->dispose (object); +} + +static void +pluma_file_browser_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - //PlumaFileBrowserPlugin * plugin = PLUMA_FILE_BROWSER_PLUGIN (object); + PlumaFileBrowserPlugin *plugin = PLUMA_FILE_BROWSER_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; - G_OBJECT_CLASS (filetree_plugin_parent_class)->finalize (object); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } -static PlumaFileBrowserPluginData * -get_plugin_data (PlumaWindow * window) +static void +pluma_file_browser_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - return (PlumaFileBrowserPluginData *) (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY)); + PlumaFileBrowserPlugin *plugin = PLUMA_FILE_BROWSER_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void on_end_loading_cb (PlumaFileBrowserStore * store, GtkTreeIter * iter, - PlumaFileBrowserPluginData * data) + PlumaFileBrowserPluginPrivate * data) { /* Disconnect the signal */ g_signal_handler_disconnect (store, data->end_loading_handle); @@ -148,7 +197,7 @@ on_end_loading_cb (PlumaFileBrowserStore * store, } static void -prepare_auto_root (PlumaFileBrowserPluginData *data) +prepare_auto_root (PlumaFileBrowserPluginPrivate *data) { PlumaFileBrowserStore *store; @@ -168,7 +217,7 @@ prepare_auto_root (PlumaFileBrowserPluginData *data) } static void -restore_default_location (PlumaFileBrowserPluginData *data) +restore_default_location (PlumaFileBrowserPluginPrivate *data) { gchar * root; gchar * virtual_root; @@ -214,7 +263,7 @@ restore_default_location (PlumaFileBrowserPluginData *data) } static void -restore_filter (PlumaFileBrowserPluginData * data) +restore_filter (PlumaFileBrowserPluginPrivate *data) { gchar *filter_mode; PlumaFileBrowserStoreFilterMode mode; @@ -269,12 +318,12 @@ on_click_policy_changed (GSettings *settings, gchar *key, gpointer user_data) { - PlumaFileBrowserPluginData * data; + PlumaFileBrowserPluginPrivate * data; gchar *click_policy; PlumaFileBrowserViewClickPolicy policy = PLUMA_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE; PlumaFileBrowserView *view; - data = (PlumaFileBrowserPluginData *)(user_data); + data = (PlumaFileBrowserPluginPrivate *)(user_data); click_policy = g_settings_get_string (settings, key); policy = click_policy_from_string (click_policy); @@ -289,10 +338,10 @@ on_enable_delete_changed (GSettings *settings, gchar *key, gpointer user_data) { - PlumaFileBrowserPluginData *data; + PlumaFileBrowserPluginPrivate *data; gboolean enable = FALSE; - data = (PlumaFileBrowserPluginData *)(user_data); + data = (PlumaFileBrowserPluginPrivate *)(user_data); enable = g_settings_get_boolean (settings, key); g_object_set (G_OBJECT (data->tree_widget), "enable-delete", enable, NULL); @@ -303,10 +352,10 @@ on_confirm_trash_changed (GSettings *settings, gchar *key, gpointer user_data) { - PlumaFileBrowserPluginData *data; + PlumaFileBrowserPluginPrivate *data; gboolean enable = FALSE; - data = (PlumaFileBrowserPluginData *)(user_data); + data = (PlumaFileBrowserPluginPrivate *)(user_data); enable = g_settings_get_boolean (settings, key); data->confirm_trash = enable; @@ -325,7 +374,7 @@ have_click_policy (void) } static void -install_caja_prefs (PlumaFileBrowserPluginData *data) +install_caja_prefs (PlumaFileBrowserPluginPrivate *data) { gchar *pref; gboolean prefb; @@ -364,7 +413,7 @@ install_caja_prefs (PlumaFileBrowserPluginData *data) } static void -set_root_from_doc (PlumaFileBrowserPluginData * data, +set_root_from_doc (PlumaFileBrowserPluginPrivate * data, PlumaDocument * doc) { GFile *file; @@ -397,17 +446,14 @@ set_root_from_doc (PlumaFileBrowserPluginData * data, static void on_action_set_active_root (GtkAction * action, - PlumaWindow * window) + PlumaFileBrowserPluginPrivate * data) { - PlumaFileBrowserPluginData *data; - - data = get_plugin_data (window); set_root_from_doc (data, - pluma_window_get_active_document (window)); + pluma_window_get_active_document (PLUMA_WINDOW (data->window))); } static gchar * -get_terminal (PlumaFileBrowserPluginData * data) +get_terminal (PlumaFileBrowserPluginPrivate * data) { gchar * terminal; @@ -428,9 +474,8 @@ get_terminal (PlumaFileBrowserPluginData * data) static void on_action_open_terminal (GtkAction * action, - PlumaWindow * window) + PlumaFileBrowserPluginPrivate * data) { - PlumaFileBrowserPluginData * data; gchar * terminal; gchar * wd = NULL; gchar * local; @@ -440,8 +485,6 @@ on_action_open_terminal (GtkAction * action, GtkTreeIter iter; PlumaFileBrowserStore * store; - data = get_plugin_data (window); - /* Get the current directory */ if (!pluma_file_browser_widget_get_selected_directory (data->tree_widget, &iter)) return; @@ -481,17 +524,14 @@ on_action_open_terminal (GtkAction * action, static void on_selection_changed_cb (GtkTreeSelection *selection, - PlumaWindow *window) + PlumaFileBrowserPluginPrivate *data) { - PlumaFileBrowserPluginData * data; GtkTreeView * tree_view; GtkTreeModel * model; GtkTreeIter iter; gboolean sensitive; gchar * uri; - data = get_plugin_data (window); - tree_view = GTK_TREE_VIEW (pluma_file_browser_widget_get_browser_view (data->tree_widget)); model = gtk_tree_view_get_model (tree_view); @@ -548,14 +588,12 @@ static GtkActionEntry extra_single_selection_actions[] = { }; static void -add_popup_ui (PlumaWindow * window) +add_popup_ui (PlumaFileBrowserPluginPrivate *data) { - PlumaFileBrowserPluginData * data; GtkUIManager * manager; GtkActionGroup * action_group; GError * error = NULL; - data = get_plugin_data (window); manager = pluma_file_browser_widget_get_ui_manager (data->tree_widget); action_group = gtk_action_group_new ("FileBrowserPluginExtra"); @@ -563,7 +601,7 @@ add_popup_ui (PlumaWindow * window) gtk_action_group_add_actions (action_group, extra_actions, G_N_ELEMENTS (extra_actions), - window); + data); gtk_ui_manager_insert_action_group (manager, action_group, 0); data->action_group = action_group; @@ -572,7 +610,7 @@ add_popup_ui (PlumaWindow * window) gtk_action_group_add_actions (action_group, extra_single_selection_actions, G_N_ELEMENTS (extra_single_selection_actions), - window); + data); gtk_ui_manager_insert_action_group (manager, action_group, 0); data->single_selection_action_group = action_group; @@ -588,12 +626,10 @@ add_popup_ui (PlumaWindow * window) } static void -remove_popup_ui (PlumaWindow * window) +remove_popup_ui (PlumaFileBrowserPluginPrivate *data) { - PlumaFileBrowserPluginData * data; GtkUIManager * manager; - data = get_plugin_data (window); manager = pluma_file_browser_widget_get_ui_manager (data->tree_widget); gtk_ui_manager_remove_ui (manager, data->merge_id); @@ -605,14 +641,14 @@ remove_popup_ui (PlumaWindow * window) } static void -impl_updateui (PlumaPlugin * plugin, PlumaWindow * window) +pluma_file_browser_plugin_update_state (PeasActivatable *activatable) { - PlumaFileBrowserPluginData * data; + PlumaFileBrowserPluginPrivate *data; PlumaDocument * doc; - data = get_plugin_data (window); + data = PLUMA_FILE_BROWSER_PLUGIN (activatable)->priv; - doc = pluma_window_get_active_document (window); + doc = pluma_window_get_active_document (PLUMA_WINDOW (data->window)); gtk_action_set_sensitive (gtk_action_group_get_action (data->action_group, "SetActiveRoot"), @@ -621,10 +657,11 @@ impl_updateui (PlumaPlugin * plugin, PlumaWindow * window) } static void -impl_activate (PlumaPlugin * plugin, PlumaWindow * window) +pluma_file_browser_plugin_activate (PeasActivatable *activatable) { + PlumaFileBrowserPluginPrivate *data; + PlumaWindow *window; PlumaPanel * panel; - PlumaFileBrowserPluginData * data; GtkWidget * image; GdkPixbuf * pixbuf; PlumaFileBrowserStore * store; @@ -632,9 +669,10 @@ impl_activate (PlumaPlugin * plugin, PlumaWindow * window) GSettingsSchemaSource *schema_source; GSettingsSchema *schema; - data = g_new0 (PlumaFileBrowserPluginData, 1); + data = PLUMA_FILE_BROWSER_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - data_dir = pluma_plugin_get_data_dir (plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); data->tree_widget = PLUMA_FILE_BROWSER_WIDGET (pluma_file_browser_widget_new (data_dir)); g_free (data_dir); @@ -647,17 +685,17 @@ impl_activate (PlumaPlugin * plugin, PlumaWindow * window) G_CALLBACK (on_uri_activated_cb), window); g_signal_connect (data->tree_widget, - "error", G_CALLBACK (on_error_cb), window); + "error", G_CALLBACK (on_error_cb), data); g_signal_connect (data->tree_widget, "notify::filter-pattern", G_CALLBACK (on_filter_pattern_changed_cb), - window); + data); g_signal_connect (data->tree_widget, "confirm-delete", G_CALLBACK (on_confirm_delete_cb), - window); + data); g_signal_connect (data->tree_widget, "confirm-no-trash", @@ -669,7 +707,7 @@ impl_activate (PlumaPlugin * plugin, PlumaWindow * window) (data->tree_widget))), "changed", G_CALLBACK (on_selection_changed_cb), - window); + data); panel = pluma_window_get_side_panel (window); pixbuf = pluma_file_browser_utils_pixbuf_from_theme("system-file-manager", @@ -688,9 +726,8 @@ impl_activate (PlumaPlugin * plugin, PlumaWindow * window) _("File Browser"), image); gtk_widget_show (GTK_WIDGET (data->tree_widget)); - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, data); - add_popup_ui (window); + add_popup_ui (data); /* Restore filter options */ restore_filter (data); @@ -708,18 +745,18 @@ impl_activate (PlumaPlugin * plugin, PlumaWindow * window) g_signal_connect (pluma_file_browser_widget_get_browser_view (data->tree_widget), "notify::model", G_CALLBACK (on_model_set_cb), - window); + data); store = pluma_file_browser_widget_get_browser_store (data->tree_widget); g_signal_connect (store, "notify::virtual-root", G_CALLBACK (on_virtual_root_changed_cb), - window); + data); g_signal_connect (store, "notify::filter-mode", G_CALLBACK (on_filter_mode_changed_cb), - window); + data); g_signal_connect (store, "rename", @@ -734,16 +771,18 @@ impl_activate (PlumaPlugin * plugin, PlumaWindow * window) /* Register messages on the bus */ pluma_file_browser_messages_register (window, data->tree_widget); - impl_updateui (plugin, window); + pluma_file_browser_plugin_update_state (activatable); } static void -impl_deactivate (PlumaPlugin * plugin, PlumaWindow * window) +pluma_file_browser_plugin_deactivate (PeasActivatable *activatable) { - PlumaFileBrowserPluginData * data; + PlumaFileBrowserPluginPrivate *data; + PlumaWindow *window; PlumaPanel * panel; - data = get_plugin_data (window); + data = PLUMA_FILE_BROWSER_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); /* Unregister messages from the bus */ pluma_file_browser_messages_unregister (window); @@ -760,31 +799,51 @@ impl_deactivate (PlumaPlugin * plugin, PlumaWindow * window) if (data->caja_settings) g_object_unref (data->caja_settings); - remove_popup_ui (window); + remove_popup_ui (data); panel = pluma_window_get_side_panel (window); pluma_panel_remove_item (panel, GTK_WIDGET (data->tree_widget)); - - g_free (data); - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -filetree_plugin_class_init (PlumaFileBrowserPluginClass * klass) +pluma_file_browser_plugin_class_init (PlumaFileBrowserPluginClass * klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass * plugin_class = PLUMA_PLUGIN_CLASS (klass); - object_class->finalize = filetree_plugin_finalize; + object_class->dispose = pluma_file_browser_plugin_dispose; + object_class->set_property = pluma_file_browser_plugin_set_property; + object_class->get_property = pluma_file_browser_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_updateui; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_type_class_add_private (object_class, sizeof (PlumaFileBrowserPluginPrivate)); } +static void +pluma_file_browser_plugin_class_finalize (PlumaFileBrowserPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_file_browser_plugin_activate; + iface->deactivate = pluma_file_browser_plugin_deactivate; + iface->update_state = pluma_file_browser_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_file_browser_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_FILE_BROWSER_PLUGIN); +} + /* Callbacks */ static void on_uri_activated_cb (PlumaFileBrowserWidget * tree_widget, @@ -795,13 +854,10 @@ on_uri_activated_cb (PlumaFileBrowserWidget * tree_widget, static void on_error_cb (PlumaFileBrowserWidget * tree_widget, - guint code, gchar const *message, PlumaWindow * window) + guint code, gchar const *message, PlumaFileBrowserPluginPrivate * data) { gchar * title; GtkWidget * dlg; - PlumaFileBrowserPluginData * data; - - data = get_plugin_data (window); /* Do not show the error when the root has been set automatically */ if (data->auto_root && (code == PLUMA_FILE_BROWSER_ERROR_SET_ROOT || @@ -848,7 +904,7 @@ on_error_cb (PlumaFileBrowserWidget * tree_widget, break; } - dlg = gtk_message_dialog_new (GTK_WINDOW (window), + dlg = gtk_message_dialog_new (GTK_WINDOW (data->window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -863,9 +919,8 @@ on_error_cb (PlumaFileBrowserWidget * tree_widget, static void on_model_set_cb (PlumaFileBrowserView * widget, GParamSpec *arg1, - PlumaWindow * window) + PlumaFileBrowserPluginPrivate * data) { - PlumaFileBrowserPluginData * data = get_plugin_data (window); GtkTreeModel * model; model = gtk_tree_view_get_model (GTK_TREE_VIEW (pluma_file_browser_widget_get_browser_view (data->tree_widget))); @@ -881,9 +936,8 @@ on_model_set_cb (PlumaFileBrowserView * widget, static void on_filter_mode_changed_cb (PlumaFileBrowserStore * model, GParamSpec * param, - PlumaWindow * window) + PlumaFileBrowserPluginPrivate * data) { - PlumaFileBrowserPluginData * data = get_plugin_data (window); PlumaFileBrowserStoreFilterMode mode; mode = pluma_file_browser_store_get_filter_mode (model); @@ -967,9 +1021,8 @@ on_rename_cb (PlumaFileBrowserStore * store, static void on_filter_pattern_changed_cb (PlumaFileBrowserWidget * widget, GParamSpec * param, - PlumaWindow * window) + PlumaFileBrowserPluginPrivate * data) { - PlumaFileBrowserPluginData * data = get_plugin_data (window); gchar * pattern; g_object_get (G_OBJECT (widget), "filter-pattern", &pattern, NULL); @@ -985,9 +1038,8 @@ on_filter_pattern_changed_cb (PlumaFileBrowserWidget * widget, static void on_virtual_root_changed_cb (PlumaFileBrowserStore * store, GParamSpec * param, - PlumaWindow * window) + PlumaFileBrowserPluginPrivate * data) { - PlumaFileBrowserPluginData * data = get_plugin_data (window); gchar * root; gchar * virtual_root; @@ -1007,7 +1059,7 @@ on_virtual_root_changed_cb (PlumaFileBrowserStore * store, g_settings_set_string (data->onload_settings, "virtual-root", virtual_root); } - g_signal_handlers_disconnect_by_func (window, + g_signal_handlers_disconnect_by_func (PLUMA_WINDOW (data->window), G_CALLBACK (on_tab_added_cb), data); @@ -1018,7 +1070,7 @@ on_virtual_root_changed_cb (PlumaFileBrowserStore * store, static void on_tab_added_cb (PlumaWindow * window, PlumaTab * tab, - PlumaFileBrowserPluginData * data) + PlumaFileBrowserPluginPrivate *data) { gboolean open; gboolean load_default = TRUE; @@ -1100,15 +1152,12 @@ static gboolean on_confirm_delete_cb (PlumaFileBrowserWidget *widget, PlumaFileBrowserStore *store, GList *paths, - PlumaWindow *window) + PlumaFileBrowserPluginPrivate *data) { gchar *normal; gchar *message; gchar *secondary; gboolean result; - PlumaFileBrowserPluginData *data; - - data = get_plugin_data (window); if (!data->confirm_trash) return TRUE; @@ -1123,7 +1172,7 @@ on_confirm_delete_cb (PlumaFileBrowserWidget *widget, secondary = _("If you delete an item, it is permanently lost."); - result = pluma_file_browser_utils_confirmation_dialog (window, + result = pluma_file_browser_utils_confirmation_dialog (PLUMA_WINDOW (data->window), GTK_MESSAGE_QUESTION, message, secondary, diff --git a/plugins/filebrowser/pluma-file-browser-plugin.h b/plugins/filebrowser/pluma-file-browser-plugin.h index 6e70efa1..89324c91 100644 --- a/plugins/filebrowser/pluma-file-browser-plugin.h +++ b/plugins/filebrowser/pluma-file-browser-plugin.h @@ -24,13 +24,15 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS + /* * Type checking and casting macros */ -#define PLUMA_TYPE_FILE_BROWSER_PLUGIN (filetree_plugin_get_type ()) +#define PLUMA_TYPE_FILE_BROWSER_PLUGIN (pluma_file_browser_plugin_get_type ()) #define PLUMA_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PLUMA_TYPE_FILE_BROWSER_PLUGIN, PlumaFileBrowserPlugin)) #define PLUMA_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PLUMA_TYPE_FILE_BROWSER_PLUGIN, PlumaFileBrowserPluginClass)) #define PLUMA_IS_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PLUMA_TYPE_FILE_BROWSER_PLUGIN)) @@ -44,28 +46,27 @@ typedef struct _PlumaFileBrowserPluginClass PlumaFileBrowserPluginClass; struct _PlumaFileBrowserPlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; /*< private > */ PlumaFileBrowserPluginPrivate *priv; }; - - struct _PlumaFileBrowserPluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType filetree_plugin_get_type (void) G_GNUC_CONST; +GType pluma_file_browser_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule * module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS + #endif /* __PLUMA_FILE_BROWSER_PLUGIN_H__ */ // ex:ts=8:noet: diff --git a/plugins/filebrowser/pluma-file-browser-store.c b/plugins/filebrowser/pluma-file-browser-store.c index ce83fc74..1615729a 100644 --- a/plugins/filebrowser/pluma-file-browser-store.c +++ b/plugins/filebrowser/pluma-file-browser-store.c @@ -26,8 +26,6 @@ #include <string.h> #include <glib/gi18n-lib.h> #include <gio/gio.h> -#include <pluma/pluma-plugin.h> -#include <pluma/pluma-utils.h> #include "pluma-file-browser-store.h" #include "pluma-file-browser-marshal.h" @@ -197,13 +195,12 @@ static void model_check_dummy (PlumaFileBrowserSto static void next_files_async (GFileEnumerator * enumerator, AsyncNode * async); -PLUMA_PLUGIN_DEFINE_TYPE_WITH_CODE (PlumaFileBrowserStore, pluma_file_browser_store, +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaFileBrowserStore, pluma_file_browser_store, G_TYPE_OBJECT, - PLUMA_PLUGIN_IMPLEMENT_INTERFACE (pluma_file_browser_store_tree_model, - GTK_TYPE_TREE_MODEL, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_MODEL, pluma_file_browser_store_iface_init) - PLUMA_PLUGIN_IMPLEMENT_INTERFACE (pluma_file_browser_store_drag_source, - GTK_TYPE_TREE_DRAG_SOURCE, + G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_DRAG_SOURCE, pluma_file_browser_store_drag_source_init)) /* Properties */ @@ -428,6 +425,12 @@ pluma_file_browser_store_class_init (PlumaFileBrowserStoreClass * klass) } static void +pluma_file_browser_store_class_finalize (PlumaFileBrowserStoreClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void pluma_file_browser_store_iface_init (GtkTreeModelIface * iface) { iface->get_flags = pluma_file_browser_store_get_flags; @@ -3622,4 +3625,10 @@ pluma_file_browser_store_new_directory (PlumaFileBrowserStore * model, return result; } +void +_pluma_file_browser_store_register_type (GTypeModule *type_module) +{ + pluma_file_browser_store_register_type (type_module); +} + // ex:ts=8:noet: diff --git a/plugins/filebrowser/pluma-file-browser-store.h b/plugins/filebrowser/pluma-file-browser-store.h index 9a63842b..da889dbd 100644 --- a/plugins/filebrowser/pluma-file-browser-store.h +++ b/plugins/filebrowser/pluma-file-browser-store.h @@ -116,7 +116,7 @@ struct _PlumaFileBrowserStoreClass { }; GType pluma_file_browser_store_get_type (void) G_GNUC_CONST; -GType pluma_file_browser_store_register_type (GTypeModule * module); +void _pluma_file_browser_store_register_type (GTypeModule * module); PlumaFileBrowserStore *pluma_file_browser_store_new (gchar const *root); diff --git a/plugins/filebrowser/pluma-file-browser-view.c b/plugins/filebrowser/pluma-file-browser-view.c index 65728b0f..a206d8a8 100644 --- a/plugins/filebrowser/pluma-file-browser-view.c +++ b/plugins/filebrowser/pluma-file-browser-view.c @@ -21,7 +21,6 @@ #include <string.h> #include <gio/gio.h> -#include <pluma/pluma-plugin.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> @@ -86,7 +85,7 @@ static const GtkTargetEntry drag_source_targets[] = { { "text/uri-list", 0, 0 } }; -PLUMA_PLUGIN_DEFINE_TYPE (PlumaFileBrowserView, pluma_file_browser_view, +G_DEFINE_DYNAMIC_TYPE (PlumaFileBrowserView, pluma_file_browser_view, GTK_TYPE_TREE_VIEW) static void on_cell_edited (GtkCellRendererText * cell, @@ -912,6 +911,12 @@ pluma_file_browser_view_class_init (PlumaFileBrowserViewClass * klass) } static void +pluma_file_browser_view_class_finalize (PlumaFileBrowserViewClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ +} + +static void cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell, GtkTreeModel * tree_model, GtkTreeIter * iter, PlumaFileBrowserView * obj) @@ -1257,5 +1262,11 @@ on_row_inserted (PlumaFileBrowserStore * model, gtk_tree_path_free (copy); } + +void +_pluma_file_browser_view_register_type (GTypeModule *type_module) +{ + pluma_file_browser_view_register_type (type_module); +} // ex:ts=8:noet: diff --git a/plugins/filebrowser/pluma-file-browser-view.h b/plugins/filebrowser/pluma-file-browser-view.h index 47de6be8..299d210c 100644 --- a/plugins/filebrowser/pluma-file-browser-view.h +++ b/plugins/filebrowser/pluma-file-browser-view.h @@ -66,7 +66,7 @@ struct _PlumaFileBrowserViewClass }; GType pluma_file_browser_view_get_type (void) G_GNUC_CONST; -GType pluma_file_browser_view_register_type (GTypeModule * module); +void _pluma_file_browser_view_register_type (GTypeModule * module); GtkWidget *pluma_file_browser_view_new (void); void pluma_file_browser_view_set_model (PlumaFileBrowserView * tree_view, diff --git a/plugins/filebrowser/pluma-file-browser-widget.c b/plugins/filebrowser/pluma-file-browser-widget.c index 535ecbc4..11fa6a20 100644 --- a/plugins/filebrowser/pluma-file-browser-widget.c +++ b/plugins/filebrowser/pluma-file-browser-widget.c @@ -32,7 +32,6 @@ #include <gdk/gdkkeysyms.h> #include <pluma/pluma-utils.h> -#include <pluma/pluma-plugin.h> #include "pluma-file-browser-utils.h" #include "pluma-file-browser-error.h" @@ -236,7 +235,7 @@ static void on_action_filter_binary (GtkAction * action, static void on_action_bookmark_open (GtkAction * action, PlumaFileBrowserWidget * obj); -PLUMA_PLUGIN_DEFINE_TYPE (PlumaFileBrowserWidget, pluma_file_browser_widget, +G_DEFINE_DYNAMIC_TYPE (PlumaFileBrowserWidget, pluma_file_browser_widget, GTK_TYPE_BOX) static void @@ -480,6 +479,12 @@ pluma_file_browser_widget_class_init (PlumaFileBrowserWidgetClass * klass) } static void +pluma_file_browser_widget_class_finalize (PlumaFileBrowserWidgetClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ +} + +static void add_signal (PlumaFileBrowserWidget * obj, gpointer object, gulong id) { SignalNode *node = g_new (SignalNode, 1); @@ -3152,4 +3157,10 @@ on_action_bookmark_open (GtkAction * action, PlumaFileBrowserWidget * obj) bookmark_open (obj, model, &iter); } +void +_pluma_file_browser_widget_register_type (GTypeModule *type_module) +{ + pluma_file_browser_widget_register_type (type_module); +} + // ex:ts=8:noet: diff --git a/plugins/filebrowser/pluma-file-browser-widget.h b/plugins/filebrowser/pluma-file-browser-widget.h index 47b0d74e..8af73381 100644 --- a/plugins/filebrowser/pluma-file-browser-widget.h +++ b/plugins/filebrowser/pluma-file-browser-widget.h @@ -71,7 +71,7 @@ struct _PlumaFileBrowserWidgetClass }; GType pluma_file_browser_widget_get_type (void) G_GNUC_CONST; -GType pluma_file_browser_widget_register_type (GTypeModule * module); +void _pluma_file_browser_widget_register_type (GTypeModule * module); GtkWidget *pluma_file_browser_widget_new (const gchar *data_dir); diff --git a/plugins/modelines/Makefile.am b/plugins/modelines/Makefile.am index e375c898..c4840177 100644 --- a/plugins/modelines/Makefile.am +++ b/plugins/modelines/Makefile.am @@ -22,10 +22,10 @@ libmodelines_la_SOURCES = \ libmodelines_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) libmodelines_la_LIBADD = $(PLUMA_LIBS) -plugin_in_files = modelines.pluma-plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +plugin_in_files = modelines.plugin.desktop.in +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = \ $(plugin_in_files) \ diff --git a/plugins/modelines/modelines.pluma-plugin.desktop.in b/plugins/modelines/modelines.plugin.desktop.in index 9adf3f4e..04c34e7f 100644 --- a/plugins/modelines/modelines.pluma-plugin.desktop.in +++ b/plugins/modelines/modelines.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=modelines IAge=2 _Name=Modelines diff --git a/plugins/modelines/pluma-modeline-plugin.c b/plugins/modelines/pluma-modeline-plugin.c index 34639324..cc7e461b 100644 --- a/plugins/modelines/pluma-modeline-plugin.c +++ b/plugins/modelines/pluma-modeline-plugin.c @@ -25,20 +25,22 @@ #include <glib/gi18n-lib.h> #include <gmodule.h> +#include <libpeas/peas-activatable.h> #include "pluma-modeline-plugin.h" #include "modeline-parser.h" +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> -#include <pluma/pluma-utils.h> -#define WINDOW_DATA_KEY "PlumaModelinePluginWindowData" #define DOCUMENT_DATA_KEY "PlumaModelinePluginDocumentData" -typedef struct +struct _PlumaModelinePluginPrivate { + GtkWidget *window; + gulong tab_added_handler_id; gulong tab_removed_handler_id; -} WindowData; +}; typedef struct { @@ -46,18 +48,19 @@ typedef struct gulong document_saved_handler_id; } DocumentData; -static void pluma_modeline_plugin_activate (PlumaPlugin *plugin, PlumaWindow *window); -static void pluma_modeline_plugin_deactivate (PlumaPlugin *plugin, PlumaWindow *window); -static GObject *pluma_modeline_plugin_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_param); -static void pluma_modeline_plugin_finalize (GObject *object); +enum { + PROP_0, + PROP_OBJECT +}; -PLUMA_PLUGIN_REGISTER_TYPE(PlumaModelinePlugin, pluma_modeline_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); -static void -window_data_free (WindowData *wdata) -{ - g_slice_free (WindowData, wdata); -} +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaModelinePlugin, + pluma_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) @@ -66,43 +69,27 @@ document_data_free (DocumentData *ddata) } static void -pluma_modeline_plugin_class_init (PlumaModelinePluginClass *klass) +pluma_modeline_plugin_constructed (GObject *object) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); - - object_class->constructor = pluma_modeline_plugin_constructor; - object_class->finalize = pluma_modeline_plugin_finalize; - - plugin_class->activate = pluma_modeline_plugin_activate; - plugin_class->deactivate = pluma_modeline_plugin_deactivate; -} - -static GObject * -pluma_modeline_plugin_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_param) -{ - GObject *object; gchar *data_dir; - object = G_OBJECT_CLASS (pluma_modeline_plugin_parent_class)->constructor (type, - n_construct_properties, - construct_param); - - data_dir = pluma_plugin_get_data_dir (PLUMA_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; + G_OBJECT_CLASS (pluma_modeline_plugin_parent_class)->constructed (object); } static void pluma_modeline_plugin_init (PlumaModelinePlugin *plugin) { pluma_debug_message (DEBUG_PLUGINS, "PlumaModelinePlugin initializing"); + + plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, + PLUMA_TYPE_MODELINE_PLUGIN, + PlumaModelinePluginPrivate); } static void @@ -116,6 +103,62 @@ pluma_modeline_plugin_finalize (GObject *object) } static void +pluma_modeline_plugin_dispose (GObject *object) +{ + PlumaModelinePlugin *plugin = PLUMA_MODELINE_PLUGIN (object); + + pluma_debug_message (DEBUG_PLUGINS, "PlumaModelinePlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (pluma_modeline_plugin_parent_class)->dispose (object); +} + +static void +pluma_modeline_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PlumaModelinePlugin *plugin = PLUMA_MODELINE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +pluma_modeline_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PlumaModelinePlugin *plugin = PLUMA_MODELINE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void on_document_loaded_or_saved (PlumaDocument *document, const GError *error, GtkSourceView *view) @@ -186,15 +229,18 @@ on_window_tab_removed (PlumaWindow *window, } static void -pluma_modeline_plugin_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_modeline_plugin_activate (PeasActivatable *activatable) { - WindowData *wdata; + PlumaModelinePluginPrivate *data; + PlumaWindow *window; GList *views; GList *l; pluma_debug (DEBUG_PLUGINS); + data = PLUMA_MODELINE_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); + views = pluma_window_get_views (window); for (l = views; l != NULL; l = l->next) { @@ -203,36 +249,30 @@ pluma_modeline_plugin_activate (PlumaPlugin *plugin, } g_list_free (views); - wdata = g_slice_new (WindowData); - - wdata->tab_added_handler_id = + data->tab_added_handler_id = g_signal_connect (window, "tab-added", G_CALLBACK (on_window_tab_added), NULL); - wdata->tab_removed_handler_id = + data->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 -pluma_modeline_plugin_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_modeline_plugin_deactivate (PeasActivatable *activatable) { - WindowData *wdata; + PlumaModelinePluginPrivate *data; + PlumaWindow *window; GList *views; GList *l; pluma_debug (DEBUG_PLUGINS); - wdata = g_object_steal_data (G_OBJECT (window), WINDOW_DATA_KEY); + data = PLUMA_MODELINE_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - g_signal_handler_disconnect (window, wdata->tab_added_handler_id); - g_signal_handler_disconnect (window, wdata->tab_removed_handler_id); - - window_data_free (wdata); + g_signal_handler_disconnect (window, data->tab_added_handler_id); + g_signal_handler_disconnect (window, data->tab_removed_handler_id); views = pluma_window_get_views (window); @@ -246,3 +286,41 @@ pluma_modeline_plugin_deactivate (PlumaPlugin *plugin, g_list_free (views); } +static void +pluma_modeline_plugin_class_init (PlumaModelinePluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = pluma_modeline_plugin_constructed; + object_class->finalize = pluma_modeline_plugin_finalize; + object_class->dispose = pluma_modeline_plugin_dispose; + object_class->set_property = pluma_modeline_plugin_set_property; + object_class->get_property = pluma_modeline_plugin_get_property; + + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (PlumaModelinePluginPrivate)); +} + +static void +pluma_modeline_plugin_class_finalize (PlumaModelinePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_modeline_plugin_activate; + iface->deactivate = pluma_modeline_plugin_deactivate; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_modeline_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_MODELINE_PLUGIN); +} diff --git a/plugins/modelines/pluma-modeline-plugin.h b/plugins/modelines/pluma-modeline-plugin.h index 4618997e..c44faf36 100644 --- a/plugins/modelines/pluma-modeline-plugin.h +++ b/plugins/modelines/pluma-modeline-plugin.h @@ -24,7 +24,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -35,13 +36,27 @@ G_BEGIN_DECLS #define PLUMA_IS_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PLUMA_TYPE_MODELINE_PLUGIN)) #define PLUMA_MODELINE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PLUMA_TYPE_MODELINE_PLUGIN, PlumaModelinePluginClass)) -/* Private structure type */ -typedef PlumaPluginClass PlumaModelinePluginClass; -typedef PlumaPlugin PlumaModelinePlugin; +typedef struct _PlumaModelinePlugin PlumaModelinePlugin; +typedef struct _PlumaModelinePluginPrivate PlumaModelinePluginPrivate; + +struct _PlumaModelinePlugin +{ + PeasExtensionBase parent_instance; + + /*< private >*/ + PlumaModelinePluginPrivate *priv; +}; + +typedef struct _PlumaModelinePluginClass PlumaModelinePluginClass; + +struct _PlumaModelinePluginClass +{ + PeasExtensionBaseClass parent_class; +}; GType pluma_modeline_plugin_get_type (void) G_GNUC_CONST; -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/sort/Makefile.am b/plugins/sort/Makefile.am index 749be6bc..18245f05 100644 --- a/plugins/sort/Makefile.am +++ b/plugins/sort/Makefile.am @@ -19,11 +19,11 @@ libsort_la_LIBADD = $(PLUMA_LIBS) uidir = $(PLUMA_PLUGINS_DATA_DIR)/sort ui_DATA = sort.ui -plugin_in_files = sort.pluma-plugin.desktop.in +plugin_in_files = sort.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(ui_DATA) $(plugin_in_files) diff --git a/plugins/sort/pluma-sort-plugin.c b/plugins/sort/pluma-sort-plugin.c index 9ca9dc63..67a3a1ce 100644 --- a/plugins/sort/pluma-sort-plugin.c +++ b/plugins/sort/pluma-sort-plugin.c @@ -30,20 +30,30 @@ #include <string.h> #include <glib/gi18n-lib.h> #include <gmodule.h> +#include <libpeas/peas-activatable.h> +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> #include <pluma/pluma-utils.h> #include <pluma/pluma-help.h> #define PLUMA_SORT_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), PLUMA_TYPE_SORT_PLUGIN, PlumaSortPluginPrivate)) -/* Key in case the plugin ever needs any settings. */ -#define SORT_BASE_KEY "/apps/pluma/plugins/sort" - -#define WINDOW_DATA_KEY "PlumaSortPluginWindowData" #define MENU_PATH "/MenuBar/EditMenu/EditOps_6" -PLUMA_PLUGIN_REGISTER_TYPE(PlumaSortPlugin, pluma_sort_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaSortPlugin, + pluma_sort_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) + +enum { + PROP_0, + PROP_OBJECT +}; typedef struct { @@ -58,17 +68,13 @@ typedef struct GtkTextIter start, end; /* selection */ } SortDialog; -typedef struct +struct _PlumaSortPluginPrivate { + GtkWidget *window; + GtkActionGroup *ui_action_group; guint ui_id; -} WindowData; - -typedef struct -{ - PlumaPlugin *plugin; - PlumaWindow *window; -} ActionData; +}; typedef struct { @@ -78,7 +84,7 @@ typedef struct gint starting_column; } SortInfo; -static void sort_cb (GtkAction *action, ActionData *action_data); +static void sort_cb (GtkAction *action, PlumaSortPlugin *plugin); static void sort_real (SortDialog *dialog); static const GtkActionEntry action_entries[] = @@ -92,7 +98,7 @@ static const GtkActionEntry action_entries[] = }; static void -sort_dialog_dispose (GObject *obj, +sort_dialog_destroy (GObject *obj, gpointer dialog_pointer) { pluma_debug (DEBUG_PLUGINS); @@ -150,8 +156,9 @@ get_current_selection (PlumaWindow *window, SortDialog *dialog) } static SortDialog * -get_sort_dialog (ActionData *action_data) +get_sort_dialog (PlumaSortPlugin *plugin) { + PlumaWindow *window; SortDialog *dialog; GtkWidget *error_widget; gboolean ret; @@ -160,9 +167,11 @@ get_sort_dialog (ActionData *action_data) pluma_debug (DEBUG_PLUGINS); + window = PLUMA_WINDOW (plugin->priv->window); + dialog = g_slice_new (SortDialog); - data_dir = pluma_plugin_get_data_dir (action_data->plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "sort.ui", NULL); g_free (data_dir); ret = pluma_utils_get_ui_objects (ui_file, @@ -181,7 +190,7 @@ get_sort_dialog (ActionData *action_data) const gchar *err_message; err_message = gtk_label_get_label (GTK_LABEL (error_widget)); - pluma_warning (GTK_WINDOW (action_data->window), + pluma_warning (GTK_WINDOW (window), "%s", err_message); g_slice_free (SortDialog, dialog); @@ -194,8 +203,8 @@ get_sort_dialog (ActionData *action_data) GTK_RESPONSE_OK); g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (sort_dialog_dispose), + "destroy", + G_CALLBACK (sort_dialog_destroy), dialog); g_signal_connect (dialog->dialog, @@ -203,35 +212,38 @@ get_sort_dialog (ActionData *action_data) G_CALLBACK (sort_dialog_response_handler), dialog); - get_current_selection (action_data->window, dialog); + get_current_selection (window, dialog); return dialog; } static void sort_cb (GtkAction *action, - ActionData *action_data) + PlumaSortPlugin *plugin) { + PlumaWindow *window; PlumaDocument *doc; GtkWindowGroup *wg; SortDialog *dialog; pluma_debug (DEBUG_PLUGINS); - doc = pluma_window_get_active_document (action_data->window); + window = PLUMA_WINDOW (plugin->priv->window); + + doc = pluma_window_get_active_document (window); g_return_if_fail (doc != NULL); - dialog = get_sort_dialog (action_data); + dialog = get_sort_dialog (plugin); g_return_if_fail (dialog != NULL); - wg = pluma_window_get_group (action_data->window); + wg = pluma_window_get_group (window); gtk_window_group_add_window (wg, GTK_WINDOW (dialog->dialog)); dialog->doc = doc; gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog), - GTK_WINDOW (action_data->window)); + GTK_WINDOW (window)); gtk_window_set_modal (GTK_WINDOW (dialog->dialog), TRUE); @@ -439,30 +451,54 @@ sort_real (SortDialog *dialog) } static void -free_window_data (WindowData *data) +pluma_sort_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - g_return_if_fail (data != NULL); + PlumaSortPlugin *plugin = PLUMA_SORT_PLUGIN (object); - g_object_unref (data->ui_action_group); - g_slice_free (WindowData, data); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -free_action_data (ActionData *data) +pluma_sort_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - g_return_if_fail (data != NULL); + PlumaSortPlugin *plugin = PLUMA_SORT_PLUGIN (object); - g_slice_free (ActionData, data); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -update_ui_real (PlumaWindow *window, - WindowData *data) +update_ui (PlumaSortPluginPrivate *data) { + PlumaWindow *window; PlumaView *view; pluma_debug (DEBUG_PLUGINS); + window = PLUMA_WINDOW (data->window); view = pluma_window_get_active_view (window); gtk_action_group_set_sensitive (data->ui_action_group, @@ -471,30 +507,28 @@ update_ui_real (PlumaWindow *window, } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_sort_plugin_activate (PeasActivatable *activatable) { + PlumaSortPlugin *plugin; + PlumaSortPluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; pluma_debug (DEBUG_PLUGINS); - data = g_slice_new (WindowData); - action_data = g_slice_new (ActionData); - action_data->window = window; - action_data->plugin = plugin; + plugin = PLUMA_SORT_PLUGIN (activatable); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); manager = pluma_window_get_ui_manager (window); data->ui_action_group = gtk_action_group_new ("PlumaSortPluginActions"); gtk_action_group_set_translation_domain (data->ui_action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->ui_action_group, + gtk_action_group_add_actions (data->ui_action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) free_action_data); + plugin); gtk_ui_manager_insert_action_group (manager, data->ui_action_group, @@ -502,11 +536,6 @@ impl_activate (PlumaPlugin *plugin, data->ui_id = gtk_ui_manager_new_merge_id (manager); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, @@ -515,74 +544,101 @@ impl_activate (PlumaPlugin *plugin, GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, - data); + update_ui (data); } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_sort_plugin_deactivate (PeasActivatable *activatable) { + PlumaSortPluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - manager = pluma_window_get_ui_manager (window); + data = PLUMA_SORT_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = pluma_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->ui_action_group); - - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - NULL); } static void -impl_update_ui (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_sort_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - pluma_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - update_ui_real (window, - data); + update_ui (PLUMA_SORT_PLUGIN (activatable)->priv); } static void pluma_sort_plugin_init (PlumaSortPlugin *plugin) { pluma_debug_message (DEBUG_PLUGINS, "PlumaSortPlugin initializing"); + + plugin->priv = PLUMA_SORT_PLUGIN_GET_PRIVATE (plugin); } static void -pluma_sort_plugin_finalize (GObject *object) +pluma_sort_plugin_dispose (GObject *object) { - pluma_debug_message (DEBUG_PLUGINS, "PlumaSortPlugin finalizing"); + PlumaSortPlugin *plugin = PLUMA_SORT_PLUGIN (object); + + pluma_debug_message (DEBUG_PLUGINS, "PlumaSortPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->ui_action_group) + { + g_object_unref (plugin->priv->ui_action_group); + plugin->priv->ui_action_group = NULL; + } - G_OBJECT_CLASS (pluma_sort_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (pluma_sort_plugin_parent_class)->dispose (object); } static void pluma_sort_plugin_class_init (PlumaSortPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); - object_class->finalize = pluma_sort_plugin_finalize; + object_class->dispose = pluma_sort_plugin_dispose; + object_class->set_property = pluma_sort_plugin_set_property; + object_class->get_property = pluma_sort_plugin_get_property; + + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (klass, sizeof (PlumaSortPluginPrivate)); +} + +static void +pluma_sort_plugin_class_finalize (PlumaSortPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_sort_plugin_activate; + iface->deactivate = pluma_sort_plugin_deactivate; + iface->update_state = pluma_sort_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_sort_plugin_register_type (G_TYPE_MODULE (module)); - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_SORT_PLUGIN); } diff --git a/plugins/sort/pluma-sort-plugin.h b/plugins/sort/pluma-sort-plugin.h index 2ba82441..fc495633 100644 --- a/plugins/sort/pluma-sort-plugin.h +++ b/plugins/sort/pluma-sort-plugin.h @@ -23,7 +23,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -47,7 +48,10 @@ typedef struct _PlumaSortPlugin PlumaSortPlugin; struct _PlumaSortPlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private >*/ + PlumaSortPluginPrivate *priv; }; /* @@ -57,7 +61,7 @@ typedef struct _PlumaSortPluginClass PlumaSortPluginClass; struct _PlumaSortPluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -66,7 +70,7 @@ struct _PlumaSortPluginClass GType pluma_sort_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/sort/sort.pluma-plugin.desktop.in b/plugins/sort/sort.plugin.desktop.in index 6676ab6b..5775a984 100644 --- a/plugins/sort/sort.pluma-plugin.desktop.in +++ b/plugins/sort/sort.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=sort IAge=2 _Name=Sort diff --git a/plugins/spell/Makefile.am b/plugins/spell/Makefile.am index 001b25ae..9b15bc36 100644 --- a/plugins/spell/Makefile.am +++ b/plugins/spell/Makefile.am @@ -44,11 +44,11 @@ pluma-spell-marshal.c: pluma-spell-marshal.list $(GLIB_GENMARSHAL) $(AM_V_GEN) echo "#include \"pluma-spell-marshal.h\"" > $@ && \ $(GLIB_GENMARSHAL) $< --body --prefix=pluma_marshal >> $@ -plugin_in_files = spell.pluma-plugin.desktop.in +plugin_in_files = spell.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) @INTLTOOL_XML_NOMERGE_RULE@ spell_gschema_in = org.mate.pluma.plugins.spell.gschema.xml.in diff --git a/plugins/spell/pluma-spell-plugin.c b/plugins/spell/pluma-spell-plugin.c index d856dd7b..b7f96eb3 100644 --- a/plugins/spell/pluma-spell-plugin.c +++ b/plugins/spell/pluma-spell-plugin.c @@ -31,9 +31,11 @@ #include <glib/gi18n.h> #include <gmodule.h> +#include <libpeas/peas-activatable.h> +#include <libpeas-gtk/peas-gtk-configurable.h> +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> -#include <pluma/pluma-help.h> #include <pluma/pluma-prefs-manager.h> #include <pluma/pluma-statusbar.h> #include <pluma/pluma-utils.h> @@ -46,7 +48,6 @@ #define PLUMA_METADATA_ATTRIBUTE_SPELL_LANGUAGE "metadata::pluma-spell-language" #define PLUMA_METADATA_ATTRIBUTE_SPELL_ENABLED "metadata::pluma-spell-enabled" -#define WINDOW_DATA_KEY "PlumaSpellPluginWindowData" #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_1" #define PLUMA_SPELL_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ @@ -57,32 +58,39 @@ #define SPELL_SCHEMA "org.mate.pluma.plugins.spell" #define AUTOCHECK_TYPE_KEY "autocheck-type" -PLUMA_PLUGIN_REGISTER_TYPE(PlumaSpellPlugin, pluma_spell_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaSpellPlugin, + pluma_spell_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, + peas_gtk_configurable_iface_init)) + +enum { + PROP_0, + PROP_OBJECT +}; -typedef struct +struct _PlumaSpellPluginPrivate { + GtkWidget *window; + GtkActionGroup *action_group; guint ui_id; guint message_cid; gulong tab_added_id; gulong tab_removed_id; - PlumaSpellPlugin *plugin; -} WindowData; -typedef struct -{ - PlumaPlugin *plugin; - PlumaWindow *window; -} ActionData; - -struct _PlumaSpellPluginPrivate -{ GSettings *settings; }; -static void spell_cb (GtkAction *action, ActionData *action_data); -static void set_language_cb (GtkAction *action, ActionData *action_data); -static void auto_spell_cb (GtkAction *action, PlumaWindow *window); +static void spell_cb (GtkAction *action, PlumaSpellPlugin *plugin); +static void set_language_cb (GtkAction *action, PlumaSpellPlugin *plugin); +static void auto_spell_cb (GtkAction *action, PlumaSpellPlugin *plugin); /* UI actions. */ static const GtkActionEntry action_entries[] = @@ -120,13 +128,13 @@ typedef struct _SpellConfigureDialog SpellConfigureDialog; struct _SpellConfigureDialog { - GtkWidget *dialog; + GtkWidget *content; GtkWidget *never; GtkWidget *always; GtkWidget *document; - PlumaSpellPlugin *plugin; + GSettings *settings; }; typedef enum @@ -163,15 +171,27 @@ pluma_spell_plugin_init (PlumaSpellPlugin *plugin) } static void -pluma_spell_plugin_finalize (GObject *object) +pluma_spell_plugin_dispose (GObject *object) { PlumaSpellPlugin *plugin = PLUMA_SPELL_PLUGIN (object); - pluma_debug_message (DEBUG_PLUGINS, "PlumaSpellPlugin finalizing"); + pluma_debug_message (DEBUG_PLUGINS, "PlumaSpellPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->action_group) + { + g_object_unref (plugin->priv->action_group); + plugin->priv->action_group = NULL; + } g_object_unref (G_OBJECT (plugin->priv->settings)); - G_OBJECT_CLASS (pluma_spell_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (pluma_spell_plugin_parent_class)->dispose (object); } static void @@ -226,16 +246,16 @@ get_autocheck_type (PlumaSpellPlugin *plugin) } static void -set_autocheck_type (PlumaSpellPlugin *plugin, +set_autocheck_type (GSettings *settings, PlumaSpellPluginAutocheckType autocheck_type) { - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, AUTOCHECK_TYPE_KEY)) { return; } - g_settings_set_enum (plugin->priv->settings, + g_settings_set_enum (settings, AUTOCHECK_TYPE_KEY, autocheck_type); } @@ -739,7 +759,6 @@ get_configure_dialog (PlumaSpellPlugin *plugin) SpellConfigureDialog *dialog = NULL; gchar *data_dir; gchar *ui_file; - GtkWidget *content; PlumaSpellPluginAutocheckType autocheck_type; GtkWidget *error_widget; gboolean ret; @@ -750,37 +769,15 @@ get_configure_dialog (PlumaSpellPlugin *plugin) pluma_debug (DEBUG_PLUGINS); - GtkWidget *dlg = gtk_dialog_new_with_buttons (_("Configure Spell Checker plugin..."), - NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); - - g_return_val_if_fail (dlg != NULL, NULL); + dialog = g_slice_new (SpellConfigureDialog); + dialog->settings = g_object_ref (plugin->priv->settings); - dialog = g_new0 (SpellConfigureDialog, 1); - dialog->dialog = dlg; - - - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6); - - data_dir = pluma_plugin_get_data_dir (PLUMA_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "pluma-spell-setup-dialog.ui", NULL); ret = pluma_utils_get_ui_objects (ui_file, root_objects, &error_widget, - "spell_dialog_content", &content, + "spell_dialog_content", &dialog->content, "autocheck_never", &dialog->never, "autocheck_document", &dialog->document, "autocheck_always", &dialog->always, @@ -791,18 +788,9 @@ get_configure_dialog (PlumaSpellPlugin *plugin) if (!ret) { - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - error_widget, TRUE, TRUE, 0); - - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - - gtk_widget_show (error_widget); - - return dialog; + return NULL; } - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - autocheck_type = get_autocheck_type (plugin); if (autocheck_type == AUTOCHECK_ALWAYS) @@ -818,75 +806,46 @@ get_configure_dialog (PlumaSpellPlugin *plugin) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->never), TRUE); } - gtk_window_set_default_size (GTK_WIDGET (content), 15, 120); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - content, FALSE, FALSE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); - - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); - return dialog; } static void -ok_button_pressed (SpellConfigureDialog *dialog) +configure_dialog_button_toggled (GtkToggleButton *button, + SpellConfigureDialog *dialog) { pluma_debug (DEBUG_PLUGINS); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->always))) { - set_autocheck_type (dialog->plugin, AUTOCHECK_ALWAYS); + set_autocheck_type (dialog->settings, AUTOCHECK_ALWAYS); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->document))) { - set_autocheck_type (dialog->plugin, AUTOCHECK_DOCUMENT); + set_autocheck_type (dialog->settings, AUTOCHECK_DOCUMENT); } else { - set_autocheck_type (dialog->plugin, AUTOCHECK_NEVER); + set_autocheck_type (dialog->settings, AUTOCHECK_NEVER); } } static void -configure_dialog_response_cb (GtkWidget *widget, - gint response, - SpellConfigureDialog *dialog) +configure_dialog_destroyed (GtkWidget *widget, + gpointer data) { - switch (response) - { - case GTK_RESPONSE_HELP: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); - - pluma_help_display (GTK_WINDOW (widget), - NULL, - "pluma-spell-checker-plugin"); - break; - } - case GTK_RESPONSE_OK: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); + SpellConfigureDialog *dialog = (SpellConfigureDialog *) data; - ok_button_pressed (dialog); + pluma_debug (DEBUG_PLUGINS); - gtk_widget_destroy (dialog->dialog); - break; - } - case GTK_RESPONSE_CANCEL: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } - } + g_object_unref (dialog->settings); + g_slice_free (SpellConfigureDialog, data); } static void set_language_cb (GtkAction *action, - ActionData *action_data) + PlumaSpellPlugin *plugin) { + PlumaWindow *window; PlumaDocument *doc; PlumaSpellChecker *spell; const PlumaSpellCheckerLanguage *lang; @@ -896,7 +855,8 @@ set_language_cb (GtkAction *action, pluma_debug (DEBUG_PLUGINS); - doc = pluma_window_get_active_document (action_data->window); + window = PLUMA_WINDOW (plugin->priv->window); + doc = pluma_window_get_active_document (window); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); @@ -904,13 +864,13 @@ set_language_cb (GtkAction *action, lang = pluma_spell_checker_get_language (spell); - data_dir = pluma_plugin_get_data_dir (action_data->plugin); - dlg = pluma_spell_language_dialog_new (GTK_WINDOW (action_data->window), + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + dlg = pluma_spell_language_dialog_new (GTK_WINDOW (window), lang, data_dir); g_free (data_dir); - wg = pluma_window_get_group (action_data->window); + wg = pluma_window_get_group (window); gtk_window_group_add_window (wg, GTK_WINDOW (dlg)); @@ -926,8 +886,10 @@ set_language_cb (GtkAction *action, static void spell_cb (GtkAction *action, - ActionData *action_data) + PlumaSpellPlugin *plugin) { + PlumaSpellPluginPrivate *data; + PlumaWindow *window; PlumaView *view; PlumaDocument *doc; PlumaSpellChecker *spell; @@ -938,7 +900,9 @@ spell_cb (GtkAction *action, pluma_debug (DEBUG_PLUGINS); - view = pluma_window_get_active_view (action_data->window); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); + view = pluma_window_get_active_view (window); g_return_if_fail (view != NULL); doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); @@ -949,14 +913,9 @@ spell_cb (GtkAction *action, if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) { - WindowData *data; GtkWidget *statusbar; - data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - statusbar = pluma_window_get_statusbar (action_data->window); + statusbar = pluma_window_get_statusbar (window); pluma_statusbar_flash_message (PLUMA_STATUSBAR (statusbar), data->message_cid, _("The document is empty.")); @@ -979,14 +938,9 @@ spell_cb (GtkAction *action, word = get_next_misspelled_word (view); if (word == NULL) { - WindowData *data; GtkWidget *statusbar; - data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - statusbar = pluma_window_get_statusbar (action_data->window); + statusbar = pluma_window_get_statusbar (window); pluma_statusbar_flash_message (PLUMA_STATUSBAR (statusbar), data->message_cid, _("No misspelled words")); @@ -994,12 +948,13 @@ spell_cb (GtkAction *action, return; } - data_dir = pluma_plugin_get_data_dir (action_data->plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); dlg = pluma_spell_checker_dialog_new_from_spell_checker (spell, data_dir); g_free (data_dir); + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); gtk_window_set_transient_for (GTK_WINDOW (dlg), - GTK_WINDOW (action_data->window)); + GTK_WINDOW (window)); g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); @@ -1059,15 +1014,16 @@ set_auto_spell (PlumaWindow *window, static void auto_spell_cb (GtkAction *action, - PlumaWindow *window) + PlumaSpellPlugin *plugin) { - + PlumaWindow *window; PlumaDocument *doc; gboolean active; - WindowData *data; pluma_debug (DEBUG_PLUGINS); + window = PLUMA_WINDOW (plugin->priv->window); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); pluma_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); @@ -1076,12 +1032,8 @@ auto_spell_cb (GtkAction *action, if (doc == NULL) return; - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT) + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) { - pluma_document_set_metadata (doc, PLUMA_METADATA_ATTRIBUTE_SPELL_ENABLED, active ? "1" : NULL, NULL); @@ -1091,26 +1043,10 @@ auto_spell_cb (GtkAction *action, } static void -free_window_data (WindowData *data) -{ - g_return_if_fail (data != NULL); - - g_object_unref (data->action_group); - g_slice_free (WindowData, data); -} - -static void -free_action_data (gpointer data) -{ - g_return_if_fail (data != NULL); - - g_slice_free (ActionData, data); -} - -static void -update_ui_real (PlumaWindow *window, - WindowData *data) +update_ui (PlumaSpellPlugin *plugin) { + PlumaSpellPluginPrivate *data; + PlumaWindow *window; PlumaDocument *doc; PlumaView *view; gboolean autospell; @@ -1118,6 +1054,8 @@ update_ui_real (PlumaWindow *window, pluma_debug (DEBUG_PLUGINS); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); doc = pluma_window_get_active_document (window); view = pluma_window_get_active_view (window); @@ -1140,12 +1078,12 @@ update_ui_real (PlumaWindow *window, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, - window); + plugin); set_auto_spell (window, doc, autospell); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell); g_signal_handlers_unblock_by_func (action, auto_spell_cb, - window); + plugin); } } @@ -1155,20 +1093,17 @@ update_ui_real (PlumaWindow *window, } static void -set_auto_spell_from_metadata (PlumaWindow *window, +set_auto_spell_from_metadata (PlumaSpellPlugin *plugin, PlumaDocument *doc, GtkActionGroup *action_group) { gboolean active = FALSE; gchar *active_str = NULL; + PlumaWindow *window; PlumaDocument *active_doc; PlumaSpellPluginAutocheckType autocheck_type; - WindowData *data; - - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - autocheck_type = get_autocheck_type(data->plugin); + autocheck_type = get_autocheck_type (plugin); switch (autocheck_type) { @@ -1196,6 +1131,8 @@ set_auto_spell_from_metadata (PlumaWindow *window, g_free (active_str); } + window = PLUMA_WINDOW (plugin->priv->window); + set_auto_spell (window, doc, active); /* In case that the doc is the active one we mark the spell action */ @@ -1209,22 +1146,21 @@ set_auto_spell_from_metadata (PlumaWindow *window, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, - window); + plugin); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active); g_signal_handlers_unblock_by_func (action, auto_spell_cb, - window); + plugin); } } static void on_document_loaded (PlumaDocument *doc, const GError *error, - PlumaWindow *window) + PlumaSpellPlugin *plugin) { if (error == NULL) { - WindowData *data; PlumaSpellChecker *spell; spell = PLUMA_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), @@ -1234,22 +1170,18 @@ on_document_loaded (PlumaDocument *doc, set_language_from_metadata (spell, doc); } - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - set_auto_spell_from_metadata (window, doc, data->action_group); + set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group); } } static void on_document_saved (PlumaDocument *doc, const GError *error, - PlumaWindow *window) + PlumaSpellPlugin *plugin) { PlumaAutomaticSpellChecker *autospell; PlumaSpellChecker *spell; const gchar *key; - WindowData *data; if (error != NULL) { @@ -1269,10 +1201,7 @@ on_document_saved (PlumaDocument *doc, key = NULL; } - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT) + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) { pluma_document_set_metadata (doc, @@ -1294,11 +1223,10 @@ on_document_saved (PlumaDocument *doc, static void tab_added_cb (PlumaWindow *window, PlumaTab *tab, - gpointer useless) + PlumaSpellPlugin *plugin) { PlumaDocument *doc; gchar *uri; - WindowData *data; doc = pluma_tab_get_document (tab); @@ -1306,67 +1234,61 @@ tab_added_cb (PlumaWindow *window, if (!uri) { - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - set_auto_spell_from_metadata (window, doc, data->action_group); + set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group); g_free(uri); } g_signal_connect (doc, "loaded", G_CALLBACK (on_document_loaded), - window); + plugin); g_signal_connect (doc, "saved", G_CALLBACK (on_document_saved), - window); + plugin); } static void tab_removed_cb (PlumaWindow *window, PlumaTab *tab, - gpointer useless) + PlumaSpellPlugin *plugin) { PlumaDocument *doc; doc = pluma_tab_get_document (tab); - g_signal_handlers_disconnect_by_func (doc, on_document_loaded, window); - g_signal_handlers_disconnect_by_func (doc, on_document_saved, window); + g_signal_handlers_disconnect_by_func (doc, on_document_loaded, plugin); + g_signal_handlers_disconnect_by_func (doc, on_document_saved, plugin); } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_spell_plugin_activate (PeasActivatable *activatable) { + PlumaSpellPlugin *plugin; + PlumaSpellPluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; GList *docs, *l; pluma_debug (DEBUG_PLUGINS); - data = g_slice_new (WindowData); - data->plugin = PLUMA_SPELL_PLUGIN (plugin); - action_data = g_slice_new (ActionData); - action_data->plugin = plugin; - action_data->window = window; + plugin = PLUMA_SPELL_PLUGIN (activatable); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); manager = pluma_window_get_ui_manager (window); data->action_group = gtk_action_group_new ("PlumaSpellPluginActions"); gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->action_group, + gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) free_action_data); + plugin); gtk_action_group_add_toggle_actions (data->action_group, toggle_action_entries, G_N_ELEMENTS (toggle_action_entries), - window); + plugin); gtk_ui_manager_insert_action_group (manager, data->action_group, -1); @@ -1376,11 +1298,6 @@ impl_activate (PlumaPlugin *plugin, (GTK_STATUSBAR (pluma_window_get_statusbar (window)), "spell_plugin_message"); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, @@ -1405,100 +1322,140 @@ impl_activate (PlumaPlugin *plugin, GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, data); + update_ui (plugin); docs = pluma_window_get_documents (window); for (l = docs; l != NULL; l = g_list_next (l)) { PlumaDocument *doc = PLUMA_DOCUMENT (l->data); - set_auto_spell_from_metadata (window, doc, + set_auto_spell_from_metadata (plugin, doc, data->action_group); g_signal_handlers_disconnect_by_func (doc, on_document_loaded, - window); + plugin); g_signal_handlers_disconnect_by_func (doc, on_document_saved, - window); + plugin); } data->tab_added_id = g_signal_connect (window, "tab-added", - G_CALLBACK (tab_added_cb), NULL); + G_CALLBACK (tab_added_cb), plugin); data->tab_removed_id = g_signal_connect (window, "tab-removed", - G_CALLBACK (tab_removed_cb), NULL); + G_CALLBACK (tab_removed_cb), plugin); } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_spell_plugin_deactivate (PeasActivatable *activatable) { + PlumaSpellPluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - manager = pluma_window_get_ui_manager (window); + data = PLUMA_SPELL_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = pluma_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); g_signal_handler_disconnect (window, data->tab_added_id); g_signal_handler_disconnect (window, data->tab_removed_id); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -impl_update_ui (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_spell_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - pluma_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + update_ui (PLUMA_SPELL_PLUGIN (activatable)); +} + +static void +pluma_spell_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PlumaSpellPlugin *plugin = PLUMA_SPELL_PLUGIN (object); - update_ui_real (window, data); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } -static GtkWidget * -impl_create_configure_dialog (PlumaPlugin *plugin) +static void +pluma_spell_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - SpellConfigureDialog *dialog; + PlumaSpellPlugin *plugin = PLUMA_SPELL_PLUGIN (object); - dialog = get_configure_dialog(PLUMA_SPELL_PLUGIN (plugin)); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; - dialog->plugin = PLUMA_SPELL_PLUGIN (plugin); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (configure_dialog_response_cb), - dialog); +static GtkWidget * +pluma_spell_plugin_create_configure_widget (PeasGtkConfigurable *configurable) +{ + SpellConfigureDialog *dialog; - return GTK_WIDGET (dialog->dialog); + dialog = get_configure_dialog (PLUMA_SPELL_PLUGIN (configurable)); + + g_signal_connect (dialog->always, + "toggled", + G_CALLBACK (configure_dialog_button_toggled), + dialog); + g_signal_connect (dialog->document, + "toggled", + G_CALLBACK (configure_dialog_button_toggled), + dialog); + g_signal_connect (dialog->never, + "toggled", + G_CALLBACK (configure_dialog_button_toggled), + dialog); + + g_signal_connect (dialog->content, + "destroy", + G_CALLBACK (configure_dialog_destroyed), + dialog); + + return dialog->content; } static void pluma_spell_plugin_class_init (PlumaSpellPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); - object_class->finalize = pluma_spell_plugin_finalize; + object_class->dispose = pluma_spell_plugin_dispose; + object_class->set_property = pluma_spell_plugin_set_property; + object_class->get_property = pluma_spell_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; - - plugin_class->create_configure_dialog = impl_create_configure_dialog; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); if (spell_checker_id == 0) spell_checker_id = g_quark_from_string ("PlumaSpellCheckerID"); @@ -1508,3 +1465,37 @@ pluma_spell_plugin_class_init (PlumaSpellPluginClass *klass) g_type_class_add_private (object_class, sizeof (PlumaSpellPluginPrivate)); } + +static void +pluma_spell_plugin_class_finalize (PlumaSpellPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_spell_plugin_activate; + iface->deactivate = pluma_spell_plugin_deactivate; + iface->update_state = pluma_spell_plugin_update_state; +} + +static void +peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface) +{ + iface->create_configure_widget = pluma_spell_plugin_create_configure_widget; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_spell_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_SPELL_PLUGIN); + + peas_object_module_register_extension_type (module, + PEAS_GTK_TYPE_CONFIGURABLE, + PLUMA_TYPE_SPELL_PLUGIN); +} diff --git a/plugins/spell/pluma-spell-plugin.h b/plugins/spell/pluma-spell-plugin.h index d2c06252..aa45eb63 100644 --- a/plugins/spell/pluma-spell-plugin.h +++ b/plugins/spell/pluma-spell-plugin.h @@ -25,7 +25,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -49,8 +50,9 @@ typedef struct _PlumaSpellPlugin PlumaSpellPlugin; struct _PlumaSpellPlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; + /*< private >*/ PlumaSpellPluginPrivate *priv; }; @@ -61,7 +63,7 @@ typedef struct _PlumaSpellPluginClass PlumaSpellPluginClass; struct _PlumaSpellPluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -70,7 +72,7 @@ struct _PlumaSpellPluginClass GType pluma_spell_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/spell/spell.pluma-plugin.desktop.in b/plugins/spell/spell.plugin.desktop.in index 970a505f..9bf11b72 100644 --- a/plugins/spell/spell.pluma-plugin.desktop.in +++ b/plugins/spell/spell.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=spell IAge=2 _Name=Spell Checker diff --git a/plugins/taglist/Makefile.am b/plugins/taglist/Makefile.am index 2b85c58a..044fae3f 100644 --- a/plugins/taglist/Makefile.am +++ b/plugins/taglist/Makefile.am @@ -30,9 +30,9 @@ libtaglist_la_SOURCES = \ libtaglist_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) libtaglist_la_LIBADD = $(PLUMA_LIBS) -plugin_in_files = taglist.pluma-plugin.desktop.in +plugin_in_files = taglist.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache GZIP_ENV = -9 @@ -41,7 +41,7 @@ GZIP_ENV = -9 LC_ALL=C $(INTLTOOL_MERGE) $(top_srcdir)/po $< $(@:.gz=) -x -u -c $(top_builddir)/po/.intltool-merge-cache GZIP=$(GZIP_ENV) gzip -n -f $(@:.gz=) -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = \ $(taglist_in_files) $(taglist_DATA) \ diff --git a/plugins/taglist/pluma-taglist-plugin-panel.c b/plugins/taglist/pluma-taglist-plugin-panel.c index 8e5fd458..3c1b39a3 100644 --- a/plugins/taglist/pluma-taglist-plugin-panel.c +++ b/plugins/taglist/pluma-taglist-plugin-panel.c @@ -39,7 +39,6 @@ #include <pluma/pluma-utils.h> #include <pluma/pluma-debug.h> -#include <pluma/pluma-plugin.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> @@ -69,7 +68,7 @@ struct _PlumaTaglistPluginPanelPrivate gchar *data_dir; }; -PLUMA_PLUGIN_DEFINE_TYPE (PlumaTaglistPluginPanel, pluma_taglist_plugin_panel, GTK_TYPE_BOX) +G_DEFINE_DYNAMIC_TYPE (PlumaTaglistPluginPanel, pluma_taglist_plugin_panel, GTK_TYPE_BOX) enum { @@ -161,6 +160,12 @@ pluma_taglist_plugin_panel_class_init (PlumaTaglistPluginPanelClass *klass) } static void +pluma_taglist_plugin_panel_class_finalize (PlumaTaglistPluginPanelClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE */ +} + +static void insert_tag (PlumaTaglistPluginPanel *panel, Tag *tag, gboolean grab_focus) @@ -783,3 +788,9 @@ pluma_taglist_plugin_panel_new (PlumaWindow *window, return GTK_WIDGET (panel); } + +void +_pluma_taglist_plugin_panel_register_type (GTypeModule *type_module) +{ + pluma_taglist_plugin_panel_register_type (type_module); +} diff --git a/plugins/taglist/pluma-taglist-plugin-panel.h b/plugins/taglist/pluma-taglist-plugin-panel.h index ab001b17..346dbd37 100644 --- a/plugins/taglist/pluma-taglist-plugin-panel.h +++ b/plugins/taglist/pluma-taglist-plugin-panel.h @@ -77,7 +77,7 @@ struct _PlumaTaglistPluginPanelClass /* * Public methods */ -GType pluma_taglist_plugin_panel_register_type (GTypeModule *module); +void _pluma_taglist_plugin_panel_register_type (GTypeModule *module); GType pluma_taglist_plugin_panel_get_type (void) G_GNUC_CONST; diff --git a/plugins/taglist/pluma-taglist-plugin-parser.c b/plugins/taglist/pluma-taglist-plugin-parser.c index a67fae5d..75c06f39 100644 --- a/plugins/taglist/pluma-taglist-plugin-parser.c +++ b/plugins/taglist/pluma-taglist-plugin-parser.c @@ -43,8 +43,6 @@ #include "pluma-taglist-plugin-parser.h" -/* we screwed up so we still look here for compatibility */ -#define USER_PLUMA_TAGLIST_PLUGIN_LOCATION_LEGACY ".pluma/plugins/taglist/" #define USER_PLUMA_TAGLIST_PLUGIN_LOCATION "pluma/taglist/" TagList* taglist = NULL; @@ -603,33 +601,12 @@ TagList* create_taglist(const gchar* data_dir) } const gchar* home; - const gchar* envvar; /* load user's taglists */ - /* legacy dir */ home = g_get_home_dir (); if (home != NULL) { - pdir = g_build_filename (home, - USER_PLUMA_TAGLIST_PLUGIN_LOCATION_LEGACY, - NULL); - parse_taglist_dir (pdir); - g_free (pdir); - } - - /* Support old libmate env var */ - envvar = g_getenv ("MATE22_USER_DIR"); - if (envvar != NULL) - { - pdir = g_build_filename (envvar, - USER_PLUMA_TAGLIST_PLUGIN_LOCATION, - NULL); - parse_taglist_dir (pdir); - g_free (pdir); - } - else if (home != NULL) - { pdir = g_build_filename(home, ".config", USER_PLUMA_TAGLIST_PLUGIN_LOCATION, NULL); parse_taglist_dir(pdir); g_free (pdir); diff --git a/plugins/taglist/pluma-taglist-plugin.c b/plugins/taglist/pluma-taglist-plugin.c index 391a6dde..7feeeb78 100644 --- a/plugins/taglist/pluma-taglist-plugin.c +++ b/plugins/taglist/pluma-taglist-plugin.c @@ -37,23 +37,37 @@ #include <glib/gi18n-lib.h> #include <gmodule.h> +#include <libpeas/peas-activatable.h> -#include <pluma/pluma-plugin.h> +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> -#define WINDOW_DATA_KEY "PlumaTaglistPluginWindowData" - #define PLUMA_TAGLIST_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), PLUMA_TYPE_TAGLIST_PLUGIN, PlumaTaglistPluginPrivate)) struct _PlumaTaglistPluginPrivate { - gpointer dummy; + GtkWidget *window; + + GtkWidget *taglist_panel; }; -PLUMA_PLUGIN_REGISTER_TYPE_WITH_CODE (PlumaTaglistPlugin, pluma_taglist_plugin, - pluma_taglist_plugin_panel_register_type (module); +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaTaglistPlugin, + pluma_taglist_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) \ + \ + _pluma_taglist_plugin_panel_register_type (type_module); \ ) +enum { + PROP_0, + PROP_OBJECT +}; + static void pluma_taglist_plugin_init (PlumaTaglistPlugin *plugin) { @@ -63,11 +77,24 @@ pluma_taglist_plugin_init (PlumaTaglistPlugin *plugin) } static void -pluma_taglist_plugin_finalize (GObject *object) +pluma_taglist_plugin_dispose (GObject *object) { -/* PlumaTaglistPlugin *plugin = PLUMA_TAGLIST_PLUGIN (object); -*/ + + pluma_debug_message (DEBUG_PLUGINS, "PlumaTaglistPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (pluma_taglist_plugin_parent_class)->dispose (object); +} + +static void +pluma_taglist_plugin_finalize (GObject *object) +{ pluma_debug_message (DEBUG_PLUGINS, "PlumaTaglistPlugin finalizing"); free_taglist (); @@ -76,85 +103,139 @@ pluma_taglist_plugin_finalize (GObject *object) } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_taglist_plugin_activate (PeasActivatable *activatable) { + PlumaTaglistPluginPrivate *priv; + PlumaWindow *window; PlumaPanel *side_panel; - GtkWidget *taglist_panel; gchar *data_dir; - + pluma_debug (DEBUG_PLUGINS); - - g_return_if_fail (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY) == NULL); - + + priv = PLUMA_TAGLIST_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (priv->window); side_panel = pluma_window_get_side_panel (window); - - data_dir = pluma_plugin_get_data_dir (plugin); - taglist_panel = pluma_taglist_plugin_panel_new (window, data_dir); + + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); + priv->taglist_panel = pluma_taglist_plugin_panel_new (window, data_dir); g_free (data_dir); - + pluma_panel_add_item_with_stock_icon (side_panel, - taglist_panel, + priv->taglist_panel, _("Tags"), GTK_STOCK_ADD); - - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - taglist_panel); } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_taglist_plugin_deactivate (PeasActivatable *activatable) { + PlumaTaglistPluginPrivate *priv; + PlumaWindow *window; PlumaPanel *side_panel; - gpointer data; pluma_debug (DEBUG_PLUGINS); - data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - + priv = PLUMA_TAGLIST_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (priv->window); side_panel = pluma_window_get_side_panel (window); pluma_panel_remove_item (side_panel, - GTK_WIDGET (data)); - - g_object_set_data (G_OBJECT (window), - WINDOW_DATA_KEY, - NULL); + priv->taglist_panel); } static void -impl_update_ui (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_taglist_plugin_update_state (PeasActivatable *activatable) { - gpointer data; + PlumaTaglistPluginPrivate *priv; + PlumaWindow *window; PlumaView *view; - + pluma_debug (DEBUG_PLUGINS); - - data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - + + priv = PLUMA_TAGLIST_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (priv->window); view = pluma_window_get_active_view (window); - - gtk_widget_set_sensitive (GTK_WIDGET (data), + + gtk_widget_set_sensitive (priv->taglist_panel, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); } static void +pluma_taglist_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PlumaTaglistPlugin *plugin = PLUMA_TAGLIST_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +pluma_taglist_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PlumaTaglistPlugin *plugin = PLUMA_TAGLIST_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void pluma_taglist_plugin_class_init (PlumaTaglistPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); object_class->finalize = pluma_taglist_plugin_finalize; + object_class->dispose = pluma_taglist_plugin_dispose; + object_class->set_property = pluma_taglist_plugin_set_property; + object_class->get_property = pluma_taglist_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_type_class_add_private (object_class, sizeof (PlumaTaglistPluginPrivate)); } + +static void +pluma_taglist_plugin_class_finalize (PlumaTaglistPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_taglist_plugin_activate; + iface->deactivate = pluma_taglist_plugin_deactivate; + iface->update_state = pluma_taglist_plugin_update_state; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_taglist_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_TAGLIST_PLUGIN); +} diff --git a/plugins/taglist/pluma-taglist-plugin.h b/plugins/taglist/pluma-taglist-plugin.h index a73fbe2d..0ffd1294 100644 --- a/plugins/taglist/pluma-taglist-plugin.h +++ b/plugins/taglist/pluma-taglist-plugin.h @@ -32,7 +32,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -56,7 +57,7 @@ typedef struct _PlumaTaglistPlugin PlumaTaglistPlugin; struct _PlumaTaglistPlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; /*< private >*/ PlumaTaglistPluginPrivate *priv; @@ -69,7 +70,7 @@ typedef struct _PlumaTaglistPluginClass PlumaTaglistPluginClass; struct _PlumaTaglistPluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -78,7 +79,7 @@ struct _PlumaTaglistPluginClass GType pluma_taglist_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/taglist/taglist.pluma-plugin.desktop.in b/plugins/taglist/taglist.plugin.desktop.in index a138ff3a..00b07952 100644 --- a/plugins/taglist/taglist.pluma-plugin.desktop.in +++ b/plugins/taglist/taglist.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=taglist IAge=2 _Name=Tag list diff --git a/plugins/time/Makefile.am b/plugins/time/Makefile.am index d1f8fe3b..30363e76 100644 --- a/plugins/time/Makefile.am +++ b/plugins/time/Makefile.am @@ -21,11 +21,11 @@ ui_DATA = \ pluma-time-dialog.ui \ pluma-time-setup-dialog.ui -plugin_in_files = time.pluma-plugin.desktop.in +plugin_in_files = time.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) @INTLTOOL_XML_NOMERGE_RULE@ time_gschema_in = org.mate.pluma.plugins.time.gschema.xml.in diff --git a/plugins/time/pluma-time-plugin.c b/plugins/time/pluma-time-plugin.c index 1cda2c35..1266f971 100644 --- a/plugins/time/pluma-time-plugin.c +++ b/plugins/time/pluma-time-plugin.c @@ -40,7 +40,10 @@ #include <glib.h> #include <gmodule.h> #include <gio/gio.h> +#include <libpeas/peas-activatable.h> +#include <libpeas-gtk/peas-gtk-configurable.h> +#include <pluma/pluma-window.h> #include <pluma/pluma-debug.h> #include <pluma/pluma-utils.h> @@ -48,7 +51,6 @@ PLUMA_TYPE_TIME_PLUGIN, \ PlumaTimePluginPrivate)) -#define WINDOW_DATA_KEY "PlumaTimePluginWindowData" #define MENU_PATH "/MenuBar/EditMenu/EditOps_4" /* GSettings keys */ @@ -106,7 +108,7 @@ typedef struct _TimeConfigureDialog TimeConfigureDialog; struct _TimeConfigureDialog { - GtkWidget *dialog; + GtkWidget *content; GtkWidget *list; @@ -118,8 +120,7 @@ struct _TimeConfigureDialog GtkWidget *custom_entry; GtkWidget *custom_format_example; - /* Info needed for the response handler */ - PlumaTimePlugin *plugin; + GSettings *settings; }; typedef struct _ChooseFormatDialog ChooseFormatDialog; @@ -139,7 +140,8 @@ struct _ChooseFormatDialog /* Info needed for the response handler */ GtkTextBuffer *buffer; - PlumaTimePlugin *plugin; + + GSettings *settings; }; typedef enum @@ -152,24 +154,32 @@ typedef enum struct _PlumaTimePluginPrivate { - GSettings *settings; -}; + GtkWidget *window; -PLUMA_PLUGIN_REGISTER_TYPE(PlumaTimePlugin, pluma_time_plugin) + GSettings *settings; -typedef struct -{ GtkActionGroup *action_group; guint ui_id; -} WindowData; +}; -typedef struct -{ - PlumaWindow *window; - PlumaTimePlugin *plugin; -} ActionData; +enum { + PROP_0, + PROP_OBJECT +}; + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); -static void time_cb (GtkAction *action, ActionData *data); +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaTimePlugin, + pluma_time_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, + peas_gtk_configurable_iface_init)) + +static void time_cb (GtkAction *action, PlumaTimePlugin *plugin); static const GtkActionEntry action_entries[] = { @@ -206,23 +216,37 @@ pluma_time_plugin_finalize (GObject *object) } static void -free_window_data (WindowData *data) +pluma_time_plugin_dispose (GObject *object) { - g_return_if_fail (data != NULL); + PlumaTimePlugin *plugin = PLUMA_TIME_PLUGIN (object); + + pluma_debug_message (DEBUG_PLUGINS, "PlumaTimePlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->action_group) + { + g_object_unref (plugin->priv->action_group); + plugin->priv->action_group = NULL; + } - g_object_unref (data->action_group); - g_free (data); + G_OBJECT_CLASS (pluma_time_plugin_parent_class)->dispose (object); } static void -update_ui_real (PlumaWindow *window, - WindowData *data) +update_ui (PlumaTimePluginPrivate *data) { + PlumaWindow *window; PlumaView *view; GtkAction *action; pluma_debug (DEBUG_PLUGINS); + window = PLUMA_WINDOW (data->window); view = pluma_window_get_active_view (window); pluma_debug_message (DEBUG_PLUGINS, "View: %p", view); @@ -235,41 +259,33 @@ update_ui_real (PlumaWindow *window, } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_time_plugin_activate (PeasActivatable *activatable) { + PlumaTimePlugin *plugin; + PlumaTimePluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; pluma_debug (DEBUG_PLUGINS); - data = g_new (WindowData, 1); - action_data = g_new (ActionData, 1); - - action_data->plugin = PLUMA_TIME_PLUGIN (plugin); - action_data->window = window; + plugin = PLUMA_TIME_PLUGIN (activatable); + data = plugin->priv; + window = PLUMA_WINDOW (data->window); manager = pluma_window_get_ui_manager (window); data->action_group = gtk_action_group_new ("PlumaTimePluginActions"); gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->action_group, + gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) g_free); + plugin); gtk_ui_manager_insert_action_group (manager, data->action_group, -1); data->ui_id = gtk_ui_manager_new_merge_id (manager); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, @@ -278,41 +294,33 @@ impl_activate (PlumaPlugin *plugin, GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, data); + update_ui (data); } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_time_plugin_deactivate (PeasActivatable *activatable) { + PlumaTimePluginPrivate *data; + PlumaWindow *window; GtkUIManager *manager; - WindowData *data; pluma_debug (DEBUG_PLUGINS); - manager = pluma_window_get_ui_manager (window); + data = PLUMA_TIME_PLUGIN (activatable)->priv; + window = PLUMA_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = pluma_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -impl_update_ui (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_time_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; - pluma_debug (DEBUG_PLUGINS); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - update_ui_real (window, data); + update_ui (PLUMA_TIME_PLUGIN (activatable)->priv); } /* whether we should prompt the user or use the specified format */ @@ -328,16 +336,16 @@ get_prompt_type (PlumaTimePlugin *plugin) } static void -set_prompt_type (PlumaTimePlugin *plugin, +set_prompt_type (GSettings *settings, PlumaTimePluginPromptType prompt_type) { - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, PROMPT_TYPE_KEY)) { return; } - g_settings_set_enum (plugin->priv->settings, + g_settings_set_enum (settings, PROMPT_TYPE_KEY, prompt_type); } @@ -355,18 +363,18 @@ get_selected_format (PlumaTimePlugin *plugin) } static void -set_selected_format (PlumaTimePlugin *plugin, +set_selected_format (GSettings *settings, const gchar *format) { g_return_if_fail (format != NULL); - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, SELECTED_FORMAT_KEY)) { return; } - g_settings_set_string (plugin->priv->settings, + g_settings_set_string (settings, SELECTED_FORMAT_KEY, format); } @@ -384,16 +392,16 @@ get_custom_format (PlumaTimePlugin *plugin) } static void -set_custom_format (PlumaTimePlugin *plugin, +set_custom_format (GSettings *settings, const gchar *format) { g_return_if_fail (format != NULL); - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, CUSTOM_FORMAT_KEY)) return; - g_settings_set_string (plugin->priv->settings, + g_settings_set_string (settings, CUSTOM_FORMAT_KEY, format); } @@ -448,13 +456,24 @@ get_time (const gchar* format) } static void -dialog_disposed (GObject *obj, gpointer dialog_pointer) +configure_dialog_destroyed (GtkWidget *widget, + gpointer data) { + TimeConfigureDialog *dialog = (TimeConfigureDialog *) data; + pluma_debug (DEBUG_PLUGINS); - g_free (dialog_pointer); + g_object_unref (dialog->settings); + g_slice_free (TimeConfigureDialog, data); +} - pluma_debug_message (DEBUG_PLUGINS, "END"); +static void +choose_format_dialog_destroyed (GtkWidget *widget, + gpointer data) +{ + pluma_debug (DEBUG_PLUGINS); + + g_slice_free (ChooseFormatDialog, data); } static GtkTreeModel * @@ -640,6 +659,7 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, TRUE); gtk_widget_set_sensitive (dialog->custom_format_example, TRUE); + set_prompt_type (dialog->settings, USE_CUSTOM_FORMAT); return; } @@ -649,6 +669,7 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, FALSE); gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + set_prompt_type (dialog->settings, USE_SELECTED_FORMAT); return; } @@ -658,6 +679,7 @@ configure_dialog_button_toggled (GtkToggleButton *button, TimeConfigureDialog *d gtk_widget_set_sensitive (dialog->custom_entry, FALSE); gtk_widget_set_sensitive (dialog->custom_format_example, FALSE); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); return; } } @@ -691,13 +713,23 @@ get_format_from_list (GtkWidget *listview) g_return_val_if_reached (0); } +static void +configure_dialog_selection_changed (GtkTreeSelection *selection, + TimeConfigureDialog *dialog) +{ + gint sel_format; + + sel_format = get_format_from_list (dialog->list); + set_selected_format (dialog->settings, formats[sel_format]); +} + static TimeConfigureDialog * get_configure_dialog (PlumaTimePlugin *plugin) { TimeConfigureDialog *dialog = NULL; + GtkTreeSelection *selection; gchar *data_dir; gchar *ui_file; - GtkWidget *content; GtkWidget *viewport; PlumaTimePluginPromptType prompt_type; gchar *sf, *cf; @@ -710,37 +742,15 @@ get_configure_dialog (PlumaTimePlugin *plugin) pluma_debug (DEBUG_PLUGINS); - GtkWidget *dlg = gtk_dialog_new_with_buttons (_("Configure insert date/time plugin..."), - NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); - - g_return_val_if_fail (dlg != NULL, NULL); + dialog = g_slice_new (TimeConfigureDialog); + dialog->settings = g_object_ref (plugin->priv->settings); - dialog = g_new0 (TimeConfigureDialog, 1); - dialog->dialog = dlg; - - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6); - - - data_dir = pluma_plugin_get_data_dir (PLUMA_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "pluma-time-setup-dialog.ui", NULL); ret = pluma_utils_get_ui_objects (ui_file, root_objects, &error_widget, - "time_dialog_content", &content, + "time_dialog_content", &dialog->content, "formats_viewport", &viewport, "formats_tree", &dialog->list, "always_prompt", &dialog->prompt, @@ -755,27 +765,20 @@ get_configure_dialog (PlumaTimePlugin *plugin) if (!ret) { - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - error_widget, - TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - - gtk_widget_show (error_widget); - - return dialog; + return NULL; } - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - sf = get_selected_format (plugin); create_formats_list (dialog->list, sf, plugin); g_free (sf); prompt_type = get_prompt_type (plugin); - cf = get_custom_format (plugin); - gtk_entry_set_text (GTK_ENTRY(dialog->custom_entry), cf); - g_free (cf); + g_settings_bind (dialog->settings, + CUSTOM_FORMAT_KEY, + dialog->custom_entry, + "text", + G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); if (prompt_type == USE_CUSTOM_FORMAT) { @@ -808,14 +811,6 @@ get_configure_dialog (PlumaTimePlugin *plugin) /* setup a window of a sane size. */ gtk_widget_set_size_request (GTK_WIDGET (viewport), 10, 200); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - content, FALSE, FALSE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); - - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); - g_signal_connect (dialog->custom, "toggled", G_CALLBACK (configure_dialog_button_toggled), @@ -828,15 +823,21 @@ get_configure_dialog (PlumaTimePlugin *plugin) "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); - g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (dialog_disposed), + g_signal_connect (dialog->content, + "destroy", + G_CALLBACK (configure_dialog_destroyed), dialog); g_signal_connect (dialog->custom_entry, "changed", G_CALLBACK (updated_custom_format_example), dialog->custom_format_example); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->list)); + g_signal_connect (selection, + "changed", + G_CALLBACK (configure_dialog_selection_changed), + dialog); + return dialog; } @@ -866,8 +867,8 @@ choose_format_dialog_row_activated (GtkTreeView *list, sel_format = get_format_from_list (dialog->list); the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->plugin, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats[sel_format]); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); + set_selected_format (dialog->settings, formats[sel_format]); g_return_if_fail (the_time != NULL); @@ -892,9 +893,10 @@ get_choose_format_dialog (GtkWindow *parent, if (parent != NULL) wg = gtk_window_get_group (parent); - dialog = g_new0 (ChooseFormatDialog, 1); + dialog = g_slice_new (ChooseFormatDialog); + dialog->settings = plugin->priv->settings; - data_dir = pluma_plugin_get_data_dir (PLUMA_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "pluma-time-dialog.ui", NULL); ret = pluma_utils_get_ui_objects (ui_file, NULL, @@ -991,8 +993,8 @@ get_choose_format_dialog (GtkWindow *parent, G_CALLBACK (choose_format_dialog_button_toggled), dialog); g_signal_connect (dialog->dialog, - "dispose", - G_CALLBACK (dialog_disposed), + "destroy", + G_CALLBACK (choose_format_dialog_destroyed), dialog); g_signal_connect (dialog->custom_entry, "changed", @@ -1037,8 +1039,8 @@ choose_format_dialog_response_cb (GtkWidget *widget, sel_format = get_format_from_list (dialog->list); the_time = get_time (formats[sel_format]); - set_prompt_type (dialog->plugin, PROMPT_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats[sel_format]); + set_prompt_type (dialog->settings, PROMPT_SELECTED_FORMAT); + set_selected_format (dialog->settings, formats[sel_format]); } else { @@ -1047,8 +1049,8 @@ choose_format_dialog_response_cb (GtkWidget *widget, format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); the_time = get_time (format); - set_prompt_type (dialog->plugin, PROMPT_CUSTOM_FORMAT); - set_custom_format (dialog->plugin, format); + set_prompt_type (dialog->settings, PROMPT_CUSTOM_FORMAT); + set_custom_format (dialog->settings, format); } g_return_if_fail (the_time != NULL); @@ -1067,28 +1069,30 @@ choose_format_dialog_response_cb (GtkWidget *widget, static void time_cb (GtkAction *action, - ActionData *data) + PlumaTimePlugin *plugin) { + PlumaWindow *window; GtkTextBuffer *buffer; gchar *the_time = NULL; PlumaTimePluginPromptType prompt_type; pluma_debug (DEBUG_PLUGINS); - buffer = GTK_TEXT_BUFFER (pluma_window_get_active_document (data->window)); + window = PLUMA_WINDOW (plugin->priv->window); + buffer = GTK_TEXT_BUFFER (pluma_window_get_active_document (window)); g_return_if_fail (buffer != NULL); - prompt_type = get_prompt_type (data->plugin); + prompt_type = get_prompt_type (plugin); if (prompt_type == USE_CUSTOM_FORMAT) { - gchar *cf = get_custom_format (data->plugin); + gchar *cf = get_custom_format (plugin); the_time = get_time (cf); g_free (cf); } else if (prompt_type == USE_SELECTED_FORMAT) { - gchar *sf = get_selected_format (data->plugin); + gchar *sf = get_selected_format (plugin); the_time = get_time (sf); g_free (sf); } @@ -1096,13 +1100,13 @@ time_cb (GtkAction *action, { ChooseFormatDialog *dialog; - dialog = get_choose_format_dialog (GTK_WINDOW (data->window), + dialog = get_choose_format_dialog (GTK_WINDOW (window), prompt_type, - data->plugin); + plugin); if (dialog != NULL) { dialog->buffer = buffer; - dialog->plugin = data->plugin; + dialog->settings = plugin->priv->settings; g_signal_connect (dialog->dialog, "response", @@ -1122,100 +1126,101 @@ time_cb (GtkAction *action, g_free (the_time); } -static void -ok_button_pressed (TimeConfigureDialog *dialog) +static GtkWidget * +pluma_time_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { - gint sel_format; - const gchar *custom_format; + TimeConfigureDialog *dialog; - pluma_debug (DEBUG_PLUGINS); + dialog = get_configure_dialog (PLUMA_TIME_PLUGIN (configurable)); - sel_format = get_format_from_list (dialog->list); + return dialog->content; +} - custom_format = gtk_entry_get_text (GTK_ENTRY (dialog->custom_entry)); +static void +pluma_time_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PlumaTimePlugin *plugin = PLUMA_TIME_PLUGIN (object); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->custom))) - { - set_prompt_type (dialog->plugin, USE_CUSTOM_FORMAT); - set_custom_format (dialog->plugin, custom_format); - } - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->use_list))) + switch (prop_id) { - set_prompt_type (dialog->plugin, USE_SELECTED_FORMAT); - set_selected_format (dialog->plugin, formats [sel_format]); - } - else - { - /* Default to prompt the user with the list selected */ - set_prompt_type (dialog->plugin, PROMPT_SELECTED_FORMAT); - } + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; - pluma_debug_message (DEBUG_PLUGINS, "Sel: %d", sel_format); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void -configure_dialog_response_cb (GtkWidget *widget, - gint response, - TimeConfigureDialog *dialog) +pluma_time_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - switch (response) - { - case GTK_RESPONSE_HELP: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); + PlumaTimePlugin *plugin = PLUMA_TIME_PLUGIN (object); - pluma_help_display (GTK_WINDOW (widget), - NULL, - "pluma-insert-date-time-plugin#pluma-date-time-configure"); + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); break; - } - case GTK_RESPONSE_OK: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); - - ok_button_pressed (dialog); - gtk_widget_destroy (dialog->dialog); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; - } - case GTK_RESPONSE_CANCEL: - { - pluma_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } } } -static GtkWidget * -impl_create_configure_dialog (PlumaPlugin *plugin) +static void +pluma_time_plugin_class_init (PlumaTimePluginClass *klass) { - TimeConfigureDialog *dialog; + GObjectClass *object_class = G_OBJECT_CLASS (klass); - dialog = get_configure_dialog (PLUMA_TIME_PLUGIN (plugin)); + object_class->finalize = pluma_time_plugin_finalize; + object_class->dispose = pluma_time_plugin_dispose; + object_class->set_property = pluma_time_plugin_set_property; + object_class->get_property = pluma_time_plugin_get_property; - dialog->plugin = PLUMA_TIME_PLUGIN (plugin); + g_object_class_override_property (object_class, PROP_OBJECT, "object"); - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (configure_dialog_response_cb), - dialog); + g_type_class_add_private (object_class, sizeof (PlumaTimePluginPrivate)); +} - return GTK_WIDGET (dialog->dialog); +static void +pluma_time_plugin_class_finalize (PlumaTimePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ } static void -pluma_time_plugin_class_init (PlumaTimePluginClass *klass) +peas_activatable_iface_init (PeasActivatableInterface *iface) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); + iface->activate = pluma_time_plugin_activate; + iface->deactivate = pluma_time_plugin_deactivate; + iface->update_state = pluma_time_plugin_update_state; +} - object_class->finalize = pluma_time_plugin_finalize; +static void +peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface) +{ + iface->create_configure_widget = pluma_time_plugin_create_configure_widget; +} - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_time_plugin_register_type (G_TYPE_MODULE (module)); - plugin_class->create_configure_dialog = impl_create_configure_dialog; + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_TIME_PLUGIN); - g_type_class_add_private (object_class, sizeof (PlumaTimePluginPrivate)); + peas_object_module_register_extension_type (module, + PEAS_GTK_TYPE_CONFIGURABLE, + PLUMA_TYPE_TIME_PLUGIN); } diff --git a/plugins/time/pluma-time-plugin.h b/plugins/time/pluma-time-plugin.h index 7795c9c8..3b9bb7bf 100644 --- a/plugins/time/pluma-time-plugin.h +++ b/plugins/time/pluma-time-plugin.h @@ -25,7 +25,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -49,7 +50,7 @@ typedef struct _PlumaTimePlugin PlumaTimePlugin; struct _PlumaTimePlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; /*< private >*/ PlumaTimePluginPrivate *priv; @@ -62,7 +63,7 @@ typedef struct _PlumaTimePluginClass PlumaTimePluginClass; struct _PlumaTimePluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -71,7 +72,7 @@ struct _PlumaTimePluginClass GType pluma_time_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/time/time.pluma-plugin.desktop.in b/plugins/time/time.plugin.desktop.in index af812768..a59f2085 100644 --- a/plugins/time/time.pluma-plugin.desktop.in +++ b/plugins/time/time.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=time IAge=2 _Name=Insert Date/Time diff --git a/plugins/trailsave/Makefile.am b/plugins/trailsave/Makefile.am index c8446959..d5879e46 100644 --- a/plugins/trailsave/Makefile.am +++ b/plugins/trailsave/Makefile.am @@ -16,11 +16,11 @@ libtrailsave_la_SOURCES = \ libtrailsave_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) libtrailsave_la_LIBADD = $(PLUMA_LIBS) -plugin_in_files = trailsave.pluma-plugin.desktop.in +plugin_in_files = trailsave.plugin.desktop.in -%.pluma-plugin: %.pluma-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache +%.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) +plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) EXTRA_DIST = $(plugin_in_files) diff --git a/plugins/trailsave/pluma-trail-save-plugin.c b/plugins/trailsave/pluma-trail-save-plugin.c index dbc1621b..589a85c2 100644 --- a/plugins/trailsave/pluma-trail-save-plugin.c +++ b/plugins/trailsave/pluma-trail-save-plugin.c @@ -22,9 +22,35 @@ #include <config.h> #endif +#include <libpeas/peas-activatable.h> + +#include <pluma/pluma-window.h> +#include <pluma/pluma-debug.h> + #include "pluma-trail-save-plugin.h" -PLUMA_PLUGIN_REGISTER_TYPE(PlumaTrailSavePlugin, pluma_trail_save_plugin) +#define PLUMA_TRAIL_SAVE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ + PLUMA_TYPE_TRAIL_SAVE_PLUGIN, \ + PlumaTrailSavePluginPrivate)) + +static void peas_activatable_iface_init (PeasActivatableInterface *iface); + +G_DEFINE_DYNAMIC_TYPE_EXTENDED (PlumaTrailSavePlugin, + pluma_trail_save_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init)) + +struct _PlumaTrailSavePluginPrivate +{ + GtkWidget *window; +}; + +enum { + PROP_0, + PROP_OBJECT +}; static void strip_trailing_spaces (GtkTextBuffer *text_buffer) @@ -107,7 +133,7 @@ on_save (PlumaDocument *document, const gchar *uri, PlumaEncoding *encoding, PlumaDocumentSaveFlags save_flags, - PlumaPlugin *plugin) + PlumaTrailSavePlugin *plugin) { GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (document); @@ -117,7 +143,7 @@ on_save (PlumaDocument *document, static void on_tab_added (PlumaWindow *window, PlumaTab *tab, - PlumaPlugin *plugin) + PlumaTrailSavePlugin *plugin) { PlumaDocument *document; @@ -128,7 +154,7 @@ on_tab_added (PlumaWindow *window, static void on_tab_removed (PlumaWindow *window, PlumaTab *tab, - PlumaPlugin *plugin) + PlumaTrailSavePlugin *plugin) { PlumaDocument *document; @@ -137,15 +163,19 @@ on_tab_removed (PlumaWindow *window, } static void -impl_activate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_trail_save_plugin_activate (PeasActivatable *activatable) { + PlumaTrailSavePlugin *plugin; + PlumaWindow *window; GList *documents; GList *documents_iter; PlumaDocument *document; pluma_debug (DEBUG_PLUGINS); + plugin = PLUMA_TRAIL_SAVE_PLUGIN (activatable); + window = PLUMA_WINDOW (plugin->priv->window); + g_signal_connect (window, "tab_added", G_CALLBACK (on_tab_added), plugin); g_signal_connect (window, "tab_removed", G_CALLBACK (on_tab_removed), plugin); @@ -163,15 +193,19 @@ impl_activate (PlumaPlugin *plugin, } static void -impl_deactivate (PlumaPlugin *plugin, - PlumaWindow *window) +pluma_trail_save_plugin_deactivate (PeasActivatable *activatable) { + PlumaTrailSavePlugin *plugin; + PlumaWindow *window; GList *documents; GList *documents_iter; PlumaDocument *document; pluma_debug (DEBUG_PLUGINS); + plugin = PLUMA_TRAIL_SAVE_PLUGIN (activatable); + window = PLUMA_WINDOW (plugin->priv->window); + g_signal_handlers_disconnect_by_data (window, plugin); documents = pluma_window_get_documents (window); @@ -191,24 +225,99 @@ static void pluma_trail_save_plugin_init (PlumaTrailSavePlugin *plugin) { pluma_debug_message (DEBUG_PLUGINS, "PlumaTrailSavePlugin initializing"); + + plugin->priv = PLUMA_TRAIL_SAVE_PLUGIN_GET_PRIVATE (plugin); +} + +static void +pluma_trail_save_plugin_dispose (GObject *object) +{ + PlumaTrailSavePlugin *plugin = PLUMA_TRAIL_SAVE_PLUGIN (object); + + pluma_debug_message (DEBUG_PLUGINS, "PlumaTrailSavePlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + G_OBJECT_CLASS (pluma_trail_save_plugin_parent_class)->dispose (object); } static void -pluma_trail_save_plugin_finalize (GObject *object) +pluma_trail_save_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - pluma_debug_message (DEBUG_PLUGINS, "PlumaTrailSavePlugin finalizing"); + PlumaTrailSavePlugin *plugin = PLUMA_TRAIL_SAVE_PLUGIN (object); - G_OBJECT_CLASS (pluma_trail_save_plugin_parent_class)->finalize (object); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +pluma_trail_save_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PlumaTrailSavePlugin *plugin = PLUMA_TRAIL_SAVE_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void pluma_trail_save_plugin_class_init (PlumaTrailSavePluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); - object_class->finalize = pluma_trail_save_plugin_finalize; + object_class->dispose = pluma_trail_save_plugin_dispose; + object_class->set_property = pluma_trail_save_plugin_set_property; + object_class->get_property = pluma_trail_save_plugin_get_property; + + g_object_class_override_property (object_class, PROP_OBJECT, "object"); + + g_type_class_add_private (object_class, sizeof (PlumaTrailSavePluginPrivate)); +} + +static void +pluma_trail_save_plugin_class_finalize (PlumaTrailSavePluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = pluma_trail_save_plugin_activate; + iface->deactivate = pluma_trail_save_plugin_deactivate; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + pluma_trail_save_plugin_register_type (G_TYPE_MODULE (module)); - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + PLUMA_TYPE_TRAIL_SAVE_PLUGIN); } diff --git a/plugins/trailsave/pluma-trail-save-plugin.h b/plugins/trailsave/pluma-trail-save-plugin.h index 4d0e3306..73608de5 100644 --- a/plugins/trailsave/pluma-trail-save-plugin.h +++ b/plugins/trailsave/pluma-trail-save-plugin.h @@ -23,7 +23,8 @@ #include <glib.h> #include <glib-object.h> -#include <pluma/pluma-plugin.h> +#include <libpeas/peas-extension-base.h> +#include <libpeas/peas-object-module.h> G_BEGIN_DECLS @@ -37,6 +38,9 @@ G_BEGIN_DECLS #define PLUMA_IS_TRAIL_SAVE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PLUMA_TYPE_TRAIL_SAVE_PLUGIN)) #define PLUMA_TRAIL_SAVE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PLUMA_TYPE_TRAIL_SAVE_PLUGIN, PlumaTrailSavePluginClass)) +/* Private structure type */ +typedef struct _PlumaTrailSavePluginPrivate PlumaTrailSavePluginPrivate; + /* * Main object structure */ @@ -44,7 +48,10 @@ typedef struct _PlumaTrailSavePlugin PlumaTrailSavePlugin; struct _PlumaTrailSavePlugin { - PlumaPlugin parent_instance; + PeasExtensionBase parent_instance; + + /*< private >*/ + PlumaTrailSavePluginPrivate *priv; }; /* @@ -54,7 +61,7 @@ typedef struct _PlumaTrailSavePluginClass PlumaTrailSavePluginClass; struct _PlumaTrailSavePluginClass { - PlumaPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* @@ -63,7 +70,7 @@ struct _PlumaTrailSavePluginClass GType pluma_trail_save_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS diff --git a/plugins/trailsave/trailsave.pluma-plugin.desktop.in b/plugins/trailsave/trailsave.plugin.desktop.in index dcdbeee6..3849ba7f 100644 --- a/plugins/trailsave/trailsave.pluma-plugin.desktop.in +++ b/plugins/trailsave/trailsave.plugin.desktop.in @@ -1,4 +1,4 @@ -[Pluma Plugin] +[Plugin] Module=trailsave IAge=2 _Name=Save Without Trailing Spaces |