diff options
author | Felix Riemann <friemann@gnome.org> | 2015-09-29 16:33:42 +0200 |
---|---|---|
committer | Felix Riemann <friemann@gnome.org> | 2015-09-29 16:33:42 +0200 |
commit | cf429103e1544c8c9de17110a29e1a7e7734dfba (patch) | |
tree | 95fec1c127e38bc7b9f37ebfebfbc40dd191ab42 | |
parent | 2a1db34f611768f245aacc785e09b22fca6bfc93 (diff) | |
download | eog-cf429103e1544c8c9de17110a29e1a7e7734dfba.tar.gz |
reload: Only offer reload option if there's something to reload
https://bugzilla.gnome.org/show_bug.cgi?id=755244
-rw-r--r-- | plugins/reload/eog-reload-plugin.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/plugins/reload/eog-reload-plugin.c b/plugins/reload/eog-reload-plugin.c index 3d9aca2f..456542b0 100644 --- a/plugins/reload/eog-reload-plugin.c +++ b/plugins/reload/eog-reload-plugin.c @@ -32,6 +32,7 @@ #include <eog-application.h> #include <eog-debug.h> +#include <eog-thumb-view.h> #include <eog-window.h> #include <eog-window-activatable.h> @@ -122,6 +123,34 @@ eog_reload_plugin_dispose (GObject *object) } static void +eog_reload_plugin_update_action_state (EogReloadPlugin *plugin) +{ + GAction *action; + EogThumbView *thumbview; + gboolean enable = FALSE; + + thumbview = EOG_THUMB_VIEW (eog_window_get_thumb_view (plugin->window)); + + if (G_LIKELY (thumbview)) + { + enable = (eog_thumb_view_get_n_selected (thumbview) != 0); + } + + action = g_action_map_lookup_action (G_ACTION_MAP (plugin->window), + EOG_RELOAD_PLUGIN_ACTION); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enable); +} + +static void +_selection_changed_cb (EogThumbView *thumbview, gpointer user_data) +{ + EogReloadPlugin *plugin = EOG_RELOAD_PLUGIN (user_data); + + if (G_LIKELY (plugin)) + eog_reload_plugin_update_action_state (plugin); +} + +static void eog_reload_plugin_activate (EogWindowActivatable *activatable) { const gchar * const accel_keys[] = { "R", NULL }; @@ -145,6 +174,12 @@ eog_reload_plugin_activate (EogWindowActivatable *activatable) G_ACTION (action)); g_object_unref (action); + g_signal_connect (G_OBJECT (eog_window_get_thumb_view (plugin->window)), + "selection-changed", + G_CALLBACK (_selection_changed_cb), + plugin); + eog_reload_plugin_update_action_state (plugin); + /* Append entry to the window's gear menu */ menu = g_menu_new (); g_menu_append (menu, _("Reload Image"), @@ -203,6 +238,11 @@ eog_reload_plugin_deactivate (EogWindowActivatable *activatable) "win." EOG_RELOAD_PLUGIN_ACTION, empty_accels); + /* Disconnect selection-changed handler as the thumbview would + * otherwise still cause callbacks during its own disposal */ + g_signal_handlers_disconnect_by_func (eog_window_get_thumb_view (plugin->window), + _selection_changed_cb, plugin); + /* Finally remove action */ g_action_map_remove_action (G_ACTION_MAP (plugin->window), EOG_RELOAD_PLUGIN_ACTION); |