Mercurial > pidgin
annotate finch/libgnt/gntbindable.c @ 17931:3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Added: If a bindinglist already exists, it isn't brought up again.
Deprecated gnt_widget_bindings_view out of gntutils and moved it to gntbindable
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Fri, 08 Jun 2007 04:14:56 +0000 |
parents | 8410511f4dbb |
children | 15988e2bd270 |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
22 |
17931
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
23 #include <string.h> |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
24 |
15817 | 25 #include "gntbindable.h" |
26 #include "gntstyle.h" | |
27 #include "gnt.h" | |
28 #include "gntutils.h" | |
17931
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
29 #include "gnttextview.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
30 #include "gnttree.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
31 #include "gntbox.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
32 #include "gntbutton.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
33 #include "gntwindow.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
34 #include "gntlabel.h" |
15817 | 35 |
36 static GObjectClass *parent_class = NULL; | |
37 | |
17931
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
38 static struct |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
39 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
40 char * okeys; /* Old keystrokes */ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
41 char * keys; /* New Keystrokes being bound to the action */ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
42 GntBindableClass * klass; /* Class of the object that's getting keys rebound */ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
43 char * name; /* The name of the action */ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
44 GList * params; /* The list of paramaters */ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
45 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
46 } rebind_info = {NULL,NULL,NULL,NULL,NULL}; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
47 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
48 static void |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
49 gnt_bindable_free_rebind_info() |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
50 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
51 g_free(rebind_info.name); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
52 g_free(rebind_info.keys); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
53 g_free(rebind_info.okeys); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
54 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
55 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
56 static gboolean |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
57 gnt_bindable_rebinding_cancel(GntBindable *bindable, gpointer data) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
58 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
59 gnt_bindable_free_rebind_info(); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
60 gnt_widget_destroy(GNT_WIDGET(data)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
61 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
62 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
63 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
64 static gboolean |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
65 gnt_bindable_rebinding_rebind(GntBindable *bindable, gpointer data) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
66 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
67 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
68 if(rebind_info.keys){ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
69 gnt_bindable_register_binding(rebind_info.klass, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
70 NULL, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
71 rebind_info.okeys, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
72 rebind_info.params); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
73 gnt_bindable_register_binding(rebind_info.klass, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
74 rebind_info.name, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
75 rebind_info.keys, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
76 rebind_info.params); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
77 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
78 gnt_bindable_free_rebind_info(); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
79 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
80 gnt_widget_destroy(GNT_WIDGET(data)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
81 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
82 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
83 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
84 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
85 static gboolean |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
86 gnt_bindable_rebinding_grab_key(GntBindable *bindable, const char *text, gpointer *data) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
87 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
88 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
89 GntTextView *textview= GNT_TEXT_VIEW(data); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
90 char *new_text; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
91 const char *tmp; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
92 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
93 if(text && *text){ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
94 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
95 if(!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)){ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
96 return FALSE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
97 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
98 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
99 tmp = gnt_key_lookup(text); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
100 new_text = g_strdup_printf("KEY: \"%s\"",tmp); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
101 gnt_text_view_clear(textview); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
102 gnt_text_view_append_text_with_flags(textview,new_text,GNT_TEXT_FLAG_NORMAL); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
103 g_free(new_text); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
104 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
105 g_free(rebind_info.keys); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
106 rebind_info.keys = g_strdup(text); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
107 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
108 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
109 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
110 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
111 return FALSE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
112 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
113 static void |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
114 gnt_bindable_rebinding_activate(GntBindable *data, gpointer bindable) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
115 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
116 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
117 GntTree * tree = GNT_TREE(data); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
118 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
119 GntWidget *vbox = gnt_box_new(FALSE,TRUE); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
120 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
121 GntWidget *label; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
122 const char * widget_name = g_type_name(G_OBJECT_TYPE(bindable)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
123 char * keys; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
124 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
125 GntWidget *key_textview; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
126 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
127 GntWidget *bind_button, *cancel_button; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
128 GntWidget *button_box; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
129 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
130 GntWidget *win = gnt_window_new(); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
131 GList * current_row_data,*itr; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
132 char * tmp; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
133 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
134 rebind_info.klass = GNT_BINDABLE_GET_CLASS(bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
135 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
136 current_row_data = gnt_tree_get_selection_text_list(tree); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
137 rebind_info.name = g_strdup(g_list_nth_data(current_row_data,1)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
138 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
139 keys = gnt_tree_get_selection_data(tree); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
140 rebind_info.okeys = g_strdup(gnt_key_translate(keys)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
141 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
142 rebind_info.params = NULL; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
143 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
144 itr = current_row_data; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
145 while(itr){ |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
146 g_free(itr->data); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
147 itr = itr->next; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
148 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
149 g_list_free(current_row_data); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
150 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
151 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
152 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
153 gnt_box_set_title(GNT_BOX(win),"Key Capture"); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
154 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
155 tmp = g_strdup_printf("Type the new bindings for %s in a %s.",rebind_info.name,widget_name); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
156 label = gnt_label_new(tmp); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
157 g_free(tmp); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
158 gnt_box_add_widget(GNT_BOX(vbox),label); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
159 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
160 tmp = g_strdup_printf("KEY: \"%s\"",keys); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
161 key_textview = gnt_text_view_new(); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
162 gnt_widget_set_size(key_textview,key_textview->priv.x,2); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
163 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(key_textview),tmp,GNT_TEXT_FLAG_NORMAL); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
164 g_free(tmp); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
165 gnt_widget_set_name(key_textview,"keystroke"); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
166 gnt_box_add_widget(GNT_BOX(vbox),key_textview); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
167 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
168 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(gnt_bindable_rebinding_grab_key),key_textview); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
169 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
170 button_box = gnt_box_new(FALSE,FALSE); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
171 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
172 bind_button = gnt_button_new("BIND"); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
173 gnt_widget_set_name(bind_button,"bind"); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
174 gnt_box_add_widget(GNT_BOX(button_box), bind_button); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
175 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
176 cancel_button = gnt_button_new("Cancel"); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
177 gnt_widget_set_name(cancel_button,"cancel"); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
178 gnt_box_add_widget(GNT_BOX(button_box),cancel_button); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
179 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
180 g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(gnt_bindable_rebinding_rebind),win); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
181 g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(gnt_bindable_rebinding_cancel),win); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
182 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
183 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
184 gnt_box_add_widget(GNT_BOX(vbox),button_box); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
185 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
186 gnt_box_add_widget(GNT_BOX(win),vbox); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
187 gnt_widget_show(win); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
188 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
189 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
190 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
191 typedef struct { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
192 GHashTable *hash; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
193 GntTree *tree; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
194 } BindingView; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
195 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
196 static void |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
197 add_binding(gpointer key, gpointer value, gpointer data) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
198 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
199 BindingView *bv = data; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
200 GntBindableActionParam *act = value; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
201 const char *name = g_hash_table_lookup(bv->hash, act->action); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
202 if (name && *name) { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
203 const char *k = gnt_key_lookup(key); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
204 if (!k) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
205 k = key; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
206 gnt_tree_add_row_after(bv->tree, (gpointer)k, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
207 gnt_tree_create_row(bv->tree, k, name), NULL, NULL); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
208 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
209 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
210 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
211 static void |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
212 add_action(gpointer key, gpointer value, gpointer data) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
213 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
214 BindingView *bv = data; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
215 g_hash_table_insert(bv->hash, value, key); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
216 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
217 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
218 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
219 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
220 |
15817 | 221 static void |
222 gnt_bindable_class_init(GntBindableClass *klass) | |
223 { | |
224 parent_class = g_type_class_peek_parent(klass); | |
225 | |
226 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
227 (GDestroyNotify)gnt_bindable_action_free); | |
228 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
229 (GDestroyNotify)gnt_bindable_action_param_free); | |
230 | |
231 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
232 GNTDEBUG; | |
233 } | |
234 | |
235 static gpointer | |
236 bindable_clone(GntBindableAction *action) | |
237 { | |
238 GntBindableAction *ret = g_new0(GntBindableAction, 1); | |
239 ret->name = g_strdup(action->name); | |
240 ret->u = action->u; | |
241 return ret; | |
242 } | |
243 | |
244 static gpointer | |
245 binding_clone(GntBindableActionParam *param) | |
246 { | |
247 GntBindableActionParam *p = g_new0(GntBindableActionParam, 1); | |
248 p->list = g_list_copy(param->list); | |
249 p->action = param->action; | |
250 return p; | |
251 } | |
252 | |
253 static void | |
254 duplicate_hashes(GntBindableClass *klass) | |
255 { | |
256 /* Duplicate the bindings from parent class */ | |
257 if (klass->actions) { | |
258 klass->actions = g_hash_table_duplicate(klass->actions, g_str_hash, | |
259 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free, | |
260 (GDupFunc)g_strdup, (GDupFunc)bindable_clone); | |
261 klass->bindings = g_hash_table_duplicate(klass->bindings, g_str_hash, | |
262 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_param_free, | |
263 (GDupFunc)g_strdup, (GDupFunc)binding_clone); | |
264 } else { | |
265 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
266 (GDestroyNotify)gnt_bindable_action_free); | |
267 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
268 (GDestroyNotify)gnt_bindable_action_param_free); | |
269 } | |
270 | |
271 GNTDEBUG; | |
272 } | |
273 | |
274 /****************************************************************************** | |
275 * GntBindable API | |
276 *****************************************************************************/ | |
277 GType | |
278 gnt_bindable_get_gtype(void) | |
279 { | |
280 static GType type = 0; | |
281 | |
282 if(type == 0) { | |
283 static const GTypeInfo info = { | |
284 sizeof(GntBindableClass), | |
285 (GBaseInitFunc)duplicate_hashes, /* base_init */ | |
286 NULL, /* base_finalize */ | |
287 (GClassInitFunc)gnt_bindable_class_init, | |
288 NULL, | |
289 NULL, /* class_data */ | |
290 sizeof(GntBindable), | |
291 0, /* n_preallocs */ | |
292 NULL, /* instance_init */ | |
293 NULL /* value_table */ | |
294 }; | |
295 | |
296 type = g_type_register_static(G_TYPE_OBJECT, | |
297 "GntBindable", | |
298 &info, G_TYPE_FLAG_ABSTRACT); | |
299 } | |
300 | |
301 return type; | |
302 } | |
303 | |
304 /** | |
305 * Key Remaps | |
306 */ | |
307 const char * | |
308 gnt_bindable_remap_keys(GntBindable *bindable, const char *text) | |
309 { | |
310 const char *remap = NULL; | |
311 GType type = G_OBJECT_TYPE(bindable); | |
312 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); | |
313 | |
314 if (klass->remaps == NULL) | |
315 { | |
316 klass->remaps = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
317 gnt_styles_get_keyremaps(type, klass->remaps); | |
318 } | |
319 | |
320 remap = g_hash_table_lookup(klass->remaps, text); | |
321 | |
322 return (remap ? remap : text); | |
323 } | |
324 | |
325 /** | |
326 * Actions and Bindings | |
327 */ | |
328 gboolean | |
329 gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...) | |
330 { | |
331 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); | |
332 GList *list = NULL; | |
333 va_list args; | |
334 GntBindableAction *action; | |
335 void *p; | |
336 | |
337 va_start(args, name); | |
338 while ((p = va_arg(args, void *)) != NULL) | |
339 list = g_list_append(list, p); | |
340 va_end(args); | |
341 | |
342 action = g_hash_table_lookup(klass->actions, name); | |
343 if (action && action->u.action) { | |
344 return action->u.action(bindable, list); | |
345 } | |
346 return FALSE; | |
347 } | |
348 | |
349 gboolean | |
350 gnt_bindable_perform_action_key(GntBindable *bindable, const char *keys) | |
351 { | |
352 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); | |
353 GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys); | |
354 | |
355 if (param && param->action) { | |
356 if (param->list) | |
357 return param->action->u.action(bindable, param->list); | |
358 else | |
359 return param->action->u.action_noparam(bindable); | |
360 } | |
361 return FALSE; | |
362 } | |
363 | |
364 static void | |
365 register_binding(GntBindableClass *klass, const char *name, const char *trigger, GList *list) | |
366 { | |
367 GntBindableActionParam *param; | |
368 GntBindableAction *action; | |
369 | |
370 if (name == NULL || *name == '\0') { | |
371 g_hash_table_remove(klass->bindings, (char*)trigger); | |
372 gnt_keys_del_combination(trigger); | |
373 return; | |
374 } | |
375 | |
376 action = g_hash_table_lookup(klass->actions, name); | |
377 if (!action) { | |
378 g_printerr("GntWidget: Invalid action name %s for %s\n", | |
379 name, g_type_name(G_OBJECT_CLASS_TYPE(klass))); | |
380 if (list) | |
381 g_list_free(list); | |
382 return; | |
383 } | |
384 | |
385 param = g_new0(GntBindableActionParam, 1); | |
386 param->action = action; | |
387 param->list = list; | |
388 g_hash_table_replace(klass->bindings, g_strdup(trigger), param); | |
389 gnt_keys_add_combination(trigger); | |
390 } | |
391 | |
392 void gnt_bindable_register_binding(GntBindableClass *klass, const char *name, | |
393 const char *trigger, ...) | |
394 { | |
395 GList *list = NULL; | |
396 va_list args; | |
397 void *data; | |
398 | |
399 va_start(args, trigger); | |
400 while ((data = va_arg(args, void *))) { | |
401 list = g_list_append(list, data); | |
402 } | |
403 va_end(args); | |
404 | |
405 register_binding(klass, name, trigger, list); | |
406 } | |
407 | |
408 void gnt_bindable_class_register_action(GntBindableClass *klass, const char *name, | |
409 GntBindableActionCallback callback, const char *trigger, ...) | |
410 { | |
411 void *data; | |
412 va_list args; | |
413 GntBindableAction *action = g_new0(GntBindableAction, 1); | |
414 GList *list; | |
415 | |
416 action->name = g_strdup(name); | |
417 action->u.action = callback; | |
418 | |
419 g_hash_table_replace(klass->actions, g_strdup(name), action); | |
420 | |
421 if (trigger && *trigger) { | |
422 list = NULL; | |
423 va_start(args, trigger); | |
424 while ((data = va_arg(args, void *))) { | |
425 list = g_list_append(list, data); | |
426 } | |
427 va_end(args); | |
428 | |
429 register_binding(klass, name, trigger, list); | |
430 } | |
431 } | |
432 | |
433 void gnt_bindable_action_free(GntBindableAction *action) | |
434 { | |
435 g_free(action->name); | |
436 g_free(action); | |
437 } | |
438 | |
439 void gnt_bindable_action_param_free(GntBindableActionParam *param) | |
440 { | |
441 g_list_free(param->list); /* XXX: There may be a leak here for string parameters */ | |
442 g_free(param); | |
443 } | |
444 | |
17931
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
445 GntBindable * gnt_bindable_bindings_view(GntBindable *bind) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
446 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
447 GntBindable *tree = GNT_BINDABLE(gnt_tree_new_with_columns(2)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
448 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bind)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
449 GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
450 BindingView bv = {hash, GNT_TREE(tree)}; |
15817 | 451 |
17931
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
452 gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
453 g_hash_table_foreach(klass->actions, add_action, &bv); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
454 g_hash_table_foreach(klass->bindings, add_binding, &bv); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
455 if (GNT_TREE(tree)->list == NULL) { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
456 gnt_widget_destroy(GNT_WIDGET(tree)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
457 tree = NULL; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
458 } else |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
459 gnt_tree_adjust_columns(bv.tree); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
460 g_hash_table_destroy(hash); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
461 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
462 return tree; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
463 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
464 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
465 gboolean |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
466 gnt_bindable_build_help_window(GntBindable *bindable) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
467 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
468 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
469 GntWidget *tree; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
470 GntBindableClass *klass = GNT_BINDABLE_GET_CLASS(bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
471 char *title; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
472 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
473 tree = GNT_WIDGET(gnt_bindable_bindings_view(bindable)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
474 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(gnt_bindable_rebinding_activate), bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
475 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
476 klass->help_window = GNT_BINDABLE(gnt_window_new()); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
477 title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(bindable))); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
478 gnt_box_set_title(GNT_BOX(klass->help_window), title); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
479 if (tree) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
480 gnt_box_add_widget(GNT_BOX(klass->help_window), tree); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
481 else |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
482 gnt_box_add_widget(GNT_BOX(klass->help_window), gnt_label_new("This widget has no customizable bindings.")); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
483 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
484 gnt_widget_show(GNT_WIDGET(klass->help_window)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
485 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
486 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
487 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
488 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
489 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17928
diff
changeset
|
490 |