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 | 215 | AC_MSG_NOTICE([Using only stable features]) |
| 216 | 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 | 240 | dnl --------------------------------------------------------------------------- |
| 220 | 241 | dnl Check for LIBV3270 | ... | ... |
pw3270.cbp
| ... | ... | @@ -107,6 +107,9 @@ |
| 107 | 107 | <Unit filename="src/objects/application/actions/preferences.c"> |
| 108 | 108 | <Option compilerVar="CC" /> |
| 109 | 109 | </Unit> |
| 110 | + <Unit filename="src/objects/application/actions/script.c"> | |
| 111 | + <Option compilerVar="CC" /> | |
| 112 | + </Unit> | |
| 110 | 113 | <Unit filename="src/objects/application/actions/window.c"> |
| 111 | 114 | <Option compilerVar="CC" /> |
| 112 | 115 | </Unit> | ... | ... |
schemas/linux/application.gschema.xml.in
| ... | ... | @@ -45,6 +45,12 @@ |
| 45 | 45 | <description>Allow changing of host session properties</description> |
| 46 | 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 | 54 | <key name="allow-open-session-actions" type="b"> |
| 49 | 55 | <default>true</default> |
| 50 | 56 | <summary>Enable open session actions actions</summary> | ... | ... |
schemas/macos/application.gschema.xml.in
| ... | ... | @@ -38,13 +38,18 @@ |
| 38 | 38 | <description>The ID of the current user interface style</description> |
| 39 | 39 | </key> |
| 40 | 40 | |
| 41 | - | |
| 42 | 41 | <key name="allow-host-settings" type="b"> |
| 43 | 42 | <default>true</default> |
| 44 | 43 | <summary>Allow host settings</summary> |
| 45 | 44 | <description>Allow changing of host session properties</description> |
| 46 | 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 | 53 | <key name="allow-open-session-actions" type="b"> |
| 49 | 54 | <default>true</default> |
| 50 | 55 | <summary>Enable open session actions actions</summary> | ... | ... |
schemas/windows/application.gschema.xml.in
| ... | ... | @@ -50,6 +50,12 @@ |
| 50 | 50 | <description>Allow changing of host session properties</description> |
| 51 | 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 | 59 | <key name="allow-open-session-actions" type="b"> |
| 54 | 60 | <default>true</default> |
| 55 | 61 | <summary>Enable open session actions actions</summary> | ... | ... |
src/include/config.h.in
src/objects/actions/save.c
| ... | ... | @@ -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 | 83 | G_GNUC_INTERNAL GAction * pw3270_open_window_action_new(); |
| 84 | 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 | 90 | #endif // PRIVATE_H_INCLUDED | ... | ... |