summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-12-04 22:31:41 +0300
committermonsta <[email protected]>2016-12-05 16:57:36 +0300
commitce25be232024458af2a28f4cf145d8cd22f2db29 (patch)
tree7d4d2ebe765d938ba63e671b199895f0d7d9921b
parent95d29254d97484cbbece5a7acd994025d90699e1 (diff)
downloadpluma-ce25be232024458af2a28f4cf145d8cd22f2db29.tar.bz2
pluma-ce25be232024458af2a28f4cf145d8cd22f2db29.tar.xz
trailsave plugin: port to libpeas
this plugin isn't present upstream, so all the changes were picked from other plugins here
-rw-r--r--plugins/trailsave/pluma-trail-save-plugin.c139
-rw-r--r--plugins/trailsave/pluma-trail-save-plugin.h15
2 files changed, 135 insertions, 19 deletions
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