taglist-plugin: Port to libpeas

Adapted from:
2aafaabdaa
This commit is contained in:
JosephMcc 2016-12-26 13:50:48 -08:00
parent e389368a91
commit 804259fe1f
4 changed files with 197 additions and 106 deletions

View File

@ -39,7 +39,6 @@
#include <xed/xed-utils.h>
#include <xed/xed-debug.h>
#include <xed/xed-plugin.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@ -69,7 +68,7 @@ struct _XedTaglistPluginPanelPrivate
gchar *data_dir;
};
XED_PLUGIN_DEFINE_TYPE (XedTaglistPluginPanel, xed_taglist_plugin_panel, GTK_TYPE_BOX)
G_DEFINE_DYNAMIC_TYPE (XedTaglistPluginPanel, xed_taglist_plugin_panel, GTK_TYPE_BOX)
enum
{
@ -160,6 +159,12 @@ xed_taglist_plugin_panel_class_init (XedTaglistPluginPanelClass *klass)
g_type_class_add_private (object_class, sizeof(XedTaglistPluginPanelPrivate));
}
static void
xed_taglist_plugin_panel_class_finalize (XedTaglistPluginPanelClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE */
}
static void
insert_tag (XedTaglistPluginPanel *panel,
Tag *tag,
@ -786,3 +791,9 @@ xed_taglist_plugin_panel_new (XedWindow *window,
return GTK_WIDGET (panel);
}
void
_xed_taglist_plugin_panel_register_type (GTypeModule *type_module)
{
xed_taglist_plugin_panel_register_type (type_module);
}

View File

@ -77,7 +77,7 @@ struct _XedTaglistPluginPanelClass
/*
* Public methods
*/
GType xed_taglist_plugin_panel_register_type (GTypeModule *module);
void _xed_taglist_plugin_panel_register_type (GTypeModule *module);
GType xed_taglist_plugin_panel_get_type (void) G_GNUC_CONST;

View File

@ -37,23 +37,38 @@
#include <glib/gi18n-lib.h>
#include <gmodule.h>
#include <libpeas/peas-activatable.h>
#include <xed/xed-plugin.h>
#include <xed/xed-window.h>
#include <xed/xed-debug.h>
#define WINDOW_DATA_KEY "XedTaglistPluginWindowData"
#define XED_TAGLIST_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginPrivate))
struct _XedTaglistPluginPrivate
{
gpointer dummy;
GtkWidget *window;
GtkWidget *taglist_panel;
};
XED_PLUGIN_REGISTER_TYPE_WITH_CODE (XedTaglistPlugin, xed_taglist_plugin,
xed_taglist_plugin_panel_register_type (module);
static void peas_activatable_iface_init (PeasActivatableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTaglistPlugin,
xed_taglist_plugin,
PEAS_TYPE_EXTENSION_BASE,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
peas_activatable_iface_init) \
\
_xed_taglist_plugin_panel_register_type (type_module); \
)
enum
{
PROP_0,
PROP_OBJECT
};
static void
xed_taglist_plugin_init (XedTaglistPlugin *plugin)
{
@ -62,12 +77,25 @@ xed_taglist_plugin_init (XedTaglistPlugin *plugin)
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin initializing");
}
static void
xed_taglist_plugin_dispose (GObject *object)
{
XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object);
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin disposing");
if (plugin->priv->window != NULL)
{
g_object_unref (plugin->priv->window);
plugin->priv->window = NULL;
}
G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->dispose (object);
}
static void
xed_taglist_plugin_finalize (GObject *object)
{
/*
XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object);
*/
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing");
free_taglist ();
@ -76,85 +104,136 @@ xed_taglist_plugin_finalize (GObject *object)
}
static void
impl_activate (XedPlugin *plugin,
XedWindow *window)
xed_taglist_plugin_activate (PeasActivatable *activatable)
{
XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel;
GtkWidget *taglist_panel;
gchar *data_dir;
xed_debug (DEBUG_PLUGINS);
g_return_if_fail (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY) == NULL);
priv = XED_TAGLIST_PLUGIN (activatable)->priv;
window = XED_WINDOW (priv->window);
side_panel = xed_window_get_side_panel (window);
data_dir = xed_plugin_get_data_dir (plugin);
taglist_panel = xed_taglist_plugin_panel_new (window, data_dir);
data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable));
priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir);
g_free (data_dir);
xed_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 (XedPlugin *plugin,
XedWindow *window)
xed_taglist_plugin_deactivate (PeasActivatable *activatable)
{
XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel;
gpointer data;
xed_debug (DEBUG_PLUGINS);
data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
g_return_if_fail (data != NULL);
priv = XED_TAGLIST_PLUGIN (activatable)->priv;
window = XED_WINDOW (priv->window);
side_panel = xed_window_get_side_panel (window);
xed_panel_remove_item (side_panel,
GTK_WIDGET (data));
g_object_set_data (G_OBJECT (window),
WINDOW_DATA_KEY,
NULL);
xed_panel_remove_item (side_panel, priv->taglist_panel);
}
static void
impl_update_ui (XedPlugin *plugin,
XedWindow *window)
xed_taglist_plugin_update_state (PeasActivatable *activatable)
{
gpointer data;
XedTaglistPluginPrivate *priv;
XedWindow *window;
XedView *view;
xed_debug (DEBUG_PLUGINS);
data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
g_return_if_fail (data != NULL);
priv = XED_TAGLIST_PLUGIN (activatable)->priv;
window = XED_WINDOW (priv->window);
view = xed_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
xed_taglist_plugin_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
XedTaglistPlugin *plugin = XED_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
xed_taglist_plugin_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
XedTaglistPlugin *plugin = XED_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
xed_taglist_plugin_class_init (XedTaglistPluginClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass);
object_class->finalize = xed_taglist_plugin_finalize;
object_class->dispose = xed_taglist_plugin_dispose;
object_class->set_property = xed_taglist_plugin_set_property;
object_class->get_property = xed_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 (XedTaglistPluginPrivate));
}
static void
xed_taglist_plugin_class_finalize (XedTaglistPluginClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
}
static void
peas_activatable_iface_init (PeasActivatableInterface *iface)
{
iface->activate = xed_taglist_plugin_activate;
iface->deactivate = xed_taglist_plugin_deactivate;
iface->update_state = xed_taglist_plugin_update_state;
}
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
xed_taglist_plugin_register_type (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE,
XED_TYPE_TAGLIST_PLUGIN);
}

View File

@ -32,7 +32,8 @@
#include <glib.h>
#include <glib-object.h>
#include <xed/xed-plugin.h>
#include <libpeas/peas-extension-base.h>
#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS
@ -56,7 +57,7 @@ typedef struct _XedTaglistPlugin XedTaglistPlugin;
struct _XedTaglistPlugin
{
XedPlugin parent_instance;
PeasExtensionBase parent_instance;
/*< private >*/
XedTaglistPluginPrivate *priv;
@ -69,7 +70,7 @@ typedef struct _XedTaglistPluginClass XedTaglistPluginClass;
struct _XedTaglistPluginClass
{
XedPluginClass parent_class;
PeasExtensionBaseClass parent_class;
};
/*
@ -78,7 +79,7 @@ struct _XedTaglistPluginClass
GType xed_taglist_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */
G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module);
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS