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,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 | g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.enabled); | 359 | g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.enabled); |
360 | } | 360 | } |
361 | 361 | ||
362 | - | ||
363 | static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { | 362 | static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { |
364 | PW3270_ACTION(action)->terminal = to; | 363 | PW3270_ACTION(action)->terminal = to; |
365 | } | 364 | } |
@@ -440,3 +439,6 @@ | @@ -440,3 +439,6 @@ | ||
440 | return NULL; | 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,6 +48,7 @@ | ||
48 | pw3270Action parent; | 48 | pw3270Action parent; |
49 | 49 | ||
50 | const LIB3270_ACTION * definition; | 50 | const LIB3270_ACTION * definition; |
51 | + const void * listener; | ||
51 | 52 | ||
52 | } Lib3270Action; | 53 | } Lib3270Action; |
53 | 54 | ||
@@ -82,6 +83,18 @@ | @@ -82,6 +83,18 @@ | ||
82 | return PW3270_LIB3270_ACTION(action)->definition->summary; | 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 | void Lib3270Action_class_init(Lib3270ActionClass *klass) { | 98 | void Lib3270Action_class_init(Lib3270ActionClass *klass) { |
86 | 99 | ||
87 | pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); | 100 | pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); |
@@ -93,6 +106,8 @@ | @@ -93,6 +106,8 @@ | ||
93 | action->get_label = get_label; | 106 | action->get_label = get_label; |
94 | action->get_tooltip = get_tooltip; | 107 | action->get_tooltip = get_tooltip; |
95 | 108 | ||
109 | + G_OBJECT_CLASS(klass)->dispose = dispose; | ||
110 | + | ||
96 | } | 111 | } |
97 | 112 | ||
98 | void Lib3270Action_init(Lib3270Action G_GNUC_UNUSED(*action)) { | 113 | void Lib3270Action_init(Lib3270Action G_GNUC_UNUSED(*action)) { |
@@ -101,7 +116,10 @@ | @@ -101,7 +116,10 @@ | ||
101 | GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) { | 116 | GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) { |
102 | 117 | ||
103 | Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL); | 118 | Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL); |
119 | + | ||
120 | + // Setup hooks. | ||
104 | action->definition = definition; | 121 | action->definition = definition; |
122 | + action->listener = NULL; | ||
105 | 123 | ||
106 | // Setup the default name. | 124 | // Setup the default name. |
107 | pw3270Action * abstract = PW3270_ACTION(action); | 125 | pw3270Action * abstract = PW3270_ACTION(action); |
@@ -114,14 +132,31 @@ | @@ -114,14 +132,31 @@ | ||
114 | return G_ACTION(action); | 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 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | 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 | PW3270_ACTION_CLASS(Lib3270Action_parent_class)->change_widget(object,from,to); | 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 | // Does the "enabled" state has changed? If yes notify customers. | 156 | // Does the "enabled" state has changed? If yes notify customers. |
122 | gboolean enabled = get_enabled(object,to); | 157 | gboolean enabled = get_enabled(object,to); |
123 | if(get_enabled(object,from) != enabled) | 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,7 +135,7 @@ | ||
135 | // Does the "enabled" state has changed? If yes notify customers. | 135 | // Does the "enabled" state has changed? If yes notify customers. |
136 | gboolean enabled = get_enabled(object,to); | 136 | gboolean enabled = get_enabled(object,to); |
137 | if(get_enabled(object,from) != enabled) | 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,7 +135,7 @@ | ||
135 | // Does the "enabled" state has changed? If yes notify customers. | 135 | // Does the "enabled" state has changed? If yes notify customers. |
136 | gboolean enabled = get_enabled(object,to); | 136 | gboolean enabled = get_enabled(object,to); |
137 | if(get_enabled(object,from) != enabled) | 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,7 +85,7 @@ | ||
85 | G_GNUC_INTERNAL GAction * pw3270_action_new_pakey(void); | 85 | G_GNUC_INTERNAL GAction * pw3270_action_new_pakey(void); |
86 | 86 | ||
87 | G_GNUC_INTERNAL void pw3270_action_change_state_boolean(GAction *action, gboolean state); | 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 | #endif // PRIVATE_H_INCLUDED | 91 | #endif // PRIVATE_H_INCLUDED |
src/objects/toolbar/actions.c
@@ -141,6 +141,7 @@ | @@ -141,6 +141,7 @@ | ||
141 | gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(item),TRUE); | 141 | gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(item),TRUE); |
142 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), pos); | 142 | gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), pos); |
143 | gtk_widget_show_all(GTK_WIDGET(item)); | 143 | gtk_widget_show_all(GTK_WIDGET(item)); |
144 | + gtk_widget_set_sensitive(GTK_WIDGET(item),g_action_get_enabled(action)); | ||
144 | 145 | ||
145 | g_signal_connect(G_OBJECT(item),"clicked",G_CALLBACK(clicked),action); | 146 | g_signal_connect(G_OBJECT(item),"clicked",G_CALLBACK(clicked),action); |
146 | g_signal_connect(G_OBJECT(action),"notify",G_CALLBACK(notify),item); | 147 | g_signal_connect(G_OBJECT(action),"notify",G_CALLBACK(notify),item); |