taglist-plugin: Port to WindowActivatable

This commit is contained in:
JosephMcc 2017-01-11 22:52:37 -08:00
parent 769f1baaaa
commit cd3ab1695d
3 changed files with 56 additions and 80 deletions

View File

@ -5,6 +5,7 @@ DIST_SUBDIRS = \
modelines \ modelines \
sort \ sort \
spell \ spell \
taglist \
time time
SUBDIRS = \ SUBDIRS = \
@ -14,6 +15,7 @@ SUBDIRS = \
modelines \ modelines \
sort \ sort \
spell \ spell \
taglist \
time time
if ENABLE_ENCHANT if ENABLE_ENCHANT

View File

@ -36,29 +36,28 @@
#include "xed-taglist-plugin-parser.h" #include "xed-taglist-plugin-parser.h"
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include <gmodule.h>
#include <libpeas/peas-activatable.h>
#include <xed/xed-window.h> #include <xed/xed-window.h>
#include <xed/xed-window-activatable.h>
#include <xed/xed-debug.h> #include <xed/xed-debug.h>
#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
{ {
GtkWidget *window; XedWindow *window;
GtkWidget *taglist_panel; GtkWidget *taglist_panel;
}; };
static void peas_activatable_iface_init (PeasActivatableInterface *iface); static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTaglistPlugin, G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTaglistPlugin,
xed_taglist_plugin, xed_taglist_plugin,
PEAS_TYPE_EXTENSION_BASE, PEAS_TYPE_EXTENSION_BASE,
0, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE,
peas_activatable_iface_init) \ xed_window_activatable_iface_init) \
\ \
_xed_taglist_plugin_panel_register_type (type_module); \ _xed_taglist_plugin_panel_register_type (type_module); \
) )
@ -66,7 +65,7 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedTaglistPlugin,
enum enum
{ {
PROP_0, PROP_0,
PROP_OBJECT PROP_WINDOW
}; };
static void static void
@ -84,11 +83,7 @@ xed_taglist_plugin_dispose (GObject *object)
xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin disposing"); xed_debug_message (DEBUG_PLUGINS, "XedTaglistPlugin disposing");
if (plugin->priv->window != NULL) g_clear_object (&plugin->priv->window);
{
g_object_unref (plugin->priv->window);
plugin->priv->window = NULL;
}
G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->dispose (object); G_OBJECT_CLASS (xed_taglist_plugin_parent_class)->dispose (object);
} }
@ -104,54 +99,48 @@ xed_taglist_plugin_finalize (GObject *object)
} }
static void static void
xed_taglist_plugin_activate (PeasActivatable *activatable) xed_taglist_plugin_activate (XedWindowActivatable *activatable)
{ {
XedTaglistPluginPrivate *priv; XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel; XedPanel *side_panel;
gchar *data_dir; gchar *data_dir;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
priv = XED_TAGLIST_PLUGIN (activatable)->priv; priv = XED_TAGLIST_PLUGIN (activatable)->priv;
window = XED_WINDOW (priv->window); side_panel = xed_window_get_side_panel (priv->window);
side_panel = xed_window_get_side_panel (window);
data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable)); data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable));
priv->taglist_panel = xed_taglist_plugin_panel_new (window, data_dir); priv->taglist_panel = xed_taglist_plugin_panel_new (priv->window, data_dir);
g_free (data_dir); g_free (data_dir);
xed_panel_add_item (side_panel, priv->taglist_panel, _("Tags"), "list-add"); xed_panel_add_item (side_panel, priv->taglist_panel, _("Tags"), "list-add");
} }
static void static void
xed_taglist_plugin_deactivate (PeasActivatable *activatable) xed_taglist_plugin_deactivate (XedWindowActivatable *activatable)
{ {
XedTaglistPluginPrivate *priv; XedTaglistPluginPrivate *priv;
XedWindow *window;
XedPanel *side_panel; XedPanel *side_panel;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
priv = XED_TAGLIST_PLUGIN (activatable)->priv; priv = XED_TAGLIST_PLUGIN (activatable)->priv;
window = XED_WINDOW (priv->window); side_panel = xed_window_get_side_panel (priv->window);
side_panel = xed_window_get_side_panel (window);
xed_panel_remove_item (side_panel, priv->taglist_panel); xed_panel_remove_item (side_panel, priv->taglist_panel);
} }
static void static void
xed_taglist_plugin_update_state (PeasActivatable *activatable) xed_taglist_plugin_update_state (XedWindowActivatable *activatable)
{ {
XedTaglistPluginPrivate *priv; XedTaglistPluginPrivate *priv;
XedWindow *window;
XedView *view; XedView *view;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
priv = XED_TAGLIST_PLUGIN (activatable)->priv; priv = XED_TAGLIST_PLUGIN (activatable)->priv;
window = XED_WINDOW (priv->window); view = xed_window_get_active_view (priv->window);
view = xed_window_get_active_view (window);
gtk_widget_set_sensitive (priv->taglist_panel, gtk_widget_set_sensitive (priv->taglist_panel,
(view != NULL) && (view != NULL) &&
@ -168,8 +157,8 @@ xed_taglist_plugin_set_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_OBJECT: case PROP_WINDOW:
plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); plugin->priv->window = XED_WINDOW (g_value_dup_object (value));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -187,7 +176,7 @@ xed_taglist_plugin_get_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_OBJECT: case PROP_WINDOW:
g_value_set_object (value, plugin->priv->window); g_value_set_object (value, plugin->priv->window);
break; break;
default: default:
@ -206,7 +195,7 @@ xed_taglist_plugin_class_init (XedTaglistPluginClass *klass)
object_class->set_property = xed_taglist_plugin_set_property; object_class->set_property = xed_taglist_plugin_set_property;
object_class->get_property = xed_taglist_plugin_get_property; object_class->get_property = xed_taglist_plugin_get_property;
g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_object_class_override_property (object_class, PROP_WINDOW, "window");
g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate)); g_type_class_add_private (object_class, sizeof (XedTaglistPluginPrivate));
} }
@ -218,7 +207,7 @@ xed_taglist_plugin_class_finalize (XedTaglistPluginClass *klass)
} }
static void static void
peas_activatable_iface_init (PeasActivatableInterface *iface) xed_window_activatable_iface_init (XedWindowActivatableInterface *iface)
{ {
iface->activate = xed_taglist_plugin_activate; iface->activate = xed_taglist_plugin_activate;
iface->deactivate = xed_taglist_plugin_deactivate; iface->deactivate = xed_taglist_plugin_deactivate;
@ -231,6 +220,6 @@ peas_register_types (PeasObjectModule *module)
xed_taglist_plugin_register_type (G_TYPE_MODULE (module)); xed_taglist_plugin_register_type (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module, peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE, XED_TYPE_WINDOW_ACTIVATABLE,
XED_TYPE_TAGLIST_PLUGIN); XED_TYPE_TAGLIST_PLUGIN);
} }

View File

@ -23,8 +23,6 @@
* Modified by the xed Team, 2002-2005. See the AUTHORS file for a * Modified by the xed Team, 2002-2005. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
*
* $Id$
*/ */
#ifndef __XED_TAGLIST_PLUGIN_H__ #ifndef __XED_TAGLIST_PLUGIN_H__
@ -47,13 +45,9 @@ G_BEGIN_DECLS
#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 */
typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate;
/*
* Main object structure
*/
typedef struct _XedTaglistPlugin XedTaglistPlugin; typedef struct _XedTaglistPlugin XedTaglistPlugin;
typedef struct _XedTaglistPluginPrivate XedTaglistPluginPrivate;
typedef struct _XedTaglistPluginClass XedTaglistPluginClass;
struct _XedTaglistPlugin struct _XedTaglistPlugin
{ {
@ -63,22 +57,13 @@ struct _XedTaglistPlugin
XedTaglistPluginPrivate *priv; XedTaglistPluginPrivate *priv;
}; };
/*
* Class definition
*/
typedef struct _XedTaglistPluginClass XedTaglistPluginClass;
struct _XedTaglistPluginClass struct _XedTaglistPluginClass
{ {
PeasExtensionBaseClass parent_class; PeasExtensionBaseClass parent_class;
}; };
/*
* 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 */
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS G_END_DECLS