# HG changeset patch # User Eric Polino # Date 1180925362 0 # Node ID b242187b3591eb26ad598f2ffec45282f4689fe7 # Parent c609b4009dbe3c1b960c3ec67d86a97482a4e96a Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains. diff -r c609b4009dbe -r b242187b3591 finch/libgnt/gntwm.c --- a/finch/libgnt/gntwm.c Wed May 30 23:38:22 2007 +0000 +++ b/finch/libgnt/gntwm.c Mon Jun 04 02:49:22 2007 +0000 @@ -10,7 +10,9 @@ #include #include +#include "gntbutton.h" #include "gntwm.h" +#include "gntentry.h" #include "gntstyle.h" #include "gntmarshal.h" #include "gnt.h" @@ -59,6 +61,15 @@ static gboolean ignore_keys = FALSE; +typedef struct { + char * keys; /* Keystrokes being bound to the action */ + GntBindableClass * klass; /* Class of the object that's getting keys rebound */ + char * name; /* Name of the action ie:window-close, wm-quit, refresh-screen */ + void * params; /* Parameters to pass to the callback */ +} RebindInfo; + +RebindInfo * rebind_info; + static GList * g_list_bring_to_front(GList *list, gpointer data) { @@ -486,6 +497,131 @@ } static gboolean +free_rebind_info(){ + g_free(rebind_info->keys); + g_free(rebind_info->name); + g_free(rebind_info->params); + g_free(rebind_info); + +} + +static gboolean +help_for_widget_cancel_button_activate(GntBindable *bindable, gpointer data){ + free_rebind_info(); + + gnt_widget_destroy(GNT_WIDGET(data)); + return TRUE; +} + +static gboolean +help_for_widget_bind_button_activate(GntBindable *bindable, gpointer data){ + + /* This will be where the rebinding happens */ +/* if(rebind_info->keys){ + gnt_bindable_class_register_action(rebind_info->klass,rebind_info->name,NULL,rebind_info->keys,rebind_info->params); + } */ + + free_rebind_info(); + + gnt_widget_destroy(GNT_WIDGET(data)); + + return TRUE; +} + +static gboolean +help_for_widget_grab_key(GntBindable *bindable, const char *text, gpointer *data){ + + GntLabel *label = GNT_LABEL(data); + char *newText; + + if(text && *text){ + + fprintf(stderr,"%d %d\n",*text,text[1]); + + if(!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)){ + return FALSE; + } + + newText = g_strdup_printf("KEY: \"%s\"",text); + gnt_label_set_text(label,newText); + + g_free(newText); + + return TRUE; + } + return FALSE; +} +static void +help_for_widget_activate(GntBindable *bindable, gpointer widget){ + + + GntTree * tree = GNT_TREE(bindable); + + GntWidget *vbox = gnt_box_new(FALSE,TRUE); + + GntWidget *label; + const char * widgetName = g_type_name(G_OBJECT_TYPE(widget)); + + GntWidget *key_label; + + GntWidget *bind_button, *cancel_button; + GntWidget *button_box; + + GntWidget *win = gnt_window_new(); + GList * currentRowData,*itr; + char * tmp; + + rebind_info = (RebindInfo*)malloc(sizeof(RebindInfo)); + rebind_info->keys = NULL; + rebind_info->klass = GNT_BINDABLE_GET_CLASS(widget); + currentRowData = gnt_tree_get_selection_text_list(tree); + rebind_info->name = g_list_nth_data(currentRowData,1); + rebind_info->params = NULL; + + itr = currentRowData; + while(itr){ + g_free(itr->data); + itr = itr->next; + } + g_list_free(currentRowData); + + gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID); + + gnt_box_set_title(GNT_BOX(win),"Key Capture"); + + tmp = g_strdup_printf("Type the new bindings for %s in a %s.",rebind_info->name,widgetName); + label = gnt_label_new(tmp); + g_free(tmp); + gnt_box_add_widget(GNT_BOX(vbox),label); + + key_label = gnt_label_new("KEY:\"\""); + gnt_widget_set_name(key_label,"keystroke"); + gnt_box_add_widget(GNT_BOX(vbox),key_label); + + g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(help_for_widget_grab_key),key_label); + + button_box = gnt_box_new(FALSE,FALSE); + + bind_button = gnt_button_new("BIND"); + gnt_widget_set_name(bind_button,"bind"); + gnt_box_add_widget(GNT_BOX(button_box), bind_button); + + cancel_button = gnt_button_new("Cancel"); + gnt_widget_set_name(cancel_button,"cancel"); + gnt_box_add_widget(GNT_BOX(button_box),cancel_button); + + g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(help_for_widget_bind_button_activate),win); + g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(help_for_widget_cancel_button_activate),win); + + + gnt_box_add_widget(GNT_BOX(vbox),button_box); + + gnt_box_add_widget(GNT_BOX(win),vbox); + gnt_widget_show(win); + +} + +static gboolean help_for_widget(GntBindable *bindable, GList *null) { GntWM *wm = GNT_WM(bindable); @@ -501,6 +637,8 @@ active = GNT_BOX(widget)->active; tree = gnt_widget_bindings_view(active); + g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(help_for_widget_activate), active); + win = gnt_window_new(); title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(active))); gnt_box_set_title(GNT_BOX(win), title);