Commit 6c0b2b0064dfbd20a19252633b04e67cd7b688c6

Authored by Perry Werneck
1 parent f5dc83cb

Fixing action engine.

@@ -86,6 +86,9 @@ @@ -86,6 +86,9 @@
86 <Unit filename="src/objects/toolbar/toolbar.c"> 86 <Unit filename="src/objects/toolbar/toolbar.c">
87 <Option compilerVar="CC" /> 87 <Option compilerVar="CC" />
88 </Unit> 88 </Unit>
  89 + <Unit filename="src/objects/toolbar/toolbutton.c">
  90 + <Option compilerVar="CC" />
  91 + </Unit>
89 <Unit filename="src/objects/window/actions.c"> 92 <Unit filename="src/objects/window/actions.c">
90 <Option compilerVar="CC" /> 93 <Option compilerVar="CC" />
91 </Unit> 94 </Unit>
src/include/pw3270/toolbar.h
@@ -57,8 +57,7 @@ @@ -57,8 +57,7 @@
57 GtkWidget * pw3270_toolbar_new(void); 57 GtkWidget * pw3270_toolbar_new(void);
58 58
59 GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos); 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 void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style); 62 void pw3270_toolbar_toolbar_set_style(GtkToolbar *toolbar, GtkToolbarStyle style);
64 // GtkToolbarStyle pw3270_toolbar_toolbar_get_style(GtkToolbar *toolbar); 63 // GtkToolbarStyle pw3270_toolbar_toolbar_get_style(GtkToolbar *toolbar);
src/objects/actions/abstract.c
@@ -356,7 +356,16 @@ @@ -356,7 +356,16 @@
356 } 356 }
357 357
358 void pw3270_action_notify_enabled(GAction *object) { 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 static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { 371 static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) {
@@ -382,13 +391,15 @@ @@ -382,13 +391,15 @@
382 391
383 gboolean pw3270_action_get_enabled(GAction *object) { 392 gboolean pw3270_action_get_enabled(GAction *object) {
384 393
  394 + gboolean enabled = FALSE;
  395 +
385 pw3270Action * action = PW3270_ACTION(object); 396 pw3270Action * action = PW3270_ACTION(object);
386 397
387 if(action && action->terminal) { 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,7 +46,7 @@
46 GAction * action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("reconnect")); 46 GAction * action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("reconnect"));
47 47
48 PW3270_ACTION(action)->activate = activate; 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 return action; 51 return action;
52 52
src/objects/actions/lib3270/action.c
@@ -133,7 +133,7 @@ @@ -133,7 +133,7 @@
133 if(abstract->name) 133 if(abstract->name)
134 g_free(abstract->name); 134 g_free(abstract->name);
135 135
136 - abstract->name = g_strconcat("win.",definition->name,NULL); 136 + abstract->name = g_strdup(definition->name);
137 137
138 return G_ACTION(action); 138 return G_ACTION(action);
139 } 139 }
src/objects/actions/lib3270/pakey.c
@@ -123,7 +123,7 @@ @@ -123,7 +123,7 @@
123 if(abstract->name) 123 if(abstract->name)
124 g_free(abstract->name); 124 g_free(abstract->name);
125 125
126 - abstract->name = g_strdup("win.pakey"); 126 + abstract->name = g_strdup("pakey");
127 127
128 return G_ACTION(action); 128 return G_ACTION(action);
129 } 129 }
src/objects/actions/lib3270/pfkey.c
@@ -122,7 +122,7 @@ @@ -122,7 +122,7 @@
122 if(abstract->name) 122 if(abstract->name)
123 g_free(abstract->name); 123 g_free(abstract->name);
124 124
125 - abstract->name = g_strdup("win.pfkey"); 125 + abstract->name = g_strdup("pfkey");
126 126
127 return G_ACTION(action); 127 return G_ACTION(action);
128 128
src/objects/actions/window.c
@@ -43,6 +43,15 @@ @@ -43,6 +43,15 @@
43 43
44 // Map lib3270 actions 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 const LIB3270_ACTION * actions = lib3270_get_actions(); 55 const LIB3270_ACTION * actions = lib3270_get_actions();
47 for(ix = 0; actions[ix].name; ix++) { 56 for(ix = 0; actions[ix].name; ix++) {
48 57
@@ -80,4 +89,5 @@ @@ -80,4 +89,5 @@
80 } 89 }
81 90
82 debug("%s ends",__FUNCTION__); 91 debug("%s ends",__FUNCTION__);
  92 +
83 } 93 }
src/objects/toolbar/actions.c
@@ -30,129 +30,7 @@ @@ -30,129 +30,7 @@
30 #include "private.h" 30 #include "private.h"
31 #include <pw3270/actions.h> 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 g_return_val_if_fail(PW3270_IS_TOOLBAR(toolbar),NULL); 35 g_return_val_if_fail(PW3270_IS_TOOLBAR(toolbar),NULL);
158 36
@@ -183,11 +61,28 @@ @@ -183,11 +61,28 @@
183 if(window) { 61 if(window) {
184 62
185 GAction *action = g_action_map_lookup_action(G_ACTION_MAP(window), name); 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,4 +44,7 @@
44 #include <pw3270/toolbar.h> 44 #include <pw3270/toolbar.h>
45 #include <lib3270/log.h> 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 #endif // PRIVATE_H_INCLUDED 50 #endif // PRIVATE_H_INCLUDED
src/objects/window/window.c
@@ -101,17 +101,17 @@ @@ -101,17 +101,17 @@
101 static GActionEntry actions[] = { 101 static GActionEntry actions[] = {
102 102
103 { 103 {
104 - .name = "win.open", 104 + .name = "open",
105 .activate = pw3270_application_generic_activated, 105 .activate = pw3270_application_generic_activated,
106 }, 106 },
107 107
108 { 108 {
109 - .name = "win.close", 109 + .name = "close",
110 .activate = pw3270_application_generic_activated, 110 .activate = pw3270_application_generic_activated,
111 }, 111 },
112 112
113 { 113 {
114 - .name = "win.preferences", 114 + .name = "preferences",
115 .activate = pw3270_application_generic_activated, 115 .activate = pw3270_application_generic_activated,
116 }, 116 },
117 117
@@ -129,6 +129,7 @@ @@ -129,6 +129,7 @@
129 // 129 //
130 { 130 {
131 static const gchar *actions[] = { 131 static const gchar *actions[] = {
  132 +
132 "win.copy", 133 "win.copy",
133 "win.paste", 134 "win.paste",
134 "win.select_all", 135 "win.select_all",
@@ -136,23 +137,19 @@ @@ -136,23 +137,19 @@
136 "win.connect", 137 "win.connect",
137 "win.disconnect", 138 "win.disconnect",
138 "separator", 139 "separator",
  140 + "win.preferences",
139 "win.print" 141 "win.print"
  142 +
140 }; 143 };
141 144
142 size_t ix; 145 size_t ix;
143 146
144 for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { 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 GtkWidget * pw3270_application_window_new(GtkApplication * application) { 155 GtkWidget * pw3270_application_window_new(GtkApplication * application) {