Commit 74f58ec3c51e4872caf8d6980d32f5c868cff141
1 parent
155e957c
Exists in
master
and in
4 other branches
Implemeting "copy-based" actions.
Showing
5 changed files
with
110 additions
and
9 deletions
Show diff stats
src/include/pw3270/actions.h
| ... | ... | @@ -215,6 +215,34 @@ |
| 215 | 215 | |
| 216 | 216 | GAction * v3270_property_action_new(GtkWidget *widget, const gchar *property_name); |
| 217 | 217 | |
| 218 | + // | |
| 219 | + // V3270 Copy action | |
| 220 | + // | |
| 221 | + #define V3270_TYPE_COPY_ACTION (v3270CopyAction_get_type()) | |
| 222 | + #define V3270_COPY_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_COPY_ACTION, v3270CopyAction)) | |
| 223 | + #define V3270_COPY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_COPY_ACTION, v3270CopyActionClass)) | |
| 224 | + #define V3270_IS_COPY_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_COPY_ACTION)) | |
| 225 | + #define V3270_IS_COPY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_COPY_ACTION)) | |
| 226 | + #define V3270_COPY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_COPY_ACTION, v3270CopyActionClass)) | |
| 227 | + | |
| 228 | + typedef struct _v3270CopyAction { | |
| 229 | + | |
| 230 | + pw3270SimpleAction parent; | |
| 231 | + | |
| 232 | + GParamSpec *pspec; | |
| 233 | + | |
| 234 | + } v3270CopyAction; | |
| 235 | + | |
| 236 | + typedef struct _v3270CopyActionClass { | |
| 237 | + | |
| 238 | + pw3270SimpleActionClass parent_class; | |
| 239 | + | |
| 240 | + } v3270CopyActionClass; | |
| 241 | + | |
| 242 | + GType v3270CopyAction_get_type(void) G_GNUC_CONST; | |
| 243 | + | |
| 244 | + GAction * v3270_copy_action_new(GtkWidget *widget); | |
| 245 | + | |
| 218 | 246 | G_END_DECLS |
| 219 | 247 | |
| 220 | 248 | #endif // PW3270_ACTIONS_H_INCLUDED | ... | ... |
src/objects/actions/private.h
| ... | ... | @@ -69,11 +69,11 @@ |
| 69 | 69 | G_GNUC_INTERNAL GAction * pw3270_action_save_new(void); |
| 70 | 70 | G_GNUC_INTERNAL GAction * pw3270_action_save_screen_new(void); |
| 71 | 71 | G_GNUC_INTERNAL GAction * pw3270_action_save_selected_new(void); |
| 72 | - G_GNUC_INTERNAL GAction * pw3270_action_save_copy_new(void); | |
| 72 | + G_GNUC_INTERNAL GAction * pw3270_action_save_copy_new(GtkWidget *widget); | |
| 73 | 73 | |
| 74 | 74 | G_GNUC_INTERNAL GAction * pw3270_action_print_new(void); |
| 75 | 75 | G_GNUC_INTERNAL GAction * pw3270_action_print_screen_new(void); |
| 76 | 76 | G_GNUC_INTERNAL GAction * pw3270_action_print_selected_new(void); |
| 77 | - G_GNUC_INTERNAL GAction * pw3270_action_print_copy_new(void); | |
| 77 | + G_GNUC_INTERNAL GAction * pw3270_action_print_copy_new(GtkWidget *widget); | |
| 78 | 78 | |
| 79 | 79 | #endif // PRIVATE_H_INCLUDED | ... | ... |
src/objects/actions/v3270/copy.c
| ... | ... | @@ -28,17 +28,81 @@ |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * @brief Implement PW3270 save actions. | |
| 31 | + * @brief Implement PW3270 copy actions. | |
| 32 | 32 | * |
| 33 | 33 | */ |
| 34 | 34 | |
| 35 | 35 | #include "../private.h" |
| 36 | 36 | #include <v3270.h> |
| 37 | 37 | |
| 38 | + static void v3270CopyAction_class_init(v3270CopyActionClass *klass); | |
| 39 | + static void v3270CopyAction_init(v3270CopyAction *action); | |
| 40 | + static GVariant * get_state(GAction *action, GtkWidget *terminal); | |
| 41 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | |
| 38 | 42 | |
| 39 | - GAction * pw3270_action_print_copy_new(void) { | |
| 43 | + G_DEFINE_TYPE(v3270CopyAction, v3270CopyAction, PW3270_TYPE_SIMPLE_ACTION); | |
| 40 | 44 | |
| 41 | - pw3270SimpleAction * action = pw3270_simple_action_new(); | |
| 45 | + void v3270CopyAction_class_init(v3270CopyActionClass *klass) { | |
| 46 | + klass->parent_class.parent_class.change_widget = change_widget; | |
| 47 | + } | |
| 48 | + | |
| 49 | + static void v3270CopyAction_init(v3270CopyAction *action) { | |
| 50 | + | |
| 51 | + action->parent.parent.get_state_property = get_state; | |
| 52 | + | |
| 53 | + } | |
| 54 | + | |
| 55 | + GVariant * get_state(GAction *object, GtkWidget *terminal) { | |
| 56 | + | |
| 57 | + | |
| 58 | + return NULL; | |
| 59 | + | |
| 60 | + } | |
| 61 | + | |
| 62 | + static void activate(GAction *object, GVariant *parameter, GtkWidget *terminal) { | |
| 63 | + | |
| 64 | + | |
| 65 | + } | |
| 66 | + | |
| 67 | + static void on_notify(GtkWidget G_GNUC_UNUSED(*terminal), GParamSpec G_GNUC_UNUSED(*pspec), GAction *action) { | |
| 68 | + | |
| 69 | + debug("%s: State of action %s has changed",__FUNCTION__, g_action_get_name(G_ACTION(action))); | |
| 70 | + pw3270_action_notify_state(action); | |
| 71 | + | |
| 72 | + } | |
| 73 | + | |
| 74 | + void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | |
| 75 | + | |
| 76 | + v3270CopyAction * action = V3270_COPY_ACTION(object); | |
| 77 | + | |
| 78 | + if(from) { | |
| 79 | + gulong handler = g_signal_handler_find( | |
| 80 | + "has-text", | |
| 81 | + G_SIGNAL_MATCH_FUNC|G_SIGNAL_MATCH_DATA, | |
| 82 | + 0, | |
| 83 | + 0, | |
| 84 | + NULL, | |
| 85 | + G_CALLBACK(on_notify), | |
| 86 | + action | |
| 87 | + ); | |
| 88 | + | |
| 89 | + if(handler) | |
| 90 | + g_signal_handler_disconnect(from, handler); | |
| 91 | + | |
| 92 | + } | |
| 93 | + | |
| 94 | + PW3270_ACTION_CLASS(v3270CopyAction_parent_class)->change_widget(object,from,to); | |
| 95 | + | |
| 96 | + if(to) { | |
| 97 | + g_signal_connect(G_OBJECT(to),"has-text",G_CALLBACK(on_notify),action); | |
| 98 | + } | |
| 99 | + | |
| 100 | + } | |
| 101 | + | |
| 102 | + | |
| 103 | + GAction * pw3270_action_print_copy_new(GtkWidget *widget) { | |
| 104 | + | |
| 105 | + pw3270SimpleAction * action = (pw3270SimpleAction *) g_object_new(V3270_TYPE_COPY_ACTION, NULL);; | |
| 42 | 106 | |
| 43 | 107 | action->group.id = LIB3270_ACTION_GROUP_ONLINE; |
| 44 | 108 | action->parent.name = "print_copy"; |
| ... | ... | @@ -48,9 +112,9 @@ |
| 48 | 112 | |
| 49 | 113 | } |
| 50 | 114 | |
| 51 | - GAction * pw3270_action_save_copy_new(void) { | |
| 115 | + GAction * pw3270_action_save_copy_new(GtkWidget *widget) { | |
| 52 | 116 | |
| 53 | - pw3270SimpleAction * action = pw3270_simple_action_new(); | |
| 117 | + pw3270SimpleAction * action = (pw3270SimpleAction *) g_object_new(V3270_TYPE_COPY_ACTION, NULL);; | |
| 54 | 118 | |
| 55 | 119 | action->group.id = LIB3270_ACTION_GROUP_ONLINE; |
| 56 | 120 | action->parent.name = "save_copy"; | ... | ... |
src/objects/actions/window.c
| ... | ... | @@ -76,11 +76,9 @@ |
| 76 | 76 | |
| 77 | 77 | pw3270_action_save_screen_new(), |
| 78 | 78 | pw3270_action_save_selected_new(), |
| 79 | - pw3270_action_save_copy_new(), | |
| 80 | 79 | |
| 81 | 80 | pw3270_action_print_screen_new(), |
| 82 | 81 | pw3270_action_print_selected_new(), |
| 83 | - pw3270_action_print_copy_new() | |
| 84 | 82 | |
| 85 | 83 | }; |
| 86 | 84 | ... | ... |
src/objects/application/application.c
| ... | ... | @@ -299,6 +299,17 @@ |
| 299 | 299 | |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | + // Create copy actions. | |
| 303 | + g_action_map_add_action( | |
| 304 | + G_ACTION_MAP(window), | |
| 305 | + pw3270_action_save_copy_new(terminal) | |
| 306 | + ); | |
| 307 | + | |
| 308 | + g_action_map_add_action( | |
| 309 | + G_ACTION_MAP(window), | |
| 310 | + pw3270_action_print_copy_new(terminal) | |
| 311 | + ); | |
| 312 | + | |
| 302 | 313 | // Present the new window |
| 303 | 314 | pw3270_window_set_current_page(window,0); |
| 304 | 315 | gtk_window_present(GTK_WINDOW(window)); | ... | ... |