changecase-plugin: Port to WindowActivatable
This commit is contained in:
parent
33cb6f4b32
commit
769f1baaaa
|
@ -1,4 +1,5 @@
|
||||||
DIST_SUBDIRS = \
|
DIST_SUBDIRS = \
|
||||||
|
changecase \
|
||||||
docinfo \
|
docinfo \
|
||||||
filebrowser \
|
filebrowser \
|
||||||
modelines \
|
modelines \
|
||||||
|
@ -7,6 +8,7 @@ DIST_SUBDIRS = \
|
||||||
time
|
time
|
||||||
|
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
|
changecase \
|
||||||
docinfo \
|
docinfo \
|
||||||
filebrowser \
|
filebrowser \
|
||||||
modelines \
|
modelines \
|
||||||
|
|
|
@ -26,29 +26,26 @@
|
||||||
|
|
||||||
#include "xed-changecase-plugin.h"
|
#include "xed-changecase-plugin.h"
|
||||||
|
|
||||||
#include <glib/gi18n-lib.h>
|
#include <glib/gi18n.h>
|
||||||
#include <gmodule.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_CHANGECASE_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
|
static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface);
|
||||||
XED_TYPE_CHANGECASE_PLUGIN, \
|
|
||||||
XedChangecasePluginPrivate))
|
|
||||||
|
|
||||||
static void peas_activatable_iface_init (PeasActivatableInterface *iface);
|
|
||||||
|
|
||||||
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedChangecasePlugin,
|
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedChangecasePlugin,
|
||||||
xed_changecase_plugin,
|
xed_changecase_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))
|
||||||
|
|
||||||
struct _XedChangecasePluginPrivate
|
struct _XedChangecasePluginPrivate
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
XedWindow *window;
|
||||||
|
|
||||||
GtkActionGroup *action_group;
|
GtkActionGroup *action_group;
|
||||||
guint ui_id;
|
guint ui_id;
|
||||||
};
|
};
|
||||||
|
@ -56,7 +53,7 @@ struct _XedChangecasePluginPrivate
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_OBJECT
|
PROP_WINDOW
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -282,7 +279,7 @@ xed_changecase_plugin_init (XedChangecasePlugin *plugin)
|
||||||
{
|
{
|
||||||
xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin initializing");
|
xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin initializing");
|
||||||
|
|
||||||
plugin->priv = XED_CHANGECASE_PLUGIN_GET_PRIVATE (plugin);
|
plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -292,17 +289,8 @@ xed_changecase_plugin_dispose (GObject *object)
|
||||||
|
|
||||||
xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin disposing");
|
xed_debug_message (DEBUG_PLUGINS, "XedChangecasePlugin disposing");
|
||||||
|
|
||||||
if (plugin->priv->window != NULL)
|
g_clear_object (&plugin->priv->window);
|
||||||
{
|
g_clear_object (&plugin->priv->action_group);
|
||||||
g_object_unref (plugin->priv->window);
|
|
||||||
plugin->priv->window = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin->priv->action_group != NULL)
|
|
||||||
{
|
|
||||||
g_object_unref (plugin->priv->action_group);
|
|
||||||
plugin->priv->action_group = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (xed_changecase_plugin_parent_class)->dispose (object);
|
G_OBJECT_CLASS (xed_changecase_plugin_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
@ -317,8 +305,8 @@ xed_changecase_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);
|
||||||
|
@ -336,7 +324,7 @@ xed_changecase_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:
|
||||||
|
@ -346,17 +334,15 @@ xed_changecase_plugin_get_property (GObject *object,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_ui (XedChangecasePluginPrivate *data)
|
update_ui (XedChangecasePlugin *plugin)
|
||||||
{
|
{
|
||||||
XedWindow *window;
|
|
||||||
GtkTextView *view;
|
GtkTextView *view;
|
||||||
GtkAction *action;
|
GtkAction *action;
|
||||||
gboolean sensitive = FALSE;
|
gboolean sensitive = FALSE;
|
||||||
|
|
||||||
xed_debug (DEBUG_PLUGINS);
|
xed_debug (DEBUG_PLUGINS);
|
||||||
|
|
||||||
window = XED_WINDOW (data->window);
|
view = GTK_TEXT_VIEW (xed_window_get_active_view (plugin->priv->window));
|
||||||
view = GTK_TEXT_VIEW (xed_window_get_active_view (window));
|
|
||||||
|
|
||||||
if (view != NULL)
|
if (view != NULL)
|
||||||
{
|
{
|
||||||
|
@ -366,65 +352,61 @@ update_ui (XedChangecasePluginPrivate *data)
|
||||||
sensitive = (gtk_text_view_get_editable (view) && gtk_text_buffer_get_has_selection (buffer));
|
sensitive = (gtk_text_view_get_editable (view) && gtk_text_buffer_get_has_selection (buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
action = gtk_action_group_get_action (data->action_group, "ChangeCase");
|
action = gtk_action_group_get_action (plugin->priv->action_group, "ChangeCase");
|
||||||
gtk_action_set_sensitive (action, sensitive);
|
gtk_action_set_sensitive (action, sensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xed_changecase_plugin_activate (PeasActivatable *activatable)
|
xed_changecase_plugin_activate (XedWindowActivatable *activatable)
|
||||||
{
|
{
|
||||||
XedChangecasePluginPrivate *data;
|
XedChangecasePluginPrivate *priv;
|
||||||
XedWindow *window;
|
|
||||||
GtkUIManager *manager;
|
GtkUIManager *manager;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
xed_debug (DEBUG_PLUGINS);
|
xed_debug (DEBUG_PLUGINS);
|
||||||
|
|
||||||
data = XED_CHANGECASE_PLUGIN (activatable)->priv;
|
priv = XED_CHANGECASE_PLUGIN (activatable)->priv;
|
||||||
window = XED_WINDOW (data->window);
|
|
||||||
|
|
||||||
manager = xed_window_get_ui_manager (window);
|
manager = xed_window_get_ui_manager (priv->window);
|
||||||
|
|
||||||
data->action_group = gtk_action_group_new ("XedChangecasePluginActions");
|
priv->action_group = gtk_action_group_new ("XedChangecasePluginActions");
|
||||||
gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE);
|
gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE);
|
||||||
gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), window);
|
gtk_action_group_add_actions (priv->action_group, action_entries, G_N_ELEMENTS (action_entries), priv->window);
|
||||||
|
|
||||||
gtk_ui_manager_insert_action_group (manager, data->action_group, -1);
|
gtk_ui_manager_insert_action_group (manager, priv->action_group, -1);
|
||||||
|
|
||||||
data->ui_id = gtk_ui_manager_add_ui_from_string (manager, submenu, -1, &error);
|
priv->ui_id = gtk_ui_manager_add_ui_from_string (manager, submenu, -1, &error);
|
||||||
if (data->ui_id == 0)
|
if (priv->ui_id == 0)
|
||||||
{
|
{
|
||||||
g_warning ("%s", error->message);
|
g_warning ("%s", error->message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_ui (data);
|
update_ui (XED_CHANGECASE_PLUGIN (activatable));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xed_changecase_plugin_deactivate (PeasActivatable *activatable)
|
xed_changecase_plugin_deactivate (XedWindowActivatable *activatable)
|
||||||
{
|
{
|
||||||
XedChangecasePluginPrivate *data;
|
XedChangecasePluginPrivate *priv;
|
||||||
XedWindow *window;
|
|
||||||
GtkUIManager *manager;
|
GtkUIManager *manager;
|
||||||
|
|
||||||
xed_debug (DEBUG_PLUGINS);
|
xed_debug (DEBUG_PLUGINS);
|
||||||
|
|
||||||
data = XED_CHANGECASE_PLUGIN (activatable)->priv;
|
priv = XED_CHANGECASE_PLUGIN (activatable)->priv;
|
||||||
window = XED_WINDOW (data->window);
|
|
||||||
|
|
||||||
manager = xed_window_get_ui_manager (window);
|
manager = xed_window_get_ui_manager (priv->window);
|
||||||
|
|
||||||
gtk_ui_manager_remove_ui (manager, data->ui_id);
|
gtk_ui_manager_remove_ui (manager, priv->ui_id);
|
||||||
gtk_ui_manager_remove_action_group (manager, data->action_group);
|
gtk_ui_manager_remove_action_group (manager, priv->action_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xed_changecase_plugin_update_state (PeasActivatable *activatable)
|
xed_changecase_plugin_update_state (XedWindowActivatable *activatable)
|
||||||
{
|
{
|
||||||
xed_debug (DEBUG_PLUGINS);
|
xed_debug (DEBUG_PLUGINS);
|
||||||
|
|
||||||
update_ui (XED_CHANGECASE_PLUGIN (activatable)->priv);
|
update_ui (XED_CHANGECASE_PLUGIN (activatable));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -436,7 +418,7 @@ xed_changecase_plugin_class_init (XedChangecasePluginClass *klass)
|
||||||
object_class->set_property = xed_changecase_plugin_set_property;
|
object_class->set_property = xed_changecase_plugin_set_property;
|
||||||
object_class->get_property = xed_changecase_plugin_get_property;
|
object_class->get_property = xed_changecase_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 (klass, sizeof (XedChangecasePluginPrivate));
|
g_type_class_add_private (klass, sizeof (XedChangecasePluginPrivate));
|
||||||
}
|
}
|
||||||
|
@ -448,7 +430,7 @@ xed_changecase_plugin_class_finalize (XedChangecasePluginClass *klass)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
peas_activatable_iface_init (PeasActivatableInterface *iface)
|
xed_window_activatable_iface_init (XedWindowActivatableInterface *iface)
|
||||||
{
|
{
|
||||||
iface->activate = xed_changecase_plugin_activate;
|
iface->activate = xed_changecase_plugin_activate;
|
||||||
iface->deactivate = xed_changecase_plugin_deactivate;
|
iface->deactivate = xed_changecase_plugin_deactivate;
|
||||||
|
@ -461,6 +443,6 @@ peas_register_types (PeasObjectModule *module)
|
||||||
xed_changecase_plugin_register_type (G_TYPE_MODULE (module));
|
xed_changecase_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_CHANGECASE_PLUGIN);
|
XED_TYPE_CHANGECASE_PLUGIN);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __XED_CHANGECASE_PLUGIN_H__
|
#ifndef __XED_CHANGECASE_PLUGIN_H__
|
||||||
|
@ -30,9 +28,6 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/*
|
|
||||||
* Type checking and casting macros
|
|
||||||
*/
|
|
||||||
#define XED_TYPE_CHANGECASE_PLUGIN (xed_changecase_plugin_get_type ())
|
#define XED_TYPE_CHANGECASE_PLUGIN (xed_changecase_plugin_get_type ())
|
||||||
#define XED_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePlugin))
|
#define XED_CHANGECASE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePlugin))
|
||||||
#define XED_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass))
|
#define XED_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass))
|
||||||
|
@ -40,12 +35,9 @@ G_BEGIN_DECLS
|
||||||
#define XED_IS_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_CHANGECASE_PLUGIN))
|
#define XED_IS_CHANGECASE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_CHANGECASE_PLUGIN))
|
||||||
#define XED_CHANGECASE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass))
|
#define XED_CHANGECASE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_CHANGECASE_PLUGIN, XedChangecasePluginClass))
|
||||||
|
|
||||||
typedef struct _XedChangecasePluginPrivate XedChangecasePluginPrivate;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Main object structure
|
|
||||||
*/
|
|
||||||
typedef struct _XedChangecasePlugin XedChangecasePlugin;
|
typedef struct _XedChangecasePlugin XedChangecasePlugin;
|
||||||
|
typedef struct _XedChangecasePluginPrivate XedChangecasePluginPrivate;
|
||||||
|
typedef struct _XedChangecasePluginClass XedChangecasePluginClass;
|
||||||
|
|
||||||
struct _XedChangecasePlugin
|
struct _XedChangecasePlugin
|
||||||
{
|
{
|
||||||
|
@ -55,22 +47,13 @@ struct _XedChangecasePlugin
|
||||||
XedChangecasePluginPrivate *priv;
|
XedChangecasePluginPrivate *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* Class definition
|
|
||||||
*/
|
|
||||||
typedef struct _XedChangecasePluginClass XedChangecasePluginClass;
|
|
||||||
|
|
||||||
struct _XedChangecasePluginClass
|
struct _XedChangecasePluginClass
|
||||||
{
|
{
|
||||||
PeasExtensionBaseClass parent_class;
|
PeasExtensionBaseClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* Public methods
|
|
||||||
*/
|
|
||||||
GType xed_changecase_plugin_get_type (void) G_GNUC_CONST;
|
GType xed_changecase_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
|
||||||
|
|
Loading…
Reference in New Issue