Commit 5fca6f1299c5c40c5ef59fd043a488eb2c97f738
1 parent
818e87e6
Exists in
script-support
Script dialog should scan plugins for an available runner.
Showing
1 changed file
with
38 additions
and
17 deletions
Show diff stats
src/objects/application/actions/script.c
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 | #ifdef ENABLE_SCRIPTS |
28 | 28 | |
29 | 29 | static GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal); |
30 | -static void response(GtkWidget *dialog, gint response_id, GtkWidget *input); | |
30 | +static void response(GtkWidget *dialog, gint response_id, GtkEntry *input); | |
31 | 31 | static void icon_press(GtkWidget *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, const void *dunno); |
32 | 32 | |
33 | 33 | GAction * pw3270_script_action_new() { |
... | ... | @@ -98,18 +98,6 @@ GtkWidget * factory(V3270SimpleAction * action, GtkWidget *terminal) { |
98 | 98 | NULL |
99 | 99 | ); |
100 | 100 | |
101 | - /* | |
102 | - // Cant use gtk_entry_bind_to_filechooser due to plugin interaction | |
103 | - gtk_entry_bind_to_filechooser( | |
104 | - input, | |
105 | - GTK_FILE_CHOOSER_ACTION_OPEN, | |
106 | - _("Run script"), | |
107 | - NULL, | |
108 | - "*.*", | |
109 | - _("All files") | |
110 | - ); | |
111 | - */ | |
112 | - | |
113 | 101 | g_signal_connect(dialog,"response",G_CALLBACK(response),input); |
114 | 102 | |
115 | 103 | gtk_widget_show_all(GTK_WIDGET(grid)); |
... | ... | @@ -117,7 +105,7 @@ GtkWidget * factory(V3270SimpleAction * action, GtkWidget *terminal) { |
117 | 105 | |
118 | 106 | } |
119 | 107 | |
120 | -void icon_press(GtkWidget *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, const void *dunno) { | |
108 | +void icon_press(GtkWidget *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, GdkEvent G_GNUC_UNUSED(*event), const void G_GNUC_UNUSED(*dunno)) { | |
121 | 109 | |
122 | 110 | GtkWidget * dialog = |
123 | 111 | gtk_file_chooser_dialog_new( |
... | ... | @@ -164,14 +152,47 @@ void icon_press(GtkWidget *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G |
164 | 152 | |
165 | 153 | } |
166 | 154 | |
167 | -void response(GtkWidget *dialog, gint response_id, GtkWidget *input) { | |
155 | +void response(GtkWidget *input_dialog, gint response_id, GtkEntry *entry) { | |
168 | 156 | |
169 | - if(response_id == GTK_RESPONSE_APPLY) { | |
157 | + g_autofree gchar *filename = g_strdup(gtk_entry_get_text(entry)); | |
170 | 158 | |
159 | + gtk_widget_destroy(input_dialog); | |
171 | 160 | |
161 | + if(response_id != GTK_RESPONSE_APPLY) { | |
162 | + return; | |
172 | 163 | } |
173 | 164 | |
174 | - gtk_widget_destroy(dialog); | |
165 | + GtkWidget * terminal = pw3270_get_active_terminal(); | |
166 | + | |
167 | + g_message("Finding worker for '%s'",filename); | |
168 | + | |
169 | + int (*call)(GtkWidget *terminal, const gchar *filename); | |
170 | + | |
171 | + GSList * item; | |
172 | + for(item = PW3270_APPLICATION(g_application_get_default())->plugins; item; item = g_slist_next(item)) { | |
173 | + if(g_module_symbol((GModule *) item->data, "pw3270_plugin_run_script", (gpointer *) &call)) { | |
174 | + if(call(terminal,filename) == 0) { | |
175 | + break; | |
176 | + } | |
177 | + } | |
178 | + } | |
179 | + | |
180 | + GtkWidget * dialog = gtk_message_dialog_new_with_markup( | |
181 | + GTK_WINDOW(gtk_widget_get_toplevel(terminal)), | |
182 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
183 | + GTK_MESSAGE_ERROR, | |
184 | + GTK_BUTTONS_OK, | |
185 | + _("Can't run \"%s\""), filename | |
186 | + ); | |
187 | + | |
188 | + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",_("No available runner for this file")); | |
189 | + | |
190 | + gtk_window_set_title(GTK_WINDOW(dialog),_("Can't run script")); | |
191 | + | |
192 | + gtk_widget_show_all(dialog); | |
193 | + | |
194 | + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
195 | + g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); | |
175 | 196 | |
176 | 197 | } |
177 | 198 | #endif // ENABLE_SCRIPTS | ... | ... |