[nautilus] Added custom shortcuts support to launch scripts
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Added custom shortcuts support to launch scripts
- Date: Wed, 11 Nov 2015 18:13:09 +0000 (UTC)
commit 9fe1335b6e68a77211b8ab1ca8a0d8bccfeb0711
Author: echo-devim <devim outlook it>
Date: Wed Nov 11 10:12:22 2015 -0800
Added custom shortcuts support to launch scripts
The problem is that Nautilus doesn't permit to map shortcuts to launch
the scripts in the scripts folder.
I added a function to read from a configuration file the shortcuts to
map the scripts.
When the scripts are added to the context menu they will have associated
the shortcuts written in the config file.
https://bugzilla.gnome.org/show_bug.cgi?id=757766
src/nautilus-files-view.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 969725b..dd40b14 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -120,6 +120,8 @@
#define MAX_MENU_LEVELS 5
#define TEMPLATE_LIMIT 30
+#define SHORTCUTS_PATH "/nautilus/scripts-accels"
+
/* Delay to show the duplicated label when creating a folder */
#define FILE_NAME_DUPLICATED_LABEL_TIMEOUT 500
@@ -161,6 +163,8 @@ static GdkAtom copied_files_atom;
static char *scripts_directory_uri = NULL;
static int scripts_directory_uri_length;
+static GHashTable *script_accels = NULL;
+
struct NautilusFilesViewDetails
{
/* Main components */
@@ -4611,6 +4615,7 @@ add_script_to_scripts_menus (NautilusFilesView *view,
ScriptLaunchParameters *launch_parameters;
GAction *action;
GMenuItem *menu_item;
+ const gchar *shortcut;
launch_parameters = script_launch_parameters_new (file, view);
@@ -4639,6 +4644,11 @@ add_script_to_scripts_menus (NautilusFilesView *view,
g_menu_append_item (menu, menu_item);
+ if (shortcut = g_hash_table_lookup (script_accels, name)) {
+ nautilus_application_add_accelerator (g_application_get_default(),
+ detailed_action_name, shortcut);
+ }
+
g_free (name);
g_free (action_name);
g_free (detailed_action_name);
@@ -4669,6 +4679,40 @@ directory_belongs_in_scripts_menu (const char *uri)
return TRUE;
}
+/* Expected format: accel script_name */
+static void
+nautilus_load_custom_accel_for_scripts (void)
+{
+ gchar *path, *contents;
+ gchar **lines, **result;
+ GError *error = NULL;
+ const int max_len = 100;
+ int i;
+
+ g_print ("loading map\n");
+
+ path = g_build_filename (g_get_user_config_dir (), SHORTCUTS_PATH, NULL);
+
+ if (g_file_get_contents (path, &contents, NULL, &error)) {
+ lines = g_strsplit (contents, "\n", -1);
+ for (i = 0; lines[i] && (strstr (lines[i], " ") > 0); i++) {
+ result = g_strsplit (lines[i], " ", 2);
+ g_hash_table_insert (script_accels,
+ g_strndup (result[1], max_len),
+ g_strndup (result[0], max_len));
+ g_strfreev (result);
+ }
+
+ g_free (contents);
+ g_strfreev (lines);
+ } else {
+ DEBUG ("Unable to open '%s', error message: %s", path, error->message);
+ g_clear_error (&error);
+ }
+
+ g_free (path);
+}
+
static GMenu *
update_directory_in_scripts_menu (NautilusFilesView *view,
NautilusDirectory *directory)
@@ -4686,6 +4730,12 @@ update_directory_in_scripts_menu (NautilusFilesView *view,
g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+ if (script_accels == NULL) {
+ script_accels = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_free);
+ nautilus_load_custom_accel_for_scripts ();
+ }
+
file_list = nautilus_directory_get_file_list (directory);
filtered = nautilus_file_list_filter_hidden (file_list, FALSE);
nautilus_file_list_free (file_list);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]