comparison finch/libgnt/gntkeys.c @ 15979:2c81ebc7bf0b

Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 04 Apr 2007 03:47:13 +0000
parents 0e3a8505ebbe
children ca463cecd432
comparison
equal deleted inserted replaced
15978:2a82bc8d57f7 15979:2c81ebc7bf0b
132 const char *gnt_key_translate(const char *name) 132 const char *gnt_key_translate(const char *name)
133 { 133 {
134 return g_hash_table_lookup(specials, name); 134 return g_hash_table_lookup(specials, name);
135 } 135 }
136 136
137 typedef struct {
138 const char *name;
139 const char *key;
140 } gntkey;
141
142 static void
143 get_key_name(gpointer key, gpointer value, gpointer data)
144 {
145 gntkey *k = data;
146 if (k->name)
147 return;
148 if (g_utf8_collate(value, k->key) == 0)
149 k->name = key;
150 }
151
152 const char *gnt_key_lookup(const char *key)
153 {
154 gntkey k = {NULL, key};
155 g_hash_table_foreach(specials, get_key_name, &k);
156 return k.name;
157 }
158
137 /** 159 /**
138 * The key-bindings will be saved in a tree. When a keystroke happens, GNT will 160 * The key-bindings will be saved in a tree. When a keystroke happens, GNT will
139 * find the sequence that matches a binding and return the length. 161 * find the sequence that matches a binding and return the length.
140 * A sequence should not be a prefix of another sequence. If it is, then only 162 * A sequence should not be a prefix of another sequence. If it is, then only
141 * the shortest one will be processed. If we want to change that, we will need 163 * the shortest one will be processed. If we want to change that, we will need