Commit 3b5d2c0c61a75e09b5e47c5dc5a1a3908f2a8a98
1 parent
fc6ea015
Exists in
master
and in
1 other branch
Implementing GActions for v3270 terminal.
Showing
4 changed files
with
614 additions
and
8 deletions
Show diff stats
src/include/v3270/actions.h
... | ... | @@ -101,6 +101,72 @@ |
101 | 101 | LIB3270_EXPORT V3270Accelerator * v3270_accelerator_clone(const V3270Accelerator *accel); |
102 | 102 | LIB3270_EXPORT const V3270Accelerator * v3270_accelerator_map_lookup_entry(GtkWidget *widget, guint keyval, GdkModifierType state); |
103 | 103 | |
104 | + // | |
105 | + // GAction wrapper for V3270 terminal widget. | |
106 | + // | |
107 | + #define V3270_TYPE_ACTION (V3270Action_get_type()) | |
108 | + #define V3270_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_ACTION, V3270Action)) | |
109 | + #define V3270_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_ACTION, V3270ActionClass)) | |
110 | + #define V3270_IS_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_ACTION)) | |
111 | + #define V3270_IS_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_ACTION)) | |
112 | + #define V3270_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_ACTION, V3270ActionClass)) | |
113 | + | |
114 | + typedef struct _V3270Action { | |
115 | + | |
116 | + GObject parent; | |
117 | + | |
118 | + GtkWidget * terminal; ///> @brief The active terminal widget. | |
119 | + const LIB3270_PROPERTY * info; ///> @brief Action info. | |
120 | + const void * listener; ///> @brief Signal listener for the action group. | |
121 | + | |
122 | + struct { | |
123 | + const GVariantType * state; ///> @brief State type type. | |
124 | + const GVariantType * parameter; ///> @brief Parameter type. | |
125 | + } types; | |
126 | + | |
127 | + /// @brief Activation method. | |
128 | + void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); | |
129 | + | |
130 | + /// @brief Get State method. | |
131 | + GVariant * (*get_state_property)(GAction *action, GtkWidget *terminal); | |
132 | + | |
133 | + /// @brief Get state hint. | |
134 | + GVariant * (*get_state_hint)(GAction *action, GtkWidget *terminal); | |
135 | + | |
136 | + } V3270Action; | |
137 | + | |
138 | + typedef struct _V3270ActionClass { | |
139 | + | |
140 | + GObjectClass parent_class; | |
141 | + | |
142 | + struct { | |
143 | + GParamSpec * state; | |
144 | + GParamSpec * enabled; | |
145 | + } properties; | |
146 | + | |
147 | + void (*change_widget)(GAction *action, GtkWidget *from, GtkWidget *to); | |
148 | + gboolean (*get_enabled)(GAction *action, GtkWidget *terminal); | |
149 | + | |
150 | + } V3270ActionClass; | |
151 | + | |
152 | + LIB3270_EXPORT GType V3270Action_get_type(void) G_GNUC_CONST; | |
153 | + LIB3270_EXPORT GAction * v3270_action_new(); | |
154 | + | |
155 | + LIB3270_EXPORT void v3270_action_set_terminal_widget(GAction *object, GtkWidget *widget); | |
156 | + LIB3270_EXPORT GtkWidget * v3270_action_get_terminal_widget(GAction *object); | |
157 | + | |
158 | + LIB3270_EXPORT void v3270_action_notify_state(GAction *action); | |
159 | + LIB3270_EXPORT void v3270_action_notify_enabled(GAction *action); | |
160 | + | |
161 | + LIB3270_EXPORT H3270 * v3270_action_get_session(GAction *action); | |
162 | + LIB3270_EXPORT const gchar * v3270_action_get_icon_name(GAction *action); | |
163 | + LIB3270_EXPORT const gchar * v3270_action_get_label(GAction *action); | |
164 | + LIB3270_EXPORT const gchar * v3270_action_get_tooltip(GAction *action); | |
165 | + LIB3270_EXPORT GdkPixbuf * v3270_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags); | |
166 | + | |
167 | + LIB3270_EXPORT void g_action_map_add_v3270_actions(GActionMap *action_map); | |
168 | + LIB3270_EXPORT void g_action_map_add_lib3270_actions(GActionMap *action_map); | |
169 | + | |
104 | 170 | G_END_DECLS |
105 | 171 | |
106 | 172 | #endif // V3270_ACTIONS_H_INCLUDED | ... | ... |
... | ... | @@ -0,0 +1,477 @@ |
1 | +/* | |
2 | + * "Software v3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como - e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | + #include <internals.h> | |
31 | + #include <v3270.h> | |
32 | + #include <v3270/actions.h> | |
33 | + #include <lib3270/actions.h> | |
34 | + #include <lib3270.h> | |
35 | + #include <lib3270/log.h> | |
36 | + | |
37 | + #define V3270_ACTION_GET_DESCRIPTOR(obj) ((V3270Action *) obj)->info | |
38 | + | |
39 | + static void V3270_action_iface_init(GActionInterface *iface); | |
40 | + static void V3270Action_class_init(V3270ActionClass *klass); | |
41 | + static void V3270Action_init(V3270Action *action); | |
42 | + | |
43 | + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | |
44 | + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | |
45 | + | |
46 | + static gboolean get_enabled(GAction *action); | |
47 | + static void activate(GAction *action, GVariant *parameter); | |
48 | + | |
49 | + static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to); | |
50 | + | |
51 | + static void finalize(GObject *object); | |
52 | + | |
53 | + static const GVariantType * get_state_type(GAction *action); | |
54 | + static GVariant * get_state_property(GAction *action); | |
55 | + | |
56 | + static GVariant * internal_get_state_property(GAction *action, GtkWidget *terminal); | |
57 | + static gboolean internal_get_enabled(GAction *action, GtkWidget *terminal); | |
58 | + static void internal_activate(GAction *action, GVariant *parameter, GtkWidget *terminal); | |
59 | + static GVariant * internal_get_state_hint(GAction *action, GtkWidget *terminal); | |
60 | + | |
61 | + static const GVariantType * get_parameter_type(GAction *action); | |
62 | + static GVariant * get_state_hint(GAction *action); | |
63 | + static const gchar * get_name(GAction *action); | |
64 | + | |
65 | + static void change_state(GAction *action, GVariant *value); | |
66 | + | |
67 | + enum { | |
68 | + PROP_NONE, | |
69 | + PROP_NAME, | |
70 | + PROP_PARAMETER_TYPE, | |
71 | + PROP_ENABLED, | |
72 | + PROP_STATE_TYPE, | |
73 | + PROP_STATE, | |
74 | + PROP_ICON_NAME, | |
75 | + PROP_LABEL, | |
76 | + PROP_TOOLTIP | |
77 | + }; | |
78 | + | |
79 | + G_DEFINE_TYPE_WITH_CODE(V3270Action, V3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, V3270_action_iface_init)) | |
80 | + | |
81 | + void V3270_action_iface_init(GActionInterface *iface) { | |
82 | + iface->get_name = get_name; | |
83 | + iface->get_parameter_type = get_parameter_type; | |
84 | + iface->get_state_type = get_state_type; | |
85 | + iface->get_state_hint = get_state_hint; | |
86 | + iface->get_enabled = get_enabled; | |
87 | + iface->get_state = get_state_property; | |
88 | + iface->change_state = change_state; | |
89 | + iface->activate = activate; | |
90 | + } | |
91 | + | |
92 | + void V3270Action_class_init(V3270ActionClass *klass) { | |
93 | + | |
94 | + GObjectClass *object_class = G_OBJECT_CLASS(klass); | |
95 | + | |
96 | + debug("%s",__FUNCTION__); | |
97 | + | |
98 | + klass->change_widget = change_widget; | |
99 | + klass->get_enabled = internal_get_enabled; | |
100 | + | |
101 | + object_class->finalize = finalize; | |
102 | + object_class->get_property = get_property; | |
103 | + object_class->set_property = set_property; | |
104 | + | |
105 | + // Install properties | |
106 | + g_object_class_install_property(object_class, PROP_NAME, | |
107 | + g_param_spec_string ( | |
108 | + "name", | |
109 | + N_("Action Name"), | |
110 | + N_("The name used to invoke the action"), | |
111 | + NULL, | |
112 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
113 | + | |
114 | + g_object_class_install_property(object_class, PROP_ICON_NAME, | |
115 | + g_param_spec_string ( | |
116 | + "icon-name", | |
117 | + N_("Icon Name"), | |
118 | + N_("The name of the icon associated with the action"), | |
119 | + NULL, | |
120 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
121 | + | |
122 | + g_object_class_install_property(object_class, PROP_LABEL, | |
123 | + g_param_spec_string ( | |
124 | + "label", | |
125 | + N_("The action label"), | |
126 | + N_("The label for the action"), | |
127 | + NULL, | |
128 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
129 | + | |
130 | + g_object_class_install_property(object_class, PROP_TOOLTIP, | |
131 | + g_param_spec_string ( | |
132 | + "tooltip", | |
133 | + N_("The action tooltip"), | |
134 | + N_("The tooltip for the action"), | |
135 | + NULL, | |
136 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
137 | + | |
138 | + g_object_class_install_property (object_class, PROP_PARAMETER_TYPE, | |
139 | + g_param_spec_boxed ("parameter-type", | |
140 | + N_("Parameter Type"), | |
141 | + N_("The type of GVariant passed to activate()"), | |
142 | + G_TYPE_VARIANT_TYPE, | |
143 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); | |
144 | + | |
145 | + g_object_class_install_property (object_class, PROP_STATE_TYPE, | |
146 | + g_param_spec_boxed ("state-type", | |
147 | + N_("State Type"), | |
148 | + N_("The type of the state kept by the action"), | |
149 | + G_TYPE_VARIANT_TYPE, | |
150 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
151 | + | |
152 | + // Enabled property | |
153 | + klass->properties.enabled = | |
154 | + g_param_spec_boolean( | |
155 | + "enabled", | |
156 | + N_("Enabled"), | |
157 | + N_("If the action can be activated"), | |
158 | + TRUE, | |
159 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | |
160 | + ); | |
161 | + | |
162 | + g_object_class_install_property(object_class, PROP_ENABLED, klass->properties.enabled); | |
163 | + | |
164 | + // State property | |
165 | + klass->properties.state = | |
166 | + g_param_spec_variant( | |
167 | + "state", | |
168 | + N_("State"), | |
169 | + N_("The state the action is in"), | |
170 | + G_VARIANT_TYPE_ANY, | |
171 | + NULL, | |
172 | + G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | |
173 | + ); | |
174 | + | |
175 | + g_object_class_install_property (object_class, PROP_STATE, klass->properties.state); | |
176 | + | |
177 | + } | |
178 | + | |
179 | + void V3270Action_init(V3270Action *action) { | |
180 | + | |
181 | + static const LIB3270_PROPERTY default_info = { | |
182 | + .name = "unnamed" | |
183 | + }; | |
184 | + | |
185 | + action->terminal = NULL; | |
186 | + action->info = &default_info; | |
187 | + action->types.parameter = NULL; | |
188 | + | |
189 | + action->activate = internal_activate; | |
190 | + action->get_state_property = internal_get_state_property; | |
191 | + action->get_state_hint = internal_get_state_hint; | |
192 | + | |
193 | + } | |
194 | + | |
195 | + void finalize(GObject *object) { | |
196 | + | |
197 | + V3270Action * action = V3270_ACTION(object); | |
198 | + | |
199 | + if(action->terminal) { | |
200 | + v3270_action_set_terminal_widget(G_ACTION(object),NULL); | |
201 | + action->terminal = NULL; | |
202 | + } | |
203 | + | |
204 | + G_OBJECT_CLASS(V3270Action_parent_class)->finalize(object); | |
205 | + | |
206 | + } | |
207 | + | |
208 | + void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { | |
209 | + | |
210 | + GAction *action = G_ACTION(object); | |
211 | + | |
212 | +// debug("%s(%d)",__FUNCTION__,prop_id); | |
213 | + | |
214 | + switch (prop_id) { | |
215 | + case PROP_NAME: | |
216 | + g_value_set_string(value, get_name(action)); | |
217 | + break; | |
218 | + | |
219 | + case PROP_ICON_NAME: | |
220 | + g_value_set_string(value, v3270_action_get_icon_name(action)); | |
221 | + break; | |
222 | + | |
223 | + case PROP_LABEL: | |
224 | + g_value_set_string(value, v3270_action_get_label(action)); | |
225 | + break; | |
226 | + | |
227 | + case PROP_TOOLTIP: | |
228 | + g_value_set_string(value, v3270_action_get_tooltip(action)); | |
229 | + break; | |
230 | + | |
231 | + case PROP_PARAMETER_TYPE: | |
232 | + g_value_set_boxed(value, get_parameter_type(action)); | |
233 | + break; | |
234 | + | |
235 | + case PROP_ENABLED: | |
236 | + g_value_set_boolean(value, get_enabled(action)); | |
237 | + break; | |
238 | + | |
239 | + case PROP_STATE_TYPE: | |
240 | + g_value_set_boxed(value, get_state_type(action)); | |
241 | + break; | |
242 | + | |
243 | + case PROP_STATE: | |
244 | + g_value_take_variant(value, get_state_property(action)); | |
245 | + break; | |
246 | + | |
247 | + default: | |
248 | + g_assert_not_reached (); | |
249 | + } | |
250 | + | |
251 | + } | |
252 | + | |
253 | + void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { | |
254 | + g_message("Action property \"%s\" is read-only",pspec->name); | |
255 | + } | |
256 | + | |
257 | + const gchar * get_name(GAction *action) { | |
258 | + return V3270_ACTION_GET_DESCRIPTOR(action)->name; | |
259 | + } | |
260 | + | |
261 | + GVariant * internal_get_state_hint(GAction G_GNUC_UNUSED(*action), GtkWidget G_GNUC_UNUSED(*terminal)) { | |
262 | + return NULL; | |
263 | + } | |
264 | + | |
265 | + GVariant * internal_get_state_property(GAction *object, GtkWidget G_GNUC_UNUSED(*terminal)) { | |
266 | + | |
267 | + V3270Action * action = V3270_ACTION(object); | |
268 | + | |
269 | + if(action->types.state == G_VARIANT_TYPE_BOOLEAN) | |
270 | + return g_variant_new_boolean(FALSE); | |
271 | + | |
272 | + return NULL; | |
273 | + } | |
274 | + | |
275 | + GVariant * get_state_property(GAction *object) { | |
276 | + | |
277 | + V3270Action * action = V3270_ACTION(object); | |
278 | + GVariant * state; | |
279 | + | |
280 | + if(action->terminal) | |
281 | + state = action->get_state_property(object,action->terminal); | |
282 | + else | |
283 | + state = internal_get_state_property(object,NULL); | |
284 | + | |
285 | + if(state) | |
286 | + g_variant_ref(state); | |
287 | + | |
288 | + return state; | |
289 | + } | |
290 | + | |
291 | + const GVariantType * get_parameter_type(GAction *action) { | |
292 | + return V3270_ACTION(action)->types.parameter; | |
293 | + } | |
294 | + | |
295 | + const GVariantType * get_state_type(GAction *object) { | |
296 | + return V3270_ACTION(object)->types.state; | |
297 | + } | |
298 | + | |
299 | + GVariant * get_state_hint(GAction *object) { | |
300 | + V3270Action *action = V3270_ACTION(object); | |
301 | + return action->get_state_hint(object,action->terminal); | |
302 | + } | |
303 | + | |
304 | + void change_state(GAction G_GNUC_UNUSED(*object), GVariant G_GNUC_UNUSED(*value)) { | |
305 | + debug("%s",__FUNCTION__); | |
306 | + } | |
307 | + | |
308 | + static gboolean bg_notify_enabled(GObject *action) { | |
309 | + debug("%s(%s,%s)",__FUNCTION__,g_action_get_name(G_ACTION(action)),(g_action_get_enabled(G_ACTION(action)) ? "enabled" : "disabled")); | |
310 | + g_object_notify(action, "enabled"); | |
311 | + return FALSE; | |
312 | + } | |
313 | + | |
314 | + static gboolean bg_notify_state(GObject *action) { | |
315 | + g_object_notify(action, "state"); | |
316 | + return FALSE; | |
317 | + } | |
318 | + | |
319 | + void v3270_action_notify_enabled(GAction *action) { | |
320 | + g_idle_add((GSourceFunc) bg_notify_enabled, G_OBJECT(action)); | |
321 | + } | |
322 | + | |
323 | + void v3270_action_notify_state(GAction *action) { | |
324 | + g_idle_add((GSourceFunc) bg_notify_state, G_OBJECT(action)); | |
325 | + } | |
326 | + | |
327 | + static void event_listener(H3270 G_GNUC_UNUSED(*hSession), void *object) { | |
328 | + g_idle_add((GSourceFunc) bg_notify_enabled, G_ACTION(object)); | |
329 | + } | |
330 | + | |
331 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | |
332 | + | |
333 | + if(from != to) { | |
334 | + | |
335 | + V3270Action *action = V3270_ACTION(object); | |
336 | + | |
337 | + if(action->listener) { | |
338 | + lib3270_unregister_action_group_listener(v3270_action_get_session(object),action->info->group,action->listener); | |
339 | + action->listener = NULL; | |
340 | + } | |
341 | + | |
342 | + action->terminal = to; | |
343 | + | |
344 | + if(action->info->group != LIB3270_ACTION_GROUP_NONE && to) { | |
345 | + action->listener = lib3270_register_action_group_listener(v3270_action_get_session(object),action->info->group,event_listener,object); | |
346 | + } | |
347 | + | |
348 | + g_idle_add((GSourceFunc) bg_notify_enabled, G_OBJECT(action)); | |
349 | + | |
350 | + if(action->types.state) | |
351 | + g_idle_add((GSourceFunc) bg_notify_state, G_OBJECT(action)); | |
352 | + | |
353 | + } | |
354 | + | |
355 | + } | |
356 | + | |
357 | + void v3270_action_set_terminal_widget(GAction *object, GtkWidget *widget) { | |
358 | + | |
359 | + g_return_if_fail(V3270_IS_ACTION(object)); | |
360 | + | |
361 | + if(widget) { | |
362 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
363 | + } | |
364 | + | |
365 | + V3270Action * action = V3270_ACTION(object); | |
366 | + | |
367 | + if(action->terminal != widget) { | |
368 | + V3270_ACTION_GET_CLASS(object)->change_widget(object,action->terminal,widget); | |
369 | + action->terminal = widget; | |
370 | + } | |
371 | + | |
372 | + } | |
373 | + | |
374 | + GtkWidget * v3270_action_get_terminal_widget(GAction *object) { | |
375 | + g_return_val_if_fail(V3270_IS_ACTION(object),NULL); | |
376 | + return V3270_ACTION(object)->terminal; | |
377 | + } | |
378 | + | |
379 | + gboolean get_enabled(GAction *object) { | |
380 | + | |
381 | + V3270Action * action = V3270_ACTION(object); | |
382 | + | |
383 | + if(action && action->terminal) { | |
384 | + | |
385 | + if(action->info->group != LIB3270_ACTION_GROUP_NONE) { | |
386 | + | |
387 | + if(!lib3270_action_group_get_activatable(v3270_get_session(action->terminal),action->info->group)) | |
388 | + return FALSE; | |
389 | + | |
390 | + } | |
391 | + | |
392 | + return V3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); | |
393 | + } | |
394 | + | |
395 | + return FALSE; | |
396 | + | |
397 | + } | |
398 | + | |
399 | + void activate(GAction *object, GVariant *parameter) { | |
400 | + | |
401 | + V3270Action * action = V3270_ACTION(object); | |
402 | + | |
403 | + debug("%s: terminal=%p",__FUNCTION__,action->terminal); | |
404 | + | |
405 | + if(action && action->terminal) { | |
406 | + action->activate(object,parameter,action->terminal); | |
407 | + } | |
408 | + | |
409 | + } | |
410 | + | |
411 | + gboolean internal_get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) { | |
412 | + return terminal != NULL; | |
413 | + } | |
414 | + | |
415 | + void internal_activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { | |
416 | + g_message("Action %s can't be activated",g_action_get_name(action)); | |
417 | + } | |
418 | + | |
419 | + const gchar * v3270_action_get_icon_name(GAction *action) { | |
420 | + return V3270_ACTION_GET_DESCRIPTOR(action)->icon; | |
421 | + } | |
422 | + | |
423 | + const gchar * v3270_action_get_label(GAction *action) { | |
424 | + const gchar * label = V3270_ACTION_GET_DESCRIPTOR(action)->label; | |
425 | + | |
426 | + if(label) | |
427 | + return gettext(label); | |
428 | + | |
429 | + return NULL; | |
430 | + } | |
431 | + | |
432 | + const gchar * v3270_action_get_tooltip(GAction *action) { | |
433 | + const gchar * tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->description; | |
434 | + | |
435 | + if(tooltip) | |
436 | + return gettext(tooltip); | |
437 | + | |
438 | + return NULL; | |
439 | + } | |
440 | + | |
441 | + H3270 * v3270_action_get_session(GAction *action) { | |
442 | + g_return_val_if_fail(V3270_IS_ACTION(action),NULL); | |
443 | + return v3270_get_session(V3270_ACTION(action)->terminal); | |
444 | + } | |
445 | + | |
446 | + GAction * v3270_action_new() { | |
447 | + return G_ACTION(g_object_new(V3270_TYPE_ACTION, NULL)); | |
448 | + } | |
449 | + | |
450 | + /* | |
451 | + static GdkPixbuf * pixbuf_from_icon_name(GValue *value, GtkIconSize icon_size) { | |
452 | + | |
453 | + const gchar * icon_name = g_value_get_string(value); | |
454 | + | |
455 | + if(!icon_name) | |
456 | + return NULL; | |
457 | + | |
458 | + } | |
459 | + */ | |
460 | + | |
461 | + GdkPixbuf * v3270_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags) { | |
462 | + | |
463 | + const gchar * icon_name = v3270_action_get_icon_name(action); | |
464 | + | |
465 | + if(!icon_name) | |
466 | + return NULL; | |
467 | + | |
468 | + return gtk_icon_theme_load_icon( | |
469 | + gtk_icon_theme_get_default(), | |
470 | + icon_name, | |
471 | + icon_size, | |
472 | + flags, | |
473 | + NULL | |
474 | + ); | |
475 | + | |
476 | + } | |
477 | + | ... | ... |
src/terminal/actions/table.c
... | ... | @@ -48,12 +48,14 @@ |
48 | 48 | { |
49 | 49 | { |
50 | 50 | .name = "keypad-add", |
51 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
51 | 52 | .key = GDK_KP_Add, |
52 | 53 | .mods = GDK_NUMLOCK_MASK, |
53 | 54 | .activate = fire_keypad_action |
54 | 55 | }, |
55 | 56 | { |
56 | 57 | .name = "keypad-subtract", |
58 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
57 | 59 | .key = GDK_KP_Subtract, |
58 | 60 | .mods = GDK_NUMLOCK_MASK, |
59 | 61 | .activate = fire_keypad_action |
... | ... | @@ -63,8 +65,9 @@ |
63 | 65 | { |
64 | 66 | .flags = 0, |
65 | 67 | .name = "copy", |
68 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
66 | 69 | .icon = "edit-copy", |
67 | - .summary = N_( "Copy" ), | |
70 | + .label = N_( "Copy" ), | |
68 | 71 | .key = 'c', |
69 | 72 | .mods = GDK_CONTROL_MASK, |
70 | 73 | .activate = fire_copy_accelerator |
... | ... | @@ -72,8 +75,9 @@ |
72 | 75 | |
73 | 76 | { |
74 | 77 | .flags = V3270_COPY_APPEND, |
78 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
75 | 79 | .name = "copy-append", |
76 | - .summary = N_( "Add to copy" ), | |
80 | + .label = N_( "Add to copy" ), | |
77 | 81 | .key = 'c', |
78 | 82 | .mods = GDK_ALT_MASK, |
79 | 83 | .activate = fire_copy_accelerator |
... | ... | @@ -81,8 +85,10 @@ |
81 | 85 | |
82 | 86 | { |
83 | 87 | .flags = V3270_COPY_TEXT, |
88 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
84 | 89 | .name = "copy-text", |
85 | 90 | .icon = "edit-copy", |
91 | + .label = N_( "Copy" ), | |
86 | 92 | .summary = N_( "Copy as plain text" ), |
87 | 93 | .key = 'c', |
88 | 94 | .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK, |
... | ... | @@ -91,9 +97,10 @@ |
91 | 97 | |
92 | 98 | { |
93 | 99 | .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_DEFAULT, |
100 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
94 | 101 | .name = "cut", |
95 | 102 | .icon = "edit-cut", |
96 | - .summary = N_( "Cut" ), | |
103 | + .label = N_( "Cut" ), | |
97 | 104 | .key = 'x', |
98 | 105 | .mods = GDK_CONTROL_MASK, |
99 | 106 | .activate = fire_copy_accelerator |
... | ... | @@ -101,7 +108,9 @@ |
101 | 108 | |
102 | 109 | { |
103 | 110 | .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_APPEND, |
111 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
104 | 112 | .name = "cut-append", |
113 | + .label = N_( "Cut" ), | |
105 | 114 | .summary = N_( "Cut and append to copy" ), |
106 | 115 | .key = 'x', |
107 | 116 | .mods = GDK_ALT_MASK, |
... | ... | @@ -110,8 +119,10 @@ |
110 | 119 | |
111 | 120 | { |
112 | 121 | .flags = V3270_ACTION_FLAG_CUT|V3270_COPY_TEXT, |
122 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
113 | 123 | .name = "cut-text", |
114 | 124 | .icon = "edit-cut", |
125 | + .label = N_( "Cut" ), | |
115 | 126 | .summary = N_( "Cut as plain text" ), |
116 | 127 | .key = 'x', |
117 | 128 | .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK, |
... | ... | @@ -120,9 +131,10 @@ |
120 | 131 | |
121 | 132 | { |
122 | 133 | .flags = 0, |
134 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
123 | 135 | .name = "paste", |
124 | 136 | .icon = "edit-paste", |
125 | - .summary = N_("Paste"), | |
137 | + .label = N_("Paste"), | |
126 | 138 | .key = 'v', |
127 | 139 | .mods = GDK_CONTROL_MASK, |
128 | 140 | .activate = fire_paste_accelerator |
... | ... | @@ -130,8 +142,10 @@ |
130 | 142 | |
131 | 143 | { |
132 | 144 | .flags = 1, |
145 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
133 | 146 | .name = "paste-text", |
134 | 147 | .icon = "edit-paste", |
148 | + .label = N_("Paste"), | |
135 | 149 | .summary = N_("Paste as plain text"), |
136 | 150 | .key = 'v', |
137 | 151 | .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK, |
... | ... | @@ -140,7 +154,9 @@ |
140 | 154 | |
141 | 155 | { |
142 | 156 | .flags = 2, |
157 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
143 | 158 | .name = "paste-file", |
159 | + .label = N_("Paste file"), | |
144 | 160 | .summary = N_("Paste from text file"), |
145 | 161 | .key = 'v', |
146 | 162 | .mods = GDK_ALT_MASK, |
... | ... | @@ -149,9 +165,10 @@ |
149 | 165 | |
150 | 166 | { |
151 | 167 | .flags = 0, |
168 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
152 | 169 | .name = "zoom-in", |
153 | 170 | .icon = "zoom-in", |
154 | - .summary = N_("Zoom in"), | |
171 | + .label = N_("Zoom in"), | |
155 | 172 | .key = GDK_KP_Add, |
156 | 173 | .mods = GDK_CONTROL_MASK, |
157 | 174 | .activate = fire_zoom_action |
... | ... | @@ -159,8 +176,9 @@ |
159 | 176 | |
160 | 177 | { |
161 | 178 | .flags = 1, |
179 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
162 | 180 | .name = "zoom-out", |
163 | - .summary = N_("Zoom out"), | |
181 | + .label = N_("Zoom out"), | |
164 | 182 | .icon = "zoom-out", |
165 | 183 | .key = GDK_KP_Subtract, |
166 | 184 | .mods = GDK_CONTROL_MASK, |
... | ... | @@ -169,7 +187,9 @@ |
169 | 187 | |
170 | 188 | { |
171 | 189 | .flags = 2, |
190 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
172 | 191 | .name = "zoom-fit-best", |
192 | + .label = N_("Fit best"), | |
173 | 193 | .summary = N_("Zoom to best size"), |
174 | 194 | .icon = "zoom-fit-best", |
175 | 195 | .key = '0', |
... | ... | @@ -182,8 +202,10 @@ |
182 | 202 | // |
183 | 203 | { |
184 | 204 | .flags = -1, |
205 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
185 | 206 | .name = "save", |
186 | 207 | .icon = "document-save-as", |
208 | + .label = N_("Save"), | |
187 | 209 | .summary = N_("Save screen or selection"), |
188 | 210 | .activate = fire_save_action |
189 | 211 | |
... | ... | @@ -191,7 +213,9 @@ |
191 | 213 | |
192 | 214 | { |
193 | 215 | .flags = LIB3270_CONTENT_ALL, |
216 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
194 | 217 | .name = "save-all", |
218 | + .label = N_("Save all"), | |
195 | 219 | .icon = "document-save-as", |
196 | 220 | .summary = N_("Save screen"), |
197 | 221 | .activate = fire_save_action |
... | ... | @@ -200,7 +224,9 @@ |
200 | 224 | |
201 | 225 | { |
202 | 226 | .flags = LIB3270_CONTENT_SELECTED, |
227 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
203 | 228 | .name = "save-selected", |
229 | + .label = N_("Save selected"), | |
204 | 230 | .icon = "document-save-as", |
205 | 231 | .summary = N_("Save selected area"), |
206 | 232 | .activate = fire_save_action |
... | ... | @@ -209,7 +235,9 @@ |
209 | 235 | |
210 | 236 | { |
211 | 237 | .flags = LIB3270_CONTENT_COPY, |
238 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
212 | 239 | .name = "save-copy", |
240 | + .label = N_("Save copy"), | |
213 | 241 | .icon = "document-save-as", |
214 | 242 | .summary = N_("Save Copy"), |
215 | 243 | .activate = fire_save_action |
... | ... | @@ -221,8 +249,10 @@ |
221 | 249 | // |
222 | 250 | { |
223 | 251 | .flags = -1, |
252 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
224 | 253 | .name = "print", |
225 | 254 | .icon = "document-print", |
255 | + .label = N_("Print"), | |
226 | 256 | .summary = N_("Print screen or selection"), |
227 | 257 | .activate = fire_print_action |
228 | 258 | |
... | ... | @@ -230,17 +260,20 @@ |
230 | 260 | |
231 | 261 | { |
232 | 262 | .flags = LIB3270_CONTENT_ALL, |
263 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
233 | 264 | .name = "print-all", |
234 | 265 | .icon = "document-print", |
235 | - .summary = N_("Print screen"), | |
266 | + .label = N_("Print screen"), | |
236 | 267 | .activate = fire_print_action |
237 | 268 | |
238 | 269 | }, |
239 | 270 | |
240 | 271 | { |
241 | 272 | .flags = LIB3270_CONTENT_SELECTED, |
273 | + .group = LIB3270_ACTION_GROUP_SELECTION, | |
242 | 274 | .name = "print-selected", |
243 | 275 | .icon = "document-print", |
276 | + .label = N_("Print selected"), | |
244 | 277 | .summary = N_("Print selected area"), |
245 | 278 | .activate = fire_print_action |
246 | 279 | |
... | ... | @@ -248,9 +281,10 @@ |
248 | 281 | |
249 | 282 | { |
250 | 283 | .flags = LIB3270_CONTENT_COPY, |
284 | + .group = LIB3270_ACTION_GROUP_ONLINE, | |
251 | 285 | .name = "print-copy", |
252 | 286 | .icon = "document-print", |
253 | - .summary = N_("Print Copy"), | |
287 | + .label = N_("Print Copy"), | |
254 | 288 | .activate = fire_print_action |
255 | 289 | |
256 | 290 | }, |
... | ... | @@ -265,4 +299,30 @@ |
265 | 299 | return actions; |
266 | 300 | } |
267 | 301 | |
302 | + static void activate_v3270(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) | |
303 | + { | |
304 | + debug("Activating action \"%s\"",g_action_get_name(action)); | |
305 | + | |
306 | + V3270_ACTION * descriptor = (V3270_ACTION *) ((V3270Action *) action)->info; | |
307 | + descriptor->activate(terminal,descriptor); | |
308 | + | |
309 | + } | |
310 | + | |
311 | + void g_action_map_add_v3270_actions(GActionMap *action_map) | |
312 | + { | |
313 | + | |
314 | + const V3270_ACTION * actions = v3270_get_actions(); | |
315 | + size_t ix; | |
316 | + | |
317 | + for(ix = 0; actions[ix].name; ix++) { | |
318 | + | |
319 | + V3270Action * action = V3270_ACTION(g_object_new(V3270_TYPE_ACTION, NULL)); | |
320 | + | |
321 | + action->info = (const LIB3270_PROPERTY *) &actions[ix]; | |
322 | + action->activate = activate_v3270; | |
323 | + g_action_map_add_action(action_map,G_ACTION(action)); | |
324 | + | |
325 | + } | |
326 | + | |
327 | + } | |
268 | 328 | ... | ... |
v3270.cbp
... | ... | @@ -228,6 +228,9 @@ |
228 | 228 | <Unit filename="src/terminal/actions.c"> |
229 | 229 | <Option compilerVar="CC" /> |
230 | 230 | </Unit> |
231 | + <Unit filename="src/terminal/actions/action.c"> | |
232 | + <Option compilerVar="CC" /> | |
233 | + </Unit> | |
231 | 234 | <Unit filename="src/terminal/actions/clipboard.c"> |
232 | 235 | <Option compilerVar="CC" /> |
233 | 236 | </Unit> | ... | ... |