Commit 6c0b2b0064dfbd20a19252633b04e67cd7b688c6
1 parent
f5dc83cb
Exists in
master
and in
4 other branches
Fixing action engine.
Showing
11 changed files
with
63 additions
and
145 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -86,6 +86,9 @@ |
| 86 | 86 | <Unit filename="src/objects/toolbar/toolbar.c"> |
| 87 | 87 | <Option compilerVar="CC" /> |
| 88 | 88 | </Unit> |
| 89 | + <Unit filename="src/objects/toolbar/toolbutton.c"> | |
| 90 | + <Option compilerVar="CC" /> | |
| 91 | + </Unit> | |
| 89 | 92 | <Unit filename="src/objects/window/actions.c"> |
| 90 | 93 | <Option compilerVar="CC" /> |
| 91 | 94 | </Unit> | ... | ... |
src/include/pw3270/toolbar.h
| ... | ... | @@ -57,8 +57,7 @@ |
| 57 | 57 | GtkWidget * pw3270_toolbar_new(void); |
| 58 | 58 | |
| 59 | 59 | GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos); |
| 60 | - GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, GAction *action, gint pos); | |
| 61 | - GtkWidget * pw3270_toolbar_insert_action_by_name(GtkWidget *toolbar, const gchar *name, gint pos); | |
| 60 | + GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos); | |
| 62 | 61 | |
| 63 | 62 | void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style); |
| 64 | 63 | // GtkToolbarStyle pw3270_toolbar_toolbar_get_style(GtkToolbar *toolbar); | ... | ... |
src/objects/actions/abstract.c
| ... | ... | @@ -356,7 +356,16 @@ |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 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 | + | |
| 360 | + debug("%s(%s) = %s", | |
| 361 | + __FUNCTION__, | |
| 362 | + g_action_get_name(G_ACTION(object)), | |
| 363 | + (g_action_get_enabled(G_ACTION(object)) ? "Enabled" : "Disabled") | |
| 364 | + ); | |
| 365 | + | |
| 366 | + // g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.enabled); | |
| 367 | + g_object_notify(G_OBJECT (object), "enabled"); | |
| 368 | + | |
| 360 | 369 | } |
| 361 | 370 | |
| 362 | 371 | static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { |
| ... | ... | @@ -382,13 +391,15 @@ |
| 382 | 391 | |
| 383 | 392 | gboolean pw3270_action_get_enabled(GAction *object) { |
| 384 | 393 | |
| 394 | + gboolean enabled = FALSE; | |
| 395 | + | |
| 385 | 396 | pw3270Action * action = PW3270_ACTION(object); |
| 386 | 397 | |
| 387 | 398 | if(action && action->terminal) { |
| 388 | - return PW3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); | |
| 399 | + enabled = PW3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); | |
| 389 | 400 | } |
| 390 | 401 | |
| 391 | - return FALSE; | |
| 402 | + return enabled; | |
| 392 | 403 | |
| 393 | 404 | } |
| 394 | 405 | ... | ... |
src/objects/actions/connect.c
| ... | ... | @@ -46,7 +46,7 @@ |
| 46 | 46 | GAction * action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("reconnect")); |
| 47 | 47 | |
| 48 | 48 | PW3270_ACTION(action)->activate = activate; |
| 49 | - pw3270_action_set_name(G_ACTION(action),"win.connect"); | |
| 49 | + pw3270_action_set_name(G_ACTION(action),"connect"); | |
| 50 | 50 | |
| 51 | 51 | return action; |
| 52 | 52 | ... | ... |
src/objects/actions/lib3270/action.c
src/objects/actions/lib3270/pakey.c
src/objects/actions/lib3270/pfkey.c
src/objects/actions/window.c
| ... | ... | @@ -43,6 +43,15 @@ |
| 43 | 43 | |
| 44 | 44 | // Map lib3270 actions |
| 45 | 45 | { |
| 46 | + GAction * action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("disconnect")); | |
| 47 | + | |
| 48 | + pw3270_action_set_name(G_ACTION(action),"disconnect"); | |
| 49 | + | |
| 50 | + g_action_map_add_action(map,action); | |
| 51 | + | |
| 52 | + } | |
| 53 | + | |
| 54 | + { | |
| 46 | 55 | const LIB3270_ACTION * actions = lib3270_get_actions(); |
| 47 | 56 | for(ix = 0; actions[ix].name; ix++) { |
| 48 | 57 | |
| ... | ... | @@ -80,4 +89,5 @@ |
| 80 | 89 | } |
| 81 | 90 | |
| 82 | 91 | debug("%s ends",__FUNCTION__); |
| 92 | + | |
| 83 | 93 | } | ... | ... |
src/objects/toolbar/actions.c
| ... | ... | @@ -30,129 +30,7 @@ |
| 30 | 30 | #include "private.h" |
| 31 | 31 | #include <pw3270/actions.h> |
| 32 | 32 | |
| 33 | - static GtkWidget * pw3270_tool_button_new(GAction *action) { | |
| 34 | - | |
| 35 | - const gchar * action_name = g_action_get_name(action); | |
| 36 | - debug("action=%s enabled=%s type=%s",action_name,g_action_get_enabled(action) ? "Yes" : "No", g_action_get_parameter_type(action)); | |
| 37 | - | |
| 38 | - if(PW3270_IS_ACTION(action)) { | |
| 39 | - | |
| 40 | - // It's a pw3270 action, get attributes from it. | |
| 41 | - | |
| 42 | - const gchar * icon_name = pw3270_action_get_icon_name(action); | |
| 43 | - if(!icon_name) { | |
| 44 | - g_message("Action doesn't have an icon"); | |
| 45 | - return NULL; | |
| 46 | - } | |
| 47 | - | |
| 48 | - debug("%s - %s",icon_name,pw3270_action_get_label(action)); | |
| 49 | - | |
| 50 | - GtkToolItem * item = gtk_tool_button_new( | |
| 51 | - NULL, | |
| 52 | - pw3270_action_get_label(action) | |
| 53 | - ); | |
| 54 | - | |
| 55 | - gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(item),icon_name); | |
| 56 | - | |
| 57 | - const gchar * tooltip = pw3270_action_get_tooltip(action); | |
| 58 | - if(tooltip) | |
| 59 | - gtk_widget_set_tooltip_markup(GTK_WIDGET(item),tooltip); | |
| 60 | - | |
| 61 | - return GTK_WIDGET(item); | |
| 62 | - | |
| 63 | - } | |
| 64 | - | |
| 65 | - // | |
| 66 | - // Check for my Actions. | |
| 67 | - // | |
| 68 | - | |
| 69 | - static const struct _actions { | |
| 70 | - const gchar * name; | |
| 71 | - const gchar * icon; | |
| 72 | - const gchar * label; | |
| 73 | - const gchar * tooltip; | |
| 74 | - } actions[] = { | |
| 75 | - | |
| 76 | - { | |
| 77 | - .name = "win.connect", | |
| 78 | - .icon = "gtk-connect", | |
| 79 | - .label = N_("Connect"), | |
| 80 | - .tooltip = N_("Connect to host") | |
| 81 | - }, | |
| 82 | - | |
| 83 | - { | |
| 84 | - .name = "win.close", | |
| 85 | - .icon = "window-close", | |
| 86 | - .label = N_("Close"), | |
| 87 | - .tooltip = N_("Close window") | |
| 88 | - } | |
| 89 | - | |
| 90 | - }; | |
| 91 | - | |
| 92 | - size_t ix; | |
| 93 | - for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { | |
| 94 | - | |
| 95 | - if(!g_ascii_strcasecmp(action_name,actions[ix].name)) { | |
| 96 | - | |
| 97 | - GtkToolItem * item = gtk_tool_button_new( | |
| 98 | - gtk_image_new_from_icon_name(actions[ix].icon,GTK_ICON_SIZE_LARGE_TOOLBAR), | |
| 99 | - gettext(actions[ix].label) | |
| 100 | - ); | |
| 101 | - | |
| 102 | - if(actions[ix].tooltip) | |
| 103 | - gtk_widget_set_tooltip_markup(GTK_WIDGET(item),gettext(actions[ix].tooltip)); | |
| 104 | - | |
| 105 | - return GTK_WIDGET(item); | |
| 106 | - } | |
| 107 | - | |
| 108 | - } | |
| 109 | - | |
| 110 | - g_warning("Action \"%s\" can't be inserted on toolbar",action_name); | |
| 111 | - | |
| 112 | - return NULL; | |
| 113 | - | |
| 114 | - } | |
| 115 | - | |
| 116 | - static void clicked(GtkToolButton G_GNUC_UNUSED(*toolbutton), GAction *action) { | |
| 117 | - | |
| 118 | - if(g_action_get_enabled(action)) { | |
| 119 | - g_action_activate(action,NULL); | |
| 120 | - } | |
| 121 | -#ifdef DEBUG | |
| 122 | - else { | |
| 123 | - debug("Action \"%s\" is disabled",g_action_get_name(action)); | |
| 124 | - } | |
| 125 | -#endif // DEBUG | |
| 126 | - | |
| 127 | - } | |
| 128 | - | |
| 129 | - static void notify(GAction *action, GParamSpec *pspec, GtkWidget *item) { | |
| 130 | - if(!strcmp(pspec->name,"enabled")) | |
| 131 | - gtk_widget_set_sensitive(item,g_action_get_enabled(action)); | |
| 132 | - } | |
| 133 | - | |
| 134 | - GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, GAction *action, gint pos) { | |
| 135 | - | |
| 136 | - g_return_val_if_fail(PW3270_IS_TOOLBAR(toolbar),NULL); | |
| 137 | - | |
| 138 | - GtkWidget * item = pw3270_tool_button_new(action); | |
| 139 | - | |
| 140 | - if(!item) | |
| 141 | - return NULL; | |
| 142 | - | |
| 143 | - gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(item),TRUE); | |
| 144 | - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), pos); | |
| 145 | - gtk_widget_show_all(GTK_WIDGET(item)); | |
| 146 | - gtk_widget_set_sensitive(GTK_WIDGET(item),g_action_get_enabled(action)); | |
| 147 | - | |
| 148 | - g_signal_connect(G_OBJECT(item),"clicked",G_CALLBACK(clicked),action); | |
| 149 | - g_signal_connect(G_OBJECT(action),"notify",G_CALLBACK(notify),item); | |
| 150 | - | |
| 151 | - return item; | |
| 152 | - | |
| 153 | - } | |
| 154 | - | |
| 155 | - GtkWidget * pw3270_toolbar_insert_action_by_name(GtkWidget *toolbar, const gchar *name, gint pos) { | |
| 33 | + GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos) { | |
| 156 | 34 | |
| 157 | 35 | g_return_val_if_fail(PW3270_IS_TOOLBAR(toolbar),NULL); |
| 158 | 36 | |
| ... | ... | @@ -183,11 +61,28 @@ |
| 183 | 61 | if(window) { |
| 184 | 62 | |
| 185 | 63 | GAction *action = g_action_map_lookup_action(G_ACTION_MAP(window), name); |
| 64 | + GtkToolItem * item = NULL; | |
| 186 | 65 | |
| 187 | - if(action) | |
| 188 | - return pw3270_toolbar_insert_action(toolbar, action, pos); | |
| 66 | + if(!action) { | |
| 67 | + const gchar *ptr = strchr(name,'.'); | |
| 189 | 68 | |
| 190 | - g_warning("Can't find action \"%s\"",name); | |
| 69 | + if(ptr) | |
| 70 | + action = g_action_map_lookup_action(G_ACTION_MAP(window), ptr+1); | |
| 71 | + } | |
| 72 | + | |
| 73 | + if(action) { | |
| 74 | + debug("Creating button \"%s\" from action \"%s\"",name,g_action_get_name(G_ACTION(action))); | |
| 75 | + item = GTK_TOOL_ITEM(pw3270_tool_button_new(action)); | |
| 76 | + } else { | |
| 77 | + debug("Creating button \"%s\" from action name",name); | |
| 78 | + item = GTK_TOOL_ITEM(pw3270_tool_button_new_from_action_name(name)); | |
| 79 | + } | |
| 80 | + | |
| 81 | + if(item) { | |
| 82 | + gtk_actionable_set_action_name(GTK_ACTIONABLE(item),name); | |
| 83 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar),item,pos); | |
| 84 | + return GTK_WIDGET(item); | |
| 85 | + } | |
| 191 | 86 | |
| 192 | 87 | } |
| 193 | 88 | ... | ... |
src/objects/toolbar/private.h
| ... | ... | @@ -44,4 +44,7 @@ |
| 44 | 44 | #include <pw3270/toolbar.h> |
| 45 | 45 | #include <lib3270/log.h> |
| 46 | 46 | |
| 47 | + G_GNUC_INTERNAL GtkWidget * pw3270_tool_button_new(GAction *action); | |
| 48 | + G_GNUC_INTERNAL GtkWidget * pw3270_tool_button_new_from_action_name(const gchar * action_name); | |
| 49 | + | |
| 47 | 50 | #endif // PRIVATE_H_INCLUDED | ... | ... |
src/objects/window/window.c
| ... | ... | @@ -101,17 +101,17 @@ |
| 101 | 101 | static GActionEntry actions[] = { |
| 102 | 102 | |
| 103 | 103 | { |
| 104 | - .name = "win.open", | |
| 104 | + .name = "open", | |
| 105 | 105 | .activate = pw3270_application_generic_activated, |
| 106 | 106 | }, |
| 107 | 107 | |
| 108 | 108 | { |
| 109 | - .name = "win.close", | |
| 109 | + .name = "close", | |
| 110 | 110 | .activate = pw3270_application_generic_activated, |
| 111 | 111 | }, |
| 112 | 112 | |
| 113 | 113 | { |
| 114 | - .name = "win.preferences", | |
| 114 | + .name = "preferences", | |
| 115 | 115 | .activate = pw3270_application_generic_activated, |
| 116 | 116 | }, |
| 117 | 117 | |
| ... | ... | @@ -129,6 +129,7 @@ |
| 129 | 129 | // |
| 130 | 130 | { |
| 131 | 131 | static const gchar *actions[] = { |
| 132 | + | |
| 132 | 133 | "win.copy", |
| 133 | 134 | "win.paste", |
| 134 | 135 | "win.select_all", |
| ... | ... | @@ -136,23 +137,19 @@ |
| 136 | 137 | "win.connect", |
| 137 | 138 | "win.disconnect", |
| 138 | 139 | "separator", |
| 140 | + "win.preferences", | |
| 139 | 141 | "win.print" |
| 142 | + | |
| 140 | 143 | }; |
| 141 | 144 | |
| 142 | 145 | size_t ix; |
| 143 | 146 | |
| 144 | 147 | for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { |
| 145 | - pw3270_toolbar_insert_action_by_name(GTK_WIDGET(widget->toolbar),actions[ix],-1); | |
| 148 | + pw3270_toolbar_insert_action(GTK_WIDGET(widget->toolbar),actions[ix],-1); | |
| 146 | 149 | } |
| 147 | 150 | |
| 148 | 151 | } |
| 149 | 152 | |
| 150 | - | |
| 151 | - debug("%s","************************************************"); | |
| 152 | - debug("Action win.copy is %p",g_action_map_lookup_action(G_ACTION_MAP(widget),"win.copy")); | |
| 153 | - debug("%s","************************************************"); | |
| 154 | - | |
| 155 | - | |
| 156 | 153 | } |
| 157 | 154 | |
| 158 | 155 | GtkWidget * pw3270_application_window_new(GtkApplication * application) { | ... | ... |