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

View File

@ -58,10 +58,10 @@ typedef struct _XedTaglistPluginPanel XedTaglistPluginPanel;
struct _XedTaglistPluginPanel struct _XedTaglistPluginPanel
{ {
GtkBox vbox; GtkBox vbox;
/*< private > */ /*< private > */
XedTaglistPluginPanelPrivate *priv; XedTaglistPluginPanelPrivate *priv;
}; };
/* /*
@ -71,18 +71,18 @@ typedef struct _XedTaglistPluginPanelClass XedTaglistPluginPanelClass;
struct _XedTaglistPluginPanelClass struct _XedTaglistPluginPanelClass
{ {
GtkBoxClass parent_class; GtkBoxClass parent_class;
}; };
/* /*
* Public methods * 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; GType xed_taglist_plugin_panel_get_type (void) G_GNUC_CONST;
GtkWidget *xed_taglist_plugin_panel_new (XedWindow *window, GtkWidget *xed_taglist_plugin_panel_new (XedWindow *window,
const gchar *data_dir); const gchar *data_dir);
G_END_DECLS G_END_DECLS

View File

@ -37,23 +37,38 @@
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include <gmodule.h> #include <gmodule.h>
#include <libpeas/peas-activatable.h>
#include <xed/xed-plugin.h> #include <xed/xed-window.h>
#include <xed/xed-debug.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)) #define XED_TAGLIST_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginPrivate))
struct _XedTaglistPluginPrivate struct _XedTaglistPluginPrivate
{ {
gpointer dummy; GtkWidget *window;
GtkWidget *taglist_panel;
}; };
XED_PLUGIN_REGISTER_TYPE_WITH_CODE (XedTaglistPlugin, xed_taglist_plugin, static void peas_activatable_iface_init (PeasActivatableInterface *iface);
xed_taglist_plugin_panel_register_type (module);
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 static void
xed_taglist_plugin_init (XedTaglistPlugin *plugin) xed_taglist_plugin_init (XedTaglistPlugin *plugin)
{ {
@ -62,13 +77,26 @@ xed_taglist_plugin_init (XedTaglistPlugin *plugin)
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin initializing"); 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 static void
xed_taglist_plugin_finalize (GObject *object) xed_taglist_plugin_finalize (GObject *object)
{ {
/* xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing");
XedTaglistPlugin *plugin = XED_TAGLIST_PLUGIN (object);
*/
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin finalizing");
free_taglist (); free_taglist ();
@ -76,85 +104,136 @@ xed_taglist_plugin_finalize (GObject *object)
} }
static void static void
impl_activate (XedPlugin *plugin, xed_taglist_plugin_activate (PeasActivatable *activatable)
XedWindow *window)
{ {
XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel; XedPanel *side_panel;
GtkWidget *taglist_panel;
gchar *data_dir; gchar *data_dir;
xed_debug (DEBUG_PLUGINS); 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); side_panel = xed_window_get_side_panel (window);
data_dir = xed_plugin_get_data_dir (plugin); data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable));
taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir);
g_free (data_dir); g_free (data_dir);
xed_panel_add_item_with_stock_icon (side_panel, xed_panel_add_item_with_stock_icon (side_panel,
taglist_panel, priv->taglist_panel,
_("Tags"), _("Tags"),
GTK_STOCK_ADD); GTK_STOCK_ADD);
g_object_set_data (G_OBJECT (window),
WINDOW_DATA_KEY,
taglist_panel);
} }
static void static void
impl_deactivate (XedPlugin *plugin, xed_taglist_plugin_deactivate (PeasActivatable *activatable)
XedWindow *window)
{ {
XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel; XedPanel *side_panel;
gpointer data;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); priv = XED_TAGLIST_PLUGIN (activatable)->priv;
g_return_if_fail (data != NULL); window = XED_WINDOW (priv->window);
side_panel = xed_window_get_side_panel (window); side_panel = xed_window_get_side_panel (window);
xed_panel_remove_item (side_panel, xed_panel_remove_item (side_panel, priv->taglist_panel);
GTK_WIDGET (data));
g_object_set_data (G_OBJECT (window),
WINDOW_DATA_KEY,
NULL);
} }
static void static void
impl_update_ui (XedPlugin *plugin, xed_taglist_plugin_update_state (PeasActivatable *activatable)
XedWindow *window)
{ {
gpointer data; XedTaglistPluginPrivate *priv;
XedWindow *window;
XedView *view; XedView *view;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); priv = XED_TAGLIST_PLUGIN (activatable)->priv;
g_return_if_fail (data != NULL); window = XED_WINDOW (priv->window);
view = xed_window_get_active_view (window); view = xed_window_get_active_view (window);
gtk_widget_set_sensitive (GTK_WIDGET (data), gtk_widget_set_sensitive (priv->taglist_panel,
(view != NULL) && (view != NULL) &&
gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); 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 static void
xed_taglist_plugin_class_init (XedTaglistPluginClass *klass) xed_taglist_plugin_class_init (XedTaglistPluginClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass);
object_class->finalize = xed_taglist_plugin_finalize; 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; g_object_class_override_property (object_class, PROP_OBJECT, "object");
plugin_class->deactivate = impl_deactivate;
plugin_class->update_ui = impl_update_ui;
g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate)); 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,53 +32,54 @@
#include <glib.h> #include <glib.h>
#include <glib-object.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 G_BEGIN_DECLS
/* /*
* Type checking and casting macros * Type checking and casting macros
*/ */
#define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ()) #define XED_TYPE_TAGLIST_PLUGIN (xed_taglist_plugin_get_type ())
#define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin)) #define XED_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPlugin))
#define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) #define XED_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass))
#define XED_IS_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TAGLIST_PLUGIN)) #define XED_IS_TAGLIST_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_TAGLIST_PLUGIN))
#define XED_IS_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TAGLIST_PLUGIN)) #define XED_IS_TAGLIST_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_TAGLIST_PLUGIN))
#define XED_TAGLIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass)) #define XED_TAGLIST_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_TAGLIST_PLUGIN, XedTaglistPluginClass))
/* Private structure type */ /* Private structure type */
typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate; typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate;
/* /*
* Main object structure * Main object structure
*/ */
typedef struct _XedTaglistPlugin XedTaglistPlugin; typedef struct _XedTaglistPlugin XedTaglistPlugin;
struct _XedTaglistPlugin struct _XedTaglistPlugin
{ {
XedPlugin parent_instance; PeasExtensionBase parent_instance;
/*< private >*/ /*< private >*/
XedTaglistPluginPrivate *priv; XedTaglistPluginPrivate *priv;
}; };
/* /*
* Class definition * Class definition
*/ */
typedef struct _XedTaglistPluginClass XedTaglistPluginClass; typedef struct _XedTaglistPluginClass XedTaglistPluginClass;
struct _XedTaglistPluginClass struct _XedTaglistPluginClass
{ {
XedPluginClass parent_class; PeasExtensionBaseClass parent_class;
}; };
/* /*
* Public methods * Public methods
*/ */
GType xed_taglist_plugin_get_type (void) G_GNUC_CONST; GType xed_taglist_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */ /* 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 G_END_DECLS