On Fr, 03.04.2009 14:00, Alexander Larsson wrote: >Is there some way we can get told of when the user changes an >accelerator so that we can queue a writeout of the file maybe? Unfortunately, not really. There's a signal for the change of the accelerator map, but I don't know of any way to determine whether this is a manual change or a programmatic one. So, during startup, dozen of signal emissions occur. Emissions also occur from time to time during normal usage, for example when opening a new tab in browser mode. Attached is a modified patch that saves the accelerator map for every batch of signal emissions in an idle callback. As said above, it will happen from time to time even without a manual change of the keyboard shortcuts, though. Holger
From a3bc9babf79c40673c8e916c74d129966ced21ab Mon Sep 17 00:00:00 2001
From: Holger Berndt <berndth gmx de>
Date: Sat, 28 Mar 2009 23:14:35 +0100
Subject: [PATCH] save and restore custom keyboard shortcuts
---
libnautilus-private/nautilus-file-utilities.c | 21 +++++++++++++
libnautilus-private/nautilus-file-utilities.h | 2 +
src/nautilus-main.c | 38 +++++++++++++++++++++++++
3 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index b3ccc53..755598a 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -111,6 +111,27 @@ nautilus_get_user_directory (void)
return user_directory;
}
+/**
+ * nautilus_get_accel_map_file:
+ *
+ * Get the path for the filename containing nautilus accelerator map.
+ * The filename need not exist.
+ *
+ * Return value: the filename path, or NULL if the home directory could not be found
+ **/
+char *
+nautilus_get_accel_map_file (void)
+{
+ const gchar *home;
+
+ home = g_get_home_dir();
+ if (home != NULL) {
+ return g_build_filename (home, ".gnome2/accels/nautilus", NULL);
+ }
+
+ return NULL;
+}
+
typedef struct {
char *type;
char *path;
diff --git a/libnautilus-private/nautilus-file-utilities.h b/libnautilus-private/nautilus-file-utilities.h
index 245d106..53c397d 100644
--- a/libnautilus-private/nautilus-file-utilities.h
+++ b/libnautilus-private/nautilus-file-utilities.h
@@ -95,4 +95,6 @@ GFile * nautilus_find_existing_uri_in_hierarchy (GFile *location);
GFile *
nautilus_find_file_insensitive (GFile *parent, const gchar *name);
+char * nautilus_get_accel_map_file (void);
+
#endif /* NAUTILUS_FILE_UTILITIES_H */
diff --git a/src/nautilus-main.c b/src/nautilus-main.c
index b9b1fd8..fe02e65 100644
--- a/src/nautilus-main.c
+++ b/src/nautilus-main.c
@@ -50,6 +50,7 @@
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-lib-self-check-functions.h>
#include <libnautilus-private/nautilus-icon-names.h>
+#include <libnautilus-private/nautilus-file-utilities.h>
#include <libxml/parser.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
@@ -64,6 +65,7 @@
/* Keeps track of everyone who wants the main event loop kept active */
static GSList *event_loop_registrants;
+static gboolean save_of_accel_map_requested = FALSE;
static gboolean
is_event_loop_needed (void)
@@ -298,6 +300,34 @@ setup_debug_log (void)
setup_debug_log_glog ();
}
+
+static
+gboolean save_accel_map_callback (gpointer data)
+{
+ if (save_of_accel_map_requested) {
+ char *accel_map_filename;
+ accel_map_filename = nautilus_get_accel_map_file ();
+ if (accel_map_filename) {
+ gtk_accel_map_save (accel_map_filename);
+ g_free (accel_map_filename);
+ }
+ save_of_accel_map_requested = FALSE;
+ }
+
+ return FALSE;
+}
+
+static
+void accel_map_changed_callback (GtkAccelMap *object, gchar *accel_path,
+ guint accel_key, GdkModifierType accel_mods,
+ gpointer user_data)
+{
+ if (!save_of_accel_map_requested) {
+ save_of_accel_map_requested = TRUE;
+ g_idle_add (save_accel_map_callback, FALSE);
+ }
+}
+
int
main (int argc, char *argv[])
{
@@ -319,6 +349,7 @@ main (int argc, char *argv[])
GPtrArray *uris_array;
GError *error;
int i;
+ char *accel_map_filename;
const GOptionEntry options[] = {
#ifndef NAUTILUS_OMIT_SELF_CHECK
@@ -492,6 +523,13 @@ main (int argc, char *argv[])
uris);
g_strfreev (uris);
+ accel_map_filename = nautilus_get_accel_map_file ();
+ if (accel_map_filename) {
+ gtk_accel_map_load (accel_map_filename);
+ g_free (accel_map_filename);
+ }
+ g_signal_connect (gtk_accel_map_get (), "changed", G_CALLBACK (accel_map_changed_callback), NULL);
+
if (is_event_loop_needed ()) {
gtk_main ();
}
--
1.5.6.3
Attachment:
signature.asc
Description: PGP signature