|
From: <sa...@us...> - 2007-04-04 03:50:24
|
Revision: 18229
http://svn.sourceforge.net/gaim/?rev=18229&view=rev
Author: sadrul
Date: 2007-04-03 20:50:24 -0700 (Tue, 03 Apr 2007)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/console/libgnt/gntkeys.c
trunk/console/libgnt/gntkeys.h
trunk/console/libgnt/gntutils.c
trunk/console/libgnt/gntutils.h
Modified: trunk/console/libgnt/gntkeys.c
===================================================================
--- trunk/console/libgnt/gntkeys.c 2007-04-01 23:59:40 UTC (rev 18228)
+++ trunk/console/libgnt/gntkeys.c 2007-04-04 03:50:24 UTC (rev 18229)
@@ -134,6 +134,28 @@
return g_hash_table_lookup(specials, name);
}
+typedef struct {
+ const char *name;
+ const char *key;
+} gntkey;
+
+static void
+get_key_name(gpointer key, gpointer value, gpointer data)
+{
+ gntkey *k = data;
+ if (k->name)
+ return;
+ if (g_utf8_collate(value, k->key) == 0)
+ k->name = key;
+}
+
+const char *gnt_key_lookup(const char *key)
+{
+ gntkey k = {NULL, key};
+ g_hash_table_foreach(specials, get_key_name, &k);
+ return k.name;
+}
+
/**
* The key-bindings will be saved in a tree. When a keystroke happens, GNT will
* find the sequence that matches a binding and return the length.
Modified: trunk/console/libgnt/gntkeys.h
===================================================================
--- trunk/console/libgnt/gntkeys.h 2007-04-01 23:59:40 UTC (rev 18228)
+++ trunk/console/libgnt/gntkeys.h 2007-04-04 03:50:24 UTC (rev 18229)
@@ -82,6 +82,7 @@
void gnt_init_keys(void);
void gnt_keys_refine(char *text);
const char *gnt_key_translate(const char *name);
+const char *gnt_key_lookup(const char *key);
void gnt_keys_add_combination(const char *path);
void gnt_keys_del_combination(const char *path);
Modified: trunk/console/libgnt/gntutils.c
===================================================================
--- trunk/console/libgnt/gntutils.c 2007-04-01 23:59:40 UTC (rev 18228)
+++ trunk/console/libgnt/gntutils.c 2007-04-04 03:50:24 UTC (rev 18229)
@@ -1,4 +1,5 @@
#include "gntutils.h"
+#include "gnttree.h"
#include <stdlib.h>
#include <string.h>
@@ -145,3 +146,47 @@
return continue_emission;
}
+typedef struct {
+ GHashTable *hash;
+ GntTree *tree;
+} BindingView;
+
+static void
+add_binding(gpointer key, gpointer value, gpointer data)
+{
+ BindingView *bv = data;
+ GntBindableActionParam *act = value;
+ const char *name = g_hash_table_lookup(bv->hash, act->action);
+ if (name && *name) {
+ const char *k = gnt_key_lookup(key);
+ if (!k)
+ k = key;
+ gnt_tree_add_row_after(bv->tree, (gpointer)k,
+ gnt_tree_create_row(bv->tree, k, name), NULL, NULL);
+ }
+}
+
+static void
+add_action(gpointer key, gpointer value, gpointer data)
+{
+ BindingView *bv = data;
+ g_hash_table_insert(bv->hash, value, key);
+}
+
+GntWidget *gnt_widget_bindings_view(GntWidget *widget)
+{
+ GntBindable *bind = GNT_BINDABLE(widget);
+ GntWidget *tree = gnt_tree_new_with_columns(2);
+ GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bind));
+ GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+ BindingView bv = {hash, GNT_TREE(tree)};
+
+ gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate);
+ g_hash_table_foreach(klass->actions, add_action, &bv);
+ g_hash_table_foreach(klass->bindings, add_binding, &bv);
+ gnt_tree_adjust_columns(bv.tree);
+ g_hash_table_destroy(hash);
+
+ return tree;
+}
+
Modified: trunk/console/libgnt/gntutils.h
===================================================================
--- trunk/console/libgnt/gntutils.h 2007-04-01 23:59:40 UTC (rev 18228)
+++ trunk/console/libgnt/gntutils.h 2007-04-04 03:50:24 UTC (rev 18229)
@@ -34,3 +34,8 @@
const GValue *handler_return,
gpointer dummy);
+/**
+ * Returns a GntTree populated with "key" -> "binding" for the widget.
+ */
+GntWidget *gnt_widget_bindings_view(GntWidget *widget);
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|