[eog] reload: Update to GAction
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog] reload: Update to GAction
- Date: Fri, 30 Jan 2015 22:32:46 +0000 (UTC)
commit 341e8b6e688bba0654f30cd40cb8d1eefbf556d3
Author: Felix Riemann <friemann gnome org>
Date: Fri Jan 30 23:30:55 2015 +0100
reload: Update to GAction
Menu handling as shown in the GTK+ plugman example.
https://bugzilla.gnome.org/show_bug.cgi?id=741050
plugins/reload/eog-reload-plugin.c | 134 ++++++++++++++++++-------------
plugins/reload/reload.plugin.desktop.in | 2 +-
2 files changed, 78 insertions(+), 58 deletions(-)
---
diff --git a/plugins/reload/eog-reload-plugin.c b/plugins/reload/eog-reload-plugin.c
index 5db6359..c391f30 100644
--- a/plugins/reload/eog-reload-plugin.c
+++ b/plugins/reload/eog-reload-plugin.c
@@ -30,13 +30,19 @@
#include <libpeas/peas.h>
+#include <eog-application.h>
#include <eog-debug.h>
-#include <eog-scroll-view.h>
-#include <eog-thumb-view.h>
-#include <eog-image.h>
#include <eog-window.h>
#include <eog-window-activatable.h>
+enum {
+ PROP_0,
+ PROP_WINDOW
+};
+
+#define EOG_RELOAD_PLUGIN_MENU_ID "EogPluginRunReload"
+#define EOG_RELOAD_PLUGIN_ACTION "reload"
+
static void eog_window_activatable_iface_init (EogWindowActivatableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogReloadPlugin,
@@ -46,37 +52,14 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogReloadPlugin,
G_IMPLEMENT_INTERFACE_DYNAMIC (EOG_TYPE_WINDOW_ACTIVATABLE,
eog_window_activatable_iface_init))
-enum {
- PROP_0,
- PROP_WINDOW
-};
-
static void
-reload_cb (GtkAction *action,
- EogWindow *window)
+reload_cb (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data)
{
- eog_window_reload_image (window);
+ eog_window_reload_image (EOG_WINDOW (user_data));
}
-static const gchar * const ui_definition =
- "<ui><menubar name=\"MainMenu\">"
- "<menu name=\"ToolsMenu\" action=\"Tools\"><separator/>"
- "<menuitem name=\"EogPluginReload\" action=\"EogPluginRunReload\"/>"
- "<separator/></menu></menubar>"
- "<popup name=\"ViewPopup\"><separator/>"
- "<menuitem action=\"EogPluginRunReload\"/><separator/>"
- "</popup></ui>";
-
-static const GtkActionEntry action_entries[] =
-{
- { "EogPluginRunReload",
- "view-refresh",
- N_("Reload Image"),
- "R",
- N_("Reload current image"),
- G_CALLBACK (reload_cb) }
-};
-
static void
eog_reload_plugin_set_property (GObject *object,
guint prop_id,
@@ -141,48 +124,85 @@ eog_reload_plugin_dispose (GObject *object)
static void
eog_reload_plugin_activate (EogWindowActivatable *activatable)
{
- GtkUIManager *manager;
+ const gchar * const accel_keys[] = { "R", NULL };
EogReloadPlugin *plugin = EOG_RELOAD_PLUGIN (activatable);
+ GMenu *model, *menu;
+ GMenuItem *item;
+ GSimpleAction *action;
eog_debug (DEBUG_PLUGINS);
- manager = eog_window_get_ui_manager (plugin->window);
-
- plugin->ui_action_group = gtk_action_group_new ("EogReloadPluginActions");
-
- gtk_action_group_set_translation_domain (plugin->ui_action_group,
- GETTEXT_PACKAGE);
-
- gtk_action_group_add_actions (plugin->ui_action_group,
- action_entries,
- G_N_ELEMENTS (action_entries),
- plugin->window);
-
- gtk_ui_manager_insert_action_group (manager,
- plugin->ui_action_group,
- -1);
-
- plugin->ui_id = gtk_ui_manager_add_ui_from_string (manager,
- ui_definition,
- -1, NULL);
- g_warn_if_fail (plugin->ui_id != 0);
+ model= eog_window_get_gear_menu_section (plugin->window,
+ "plugins-section");
+
+ g_return_if_fail (G_IS_MENU (model));
+
+ /* Setup and inject action */
+ action = g_simple_action_new (EOG_RELOAD_PLUGIN_ACTION, NULL);
+ g_signal_connect(action, "activate",
+ G_CALLBACK (reload_cb), plugin->window);
+ g_action_map_add_action (G_ACTION_MAP (plugin->window),
+ G_ACTION (action));
+ g_object_unref (action);
+
+ /* Append entry to the window's gear menu */
+ menu = g_menu_new ();
+ g_menu_append (menu, _("Reload Image"),
+ "win." EOG_RELOAD_PLUGIN_ACTION);
+
+ item = g_menu_item_new_section (NULL, G_MENU_MODEL (menu));
+ g_menu_item_set_attribute (item, "id",
+ "s", EOG_RELOAD_PLUGIN_MENU_ID);
+ g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_ICON,
+ "s", "view-refresh-symbolic");
+ g_menu_append_item (model, item);
+ g_object_unref (item);
+
+ g_object_unref (menu);
+
+ /* Define accelerator keys */
+ gtk_application_set_accels_for_action (GTK_APPLICATION (EOG_APP),
+ "win." EOG_RELOAD_PLUGIN_ACTION,
+ accel_keys);
}
static void
eog_reload_plugin_deactivate (EogWindowActivatable *activatable)
{
- GtkUIManager *manager;
+ const gchar * const empty_accels[1] = { NULL };
EogReloadPlugin *plugin = EOG_RELOAD_PLUGIN (activatable);
+ GMenu *menu;
+ GMenuModel *model;
+ const gchar *id;
+ gint i;
eog_debug (DEBUG_PLUGINS);
- manager = eog_window_get_ui_manager (plugin->window);
+ menu = eog_window_get_gear_menu_section (plugin->window,
+ "plugins-section");
+
+ g_return_if_fail (G_IS_MENU (menu));
+
+ /* Remove menu entry */
+ model = G_MENU_MODEL (menu);
+ for (i = 0; i < g_menu_model_get_n_items (model); i++) {
+ if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)
+ && g_strcmp0 (id, EOG_RELOAD_PLUGIN_MENU_ID) == 0)
+ {
+ g_menu_remove (menu, i);
+ break;
+ }
+ }
+
+ /* Unset accelerator */
+ gtk_application_set_accels_for_action(GTK_APPLICATION (EOG_APP),
+ "win." EOG_RELOAD_PLUGIN_ACTION,
+ empty_accels);
- gtk_ui_manager_remove_ui (manager,
- plugin->ui_id);
+ /* Finally remove action */
+ g_action_map_remove_action (G_ACTION_MAP (plugin->window),
+ EOG_RELOAD_PLUGIN_ACTION);
- gtk_ui_manager_remove_action_group (manager,
- plugin->ui_action_group);
}
static void
diff --git a/plugins/reload/reload.plugin.desktop.in b/plugins/reload/reload.plugin.desktop.in
index d80567f..8dedd65 100644
--- a/plugins/reload/reload.plugin.desktop.in
+++ b/plugins/reload/reload.plugin.desktop.in
@@ -1,6 +1,6 @@
[Plugin]
Module=reload
-IAge=2
+IAge=3
_Name=Reload Image
Icon=view-refresh
_Description=Reload current image
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]