Commit 9f878ea91db102b222353b2995843cdd7861315f
1 parent
54c30a12
Exists in
master
and in
4 other branches
Implementins signal and enable/disable notification.
Showing
3 changed files
with
54 additions
and
2 deletions
Show diff stats
src/actions/abstract.c
... | ... | @@ -60,6 +60,13 @@ |
60 | 60 | PROP_STATE |
61 | 61 | }; |
62 | 62 | |
63 | + enum { | |
64 | + SIGNAL_CHANGE_STATE, | |
65 | + NR_SIGNALS | |
66 | + }; | |
67 | + | |
68 | + static guint action_signals[NR_SIGNALS]; | |
69 | + | |
63 | 70 | G_DEFINE_TYPE_WITH_CODE(pw3270Action, pw3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, pw3270_action_iface_init)) |
64 | 71 | |
65 | 72 | void pw3270_action_iface_init(GActionInterface *iface) { |
... | ... | @@ -128,6 +135,18 @@ |
128 | 135 | NULL, |
129 | 136 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT | |
130 | 137 | G_PARAM_STATIC_STRINGS)); |
138 | + | |
139 | + // Install signals | |
140 | + action_signals[SIGNAL_CHANGE_STATE] = | |
141 | + g_signal_new( | |
142 | + I_("change-state"), | |
143 | + G_TYPE_SIMPLE_ACTION, | |
144 | + G_SIGNAL_RUN_LAST | G_SIGNAL_MUST_COLLECT, | |
145 | + 0, NULL, NULL, | |
146 | + NULL, | |
147 | + G_TYPE_NONE, 1, | |
148 | + G_TYPE_VARIANT | |
149 | + ); | |
131 | 150 | } |
132 | 151 | |
133 | 152 | void pw3270Action_init(pw3270Action *action) { |
... | ... | @@ -304,6 +323,10 @@ |
304 | 323 | |
305 | 324 | action->state = g_variant_ref(value); |
306 | 325 | |
326 | + if (g_signal_has_handler_pending(object, action_signals[SIGNAL_CHANGE_STATE], 0, TRUE)) { | |
327 | + g_signal_emit(object, action_signals[SIGNAL_CHANGE_STATE], 0, value); | |
328 | + } | |
329 | + | |
307 | 330 | g_object_notify(G_OBJECT(object), "state"); |
308 | 331 | |
309 | 332 | } |
... | ... | @@ -314,6 +337,14 @@ |
314 | 337 | |
315 | 338 | } |
316 | 339 | |
340 | + void pw3270_action_set_enabled(GAction *object, gboolean state) { | |
341 | + | |
342 | +// pw3270Action * action = PW3270_ACTION(object); | |
343 | + | |
344 | + g_object_notify(G_OBJECT(object), "enabled"); | |
345 | + } | |
346 | + | |
347 | + | |
317 | 348 | static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { |
318 | 349 | PW3270_ACTION(action)->terminal = to; |
319 | 350 | } |
... | ... | @@ -354,7 +385,7 @@ |
354 | 385 | debug("%s: terminal=%p",__FUNCTION__,action->terminal); |
355 | 386 | |
356 | 387 | if(action && action->terminal) { |
357 | - return PW3270_ACTION_GET_CLASS(object)->activate(object,parameter,action->terminal); | |
388 | + PW3270_ACTION_GET_CLASS(object)->activate(object,parameter,action->terminal); | |
358 | 389 | } |
359 | 390 | |
360 | 391 | } | ... | ... |
src/actions/lib3270/action.c
... | ... | @@ -53,11 +53,17 @@ |
53 | 53 | |
54 | 54 | static void Lib3270Action_class_init(Lib3270ActionClass *klass); |
55 | 55 | static void Lib3270Action_init(Lib3270Action *action); |
56 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | |
56 | 57 | |
57 | 58 | G_DEFINE_TYPE(Lib3270Action, Lib3270Action, PW3270_TYPE_ACTION); |
58 | 59 | |
59 | 60 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { |
60 | - return PW3270_LIB3270_ACTION(action)->definition->activatable(v3270_get_session(terminal)) > 0 ? TRUE : FALSE; | |
61 | + | |
62 | + if(terminal) | |
63 | + return PW3270_LIB3270_ACTION(action)->definition->activatable(v3270_get_session(terminal)) > 0 ? TRUE : FALSE; | |
64 | + | |
65 | + return FALSE; | |
66 | + | |
61 | 67 | } |
62 | 68 | |
63 | 69 | static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) { |
... | ... | @@ -70,6 +76,7 @@ |
70 | 76 | |
71 | 77 | action->activate = activate; |
72 | 78 | action->get_enabled = get_enabled; |
79 | + action->change_widget = change_widget; | |
73 | 80 | |
74 | 81 | } |
75 | 82 | |
... | ... | @@ -92,4 +99,14 @@ |
92 | 99 | return G_ACTION(action); |
93 | 100 | } |
94 | 101 | |
102 | + void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | |
103 | + | |
104 | + PW3270_ACTION_CLASS(Lib3270Action_parent_class)->change_widget(object,from,to); | |
105 | + | |
106 | + // Does the "enabled" state has changed? If yes notify customers. | |
107 | + gboolean enabled = get_enabled(object,to); | |
108 | + if(get_enabled(object,from) != enabled) | |
109 | + pw3270_action_set_enabled(object,enabled); | |
110 | + | |
111 | + } | |
95 | 112 | ... | ... |
src/actions/private.h
... | ... | @@ -48,6 +48,9 @@ |
48 | 48 | |
49 | 49 | #include <lib3270/log.h> |
50 | 50 | |
51 | + /* not really I18N-related, but also a string marker macro */ | |
52 | + #define I_(string) g_intern_static_string (string) | |
53 | + | |
51 | 54 | struct _pw3270Action { |
52 | 55 | GObject parent; |
53 | 56 | |
... | ... | @@ -71,6 +74,7 @@ |
71 | 74 | G_GNUC_INTERNAL GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE * definition); |
72 | 75 | |
73 | 76 | G_GNUC_INTERNAL void pw3270_action_change_state_boolean(GAction *action, gboolean state); |
77 | + G_GNUC_INTERNAL void pw3270_action_set_enabled(GAction *action, gboolean state); | |
74 | 78 | |
75 | 79 | |
76 | 80 | #endif // PRIVATE_H_INCLUDED | ... | ... |