[eog-plugins] send-by-mail: Only enable action if an image is selected



commit f0310c403fbf5d69087ec2b08ebf444894def23a
Author: Felix Riemann <friemann gnome org>
Date:   Tue Sep 29 14:51:34 2015 +0200

    send-by-mail: Only enable action if an image is selected
    
    The result is not really nice if used without selection. Evolution for
    example will open with an error message. Will also avoid offering
    the action if no image is loaded.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755244

 plugins/send-by-mail/eog-send-by-mail-plugin.c |   37 ++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/plugins/send-by-mail/eog-send-by-mail-plugin.c b/plugins/send-by-mail/eog-send-by-mail-plugin.c
index b63b2c4..b48c1ac 100644
--- a/plugins/send-by-mail/eog-send-by-mail-plugin.c
+++ b/plugins/send-by-mail/eog-send-by-mail-plugin.c
@@ -59,6 +59,34 @@ eog_send_by_mail_plugin_init (EogSendByMailPlugin *plugin)
 }
 
 static void
+eog_send_by_mail_plugin_update_action_state (EogSendByMailPlugin *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_SEND_BY_MAIL_PLUGIN_ACTION);
+       g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enable);
+}
+
+static void
+_selection_changed_cb (EogThumbView *thumbview, gpointer user_data)
+{
+       EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (user_data);
+
+       if (G_LIKELY (plugin))
+               eog_send_by_mail_plugin_update_action_state (plugin);
+}
+
+static void
 impl_activate (EogWindowActivatable *activatable)
 {
        EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (activatable);
@@ -79,6 +107,12 @@ impl_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_send_by_mail_plugin_update_action_state (plugin);
+
        /* Append entry to the window's gear menu */
        menu = g_menu_new ();
        g_menu_append (menu, _("Send by Mail"),
@@ -124,6 +158,9 @@ impl_deactivate     (EogWindowActivatable *activatable)
                }
        }
 
+       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_SEND_BY_MAIL_PLUGIN_ACTION);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]