Commit e812d17c2a22568a0c6f96b39542a13d9deb84e6
1 parent
5abb8018
Exists in
master
and in
5 other branches
Iniciando implementação da action que seleciona e executa um plugin rexx
Showing
3 changed files
with
141 additions
and
1 deletions
Show diff stats
src/include/pw3270.h
... | ... | @@ -71,6 +71,11 @@ |
71 | 71 | LIB3270_EXPORT void pw3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options); |
72 | 72 | LIB3270_EXPORT int pw3270_set_session_color_type(GtkWidget *widget, unsigned short color_type); |
73 | 73 | |
74 | + LIB3270_EXPORT gchar * pw3270_get_filename(GtkWidget *widget, const gchar *group, const gchar *key, GtkFileFilter **filter, const gchar *title); | |
75 | + | |
76 | + LIB3270_EXPORT gchar * pw3270_get_string(GtkWidget *widget, const gchar *group, const gchar *key, const gchar *def); | |
77 | + LIB3270_EXPORT void pw3270_set_string(GtkWidget *widget, const gchar *group, const gchar *key, const gchar *val); | |
78 | + | |
74 | 79 | LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint def); |
75 | 80 | LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val); |
76 | 81 | ... | ... |
src/plugins/rx3270/pluginmain.cc
... | ... | @@ -27,8 +27,17 @@ |
27 | 27 | * |
28 | 28 | */ |
29 | 29 | |
30 | + #define ENABLE_NLS | |
31 | + #define GETTEXT_PACKAGE PACKAGE_NAME | |
32 | + | |
30 | 33 | #include "rx3270.h" |
34 | + | |
35 | + #include <libintl.h> | |
36 | + #include <glib/gi18n.h> | |
37 | + #include <gtk/gtk.h> | |
38 | + | |
31 | 39 | #include <string.h> |
40 | + #include <pw3270.h> | |
32 | 41 | #include <pw3270/plugin.h> |
33 | 42 | #include <pw3270/v3270.h> |
34 | 43 | #include <lib3270/actions.h> |
... | ... | @@ -72,12 +81,16 @@ |
72 | 81 | |
73 | 82 | }; |
74 | 83 | |
75 | - static plugin * session = NULL; | |
84 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
85 | + | |
86 | + static plugin * session = NULL; | |
87 | + static GMutex mutex; | |
76 | 88 | |
77 | 89 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
78 | 90 | |
79 | 91 | LIB3270_EXPORT int pw3270_plugin_init(GtkWidget *window) |
80 | 92 | { |
93 | + g_mutex_init(&mutex); | |
81 | 94 | session = new plugin(lib3270_get_default_session_handle()); |
82 | 95 | session->set_plugin(); |
83 | 96 | trace("%s: Rexx object is %p",__FUNCTION__,session); |
... | ... | @@ -91,6 +104,7 @@ |
91 | 104 | delete session; |
92 | 105 | session = NULL; |
93 | 106 | } |
107 | + g_mutex_clear(&mutex); | |
94 | 108 | return 0; |
95 | 109 | } |
96 | 110 | |
... | ... | @@ -203,12 +217,79 @@ |
203 | 217 | extern "C" |
204 | 218 | { |
205 | 219 | |
220 | + static void call_rexx_script(const gchar *filename) | |
221 | + { | |
222 | + | |
223 | + } | |
224 | + | |
206 | 225 | LIB3270_EXPORT void pw3270_action_rexx_activated(GtkAction *action, GtkWidget *widget) |
207 | 226 | { |
227 | + gchar *filename = (gchar *) g_object_get_data(G_OBJECT(action),"src"); | |
228 | + | |
208 | 229 | lib3270_trace_event(v3270_get_session(widget),"Action %s activated on widget %p",gtk_action_get_name(action),widget); |
209 | 230 | |
231 | + if(!g_mutex_trylock(&mutex)) | |
232 | + { | |
233 | + GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
234 | + GTK_DIALOG_DESTROY_WITH_PARENT, | |
235 | + GTK_MESSAGE_ERROR, | |
236 | + GTK_BUTTONS_CANCEL, | |
237 | + "%s", _( "Can't start script" )); | |
238 | + | |
239 | + gtk_window_set_title(GTK_WINDOW(dialog),_( "System busy" )); | |
240 | + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",_( "Please, try again in a few moments" )); | |
241 | + | |
242 | + gtk_dialog_run(GTK_DIALOG (dialog)); | |
243 | + gtk_widget_destroy(dialog); | |
244 | + return; | |
245 | + } | |
246 | + | |
247 | + gtk_action_set_sensitive(action,FALSE); | |
210 | 248 | |
249 | + if(filename) | |
250 | + { | |
251 | + // Has filename, call it directly | |
252 | + call_rexx_script(filename); | |
253 | + } | |
254 | + else | |
255 | + { | |
256 | + // No filename, ask user | |
257 | + static const struct _list | |
258 | + { | |
259 | + const gchar *name; | |
260 | + const gchar *pattern; | |
261 | + } list[] = | |
262 | + { | |
263 | + { N_( "Rexx script file" ), "*.rex" }, | |
264 | + { N_( "Rexx class file" ), "*.cls" } | |
265 | + }; | |
266 | + | |
267 | + GtkFileFilter * filter[G_N_ELEMENTS(list)+1]; | |
268 | + unsigned int f; | |
269 | + | |
270 | + memset(filter,0,sizeof(filter)); | |
271 | + | |
272 | + for(f=0;f<G_N_ELEMENTS(list);f++) | |
273 | + { | |
274 | + filter[f] = gtk_file_filter_new(); | |
275 | + gtk_file_filter_set_name(filter[f],gettext(list[f].name)); | |
276 | + gtk_file_filter_add_pattern(filter[f],list[f].pattern); | |
277 | + } | |
278 | + | |
279 | + filename = pw3270_get_filename(widget,"rexx","script",filter,_( "Select Rexx script to run" )); | |
280 | + | |
281 | + if(filename) | |
282 | + { | |
283 | + call_rexx_script(filename); | |
284 | + g_free(filename); | |
285 | + } | |
286 | + | |
287 | + } | |
288 | + | |
289 | + gtk_action_set_sensitive(action,TRUE); | |
290 | + g_mutex_unlock(&mutex); | |
211 | 291 | |
212 | 292 | } |
213 | 293 | |
214 | 294 | } |
295 | + | ... | ... |
src/pw3270/tools.c
... | ... | @@ -105,11 +105,21 @@ LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, co |
105 | 105 | return get_integer_from_config(group, key, def); |
106 | 106 | } |
107 | 107 | |
108 | +LIB3270_EXPORT gchar * pw3270_get_string(GtkWidget *widget, const gchar *group, const gchar *key, const gchar *def) | |
109 | +{ | |
110 | + return get_string_from_config(group, key, def); | |
111 | +} | |
112 | + | |
108 | 113 | LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val) |
109 | 114 | { |
110 | 115 | set_integer_to_config(group, key, val); |
111 | 116 | } |
112 | 117 | |
118 | +LIB3270_EXPORT void pw3270_set_string(GtkWidget *widget, const gchar *group, const gchar *key, const gchar *val) | |
119 | +{ | |
120 | + set_string_to_config(group, key, val); | |
121 | +} | |
122 | + | |
113 | 123 | LIB3270_EXPORT gint pw3270_get_boolean(GtkWidget *widget, const gchar *group, const gchar *key, gint def) |
114 | 124 | { |
115 | 125 | return get_boolean_from_config(group, key, def); |
... | ... | @@ -131,3 +141,47 @@ LIB3270_EXPORT gboolean pw3270_set_toggle_by_name(GtkWidget *widget, const gchar |
131 | 141 | lib3270_set_toggle(hSession,id,(int) flag); |
132 | 142 | return TRUE; |
133 | 143 | } |
144 | + | |
145 | +LIB3270_EXPORT gchar * pw3270_get_filename(GtkWidget *widget, const gchar *group, const gchar *key, GtkFileFilter **filter, const gchar *title) | |
146 | +{ | |
147 | + gchar * filename = NULL; | |
148 | + gchar * ptr; | |
149 | + GtkWidget * dialog = gtk_file_chooser_dialog_new( title, | |
150 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
151 | + GTK_FILE_CHOOSER_ACTION_OPEN, | |
152 | + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
153 | + GTK_STOCK_EXECUTE, GTK_RESPONSE_ACCEPT, | |
154 | + NULL ); | |
155 | + | |
156 | + if(filter) | |
157 | + { | |
158 | + int f; | |
159 | + | |
160 | + for(f=0;filter[f];f++) | |
161 | + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter[f]); | |
162 | + } | |
163 | + | |
164 | + gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog),FALSE); | |
165 | + | |
166 | + ptr = pw3270_get_string(widget,group,key,NULL); | |
167 | + if(ptr) | |
168 | + { | |
169 | + gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(dialog),ptr); | |
170 | + g_free(ptr); | |
171 | + } | |
172 | + | |
173 | + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
174 | + { | |
175 | + gchar *uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
176 | + | |
177 | + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
178 | + | |
179 | + pw3270_set_string(widget,group,key,uri); | |
180 | + g_free(uri); | |
181 | + | |
182 | + } | |
183 | + | |
184 | + gtk_widget_destroy(dialog); | |
185 | + | |
186 | + return filename; | |
187 | +} | ... | ... |