Commit 068bbf7b306f350263511a4b9672038a597753b9
1 parent
17bb509e
Exists in
master
and in
4 other branches
Refactoring terminal property actions.
Showing
2 changed files
with
70 additions
and
43 deletions
Show diff stats
src/include/pw3270/actions.h
| ... | ... | @@ -200,29 +200,6 @@ |
| 200 | 200 | // |
| 201 | 201 | // V3270 Property Action |
| 202 | 202 | // |
| 203 | - #define V3270_TYPE_PROPERTY_ACTION (v3270PropertyAction_get_type()) | |
| 204 | - #define V3270_PROPERTY_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_PROPERTY_ACTION, v3270PropertyAction)) | |
| 205 | - #define V3270_PROPERTY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_PROPERTY_ACTION, v3270PropertyActionClass)) | |
| 206 | - #define V3270_IS_PROPERTY_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_PROPERTY_ACTION)) | |
| 207 | - #define V3270_IS_PROPERTY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_PROPERTY_ACTION)) | |
| 208 | - #define V3270_PROPERTY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_PROPERTY_ACTION, v3270PropertyActionClass)) | |
| 209 | - | |
| 210 | - typedef struct _v3270PropertyAction { | |
| 211 | - | |
| 212 | - pw3270SimpleAction parent; | |
| 213 | - | |
| 214 | - GParamSpec *pspec; | |
| 215 | - | |
| 216 | - } v3270PropertyAction; | |
| 217 | - | |
| 218 | - typedef struct _v3270PropertyActionClass { | |
| 219 | - | |
| 220 | - pw3270SimpleActionClass parent_class; | |
| 221 | - | |
| 222 | - } v3270PropertyActionClass; | |
| 223 | - | |
| 224 | - GType v3270PropertyAction_get_type(void) G_GNUC_CONST; | |
| 225 | - | |
| 226 | 203 | GAction * v3270_property_action_new(GtkWidget *widget, const gchar *property_name); |
| 227 | 204 | |
| 228 | 205 | // | ... | ... |
src/objects/actions/v3270/property.c
| ... | ... | @@ -42,21 +42,49 @@ |
| 42 | 42 | #include <v3270.h> |
| 43 | 43 | #include <lib3270/properties.h> |
| 44 | 44 | |
| 45 | - static void v3270PropertyAction_class_init(v3270PropertyActionClass *klass); | |
| 46 | - static void v3270PropertyAction_init(v3270PropertyAction *action); | |
| 47 | - static GVariant * get_state(GAction *action, GtkWidget *terminal); | |
| 48 | - static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | |
| 45 | + // | |
| 46 | + // V3270 Property Action | |
| 47 | + // | |
| 48 | + #define V3270_TYPE_PROPERTY_ACTION (v3270PropertyAction_get_type()) | |
| 49 | + #define V3270_PROPERTY_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_PROPERTY_ACTION, v3270PropertyAction)) | |
| 50 | + #define V3270_PROPERTY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_PROPERTY_ACTION, v3270PropertyActionClass)) | |
| 51 | + #define V3270_IS_PROPERTY_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_PROPERTY_ACTION)) | |
| 52 | + #define V3270_IS_PROPERTY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_PROPERTY_ACTION)) | |
| 53 | + #define V3270_PROPERTY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_PROPERTY_ACTION, v3270PropertyActionClass)) | |
| 49 | 54 | |
| 50 | - G_DEFINE_TYPE(v3270PropertyAction, v3270PropertyAction, PW3270_TYPE_SIMPLE_ACTION); | |
| 55 | + typedef struct _v3270PropertyAction { | |
| 56 | + | |
| 57 | + V3270SimpleAction parent; | |
| 58 | + | |
| 59 | + GParamSpec *pspec; | |
| 60 | + | |
| 61 | + } v3270PropertyAction; | |
| 62 | + | |
| 63 | + typedef struct _v3270PropertyActionClass { | |
| 64 | + | |
| 65 | + V3270SimpleActionClass parent_class; | |
| 66 | + | |
| 67 | + } v3270PropertyActionClass; | |
| 68 | + | |
| 69 | +// static void v3270PropertyAction_class_init(v3270PropertyActionClass *klass); | |
| 70 | +// static void v3270PropertyAction_init(v3270PropertyAction *action); | |
| 71 | + | |
| 72 | + static GVariant * get_state(GAction *action, GtkWidget *terminal); | |
| 73 | + static const GVariantType * get_state_type(GAction *object); | |
| 74 | + static const GVariantType * get_parameter_type(GAction *object); | |
| 75 | + | |
| 76 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | |
| 77 | + | |
| 78 | + G_DEFINE_TYPE(v3270PropertyAction, v3270PropertyAction, V3270_TYPE_SIMPLE_ACTION); | |
| 51 | 79 | |
| 52 | 80 | void v3270PropertyAction_class_init(v3270PropertyActionClass *klass) { |
| 53 | 81 | klass->parent_class.parent_class.change_widget = change_widget; |
| 82 | + klass->parent_class.parent_class.get_parameter_type = get_parameter_type; | |
| 83 | + klass->parent_class.parent_class.get_state = get_state; | |
| 84 | + klass->parent_class.parent_class.get_state_type = get_state_type; | |
| 54 | 85 | } |
| 55 | 86 | |
| 56 | - static void v3270PropertyAction_init(v3270PropertyAction *action) { | |
| 57 | - | |
| 58 | - action->parent.parent.get_state_property = get_state; | |
| 59 | - | |
| 87 | + static void v3270PropertyAction_init(v3270PropertyAction G_GNUC_UNUSED(*action)) { | |
| 60 | 88 | } |
| 61 | 89 | |
| 62 | 90 | GVariant * get_state(GAction *object, GtkWidget *terminal) { |
| ... | ... | @@ -207,26 +235,48 @@ |
| 207 | 235 | |
| 208 | 236 | v3270PropertyAction * action = (v3270PropertyAction *) g_object_new(V3270_TYPE_PROPERTY_ACTION, NULL); |
| 209 | 237 | |
| 210 | - pw3270_simple_action_set_lib3270_property(PW3270_SIMPLE_ACTION(action), lib3270_property_get_by_name(pspec->name)); | |
| 211 | - | |
| 212 | - action->parent.parent.name = g_param_spec_get_name(pspec); | |
| 213 | - action->parent.tooltip = g_param_spec_get_blurb(pspec); | |
| 238 | + action->parent.name = g_param_spec_get_name(pspec); | |
| 214 | 239 | |
| 215 | - if(pspec->value_type == G_TYPE_BOOLEAN) { | |
| 216 | - action->parent.parent.types.state = G_VARIANT_TYPE_BOOLEAN; | |
| 217 | - } else { | |
| 218 | - action->parent.parent.types.state = G_VARIANT_TYPE_STRING; | |
| 219 | - action->parent.parent.types.parameter = G_VARIANT_TYPE_STRING; | |
| 240 | + const LIB3270_PROPERTY * lProperty = lib3270_property_get_by_name(pspec->name); | |
| 241 | + if(lProperty) { | |
| 242 | + action->parent.label = lib3270_property_get_label(lProperty); | |
| 243 | + action->parent.tooltip = lib3270_property_get_summary(lProperty); | |
| 244 | +// action->group.id = lProperty->group; | |
| 220 | 245 | } |
| 221 | 246 | |
| 247 | + if(!action->parent.tooltip) | |
| 248 | + action->parent.tooltip = g_param_spec_get_blurb(pspec); | |
| 249 | + | |
| 222 | 250 | action->parent.parent.activate = activate; |
| 223 | 251 | action->pspec = pspec; |
| 224 | 252 | |
| 225 | - pw3270_action_set_terminal_widget(G_ACTION(action), widget); | |
| 253 | + v3270_action_set_terminal_widget(G_ACTION(action), widget); | |
| 226 | 254 | |
| 227 | 255 | return G_ACTION(action); |
| 228 | 256 | } |
| 229 | 257 | |
| 258 | + const GVariantType * get_state_type(GAction *object) { | |
| 259 | + | |
| 260 | + v3270PropertyAction * action = V3270_PROPERTY_ACTION(object); | |
| 261 | + | |
| 262 | + if(action->pspec->value_type == G_TYPE_BOOLEAN) | |
| 263 | + return G_VARIANT_TYPE_BOOLEAN; | |
| 264 | + | |
| 265 | + return G_VARIANT_TYPE_STRING; | |
| 266 | + | |
| 267 | + } | |
| 268 | + | |
| 269 | + const GVariantType * get_parameter_type(GAction *object) { | |
| 270 | + | |
| 271 | + v3270PropertyAction * action = V3270_PROPERTY_ACTION(object); | |
| 272 | + | |
| 273 | + if(action->pspec->value_type == G_TYPE_BOOLEAN) | |
| 274 | + return G_VARIANT_TYPE_BOOLEAN; | |
| 275 | + | |
| 276 | + return G_VARIANT_TYPE_STRING; | |
| 277 | + | |
| 278 | + } | |
| 279 | + | |
| 230 | 280 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { |
| 231 | 281 | |
| 232 | 282 | v3270PropertyAction * action = V3270_PROPERTY_ACTION(object); |
| ... | ... | @@ -248,7 +298,7 @@ |
| 248 | 298 | |
| 249 | 299 | } |
| 250 | 300 | |
| 251 | - PW3270_ACTION_CLASS(v3270PropertyAction_parent_class)->change_widget(object,from,to); | |
| 301 | + V3270_ACTION_CLASS(v3270PropertyAction_parent_class)->change_widget(object,from,to); | |
| 252 | 302 | |
| 253 | 303 | if(to) { |
| 254 | 304 | g_signal_connect(G_OBJECT(to),signal_name,G_CALLBACK(on_notify),action); | ... | ... |