Re: [tin 1.7.x] 'unbinding' keys

Michael Bienia <[email protected]>
Newsgroups gmane.network.tin.devel
Message-ID <[email protected]>
On 2005-06-29 16:17:14 +0200, Urs Janßen wrote:
> one can not 'unbind' the actions from the defauilt keys, e.g.
> ShellEscape	"
> in .tin/keymap still allows the default of '!' as ShellEscape key.
> as ppl. might like disable certain functions (e.g. QuitTin or
> SelectQuitNoWrite) by binding them to a 'safer' key (like '^') this
> isn't very usefull. we might also need some wey of completly disable
> certain functions by bimnding them to an 'empty' key like:
> QuitTin		EMPTY
> 
> comments? code? ,-)

The attached patch adds a check to keymap.c:add_key() to also check if a
function has already a assigned key before adding the default one. This
should prevent the first problem.

For the second problem I might have an idea but I haven't tested yet if
it is working: to disable a function we could assign a key,
which can't be pressed, to this function. This would prevent that a
default key is assigned to this function and therefore disabling it.
Looking at the table at the beginning of keymap.h, there aren't much
possiblities for such a key. Perhaps '\0' is working.

Michael
patch-20050701.diff (text/plain, 1.9 KB)
 keymap.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
diff -Nurp tin-1.7.9/src/keymap.c tin-1.7.9.new/src/keymap.c
--- tin-1.7.9/src/keymap.c	2005-06-28 10:31:21.000000000 +0200
+++ tin-1.7.9.new/src/keymap.c	2005-07-01 19:09:04.355518064 +0200
@@ -51,7 +51,7 @@ static void add_default_key(struct keyli
 static void add_global_keys(struct keylist *keys);
 static void free_keylist(struct keylist *keys);
 static void upgrade_keymap_file(char *old);
-static t_bool add_key(struct keylist *keys, char key, t_function func, t_bool overwrite);
+static t_bool add_key(struct keylist *keys, char key, t_function func, t_bool default_key);
 static t_bool process_keys(t_function func, const char *keys, struct keylist *kl);
 static t_bool process_mapping(char *keyname, char *keys);
 
@@ -124,6 +124,7 @@ func_to_key(
 
 /*
  * adds a key to a keylist
+ * default_key: TRUE if a default key should be added
  * returns TRUE if the key was succesfully added else FALSE
  */
 static t_bool
@@ -131,11 +132,15 @@ add_key(
 	struct keylist *keys,
 	char key,
 	t_function func,
-	t_bool overwrite)
+	t_bool default_key)
 {
 	size_t i;
 	struct keynode *entry = NULL;
 
+	/* check if the function has already a key assigned before we add the default one */
+	if (default_key && func_to_key(func, *keys) != '?')
+		return FALSE;
+
 	/* is a function already associated with this key */
 	for (i = 0; i < keys->used; i++) {
 		if (keys->list[i].key == key)
@@ -143,7 +148,7 @@ add_key(
 	}
 
 	if (entry != NULL) {
-		if (overwrite) {
+		if (!default_key) {
 			entry->function = func;
 			return TRUE;
 		} else
@@ -174,7 +179,7 @@ add_default_key(
 	char key,
 	t_function func)
 {
-	add_key(keys, key, func, FALSE);
+	add_key(keys, key, func, TRUE);
 }
 
 
@@ -421,7 +426,7 @@ process_keys(
 		}
 
 		if (!error)
-			add_key(kl, key, func, TRUE);
+			add_key(kl, key, func, FALSE);
 
 		keydef = strtok(NULL, KEYSEPS);
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.