Mercurial > pidgin.yaz
annotate finch/libgnt/gntmenuitem.c @ 21212:b65f1bff6412
Allow binding key-shortcuts to menuitems.
For example, to bind ctrl+m to the 'Options -> Send IM...' menu, you would add:
[buddylist::menu]
c-m = send-im
in ~/.gntrc
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 03 Oct 2007 06:51:26 +0000 |
parents | 44b4e8bd759b |
children | e8b0f224483f |
rev | line source |
---|---|
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
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:
15931
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:
15931
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
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:
15931
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:
15931
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:
15931
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
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:
15931
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
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:
15931
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:
18440
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:
15931
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
22 |
15818 | 23 #include "gntmenu.h" |
24 #include "gntmenuitem.h" | |
25 | |
26 static GObjectClass *parent_class = NULL; | |
27 | |
28 static void | |
29 gnt_menuitem_destroy(GObject *obj) | |
30 { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
31 GntMenuItem *item = GNT_MENU_ITEM(obj); |
15818 | 32 g_free(item->text); |
33 item->text = NULL; | |
34 if (item->submenu) | |
35 gnt_widget_destroy(GNT_WIDGET(item->submenu)); | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
36 g_free(item->priv.id); |
15818 | 37 parent_class->dispose(obj); |
38 } | |
39 | |
40 static void | |
41 gnt_menuitem_class_init(GntMenuItemClass *klass) | |
42 { | |
43 GObjectClass *obj_class = G_OBJECT_CLASS(klass); | |
44 parent_class = g_type_class_peek_parent(klass); | |
45 | |
46 obj_class->dispose = gnt_menuitem_destroy; | |
47 } | |
48 | |
49 static void | |
50 gnt_menuitem_init(GTypeInstance *instance, gpointer class) | |
51 { | |
52 } | |
53 | |
54 /****************************************************************************** | |
55 * GntMenuItem API | |
56 *****************************************************************************/ | |
57 GType | |
58 gnt_menuitem_get_gtype(void) | |
59 { | |
60 static GType type = 0; | |
61 | |
62 if(type == 0) | |
63 { | |
64 static const GTypeInfo info = { | |
65 sizeof(GntMenuItemClass), | |
66 NULL, /* base_init */ | |
67 NULL, /* base_finalize */ | |
68 (GClassInitFunc)gnt_menuitem_class_init, | |
69 NULL, /* class_finalize */ | |
70 NULL, /* class_data */ | |
71 sizeof(GntMenuItem), | |
72 0, /* n_preallocs */ | |
73 gnt_menuitem_init, /* instance_init */ | |
74 NULL /* value_table */ | |
75 }; | |
76 | |
77 type = g_type_register_static(G_TYPE_OBJECT, | |
78 "GntMenuItem", | |
79 &info, 0); | |
80 } | |
81 | |
82 return type; | |
83 } | |
84 | |
85 GntMenuItem *gnt_menuitem_new(const char *text) | |
86 { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
87 GObject *item = g_object_new(GNT_TYPE_MENU_ITEM, NULL); |
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
88 GntMenuItem *menuitem = GNT_MENU_ITEM(item); |
15818 | 89 |
90 menuitem->text = g_strdup(text); | |
91 | |
92 return menuitem; | |
93 } | |
94 | |
95 void gnt_menuitem_set_callback(GntMenuItem *item, GntMenuItemCallback callback, gpointer data) | |
96 { | |
97 item->callback = callback; | |
98 item->callbackdata = data; | |
99 } | |
100 | |
101 void gnt_menuitem_set_submenu(GntMenuItem *item, GntMenu *menu) | |
102 { | |
103 if (item->submenu) | |
104 gnt_widget_destroy(GNT_WIDGET(item->submenu)); | |
105 item->submenu = menu; | |
106 } | |
107 | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
108 GntMenu *gnt_menuitem_get_submenu(GntMenuItem *item) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
109 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
110 return item->submenu; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
111 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
112 |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
113 void gnt_menuitem_set_trigger(GntMenuItem *item, char trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
114 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
115 item->priv.trigger = trigger; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
116 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
117 |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
118 char gnt_menuitem_get_trigger(GntMenuItem *item) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
119 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
120 return item->priv.trigger; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
121 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
122 |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
123 void gnt_menuitem_set_id(GntMenuItem *item, const char *id) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
124 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
125 g_free(item->priv.id); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
126 item->priv.id = g_strdup(id); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
127 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
128 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
129 const char * gnt_menuitem_get_id(GntMenuItem *item) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
130 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
131 return item->priv.id; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
132 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
133 |