[gthumb] scripts: disable execution when there is no file selected



commit 2c9b478c1775baba4c04682f1a99cb83614ec0e3
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Nov 14 16:57:35 2019 +0100

    scripts: disable execution when there is no file selected

 extensions/list_tools/callbacks.c | 27 +++++++--------------------
 extensions/list_tools/callbacks.h |  4 +++-
 extensions/list_tools/main.c      |  1 +
 gthumb/gth-browser.c              |  4 +++-
 gthumb/gth-main-default-hooks.c   |  8 ++++++++
 5 files changed, 22 insertions(+), 22 deletions(-)
---
diff --git a/extensions/list_tools/callbacks.c b/extensions/list_tools/callbacks.c
index f0f2422c..9af60b2a 100644
--- a/extensions/list_tools/callbacks.c
+++ b/extensions/list_tools/callbacks.c
@@ -58,24 +58,6 @@ browser_data_free (BrowserData *data)
 
 
 static void
-list_tools__gth_browser_update_sensitivity_cb (GthBrowser *browser)
-{
-       BrowserData *data;
-       int          n_selected;
-       gboolean     sensitive;
-
-       data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
-       g_return_if_fail (data != NULL);
-
-       n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view 
(browser)));
-       sensitive = (n_selected > 0);
-
-       gth_window_enable_action (GTH_WINDOW (browser), "exec-script", sensitive);
-}
-
-
-static void
-update_scripts_menu (BrowserData *data)
 update_scripts (BrowserData *data)
 {
        GthMenuManager  *menu_manager;
@@ -116,8 +98,6 @@ update_scripts (BrowserData *data)
                gth_shortcut_free (shortcut);
        }
 
-       list_tools__gth_browser_update_sensitivity_cb (data->browser);
-
        _g_object_list_unref (script_list);
 }
 
@@ -183,7 +163,14 @@ list_tools__gth_browser_construct_cb (GthBrowser *browser)
 }
 
 
+void
+list_tools__gth_browser_file_list_selection_changed (GthBrowser *browser,
+                                                    int         n_selected)
 {
+       BrowserData *data;
 
+       data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
+       g_return_if_fail (data != NULL);
 
+       gth_window_enable_action (GTH_WINDOW (browser), "exec-script", n_selected > 0);
 }
diff --git a/extensions/list_tools/callbacks.h b/extensions/list_tools/callbacks.h
index efb5e83b..9c172581 100644
--- a/extensions/list_tools/callbacks.h
+++ b/extensions/list_tools/callbacks.h
@@ -24,6 +24,8 @@
 
 #include <gthumb.h>
 
-void      list_tools__gth_browser_construct_cb           (GthBrowser  *browser);
+void list_tools__gth_browser_construct_cb                (GthBrowser *browser);
+void list_tools__gth_browser_file_list_selection_changed (GthBrowser *browser,
+                                                         int         n_selected);
 
 #endif /* CALLBACKS_H */
diff --git a/extensions/list_tools/main.c b/extensions/list_tools/main.c
index 1eaa5a4c..4de9fcb7 100644
--- a/extensions/list_tools/main.c
+++ b/extensions/list_tools/main.c
@@ -30,6 +30,7 @@ G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
        gth_hook_add_callback ("gth-browser-construct", 5, G_CALLBACK (list_tools__gth_browser_construct_cb), 
NULL);
+       gth_hook_add_callback ("gth-browser-file-list-selection-changed", 5, G_CALLBACK 
(list_tools__gth_browser_file_list_selection_changed), NULL);
 }
 
 
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 7b2d5e11..a7a00d0b 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -3634,10 +3634,12 @@ update_selection_cb (gpointer user_data)
        gth_browser_update_sensitivity (browser);
        _gth_browser_update_statusbar_list_info (browser);
 
+       n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view 
(browser)));
+       gth_hook_invoke ("gth-browser-file-list-selection-changed", browser, n_selected);
+
        if (gth_window_get_current_page (GTH_WINDOW (browser)) != GTH_BROWSER_PAGE_BROWSER)
                return FALSE;
 
-       n_selected = gth_file_selection_get_n_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view 
(browser)));
        if (n_selected == 1) {
                GList       *items;
                GList       *file_list;
diff --git a/gthumb/gth-main-default-hooks.c b/gthumb/gth-main-default-hooks.c
index 777cfd3d..7833a961 100644
--- a/gthumb/gth-main-default-hooks.c
+++ b/gthumb/gth-main-default-hooks.c
@@ -89,6 +89,14 @@ gth_main_register_default_hooks (void)
         **/
        gth_hook_register ("gth-browser-update-sensitivity", 1);
 
+       /**
+        *  Called when the file list selection changes
+        *
+        *  @browser (GthBrowser*): the relative window.
+        *  @n_selected (int): number of selected files.
+        */
+       gth_hook_register ("gth-browser-file-list-selection-changed", 2);
+
        /**
         *  Called when the current page changes.
         *


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