Commit d784dee6aaa939d82d66c9a4c2239ce9fc2999d2
1 parent
62d8ad06
Exists in
master
and in
4 other branches
Implemeting action group listeners.
Showing
6 changed files
with
44 additions
and
6 deletions
Show diff stats
src/objects/actions/abstract.c
| ... | ... | @@ -355,11 +355,10 @@ |
| 355 | 355 | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - void pw3270_action_set_enabled(GAction *object, gboolean G_GNUC_UNUSED(state)) { | |
| 358 | + void pw3270_action_notify_enabled(GAction *object) { | |
| 359 | 359 | g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.enabled); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - | |
| 363 | 362 | static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { |
| 364 | 363 | PW3270_ACTION(action)->terminal = to; |
| 365 | 364 | } |
| ... | ... | @@ -440,3 +439,6 @@ |
| 440 | 439 | return NULL; |
| 441 | 440 | } |
| 442 | 441 | |
| 442 | + H3270 * pw3270_action_get_session(GAction *action) { | |
| 443 | + return v3270_get_session(PW3270_ACTION(action)->terminal); | |
| 444 | + } | ... | ... |
src/objects/actions/lib3270/action.c
| ... | ... | @@ -48,6 +48,7 @@ |
| 48 | 48 | pw3270Action parent; |
| 49 | 49 | |
| 50 | 50 | const LIB3270_ACTION * definition; |
| 51 | + const void * listener; | |
| 51 | 52 | |
| 52 | 53 | } Lib3270Action; |
| 53 | 54 | |
| ... | ... | @@ -82,6 +83,18 @@ |
| 82 | 83 | return PW3270_LIB3270_ACTION(action)->definition->summary; |
| 83 | 84 | } |
| 84 | 85 | |
| 86 | + static void dispose(GObject *object) { | |
| 87 | + | |
| 88 | + Lib3270Action *action = PW3270_LIB3270_ACTION(object); | |
| 89 | + | |
| 90 | + if(action->listener) { | |
| 91 | + lib3270_unregister_action_group_listener(pw3270_action_get_session(G_ACTION(object)),action->definition->group,action->listener); | |
| 92 | + action->listener = NULL; | |
| 93 | + } | |
| 94 | + | |
| 95 | + G_OBJECT_CLASS(Lib3270Action_parent_class)->dispose(object); | |
| 96 | + } | |
| 97 | + | |
| 85 | 98 | void Lib3270Action_class_init(Lib3270ActionClass *klass) { |
| 86 | 99 | |
| 87 | 100 | pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); |
| ... | ... | @@ -93,6 +106,8 @@ |
| 93 | 106 | action->get_label = get_label; |
| 94 | 107 | action->get_tooltip = get_tooltip; |
| 95 | 108 | |
| 109 | + G_OBJECT_CLASS(klass)->dispose = dispose; | |
| 110 | + | |
| 96 | 111 | } |
| 97 | 112 | |
| 98 | 113 | void Lib3270Action_init(Lib3270Action G_GNUC_UNUSED(*action)) { |
| ... | ... | @@ -101,7 +116,10 @@ |
| 101 | 116 | GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) { |
| 102 | 117 | |
| 103 | 118 | Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL); |
| 119 | + | |
| 120 | + // Setup hooks. | |
| 104 | 121 | action->definition = definition; |
| 122 | + action->listener = NULL; | |
| 105 | 123 | |
| 106 | 124 | // Setup the default name. |
| 107 | 125 | pw3270Action * abstract = PW3270_ACTION(action); |
| ... | ... | @@ -114,14 +132,31 @@ |
| 114 | 132 | return G_ACTION(action); |
| 115 | 133 | } |
| 116 | 134 | |
| 135 | + static void event_listener(H3270 G_GNUC_UNUSED(*hSession), void *object) { | |
| 136 | + pw3270_action_notify_enabled(G_ACTION(object)); | |
| 137 | + } | |
| 138 | + | |
| 117 | 139 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { |
| 118 | 140 | |
| 141 | + // Remove old listener | |
| 142 | + Lib3270Action * action = PW3270_LIB3270_ACTION(object); | |
| 143 | + if(action->listener) { | |
| 144 | + lib3270_unregister_action_group_listener(pw3270_action_get_session(object),action->definition->group,action->listener); | |
| 145 | + action->listener = NULL; | |
| 146 | + } | |
| 147 | + | |
| 148 | + // Change widget | |
| 119 | 149 | PW3270_ACTION_CLASS(Lib3270Action_parent_class)->change_widget(object,from,to); |
| 120 | 150 | |
| 151 | + // Setup new listener | |
| 152 | + if(action->definition->group && to) { | |
| 153 | + action->listener = lib3270_register_action_group_listener(pw3270_action_get_session(object),action->definition->group,event_listener,object); | |
| 154 | + } | |
| 155 | + | |
| 121 | 156 | // Does the "enabled" state has changed? If yes notify customers. |
| 122 | 157 | gboolean enabled = get_enabled(object,to); |
| 123 | 158 | if(get_enabled(object,from) != enabled) |
| 124 | - pw3270_action_set_enabled(object,enabled); | |
| 159 | + pw3270_action_notify_enabled(object); | |
| 125 | 160 | |
| 126 | 161 | } |
| 127 | 162 | ... | ... |
src/objects/actions/lib3270/pakey.c
| ... | ... | @@ -135,7 +135,7 @@ |
| 135 | 135 | // Does the "enabled" state has changed? If yes notify customers. |
| 136 | 136 | gboolean enabled = get_enabled(object,to); |
| 137 | 137 | if(get_enabled(object,from) != enabled) |
| 138 | - pw3270_action_set_enabled(object,enabled); | |
| 138 | + pw3270_action_notify_enabled(object); | |
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | ... | ... |
src/objects/actions/lib3270/pfkey.c
| ... | ... | @@ -135,7 +135,7 @@ |
| 135 | 135 | // Does the "enabled" state has changed? If yes notify customers. |
| 136 | 136 | gboolean enabled = get_enabled(object,to); |
| 137 | 137 | if(get_enabled(object,from) != enabled) |
| 138 | - pw3270_action_set_enabled(object,enabled); | |
| 138 | + pw3270_action_notify_enabled(object); | |
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | ... | ... |
src/objects/actions/private.h
| ... | ... | @@ -85,7 +85,7 @@ |
| 85 | 85 | G_GNUC_INTERNAL GAction * pw3270_action_new_pakey(void); |
| 86 | 86 | |
| 87 | 87 | G_GNUC_INTERNAL void pw3270_action_change_state_boolean(GAction *action, gboolean state); |
| 88 | - G_GNUC_INTERNAL void pw3270_action_set_enabled(GAction *action, gboolean state); | |
| 88 | + G_GNUC_INTERNAL void pw3270_action_notify_enabled(GAction *action); | |
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | #endif // PRIVATE_H_INCLUDED | ... | ... |
src/objects/toolbar/actions.c
| ... | ... | @@ -141,6 +141,7 @@ |
| 141 | 141 | gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(item),TRUE); |
| 142 | 142 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), pos); |
| 143 | 143 | gtk_widget_show_all(GTK_WIDGET(item)); |
| 144 | + gtk_widget_set_sensitive(GTK_WIDGET(item),g_action_get_enabled(action)); | |
| 144 | 145 | |
| 145 | 146 | g_signal_connect(G_OBJECT(item),"clicked",G_CALLBACK(clicked),action); |
| 146 | 147 | g_signal_connect(G_OBJECT(action),"notify",G_CALLBACK(notify),item); | ... | ... |