Commit fc3438274130fcd419e9de9f0a189d512375b11f
1 parent
766bb646
Exists in
master
and in
4 other branches
Refactoring toggle action.
Showing
8 changed files
with
92 additions
and
72 deletions
Show diff stats
Makefile.in
src/include/pw3270/actions.h
... | ... | @@ -56,14 +56,21 @@ |
56 | 56 | |
57 | 57 | GObject parent; |
58 | 58 | |
59 | - const gchar * name; /// @brief Action name (const string). | |
60 | - GVariantType * parameter_type; /// @brief Parameter type. | |
61 | - GVariant * state; /// @brief Action state. | |
62 | - GtkWidget * terminal; /// @brief The active terminal widget. | |
59 | + const gchar * name; ///> @brief Action name (const string). | |
60 | + GtkWidget * terminal; ///> @brief The active terminal widget. | |
61 | + | |
62 | + struct { | |
63 | + const GVariantType * state; ///> @brief State type type. | |
64 | + const GVariantType * parameter; ///> @brief Parameter type. | |
65 | + } types; | |
63 | 66 | |
64 | 67 | /// @brief Activation method. |
65 | 68 | void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); |
66 | 69 | |
70 | + /// @brief Get State method. | |
71 | + GVariant * (*get_state_property)(GAction *action, GtkWidget *terminal); | |
72 | + | |
73 | + | |
67 | 74 | } pw3270Action; |
68 | 75 | |
69 | 76 | typedef struct _pw3270ActionClass { |
... | ... | @@ -77,7 +84,7 @@ |
77 | 84 | |
78 | 85 | void (*change_widget)(GAction *action, GtkWidget *from, GtkWidget *to); |
79 | 86 | gboolean (*get_enabled)(GAction *action, GtkWidget *terminal); |
80 | - const GVariantType * (*get_parameter_type)(GAction *action); | |
87 | + | |
81 | 88 | const gchar * (*get_icon_name)(GAction *action); |
82 | 89 | const gchar * (*get_label)(GAction *action); |
83 | 90 | const gchar * (*get_tooltip)(GAction *action); | ... | ... |
src/objects/actions/abstract.c
... | ... | @@ -46,9 +46,12 @@ |
46 | 46 | |
47 | 47 | static void finalize(GObject *object); |
48 | 48 | |
49 | - static const GVariantType * pw3270_action_get_state_type(GAction *action); | |
50 | - static GVariant * pw3270_action_get_state_property(GAction *action); | |
51 | - static const GVariantType * pw3270_action_get_parameter_type(GAction *action); | |
49 | + static const GVariantType * get_state_type(GAction *action); | |
50 | + static GVariant * get_state_property(GAction *action); | |
51 | + | |
52 | + static GVariant * internal_get_state_property(GAction *action, GtkWidget *terminal); | |
53 | + | |
54 | + static const GVariantType * get_parameter_type(GAction *action); | |
52 | 55 | static GVariant * pw3270_action_get_state_hint(GAction *action); |
53 | 56 | static void pw3270_action_change_state(GAction *action, GVariant *value); |
54 | 57 | |
... | ... | @@ -72,20 +75,15 @@ |
72 | 75 | |
73 | 76 | void pw3270_action_iface_init(GActionInterface *iface) { |
74 | 77 | iface->get_name = pw3270_action_get_name; |
75 | - iface->get_parameter_type = pw3270_action_get_parameter_type; | |
76 | - iface->get_state_type = pw3270_action_get_state_type; | |
78 | + iface->get_parameter_type = get_parameter_type; | |
79 | + iface->get_state_type = get_state_type; | |
77 | 80 | iface->get_state_hint = pw3270_action_get_state_hint; |
78 | 81 | iface->get_enabled = pw3270_action_get_enabled; |
79 | - iface->get_state = pw3270_action_get_state_property; | |
82 | + iface->get_state = get_state_property; | |
80 | 83 | iface->change_state = pw3270_action_change_state; |
81 | 84 | iface->activate = pw3270_action_activate; |
82 | 85 | } |
83 | 86 | |
84 | - static const GVariantType * get_parameter_type(GAction G_GNUC_UNUSED(*action)) | |
85 | - { | |
86 | - return NULL; | |
87 | - } | |
88 | - | |
89 | 87 | void pw3270Action_class_init(pw3270ActionClass *klass) { |
90 | 88 | |
91 | 89 | GObjectClass *object_class = G_OBJECT_CLASS(klass); |
... | ... | @@ -94,7 +92,6 @@ |
94 | 92 | |
95 | 93 | klass->change_widget = change_widget; |
96 | 94 | klass->get_enabled = get_enabled; |
97 | - klass->get_parameter_type = get_parameter_type; | |
98 | 95 | klass->get_icon_name = get_null; |
99 | 96 | klass->get_label = get_null; |
100 | 97 | klass->get_tooltip = get_null; |
... | ... | @@ -171,9 +168,11 @@ |
171 | 168 | |
172 | 169 | void pw3270Action_init(pw3270Action *action) { |
173 | 170 | |
174 | - action->terminal = NULL; | |
175 | - action->state = NULL; | |
176 | - action->activate = activate; | |
171 | + action->terminal = NULL; | |
172 | + action->types.parameter = NULL; | |
173 | + | |
174 | + action->activate = activate; | |
175 | + action->get_state_property = internal_get_state_property; | |
177 | 176 | |
178 | 177 | } |
179 | 178 | |
... | ... | @@ -181,30 +180,11 @@ |
181 | 180 | |
182 | 181 | pw3270Action * action = PW3270_ACTION(object); |
183 | 182 | |
184 | -// debug("Finalizing action %p (%s)",object,action->name); | |
185 | - | |
186 | - if(action->state) { | |
187 | - g_variant_unref(action->state); | |
188 | - action->state = NULL; | |
189 | - } | |
190 | - | |
191 | 183 | if(action->terminal) { |
192 | 184 | pw3270_action_set_terminal_widget(G_ACTION(object),NULL); |
193 | 185 | action->terminal = NULL; |
194 | 186 | } |
195 | 187 | |
196 | - /* | |
197 | - if(action->name) { | |
198 | - g_free(action->name); | |
199 | - action->name = NULL; | |
200 | - } | |
201 | - */ | |
202 | - | |
203 | - if(action->parameter_type) { | |
204 | - g_variant_type_free(action->parameter_type); | |
205 | - action->parameter_type = NULL; | |
206 | - } | |
207 | - | |
208 | 188 | G_OBJECT_CLASS(pw3270Action_parent_class)->finalize(object); |
209 | 189 | |
210 | 190 | } |
... | ... | @@ -221,7 +201,7 @@ |
221 | 201 | break; |
222 | 202 | |
223 | 203 | case PROP_PARAMETER_TYPE: |
224 | - g_value_set_boxed(value, pw3270_action_get_parameter_type(action)); | |
204 | + g_value_set_boxed(value, get_parameter_type(action)); | |
225 | 205 | break; |
226 | 206 | |
227 | 207 | case PROP_ENABLED: |
... | ... | @@ -229,11 +209,11 @@ |
229 | 209 | break; |
230 | 210 | |
231 | 211 | case PROP_STATE_TYPE: |
232 | - g_value_set_boxed(value, pw3270_action_get_state_type(action)); | |
212 | + g_value_set_boxed(value, get_state_type(action)); | |
233 | 213 | break; |
234 | 214 | |
235 | 215 | case PROP_STATE: |
236 | - g_value_take_variant(value, pw3270_action_get_state_property(action)); | |
216 | + g_value_take_variant(value, get_state_property(action)); | |
237 | 217 | break; |
238 | 218 | |
239 | 219 | default: |
... | ... | @@ -283,24 +263,38 @@ |
283 | 263 | |
284 | 264 | } |
285 | 265 | |
286 | - GVariant * pw3270_action_get_state_property(GAction *object) { | |
287 | - pw3270Action *action = PW3270_ACTION(object); | |
288 | - return action->state ? g_variant_ref(action->state) : NULL; | |
289 | - } | |
266 | + GVariant * internal_get_state_property(GAction *object, GtkWidget G_GNUC_UNUSED(*terminal)) { | |
267 | + | |
268 | + pw3270Action * action = PW3270_ACTION(object); | |
269 | + | |
270 | + if(action->types.state == G_VARIANT_TYPE_BOOLEAN) | |
271 | + return g_variant_new_boolean(TRUE); | |
290 | 272 | |
291 | - const GVariantType * pw3270_action_get_parameter_type(GAction *action) { | |
292 | - return PW3270_ACTION_GET_CLASS(action)->get_parameter_type(action); | |
273 | + return NULL; | |
293 | 274 | } |
294 | 275 | |
295 | - const GVariantType * pw3270_action_get_state_type(GAction *object) { | |
276 | + GVariant * get_state_property(GAction *object) { | |
296 | 277 | |
297 | - pw3270Action * action = PW3270_ACTION(object); | |
278 | + pw3270Action * action = PW3270_ACTION(object); | |
279 | + GVariant * state; | |
298 | 280 | |
299 | - if(action->state) | |
300 | - return g_variant_get_type(action->state); | |
281 | + if(action->terminal) | |
282 | + state = action->get_state_property(object,action->terminal); | |
283 | + else | |
284 | + state = internal_get_state_property(object,NULL); | |
301 | 285 | |
302 | - return NULL; | |
286 | + if(state) | |
287 | + g_variant_ref(state); | |
288 | + | |
289 | + return state; | |
290 | + } | |
303 | 291 | |
292 | + const GVariantType * get_parameter_type(GAction *action) { | |
293 | + return PW3270_ACTION(action)->types.parameter; | |
294 | + } | |
295 | + | |
296 | + const GVariantType * get_state_type(GAction *object) { | |
297 | + return PW3270_ACTION(object)->types.state; | |
304 | 298 | } |
305 | 299 | |
306 | 300 | GVariant * pw3270_action_get_state_hint(GAction G_GNUC_UNUSED(*action)) { |
... | ... | @@ -320,6 +314,7 @@ |
320 | 314 | |
321 | 315 | void pw3270_action_set_state(GAction *object, GVariant *value) { |
322 | 316 | |
317 | + /* | |
323 | 318 | if(value) { |
324 | 319 | |
325 | 320 | pw3270Action * action = PW3270_ACTION(object); |
... | ... | @@ -344,6 +339,7 @@ |
344 | 339 | g_variant_unref(value); |
345 | 340 | |
346 | 341 | } |
342 | + */ | |
347 | 343 | |
348 | 344 | } |
349 | 345 | ... | ... |
src/objects/actions/lib3270/pakey.c
... | ... | @@ -94,18 +94,10 @@ |
94 | 94 | |
95 | 95 | } |
96 | 96 | |
97 | - static const GVariantType * get_parameter_type(GAction G_GNUC_UNUSED(*action)) | |
98 | - { | |
99 | - return G_VARIANT_TYPE_UINT16; | |
100 | - } | |
101 | - | |
102 | 97 | void Lib3270PaAction_class_init(Lib3270PaActionClass *klass) { |
103 | 98 | |
104 | - pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); | |
105 | - | |
106 | - action->get_enabled = get_enabled; | |
107 | - action->change_widget = change_widget; | |
108 | - action->get_parameter_type = get_parameter_type; | |
99 | + klass->parent_class.get_enabled = get_enabled; | |
100 | + klass->parent_class.change_widget = change_widget; | |
109 | 101 | |
110 | 102 | } |
111 | 103 | ... | ... |
src/objects/actions/lib3270/pfkey.c
... | ... | @@ -94,17 +94,20 @@ |
94 | 94 | |
95 | 95 | } |
96 | 96 | |
97 | - static const GVariantType * get_parameter_type(GAction G_GNUC_UNUSED(*action)) { | |
98 | - return G_VARIANT_TYPE_UINT16; | |
99 | - } | |
100 | - | |
101 | 97 | void Lib3270PfAction_class_init(Lib3270PfActionClass *klass) { |
102 | 98 | |
99 | + klass->parent_class.get_enabled = get_enabled; | |
100 | + klass->parent_class.change_widget = change_widget; | |
101 | + | |
102 | + /* | |
103 | 103 | pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); |
104 | 104 | |
105 | 105 | action->get_enabled = get_enabled; |
106 | 106 | action->change_widget = change_widget; |
107 | + | |
108 | + action-> | |
107 | 109 | action->get_parameter_type = get_parameter_type; |
110 | +*/ | |
108 | 111 | |
109 | 112 | } |
110 | 113 | ... | ... |
src/objects/actions/lib3270/toggle.c
... | ... | @@ -104,8 +104,18 @@ |
104 | 104 | |
105 | 105 | void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) { |
106 | 106 | |
107 | - pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); | |
108 | - action->change_widget = change_widget; | |
107 | + klass->parent_class.change_widget = change_widget; | |
108 | + | |
109 | + } | |
110 | + | |
111 | + static GVariant * get_state_property(GAction *action, GtkWidget *terminal) { | |
112 | + | |
113 | + return g_variant_new_boolean( | |
114 | + lib3270_get_toggle( | |
115 | + v3270_get_session(terminal), | |
116 | + PW3270_LIB3270_TOGGLE_ACTION(action)->definition->id | |
117 | + ) | |
118 | + ); | |
109 | 119 | |
110 | 120 | } |
111 | 121 | |
... | ... | @@ -114,8 +124,12 @@ |
114 | 124 | action->definition = NULL; |
115 | 125 | action->listener = NULL; |
116 | 126 | |
117 | - action->parent.activate = activate; | |
118 | - action->parent.name = "toggle"; | |
127 | + action->parent.name = "toggle"; | |
128 | + | |
129 | + action->parent.get_state_property = get_state_property; | |
130 | + action->parent.activate = activate; | |
131 | + | |
132 | + action->parent.types.state = G_VARIANT_TYPE_BOOLEAN; | |
119 | 133 | |
120 | 134 | } |
121 | 135 | ... | ... |
src/objects/application/actions/window.c
... | ... | @@ -35,7 +35,7 @@ |
35 | 35 | #include <pw3270/application.h> |
36 | 36 | |
37 | 37 | |
38 | - void pw3270_application_quit_activated(GSimpleAction * action, GVariant *parameter, gpointer application) { | |
38 | + void pw3270_application_quit_activated(GSimpleAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), gpointer G_GNUC_UNUSED(application)) { | |
39 | 39 | |
40 | 40 | g_print("Exiting application\n"); |
41 | 41 | ... | ... |
ui/application.xml
... | ... | @@ -148,6 +148,7 @@ |
148 | 148 | </item> |
149 | 149 | |
150 | 150 | </section> |
151 | + | |
151 | 152 | |
152 | 153 | <section> |
153 | 154 | |
... | ... | @@ -204,6 +205,12 @@ |
204 | 205 | |
205 | 206 | </submenu> |
206 | 207 | |
208 | + <submenu id="view-menu-placeholder"> | |
209 | + | |
210 | + <attribute name='label' translatable='yes'>_View</attribute> | |
211 | + | |
212 | + </submenu> | |
213 | + | |
207 | 214 | <submenu> |
208 | 215 | |
209 | 216 | <attribute name='label' translatable='yes'>_Network</attribute> | ... | ... |