From 40393e6d8d81259a6fcf68c2d5eb791b0bd01312 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 19 May 2022 16:57:06 -0300 Subject: [PATCH] Starting implementation of the script action. --- configure.ac | 21 +++++++++++++++++++++ pw3270.cbp | 3 +++ schemas/linux/application.gschema.xml.in | 6 ++++++ schemas/macos/application.gschema.xml.in | 7 ++++++- schemas/windows/application.gschema.xml.in | 6 ++++++ src/include/config.h.in | 1 + src/objects/actions/save.c | 1 - src/objects/application/actions/script.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/objects/application/private.h | 4 ++++ 9 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 src/objects/application/actions/script.c diff --git a/configure.ac b/configure.ac index 1467c90..0f79810 100644 --- a/configure.ac +++ b/configure.ac @@ -215,6 +215,27 @@ else AC_MSG_NOTICE([Using only stable features]) fi +dnl --------------------------------------------------------------------------- +dnl Check for script support +dnl --------------------------------------------------------------------------- + +AC_ARG_ENABLE([scripts], + [AS_HELP_STRING([--enable-scripts], [enable script support on GUI])], +[ + + AC_DEFINE(ENABLE_SCRIPTS) + AC_MSG_NOTICE([Script action is enabled]) + +],[ + + if test "$app_cv_unstable" == "yes"; then + AC_DEFINE(ENABLE_SCRIPTS) + AC_MSG_NOTICE([Script action is enabled]) + else + AC_MSG_NOTICE([Script action is disabled]) + fi + +]) dnl --------------------------------------------------------------------------- dnl Check for LIBV3270 diff --git a/pw3270.cbp b/pw3270.cbp index 449b3c5..df5eb3b 100644 --- a/pw3270.cbp +++ b/pw3270.cbp @@ -107,6 +107,9 @@ + + diff --git a/schemas/linux/application.gschema.xml.in b/schemas/linux/application.gschema.xml.in index a51f8dc..bb8f3a4 100644 --- a/schemas/linux/application.gschema.xml.in +++ b/schemas/linux/application.gschema.xml.in @@ -45,6 +45,12 @@ Allow changing of host session properties + + true + Allow script action and dialog + Enable start of scripts from application menu + + true Enable open session actions actions diff --git a/schemas/macos/application.gschema.xml.in b/schemas/macos/application.gschema.xml.in index a51f8dc..cb91662 100644 --- a/schemas/macos/application.gschema.xml.in +++ b/schemas/macos/application.gschema.xml.in @@ -38,13 +38,18 @@ The ID of the current user interface style - true Allow host settings Allow changing of host session properties + + false + Allow script action and dialog + Enable start of scripts from application menu + + true Enable open session actions actions diff --git a/schemas/windows/application.gschema.xml.in b/schemas/windows/application.gschema.xml.in index 1b69d0e..842b444 100644 --- a/schemas/windows/application.gschema.xml.in +++ b/schemas/windows/application.gschema.xml.in @@ -50,6 +50,12 @@ Allow changing of host session properties + + false + Allow script action and dialog + Enable start of scripts from application menu + + true Enable open session actions actions diff --git a/src/include/config.h.in b/src/include/config.h.in index 85809ee..6584616 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -37,6 +37,7 @@ #undef PRODUCT_NAME #undef APPLICATION_ID #undef ENABLE_UNSTABLE_FEATURES + #undef ENABLE_SCRIPTS #endif /* PW3270_CONFIG_H_INCLUDED */ diff --git a/src/objects/actions/save.c b/src/objects/actions/save.c index b951cdf..d49e78d 100644 --- a/src/objects/actions/save.c +++ b/src/objects/actions/save.c @@ -204,7 +204,6 @@ void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal) { } - gtk_widget_destroy(dialog); } diff --git a/src/objects/application/actions/script.c b/src/objects/application/actions/script.c new file mode 100644 index 0000000..bc77c69 --- /dev/null +++ b/src/objects/application/actions/script.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ + +/* + * Copyright (C) 2021 Perry Werneck + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include "../private.h" +#include +#include +#include +#include + +#ifdef ENABLE_SCRIPTS + +static GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal); +static void response(GtkWidget *dialog, gint response_id, GtkWidget *input); + +GAction * pw3270_script_action_new() { + + V3270SimpleAction * action = v3270_dialog_action_new(factory); + + action->name = "open-script"; + action->label = _("Run script"); + action->icon_name = "system-run"; + action->tooltip = _("Open and execute a script file"); + + return G_ACTION(action); +} + + +GtkWidget * factory(V3270SimpleAction * action, GtkWidget *terminal) { + + // Create dialog + gboolean use_header; + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); + + GtkWidget * dialog = + GTK_WIDGET(g_object_new( + GTK_TYPE_DIALOG, + "use-header-bar", (use_header ? 1 : 0), + NULL + )); + + + // Create entry field + GtkGrid * grid = GTK_GRID(gtk_grid_new()); + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(grid),TRUE,TRUE,0); + + // https://developer.gnome.org/hig/stable/visual-layout.html.en + gtk_container_set_border_width(GTK_CONTAINER(grid),18); + gtk_grid_set_row_spacing(GTK_GRID(grid),6); + gtk_grid_set_column_spacing(GTK_GRID(grid),12); + + GtkWidget * label = gtk_label_new(_("Script filename")); + gtk_label_set_xalign(GTK_LABEL(label),1); + gtk_grid_attach(grid,label,0,0,1,1); + + GtkWidget * input = gtk_entry_new(); + + gtk_widget_set_hexpand(input,TRUE); + gtk_widget_set_vexpand(input,FALSE); + + gtk_grid_attach(grid,input,0,1,10,1); + + // Setup window + gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(gtk_widget_get_toplevel(terminal))); + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); + gtk_window_set_title(GTK_WINDOW(dialog),action->label); + + gtk_dialog_add_buttons( + GTK_DIALOG(dialog), + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Open"), GTK_RESPONSE_APPLY, + NULL + ); + + gtk_entry_bind_to_filechooser( + input, + GTK_FILE_CHOOSER_ACTION_OPEN, + _("Run script"), + NULL, + "*.*", + _("All files") + ); + + g_signal_connect(dialog,"response",G_CALLBACK(response),input); + + gtk_widget_show_all(GTK_WIDGET(grid)); + return dialog; + +} + +void response(GtkWidget *dialog, gint response_id, GtkWidget *input) { + + if(response_id == GTK_RESPONSE_APPLY) { + + + } + + gtk_widget_destroy(dialog); + +} +#endif // ENABLE_SCRIPTS + diff --git a/src/objects/application/private.h b/src/objects/application/private.h index 603999f..afad917 100644 --- a/src/objects/application/private.h +++ b/src/objects/application/private.h @@ -83,4 +83,8 @@ G_GNUC_INTERNAL GAction * pw3270_open_session_action_new(); G_GNUC_INTERNAL GAction * pw3270_open_window_action_new(); G_GNUC_INTERNAL GAction * pw3270_open_tab_action_new(); +#ifdef ENABLE_SCRIPTS + G_GNUC_INTERNAL GAction * pw3270_script_action_new(); +#endif // ENABLE_SCRIPTS + #endif // PRIVATE_H_INCLUDED -- libgit2 0.21.2