[gthumb: 7/23] work queues: added keyboard accelerators to view the queues
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 7/23] work queues: added keyboard accelerators to view the queues
- Date: Sun, 4 Mar 2012 17:55:49 +0000 (UTC)
commit b8ea54006fb2419238bebc17476a176fdf0d43b5
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Feb 19 15:07:15 2012 +0100
work queues: added keyboard accelerators to view the queues
Ctrl+n to view the queue n with n in 1,2,3
extensions/work_queues/actions.c | 40 ++++++++++++++++
extensions/work_queues/actions.h | 3 +
extensions/work_queues/callbacks.c | 91 +++++++++++++++++++++++++++++++----
extensions/work_queues/callbacks.h | 3 +-
extensions/work_queues/main.c | 1 +
5 files changed, 126 insertions(+), 12 deletions(-)
---
diff --git a/extensions/work_queues/actions.c b/extensions/work_queues/actions.c
index 109bb90..bba144e 100644
--- a/extensions/work_queues/actions.c
+++ b/extensions/work_queues/actions.c
@@ -22,3 +22,43 @@
#include <config.h>
#include <gthumb.h>
+
+
+static void
+gth_browser_activate_action_show_work_queue (GthBrowser *browser,
+ int n_queue)
+{
+ char *uri;
+ GFile *location;
+
+ uri = g_strdup_printf ("queue:///%d", n_queue);
+ location = g_file_new_for_uri (uri);
+ gth_browser_load_location (browser, location);
+
+ g_free (uri);
+ g_object_unref (location);
+}
+
+
+void
+gth_browser_activate_action_go_queue_1 (GtkAction *action,
+ GthBrowser *browser)
+{
+ gth_browser_activate_action_show_work_queue (browser, 1);
+}
+
+
+void
+gth_browser_activate_action_go_queue_2 (GtkAction *action,
+ GthBrowser *browser)
+{
+ gth_browser_activate_action_show_work_queue (browser, 2);
+}
+
+
+void
+gth_browser_activate_action_go_queue_3 (GtkAction *action,
+ GthBrowser *browser)
+{
+ gth_browser_activate_action_show_work_queue (browser, 3);
+}
diff --git a/extensions/work_queues/actions.h b/extensions/work_queues/actions.h
index b4ef1e1..72ca7fb 100644
--- a/extensions/work_queues/actions.h
+++ b/extensions/work_queues/actions.h
@@ -26,5 +26,8 @@
#define DEFINE_ACTION(x) void x (GtkAction *action, gpointer data);
+DEFINE_ACTION(gth_browser_activate_action_go_queue_1)
+DEFINE_ACTION(gth_browser_activate_action_go_queue_2)
+DEFINE_ACTION(gth_browser_activate_action_go_queue_3)
#endif /* ACTIONS_H */
diff --git a/extensions/work_queues/callbacks.c b/extensions/work_queues/callbacks.c
index 940eafa..498de18 100644
--- a/extensions/work_queues/callbacks.c
+++ b/extensions/work_queues/callbacks.c
@@ -3,7 +3,7 @@
/*
* GThumb
*
- * Copyright (C) 2009 Free Software Foundation, Inc.
+ * Copyright (C) 2012 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,6 +29,76 @@
#include "gth-queue-manager.h"
+#define BROWSER_DATA_KEY "work-queues-browser-data"
+
+
+static const char *fixed_ui_info =
+"<ui>"
+" <accelerator action=\"Go_Queue_1\" />"
+" <accelerator action=\"Go_Queue_2\" />"
+" <accelerator action=\"Go_Queue_3\" />"
+"</ui>";
+
+
+static GtkActionEntry work_queues_action_entries[] = {
+ { "Go_Queue_1", NULL,
+ NULL, "<control>1",
+ NULL,
+ G_CALLBACK (gth_browser_activate_action_go_queue_1) },
+ { "Go_Queue_2", NULL,
+ NULL, "<control>2",
+ NULL,
+ G_CALLBACK (gth_browser_activate_action_go_queue_2) },
+ { "Go_Queue_3", NULL,
+ NULL, "<control>3",
+ NULL,
+ G_CALLBACK (gth_browser_activate_action_go_queue_3) }
+
+};
+static guint work_queues_action_entries_size = G_N_ELEMENTS (work_queues_action_entries);
+
+
+typedef struct {
+ GthBrowser *browser;
+ GtkActionGroup *actions;
+} BrowserData;
+
+
+static void
+browser_data_free (BrowserData *data)
+{
+ g_free (data);
+}
+
+
+void
+work_queues__gth_browser_construct_cb (GthBrowser *browser)
+{
+ BrowserData *data;
+ GError *error = NULL;
+
+ g_return_if_fail (GTH_IS_BROWSER (browser));
+
+ data = g_new0 (BrowserData, 1);
+ g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
+
+ data->browser = browser;
+
+ data->actions = gtk_action_group_new ("Work Queues Actions");
+ gtk_action_group_set_translation_domain (data->actions, NULL);
+ gtk_action_group_add_actions (data->actions,
+ work_queues_action_entries,
+ work_queues_action_entries_size,
+ browser);
+ gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->actions, 0);
+
+ if (! gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error)) {
+ g_message ("building menus failed: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+
static void
gth_browser_activate_action_add_to_work_queue (GthBrowser *browser,
int n_queue)
@@ -62,16 +132,15 @@ work_queues__gth_browser_file_list_key_press_cb (GthBrowser *browser,
guint modifiers;
modifiers = gtk_accelerator_get_default_mod_mask ();
- if ((event->state & modifiers) != GDK_MOD1_MASK)
- return NULL;
-
- switch (gdk_keyval_to_lower (event->keyval)) {
- case GDK_KEY_1:
- case GDK_KEY_2:
- case GDK_KEY_3:
- gth_browser_activate_action_add_to_work_queue (browser, gdk_keyval_to_lower (event->keyval) - GDK_KEY_1 + 1);
- result = GINT_TO_POINTER (1);
- break;
+ if ((event->state & modifiers) == GDK_MOD1_MASK) {
+ switch (gdk_keyval_to_lower (event->keyval)) {
+ case GDK_KEY_1:
+ case GDK_KEY_2:
+ case GDK_KEY_3:
+ gth_browser_activate_action_add_to_work_queue (browser, gdk_keyval_to_lower (event->keyval) - GDK_KEY_1 + 1);
+ result = GINT_TO_POINTER (1);
+ break;
+ }
}
return result;
diff --git a/extensions/work_queues/callbacks.h b/extensions/work_queues/callbacks.h
index c650ab5..fcb6970 100644
--- a/extensions/work_queues/callbacks.h
+++ b/extensions/work_queues/callbacks.h
@@ -3,7 +3,7 @@
/*
* GThumb
*
- * Copyright (C) 2009 Free Software Foundation, Inc.
+ * Copyright (C) 2012 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
#include <gthumb.h>
+void work_queues__gth_browser_construct_cb (GthBrowser *browser);
gpointer work_queues__gth_browser_file_list_key_press_cb (GthBrowser *browser,
GdkEventKey *event);
diff --git a/extensions/work_queues/main.c b/extensions/work_queues/main.c
index 9185a5c..66b8844 100644
--- a/extensions/work_queues/main.c
+++ b/extensions/work_queues/main.c
@@ -31,6 +31,7 @@ G_MODULE_EXPORT void
gthumb_extension_activate (void)
{
gth_main_register_file_source (GTH_TYPE_FILE_SOURCE_WORK_QUEUES);
+ gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (work_queues__gth_browser_construct_cb), NULL);
gth_hook_add_callback ("gth-browser-file-list-key-press", 10, G_CALLBACK (work_queues__gth_browser_file_list_key_press_cb), NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]