Commit 40393e6d8d81259a6fcf68c2d5eb791b0bd01312
1 parent
fe323054
Exists in
script-support
Starting implementation of the script action.
Showing
9 changed files
with
165 additions
and
2 deletions
Show diff stats
configure.ac
| @@ -215,6 +215,27 @@ else | @@ -215,6 +215,27 @@ else | ||
| 215 | AC_MSG_NOTICE([Using only stable features]) | 215 | AC_MSG_NOTICE([Using only stable features]) |
| 216 | fi | 216 | fi |
| 217 | 217 | ||
| 218 | +dnl --------------------------------------------------------------------------- | ||
| 219 | +dnl Check for script support | ||
| 220 | +dnl --------------------------------------------------------------------------- | ||
| 221 | + | ||
| 222 | +AC_ARG_ENABLE([scripts], | ||
| 223 | + [AS_HELP_STRING([--enable-scripts], [enable script support on GUI])], | ||
| 224 | +[ | ||
| 225 | + | ||
| 226 | + AC_DEFINE(ENABLE_SCRIPTS) | ||
| 227 | + AC_MSG_NOTICE([Script action is enabled]) | ||
| 228 | + | ||
| 229 | +],[ | ||
| 230 | + | ||
| 231 | + if test "$app_cv_unstable" == "yes"; then | ||
| 232 | + AC_DEFINE(ENABLE_SCRIPTS) | ||
| 233 | + AC_MSG_NOTICE([Script action is enabled]) | ||
| 234 | + else | ||
| 235 | + AC_MSG_NOTICE([Script action is disabled]) | ||
| 236 | + fi | ||
| 237 | + | ||
| 238 | +]) | ||
| 218 | 239 | ||
| 219 | dnl --------------------------------------------------------------------------- | 240 | dnl --------------------------------------------------------------------------- |
| 220 | dnl Check for LIBV3270 | 241 | dnl Check for LIBV3270 |
pw3270.cbp
| @@ -107,6 +107,9 @@ | @@ -107,6 +107,9 @@ | ||
| 107 | <Unit filename="src/objects/application/actions/preferences.c"> | 107 | <Unit filename="src/objects/application/actions/preferences.c"> |
| 108 | <Option compilerVar="CC" /> | 108 | <Option compilerVar="CC" /> |
| 109 | </Unit> | 109 | </Unit> |
| 110 | + <Unit filename="src/objects/application/actions/script.c"> | ||
| 111 | + <Option compilerVar="CC" /> | ||
| 112 | + </Unit> | ||
| 110 | <Unit filename="src/objects/application/actions/window.c"> | 113 | <Unit filename="src/objects/application/actions/window.c"> |
| 111 | <Option compilerVar="CC" /> | 114 | <Option compilerVar="CC" /> |
| 112 | </Unit> | 115 | </Unit> |
schemas/linux/application.gschema.xml.in
| @@ -45,6 +45,12 @@ | @@ -45,6 +45,12 @@ | ||
| 45 | <description>Allow changing of host session properties</description> | 45 | <description>Allow changing of host session properties</description> |
| 46 | </key> | 46 | </key> |
| 47 | 47 | ||
| 48 | + <key name="allow-scripts" type="b"> | ||
| 49 | + <default>true</default> | ||
| 50 | + <summary>Allow script action and dialog</summary> | ||
| 51 | + <description>Enable start of scripts from application menu</description> | ||
| 52 | + </key> | ||
| 53 | + | ||
| 48 | <key name="allow-open-session-actions" type="b"> | 54 | <key name="allow-open-session-actions" type="b"> |
| 49 | <default>true</default> | 55 | <default>true</default> |
| 50 | <summary>Enable open session actions actions</summary> | 56 | <summary>Enable open session actions actions</summary> |
schemas/macos/application.gschema.xml.in
| @@ -38,13 +38,18 @@ | @@ -38,13 +38,18 @@ | ||
| 38 | <description>The ID of the current user interface style</description> | 38 | <description>The ID of the current user interface style</description> |
| 39 | </key> | 39 | </key> |
| 40 | 40 | ||
| 41 | - | ||
| 42 | <key name="allow-host-settings" type="b"> | 41 | <key name="allow-host-settings" type="b"> |
| 43 | <default>true</default> | 42 | <default>true</default> |
| 44 | <summary>Allow host settings</summary> | 43 | <summary>Allow host settings</summary> |
| 45 | <description>Allow changing of host session properties</description> | 44 | <description>Allow changing of host session properties</description> |
| 46 | </key> | 45 | </key> |
| 47 | 46 | ||
| 47 | + <key name="allow-scripts" type="b"> | ||
| 48 | + <default>false</default> | ||
| 49 | + <summary>Allow script action and dialog</summary> | ||
| 50 | + <description>Enable start of scripts from application menu</description> | ||
| 51 | + </key> | ||
| 52 | + | ||
| 48 | <key name="allow-open-session-actions" type="b"> | 53 | <key name="allow-open-session-actions" type="b"> |
| 49 | <default>true</default> | 54 | <default>true</default> |
| 50 | <summary>Enable open session actions actions</summary> | 55 | <summary>Enable open session actions actions</summary> |
schemas/windows/application.gschema.xml.in
| @@ -50,6 +50,12 @@ | @@ -50,6 +50,12 @@ | ||
| 50 | <description>Allow changing of host session properties</description> | 50 | <description>Allow changing of host session properties</description> |
| 51 | </key> | 51 | </key> |
| 52 | 52 | ||
| 53 | + <key name="allow-scripts" type="b"> | ||
| 54 | + <default>false</default> | ||
| 55 | + <summary>Allow script action and dialog</summary> | ||
| 56 | + <description>Enable start of scripts from application menu</description> | ||
| 57 | + </key> | ||
| 58 | + | ||
| 53 | <key name="allow-open-session-actions" type="b"> | 59 | <key name="allow-open-session-actions" type="b"> |
| 54 | <default>true</default> | 60 | <default>true</default> |
| 55 | <summary>Enable open session actions actions</summary> | 61 | <summary>Enable open session actions actions</summary> |
src/include/config.h.in
| @@ -37,6 +37,7 @@ | @@ -37,6 +37,7 @@ | ||
| 37 | #undef PRODUCT_NAME | 37 | #undef PRODUCT_NAME |
| 38 | #undef APPLICATION_ID | 38 | #undef APPLICATION_ID |
| 39 | #undef ENABLE_UNSTABLE_FEATURES | 39 | #undef ENABLE_UNSTABLE_FEATURES |
| 40 | + #undef ENABLE_SCRIPTS | ||
| 40 | 41 | ||
| 41 | #endif /* PW3270_CONFIG_H_INCLUDED */ | 42 | #endif /* PW3270_CONFIG_H_INCLUDED */ |
| 42 | 43 |
src/objects/actions/save.c
| @@ -204,7 +204,6 @@ void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal) { | @@ -204,7 +204,6 @@ void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal) { | ||
| 204 | 204 | ||
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | - | ||
| 208 | gtk_widget_destroy(dialog); | 207 | gtk_widget_destroy(dialog); |
| 209 | 208 | ||
| 210 | } | 209 | } |
| @@ -0,0 +1,118 @@ | @@ -0,0 +1,118 @@ | ||
| 1 | +/* SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
| 2 | + | ||
| 3 | +/* | ||
| 4 | + * Copyright (C) 2021 Perry Werneck <perry.werneck@gmail.com> | ||
| 5 | + * | ||
| 6 | + * This program is free software: you can redistribute it and/or modify | ||
| 7 | + * it under the terms of the GNU Lesser General Public License as published | ||
| 8 | + * by the Free Software Foundation, either version 3 of the License, or | ||
| 9 | + * (at your option) any later version. | ||
| 10 | + * | ||
| 11 | + * This program is distributed in the hope that it will be useful, | ||
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | + * GNU General Public License for more details. | ||
| 15 | + * | ||
| 16 | + * You should have received a copy of the GNU Lesser General Public License | ||
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 18 | + */ | ||
| 19 | + | ||
| 20 | +#include <config.h> | ||
| 21 | +#include "../private.h" | ||
| 22 | +#include <pw3270.h> | ||
| 23 | +#include <pw3270/application.h> | ||
| 24 | +#include <pw3270/actions.h> | ||
| 25 | +#include <v3270/tools.h> | ||
| 26 | + | ||
| 27 | +#ifdef ENABLE_SCRIPTS | ||
| 28 | + | ||
| 29 | +static GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal); | ||
| 30 | +static void response(GtkWidget *dialog, gint response_id, GtkWidget *input); | ||
| 31 | + | ||
| 32 | +GAction * pw3270_script_action_new() { | ||
| 33 | + | ||
| 34 | + V3270SimpleAction * action = v3270_dialog_action_new(factory); | ||
| 35 | + | ||
| 36 | + action->name = "open-script"; | ||
| 37 | + action->label = _("Run script"); | ||
| 38 | + action->icon_name = "system-run"; | ||
| 39 | + action->tooltip = _("Open and execute a script file"); | ||
| 40 | + | ||
| 41 | + return G_ACTION(action); | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | + | ||
| 45 | +GtkWidget * factory(V3270SimpleAction * action, GtkWidget *terminal) { | ||
| 46 | + | ||
| 47 | + // Create dialog | ||
| 48 | + gboolean use_header; | ||
| 49 | + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); | ||
| 50 | + | ||
| 51 | + GtkWidget * dialog = | ||
| 52 | + GTK_WIDGET(g_object_new( | ||
| 53 | + GTK_TYPE_DIALOG, | ||
| 54 | + "use-header-bar", (use_header ? 1 : 0), | ||
| 55 | + NULL | ||
| 56 | + )); | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + // Create entry field | ||
| 60 | + GtkGrid * grid = GTK_GRID(gtk_grid_new()); | ||
| 61 | + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(grid),TRUE,TRUE,0); | ||
| 62 | + | ||
| 63 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | ||
| 64 | + gtk_container_set_border_width(GTK_CONTAINER(grid),18); | ||
| 65 | + gtk_grid_set_row_spacing(GTK_GRID(grid),6); | ||
| 66 | + gtk_grid_set_column_spacing(GTK_GRID(grid),12); | ||
| 67 | + | ||
| 68 | + GtkWidget * label = gtk_label_new(_("Script filename")); | ||
| 69 | + gtk_label_set_xalign(GTK_LABEL(label),1); | ||
| 70 | + gtk_grid_attach(grid,label,0,0,1,1); | ||
| 71 | + | ||
| 72 | + GtkWidget * input = gtk_entry_new(); | ||
| 73 | + | ||
| 74 | + gtk_widget_set_hexpand(input,TRUE); | ||
| 75 | + gtk_widget_set_vexpand(input,FALSE); | ||
| 76 | + | ||
| 77 | + gtk_grid_attach(grid,input,0,1,10,1); | ||
| 78 | + | ||
| 79 | + // Setup window | ||
| 80 | + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(gtk_widget_get_toplevel(terminal))); | ||
| 81 | + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); | ||
| 82 | + gtk_window_set_title(GTK_WINDOW(dialog),action->label); | ||
| 83 | + | ||
| 84 | + gtk_dialog_add_buttons( | ||
| 85 | + GTK_DIALOG(dialog), | ||
| 86 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | ||
| 87 | + _("_Open"), GTK_RESPONSE_APPLY, | ||
| 88 | + NULL | ||
| 89 | + ); | ||
| 90 | + | ||
| 91 | + gtk_entry_bind_to_filechooser( | ||
| 92 | + input, | ||
| 93 | + GTK_FILE_CHOOSER_ACTION_OPEN, | ||
| 94 | + _("Run script"), | ||
| 95 | + NULL, | ||
| 96 | + "*.*", | ||
| 97 | + _("All files") | ||
| 98 | + ); | ||
| 99 | + | ||
| 100 | + g_signal_connect(dialog,"response",G_CALLBACK(response),input); | ||
| 101 | + | ||
| 102 | + gtk_widget_show_all(GTK_WIDGET(grid)); | ||
| 103 | + return dialog; | ||
| 104 | + | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +void response(GtkWidget *dialog, gint response_id, GtkWidget *input) { | ||
| 108 | + | ||
| 109 | + if(response_id == GTK_RESPONSE_APPLY) { | ||
| 110 | + | ||
| 111 | + | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + gtk_widget_destroy(dialog); | ||
| 115 | + | ||
| 116 | +} | ||
| 117 | +#endif // ENABLE_SCRIPTS | ||
| 118 | + |
src/objects/application/private.h
| @@ -83,4 +83,8 @@ G_GNUC_INTERNAL GAction * pw3270_open_session_action_new(); | @@ -83,4 +83,8 @@ G_GNUC_INTERNAL GAction * pw3270_open_session_action_new(); | ||
| 83 | G_GNUC_INTERNAL GAction * pw3270_open_window_action_new(); | 83 | G_GNUC_INTERNAL GAction * pw3270_open_window_action_new(); |
| 84 | G_GNUC_INTERNAL GAction * pw3270_open_tab_action_new(); | 84 | G_GNUC_INTERNAL GAction * pw3270_open_tab_action_new(); |
| 85 | 85 | ||
| 86 | +#ifdef ENABLE_SCRIPTS | ||
| 87 | + G_GNUC_INTERNAL GAction * pw3270_script_action_new(); | ||
| 88 | +#endif // ENABLE_SCRIPTS | ||
| 89 | + | ||
| 86 | #endif // PRIVATE_H_INCLUDED | 90 | #endif // PRIVATE_H_INCLUDED |