summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-12-04 15:46:17 +0300
committermonsta <[email protected]>2016-12-05 16:57:36 +0300
commit2aafaabdaa4854b3941bd9f3319b89c807abf306 (patch)
treebde020ebc3b53a6fe613fa83ed042e2feb52f0fd /plugins
parentd050af62cd08c234e53897a7d9dccb560dba329a (diff)
downloadpluma-2aafaabdaa4854b3941bd9f3319b89c807abf306.tar.bz2
pluma-2aafaabdaa4854b3941bd9f3319b89c807abf306.tar.xz
taglist plugin: port to libpeas
mostly adapted from: https://git.gnome.org/browse/gedit/commit/?id=c3471ad0a1e2a60a588f203421da1779a60649ff https://git.gnome.org/browse/gedit/commit/?id=05ca83131a21c35e7b2792bbf76c4c6897d084e9
Diffstat (limited to 'plugins')
-rw-r--r--plugins/taglist/pluma-taglist-plugin-panel.c15
-rw-r--r--plugins/taglist/pluma-taglist-plugin-panel.h2
-rw-r--r--plugins/taglist/pluma-taglist-plugin.c181
-rw-r--r--plugins/taglist/pluma-taglist-plugin.h9
4 files changed, 150 insertions, 57 deletions
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.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