[gthumb] allow to set shortcuts for filters
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] allow to set shortcuts for filters
- Date: Sun, 22 Aug 2021 05:31:43 +0000 (UTC)
commit 911d635bc6328df9785988946d3cabdf83528665
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Aug 4 10:44:19 2021 +0200
allow to set shortcuts for filters
gthumb/gth-browser-actions-callbacks.c | 16 ++++++++++++++++
gthumb/gth-browser-actions-callbacks.h | 1 +
gthumb/gth-browser-actions-entries.h | 2 ++
gthumb/gth-browser.c | 32 +++++++++++++++++++++++++++++++-
gthumb/gth-filterbar.c | 2 ++
gthumb/gth-main-default-types.c | 1 +
gthumb/gth-shortcut.h | 1 +
gthumb/gth-window.c | 26 ++++++++++++++++++++++++++
gthumb/gth-window.h | 2 ++
9 files changed, 82 insertions(+), 1 deletion(-)
---
diff --git a/gthumb/gth-browser-actions-callbacks.c b/gthumb/gth-browser-actions-callbacks.c
index 96197916..0c7ff437 100644
--- a/gthumb/gth-browser-actions-callbacks.c
+++ b/gthumb/gth-browser-actions-callbacks.c
@@ -30,6 +30,7 @@
#include "gth-browser-actions-callbacks.h"
#include "gth-file-list.h"
#include "gth-file-selection.h"
+#include "gth-filterbar.h"
#include "gth-folder-tree.h"
#include "gth-main.h"
#include "gth-preferences.h"
@@ -625,3 +626,18 @@ gth_browser_activate_show_menu (GSimpleAction *action,
{
gth_browser_show_menu (GTH_BROWSER (user_data));
}
+
+
+void
+gth_browser_activate_set_filter (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GthBrowser *browser = GTH_BROWSER (user_data);
+ const char *test_id;
+ GtkWidget *filterbar;
+
+ test_id = g_variant_get_string (parameter, NULL);
+ filterbar = gth_browser_get_filterbar (browser);
+ gth_filterbar_set_test_by_id (GTH_FILTERBAR (filterbar), test_id);
+}
diff --git a/gthumb/gth-browser-actions-callbacks.h b/gthumb/gth-browser-actions-callbacks.h
index f8467504..06e4f548 100644
--- a/gthumb/gth-browser-actions-callbacks.h
+++ b/gthumb/gth-browser-actions-callbacks.h
@@ -71,5 +71,6 @@ DEF_ACTION_CALLBACK (gth_browser_activate_apply_editor_changes)
DEF_ACTION_CALLBACK (gth_browser_activate_select_all)
DEF_ACTION_CALLBACK (gth_browser_activate_unselect_all)
DEF_ACTION_CALLBACK (gth_browser_activate_show_menu)
+DEF_ACTION_CALLBACK (gth_browser_activate_set_filter)
#endif /* GTH_BROWSER_ACTIONS_CALLBACK_H */
diff --git a/gthumb/gth-browser-actions-entries.h b/gthumb/gth-browser-actions-entries.h
index 791f7cda..fb0107e6 100644
--- a/gthumb/gth-browser-actions-entries.h
+++ b/gthumb/gth-browser-actions-entries.h
@@ -82,6 +82,8 @@ static const GActionEntry gth_browser_actions[] = {
{ "file-list-select-all", gth_browser_activate_select_all },
{ "file-list-unselect-all", gth_browser_activate_unselect_all },
+
+ { "set-filter", gth_browser_activate_set_filter, "s" },
};
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 7ab74609..9a14997a 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -4346,14 +4346,44 @@ browser_gesture_pressed_cb (GtkGestureMultiPress *gesture,
}
+#define FILTERS_GROUP "filters"
+
+
static void
_gth_browser_update_filter_list (GthBrowser *browser)
{
- GList *filters;
+ GHashTable *accels;
+ GList *filters;
+ GList *scan;
+
+ accels = gth_window_get_accels_for_group (GTH_WINDOW (browser), FILTERS_GROUP);
+ gth_window_remove_shortcuts (GTH_WINDOW (browser), FILTERS_GROUP);
+
filters = gth_main_get_all_filters ();
+ for (scan = filters; scan; scan = scan->next) {
+ GthTest *test = scan->data;
+ GthShortcut *shortcut;
+
+ if (! gth_test_is_visible (test))
+ continue;
+
+ shortcut = gth_shortcut_new ("set-filter", g_variant_new_string (gth_test_get_id (test)));
+ shortcut->description = g_strdup (gth_test_get_display_name (test));
+ shortcut->context = GTH_SHORTCUT_CONTEXT_BROWSER;
+ shortcut->category = GTH_SHORTCUT_CATEGORY_FILTERS;
+ gth_shortcut_set_accelerator (shortcut, g_hash_table_lookup (accels,
shortcut->detailed_action));
+ shortcut->default_accelerator = g_strdup ("");
+
+ gth_window_add_removable_shortcut (GTH_WINDOW (browser),
+ FILTERS_GROUP,
+ shortcut);
+
+ gth_shortcut_free (shortcut);
+ }
gth_filterbar_set_filter_list (GTH_FILTERBAR (browser->priv->filterbar), filters);
_g_object_list_unref (filters);
+ g_hash_table_unref (accels);
}
diff --git a/gthumb/gth-filterbar.c b/gthumb/gth-filterbar.c
index 6ce5ed37..71834d61 100644
--- a/gthumb/gth-filterbar.c
+++ b/gthumb/gth-filterbar.c
@@ -233,6 +233,8 @@ _gth_filterbar_set_test (GthFilterbar *filterbar,
if (iter != NULL)
local_iter = *iter;
+ else if (test == NULL)
+ gtk_tree_model_get_iter_first (GTK_TREE_MODEL (filterbar->priv->model), &local_iter);
else if (! find_test_by_id (filterbar,
gth_test_get_id (test),
NULL,
diff --git a/gthumb/gth-main-default-types.c b/gthumb/gth-main-default-types.c
index c4db8bb8..8bb712a1 100644
--- a/gthumb/gth-main-default-types.c
+++ b/gthumb/gth-main-default-types.c
@@ -40,6 +40,7 @@ static GthShortcutCategory shortcut_categories[] = {
{ GTH_SHORTCUT_CATEGORY_NAVIGATION, N_("Navigation"), 12 },
{ GTH_SHORTCUT_CATEGORY_FILE_MANAGER, N_("File Manager"), 10 },
{ GTH_SHORTCUT_CATEGORY_VIEWER, N_("Viewer"), 20 },
+ { GTH_SHORTCUT_CATEGORY_FILTERS, N_("Filters"), 13 },
};
diff --git a/gthumb/gth-shortcut.h b/gthumb/gth-shortcut.h
index 4266e821..998bd3d7 100644
--- a/gthumb/gth-shortcut.h
+++ b/gthumb/gth-shortcut.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
#define GTH_SHORTCUT_CATEGORY_NAVIGATION "file-navigation"
#define GTH_SHORTCUT_CATEGORY_FILE_MANAGER "file-manager"
#define GTH_SHORTCUT_CATEGORY_VIEWER "file-viewer"
+#define GTH_SHORTCUT_CATEGORY_FILTERS "filters"
#define GTH_SHORTCUT_VIEWER_CONTEXT_ANY NULL
diff --git a/gthumb/gth-window.c b/gthumb/gth-window.c
index e1352e91..605f3f9d 100644
--- a/gthumb/gth-window.c
+++ b/gthumb/gth-window.c
@@ -1012,6 +1012,32 @@ gth_window_remove_shortcuts (GthWindow *window,
}
+GHashTable *
+gth_window_get_accels_for_group (GthWindow *window,
+ const char *group_name)
+{
+ GHashTable *map;
+ GPtrArray *shortcuts_v;
+ int i;
+
+ g_return_val_if_fail (GTH_IS_WINDOW (window), NULL);
+ g_return_val_if_fail (group_name != NULL, NULL);
+
+ map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ shortcuts_v = g_hash_table_lookup (window->priv->shortcut_groups, group_name);
+ if (shortcuts_v == NULL)
+ return map;
+
+ for (i = 0; i < shortcuts_v->len; i++) {
+ GthShortcut *shortcut = g_ptr_array_index (shortcuts_v, i);
+ g_hash_table_insert (map, g_strdup (shortcut->detailed_action), g_strdup
(shortcut->accelerator));
+ }
+
+ return map;
+}
+
+
gboolean
gth_window_can_change_shortcut (GthWindow *window,
const char *detailed_action,
diff --git a/gthumb/gth-window.h b/gthumb/gth-window.h
index 99e2ffa6..668bc348 100644
--- a/gthumb/gth-window.h
+++ b/gthumb/gth-window.h
@@ -148,6 +148,8 @@ void gth_window_add_removable_shortcut
GthShortcut *shortcut);
void gth_window_remove_shortcuts (GthWindow *window,
const char *group_name);
+GHashTable * gth_window_get_accels_for_group (GthWindow *window,
+ const char *group_name);
gboolean gth_window_can_change_shortcut (GthWindow *window,
const char *detailed_action,
int context,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]