changeset 15987:7adb832667fd

merge of 'a9451570b92d0f29b2e120ce02c4301e9ed3ced6' and 'de18d679886cc754f6e5eb54eea8f21cfe64284f'
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 04 Apr 2007 03:50:15 +0000
parents 0315b014741b (current diff) 2c81ebc7bf0b (diff)
children e05e5b148723
files
diffstat 4 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntkeys.c	Tue Apr 03 06:30:22 2007 +0000
+++ b/finch/libgnt/gntkeys.c	Wed Apr 04 03:50:15 2007 +0000
@@ -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.
--- a/finch/libgnt/gntkeys.h	Tue Apr 03 06:30:22 2007 +0000
+++ b/finch/libgnt/gntkeys.h	Wed Apr 04 03:50:15 2007 +0000
@@ -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);
--- a/finch/libgnt/gntutils.c	Tue Apr 03 06:30:22 2007 +0000
+++ b/finch/libgnt/gntutils.c	Wed Apr 04 03:50:15 2007 +0000
@@ -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;
+}
+
--- a/finch/libgnt/gntutils.h	Tue Apr 03 06:30:22 2007 +0000
+++ b/finch/libgnt/gntutils.h	Wed Apr 04 03:50:15 2007 +0000
@@ -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);
+