Mercurial > pidgin.yaz
annotate finch/libgnt/gntbindable.c @ 25209:4d6d7aeb3150
propagate from branch 'im.pidgin.pidgin' (head 3ffe6fd197f037185a0012875ef68c8f6d6c2f89)
to branch 'im.pidgin.cpw.malu.xmpp.ibb_ft' (head f595301f7175800c4e04b36cace91a9061db5724)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Tue, 16 Sep 2008 20:05:18 +0000 |
parents | 24dfef623410 |
children | e2e57d3c0578 |
rev | line source |
---|---|
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
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:
15818
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:
15818
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
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:
15818
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:
15818
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:
15818
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
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:
15818
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
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:
15818
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19179
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
22 |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
23 #include <string.h> |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
24 |
15818 | 25 #include "gntbindable.h" |
26 #include "gntstyle.h" | |
27 #include "gnt.h" | |
28 #include "gntutils.h" | |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
29 #include "gnttextview.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
30 #include "gnttree.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
31 #include "gntbox.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
32 #include "gntbutton.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
33 #include "gntwindow.h" |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
34 #include "gntlabel.h" |
15818 | 35 |
36 static GObjectClass *parent_class = NULL; | |
37 | |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
38 static struct |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
39 { |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
40 char * okeys; /* Old keystrokes */ |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
41 char * keys; /* New Keystrokes being bound to the action */ |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
42 GntBindableClass * klass; /* Class of the object that's getting keys rebound */ |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
43 char * name; /* The name of the action */ |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
44 GList * params; /* The list of paramaters */ |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
45 } rebind_info; |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
46 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
47 static void |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
48 gnt_bindable_free_rebind_info(void) |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
49 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
50 g_free(rebind_info.name); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
51 g_free(rebind_info.keys); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
52 g_free(rebind_info.okeys); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
53 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
54 |
19130
d5a0b09470ee
Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents:
17724
diff
changeset
|
55 static void |
d5a0b09470ee
Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents:
17724
diff
changeset
|
56 gnt_bindable_rebinding_cancel(GntWidget *button, gpointer data) |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
57 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
58 gnt_bindable_free_rebind_info(); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
59 gnt_widget_destroy(GNT_WIDGET(data)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
60 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
61 |
19130
d5a0b09470ee
Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents:
17724
diff
changeset
|
62 static void |
d5a0b09470ee
Cleaned up a few poorly written "activate" callbacks.
Eric Polino <aluink@pidgin.im>
parents:
17724
diff
changeset
|
63 gnt_bindable_rebinding_rebind(GntWidget *button, gpointer data) |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
64 { |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
65 if (rebind_info.keys) { |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
66 gnt_bindable_register_binding(rebind_info.klass, |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
67 NULL, |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
68 rebind_info.okeys, |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
69 rebind_info.params); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
70 gnt_bindable_register_binding(rebind_info.klass, |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
71 rebind_info.name, |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
72 rebind_info.keys, |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
73 rebind_info.params); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
74 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
75 gnt_bindable_free_rebind_info(); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
76 gnt_widget_destroy(GNT_WIDGET(data)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
77 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
78 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
79 static gboolean |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
80 gnt_bindable_rebinding_grab_key(GntBindable *bindable, const char *text, gpointer data) |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
81 { |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
82 GntTextView *textview = GNT_TEXT_VIEW(data); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
83 char *new_text; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
84 const char *tmp; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
85 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
86 if (text && *text) { |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
87 /* Rebinding tab or enter for something is probably not that great an idea */ |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
88 if (!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)) { |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
89 return FALSE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
90 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
91 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
92 tmp = gnt_key_lookup(text); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
93 new_text = g_strdup_printf("KEY: \"%s\"", tmp); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
94 gnt_text_view_clear(textview); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
95 gnt_text_view_append_text_with_flags(textview, new_text, GNT_TEXT_FLAG_NORMAL); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
96 g_free(new_text); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
97 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
98 g_free(rebind_info.keys); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
99 rebind_info.keys = g_strdup(text); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
100 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
101 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
102 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
103 return FALSE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
104 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
105 static void |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
106 gnt_bindable_rebinding_activate(GntBindable *data, gpointer bindable) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
107 { |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
108 const char *widget_name = g_type_name(G_OBJECT_TYPE(bindable)); |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
109 char *keys; |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
110 GntWidget *key_textview; |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
111 GntWidget *label; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
112 GntWidget *bind_button, *cancel_button; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
113 GntWidget *button_box; |
19177
19a4594e939c
Fix a memory leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19176
diff
changeset
|
114 GList *current_row_data; |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
115 char *tmp; |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
116 GntWidget *win = gnt_window_new(); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
117 GntTree *tree = GNT_TREE(data); |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
118 GntWidget *vbox = gnt_box_new(FALSE, TRUE); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
119 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
120 rebind_info.klass = GNT_BINDABLE_GET_CLASS(bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
121 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
122 current_row_data = gnt_tree_get_selection_text_list(tree); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
123 rebind_info.name = g_strdup(g_list_nth_data(current_row_data, 1)); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
124 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
125 keys = gnt_tree_get_selection_data(tree); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
126 rebind_info.okeys = g_strdup(gnt_key_translate(keys)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
127 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
128 rebind_info.params = NULL; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
129 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
130 g_list_foreach(current_row_data, (GFunc)g_free, NULL); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
131 g_list_free(current_row_data); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
132 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
133 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
134 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
135 gnt_box_set_title(GNT_BOX(win), "Key Capture"); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
136 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
137 tmp = g_strdup_printf("Type the new bindings for %s in a %s.", rebind_info.name, widget_name); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
138 label = gnt_label_new(tmp); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
139 g_free(tmp); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
140 gnt_box_add_widget(GNT_BOX(vbox), label); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
141 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
142 tmp = g_strdup_printf("KEY: \"%s\"", keys); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
143 key_textview = gnt_text_view_new(); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
144 gnt_widget_set_size(key_textview, key_textview->priv.x, 2); |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
145 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(key_textview), tmp, GNT_TEXT_FLAG_NORMAL); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
146 g_free(tmp); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
147 gnt_widget_set_name(key_textview, "keystroke"); |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
148 gnt_box_add_widget(GNT_BOX(vbox), key_textview); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
149 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
150 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(gnt_bindable_rebinding_grab_key), key_textview); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
151 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
152 button_box = gnt_box_new(FALSE, FALSE); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
153 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
154 bind_button = gnt_button_new("BIND"); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
155 gnt_widget_set_name(bind_button, "bind"); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
156 gnt_box_add_widget(GNT_BOX(button_box), bind_button); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
157 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
158 cancel_button = gnt_button_new("Cancel"); |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
159 gnt_widget_set_name(cancel_button, "cancel"); |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
160 gnt_box_add_widget(GNT_BOX(button_box), cancel_button); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
161 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
162 g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(gnt_bindable_rebinding_rebind), win); |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
163 g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(gnt_bindable_rebinding_cancel), win); |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
164 |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
165 gnt_box_add_widget(GNT_BOX(vbox), button_box); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
166 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
167 gnt_box_add_widget(GNT_BOX(win), vbox); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
168 gnt_widget_show(win); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
169 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
170 |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
171 typedef struct |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
172 { |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
173 GHashTable *hash; |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
174 GntTree *tree; |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
175 } BindingView; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
176 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
177 static void |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
178 add_binding(gpointer key, gpointer value, gpointer data) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
179 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
180 BindingView *bv = data; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
181 GntBindableActionParam *act = value; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
182 const char *name = g_hash_table_lookup(bv->hash, act->action); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
183 if (name && *name) { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
184 const char *k = gnt_key_lookup(key); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
185 if (!k) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
186 k = key; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
187 gnt_tree_add_row_after(bv->tree, (gpointer)k, |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
188 gnt_tree_create_row(bv->tree, k, name), NULL, NULL); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
189 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
190 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
191 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
192 static void |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
193 add_action(gpointer key, gpointer value, gpointer data) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
194 { |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
195 BindingView *bv = data; |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
196 g_hash_table_insert(bv->hash, value, key); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
197 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
198 |
15818 | 199 static void |
200 gnt_bindable_class_init(GntBindableClass *klass) | |
201 { | |
202 parent_class = g_type_class_peek_parent(klass); | |
203 | |
204 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
205 (GDestroyNotify)gnt_bindable_action_free); | |
206 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
207 (GDestroyNotify)gnt_bindable_action_param_free); | |
208 | |
209 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
210 GNTDEBUG; | |
211 } | |
212 | |
213 static gpointer | |
214 bindable_clone(GntBindableAction *action) | |
215 { | |
216 GntBindableAction *ret = g_new0(GntBindableAction, 1); | |
217 ret->name = g_strdup(action->name); | |
218 ret->u = action->u; | |
219 return ret; | |
220 } | |
221 | |
222 static gpointer | |
223 binding_clone(GntBindableActionParam *param) | |
224 { | |
225 GntBindableActionParam *p = g_new0(GntBindableActionParam, 1); | |
226 p->list = g_list_copy(param->list); | |
227 p->action = param->action; | |
228 return p; | |
229 } | |
230 | |
231 static void | |
232 duplicate_hashes(GntBindableClass *klass) | |
233 { | |
234 /* Duplicate the bindings from parent class */ | |
235 if (klass->actions) { | |
236 klass->actions = g_hash_table_duplicate(klass->actions, g_str_hash, | |
237 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free, | |
238 (GDupFunc)g_strdup, (GDupFunc)bindable_clone); | |
239 klass->bindings = g_hash_table_duplicate(klass->bindings, g_str_hash, | |
240 g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_param_free, | |
241 (GDupFunc)g_strdup, (GDupFunc)binding_clone); | |
242 } else { | |
243 klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
244 (GDestroyNotify)gnt_bindable_action_free); | |
245 klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
246 (GDestroyNotify)gnt_bindable_action_param_free); | |
247 } | |
248 | |
249 GNTDEBUG; | |
250 } | |
251 | |
252 /****************************************************************************** | |
253 * GntBindable API | |
254 *****************************************************************************/ | |
255 GType | |
256 gnt_bindable_get_gtype(void) | |
257 { | |
258 static GType type = 0; | |
259 | |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19130
diff
changeset
|
260 if (type == 0) { |
15818 | 261 static const GTypeInfo info = { |
262 sizeof(GntBindableClass), | |
263 (GBaseInitFunc)duplicate_hashes, /* base_init */ | |
264 NULL, /* base_finalize */ | |
265 (GClassInitFunc)gnt_bindable_class_init, | |
266 NULL, | |
267 NULL, /* class_data */ | |
268 sizeof(GntBindable), | |
269 0, /* n_preallocs */ | |
270 NULL, /* instance_init */ | |
271 NULL /* value_table */ | |
272 }; | |
273 | |
274 type = g_type_register_static(G_TYPE_OBJECT, | |
275 "GntBindable", | |
276 &info, G_TYPE_FLAG_ABSTRACT); | |
277 } | |
278 | |
279 return type; | |
280 } | |
281 | |
282 /** | |
283 * Key Remaps | |
284 */ | |
285 const char * | |
286 gnt_bindable_remap_keys(GntBindable *bindable, const char *text) | |
287 { | |
288 const char *remap = NULL; | |
289 GType type = G_OBJECT_TYPE(bindable); | |
290 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); | |
291 | |
292 if (klass->remaps == NULL) | |
293 { | |
294 klass->remaps = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
295 gnt_styles_get_keyremaps(type, klass->remaps); | |
296 } | |
297 | |
298 remap = g_hash_table_lookup(klass->remaps, text); | |
299 | |
300 return (remap ? remap : text); | |
301 } | |
302 | |
303 /** | |
304 * Actions and Bindings | |
305 */ | |
306 gboolean | |
307 gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...) | |
308 { | |
309 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); | |
310 GList *list = NULL; | |
311 va_list args; | |
312 GntBindableAction *action; | |
313 void *p; | |
314 | |
315 va_start(args, name); | |
316 while ((p = va_arg(args, void *)) != NULL) | |
317 list = g_list_append(list, p); | |
318 va_end(args); | |
319 | |
320 action = g_hash_table_lookup(klass->actions, name); | |
321 if (action && action->u.action) { | |
322 return action->u.action(bindable, list); | |
323 } | |
324 return FALSE; | |
325 } | |
326 | |
327 gboolean | |
328 gnt_bindable_perform_action_key(GntBindable *bindable, const char *keys) | |
329 { | |
330 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); | |
331 GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys); | |
332 | |
333 if (param && param->action) { | |
334 if (param->list) | |
335 return param->action->u.action(bindable, param->list); | |
336 else | |
337 return param->action->u.action_noparam(bindable); | |
338 } | |
339 return FALSE; | |
340 } | |
341 | |
22871
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22007
diff
changeset
|
342 gboolean |
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22007
diff
changeset
|
343 gnt_bindable_check_key(GntBindable *bindable, const char *keys) { |
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22007
diff
changeset
|
344 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bindable)); |
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22007
diff
changeset
|
345 GntBindableActionParam *param = g_hash_table_lookup(klass->bindings, keys); |
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22007
diff
changeset
|
346 return (param && param->action); |
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22007
diff
changeset
|
347 } |
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22007
diff
changeset
|
348 |
15818 | 349 static void |
350 register_binding(GntBindableClass *klass, const char *name, const char *trigger, GList *list) | |
351 { | |
352 GntBindableActionParam *param; | |
353 GntBindableAction *action; | |
354 | |
355 if (name == NULL || *name == '\0') { | |
356 g_hash_table_remove(klass->bindings, (char*)trigger); | |
357 gnt_keys_del_combination(trigger); | |
358 return; | |
359 } | |
360 | |
361 action = g_hash_table_lookup(klass->actions, name); | |
362 if (!action) { | |
18680
fd01bac27b79
Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
363 g_printerr("GntBindable: Invalid action name %s for %s\n", |
15818 | 364 name, g_type_name(G_OBJECT_CLASS_TYPE(klass))); |
365 if (list) | |
366 g_list_free(list); | |
367 return; | |
368 } | |
369 | |
370 param = g_new0(GntBindableActionParam, 1); | |
371 param->action = action; | |
372 param->list = list; | |
373 g_hash_table_replace(klass->bindings, g_strdup(trigger), param); | |
374 gnt_keys_add_combination(trigger); | |
375 } | |
376 | |
377 void gnt_bindable_register_binding(GntBindableClass *klass, const char *name, | |
378 const char *trigger, ...) | |
379 { | |
380 GList *list = NULL; | |
381 va_list args; | |
382 void *data; | |
383 | |
384 va_start(args, trigger); | |
385 while ((data = va_arg(args, void *))) { | |
386 list = g_list_append(list, data); | |
387 } | |
388 va_end(args); | |
389 | |
390 register_binding(klass, name, trigger, list); | |
391 } | |
392 | |
393 void gnt_bindable_class_register_action(GntBindableClass *klass, const char *name, | |
394 GntBindableActionCallback callback, const char *trigger, ...) | |
395 { | |
396 void *data; | |
397 va_list args; | |
398 GntBindableAction *action = g_new0(GntBindableAction, 1); | |
399 GList *list; | |
400 | |
401 action->name = g_strdup(name); | |
402 action->u.action = callback; | |
403 | |
404 g_hash_table_replace(klass->actions, g_strdup(name), action); | |
405 | |
406 if (trigger && *trigger) { | |
407 list = NULL; | |
408 va_start(args, trigger); | |
409 while ((data = va_arg(args, void *))) { | |
410 list = g_list_append(list, data); | |
411 } | |
412 va_end(args); | |
413 | |
414 register_binding(klass, name, trigger, list); | |
415 } | |
416 } | |
417 | |
418 void gnt_bindable_action_free(GntBindableAction *action) | |
419 { | |
420 g_free(action->name); | |
421 g_free(action); | |
422 } | |
423 | |
424 void gnt_bindable_action_param_free(GntBindableActionParam *param) | |
425 { | |
426 g_list_free(param->list); /* XXX: There may be a leak here for string parameters */ | |
427 g_free(param); | |
428 } | |
429 | |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
430 GntBindable * gnt_bindable_bindings_view(GntBindable *bind) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
431 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
432 GntBindable *tree = GNT_BINDABLE(gnt_tree_new_with_columns(2)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
433 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bind)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
434 GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
435 BindingView bv = {hash, GNT_TREE(tree)}; |
15818 | 436 |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
437 gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
438 g_hash_table_foreach(klass->actions, add_action, &bv); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
439 g_hash_table_foreach(klass->bindings, add_binding, &bv); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
440 if (GNT_TREE(tree)->list == NULL) { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
441 gnt_widget_destroy(GNT_WIDGET(tree)); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
442 tree = NULL; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
443 } else |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
444 gnt_tree_adjust_columns(bv.tree); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
445 g_hash_table_destroy(hash); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
446 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
447 return tree; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
448 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
449 |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
450 static void |
17724
d7cd0afd3c36
FIX: The help_window pointer wasn't being set to null properly in the destroy callback.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
451 reset_binding_window(GntBindableClass *window, gpointer k) |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
452 { |
17724
d7cd0afd3c36
FIX: The help_window pointer wasn't being set to null properly in the destroy callback.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
453 GntBindableClass *klass = GNT_BINDABLE_CLASS(k); |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
454 klass->help_window = NULL; |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
455 } |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
456 |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
457 gboolean |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
458 gnt_bindable_build_help_window(GntBindable *bindable) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
459 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
460 GntWidget *tree; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
461 GntBindableClass *klass = GNT_BINDABLE_GET_CLASS(bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
462 char *title; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
463 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
464 tree = GNT_WIDGET(gnt_bindable_bindings_view(bindable)); |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
465 |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
466 klass->help_window = GNT_BINDABLE(gnt_window_new()); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
467 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:
17718
diff
changeset
|
468 gnt_box_set_title(GNT_BOX(klass->help_window), title); |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
469 if (tree) { |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
470 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(gnt_bindable_rebinding_activate), bindable); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
471 gnt_box_add_widget(GNT_BOX(klass->help_window), tree); |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
472 } else |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
473 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:
17718
diff
changeset
|
474 |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
475 g_signal_connect(G_OBJECT(klass->help_window), "destroy", G_CALLBACK(reset_binding_window), klass); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
476 gnt_widget_show(GNT_WIDGET(klass->help_window)); |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
477 g_free(title); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
478 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
479 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
480 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17718
diff
changeset
|
481 |