From 56954fbde3f8aa1d42072b04b266285702e7ead8 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 24 Jan 2020 11:42:09 -0300 Subject: [PATCH] Implementing configuration for the "paste screen" option. --- src/dialogs/settings/clipboard.c | 21 +++++++++++++++++++-- src/include/terminal.h | 1 + src/selection/copy.c | 3 ++- src/selection/linux/paste.c | 22 ++++++++++++++++------ src/terminal/actions/action.c | 2 +- src/terminal/actions/clipboard.c | 5 ++++- src/terminal/actions/table.c | 11 +++++++++++ 7 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/dialogs/settings/clipboard.c b/src/dialogs/settings/clipboard.c index d45a9ba..f910993 100644 --- a/src/dialogs/settings/clipboard.c +++ b/src/dialogs/settings/clipboard.c @@ -146,7 +146,17 @@ .top = 2, .width = 1, .height = 1, - .grid = 2 + .grid = HTML_SETTINGS + }, + + { + .label = N_("Paste formatted screen"), + .tooltip = N_("If enabled search clipboard for a similar screen, if found paste unprotected fields and restore cursor position"), + .left = 0, + .top = 2, + .width = 1, + .height = 1, + .grid = PASTE_SETTINGS } }; @@ -336,7 +346,7 @@ static void V3270ClipboardSettings_init(V3270ClipboardSettings *widget) { // Copy format combo static const gchar * copy_formats[] = { N_("Plain text only"), - N_("Complete with terminal attributes") + N_("Screen with terminal attributes") }; gtk_combo_box_set_id_column(widget->input.combos[0],1); @@ -434,6 +444,7 @@ static void load(GtkWidget *w, GtkWidget *t) { gtk_combo_box_set_active_id(widget->input.combos[2],(terminal->selection.options & (V3270_SELECTION_ENABLE_HTML|V3270_SELECTION_DIALOG_STATE)) == 0 ? "0" : "1"); gtk_toggle_button_set_active(widget->input.checkboxes[0],(terminal->selection.options & V3270_SELECTION_NON_BREAKABLE_SPACE) != 0); + gtk_toggle_button_set_active(widget->input.checkboxes[1],(terminal->selection.options & V3270_SELECTION_SCREEN_PASTE) != 0); // // Set font combo-box @@ -507,6 +518,12 @@ static void apply(GtkWidget *w, GtkWidget *t) { terminal->selection.options &= ~V3270_SELECTION_NON_BREAKABLE_SPACE; } + if(gtk_toggle_button_get_active(widget->input.checkboxes[0])) { + terminal->selection.options |= V3270_SELECTION_SCREEN_PASTE; + } else { + terminal->selection.options &= ~V3270_SELECTION_SCREEN_PASTE; + } + // Get font settings switch(get_active_id(widget,0)) { case '0': diff --git a/src/include/terminal.h b/src/include/terminal.h index da8faae..99512ef 100644 --- a/src/include/terminal.h +++ b/src/include/terminal.h @@ -125,6 +125,7 @@ G_BEGIN_DECLS V3270_SELECTION_COLORS = 0x0002, ///< @brief Inform terminal colors. V3270_SELECTION_NON_BREAKABLE_SPACE = 0x0004, ///< @brief Use non breakable spaces. V3270_SELECTION_DIALOG_STATE = 0x0010, ///< @brief Used for settings dialog. + V3270_SELECTION_SCREEN_PASTE = 0x0020, ///< @brief Enable screen paste. } V3270SelectionOption; diff --git a/src/selection/copy.c b/src/selection/copy.c index f5dc12e..25f783f 100644 --- a/src/selection/copy.c +++ b/src/selection/copy.c @@ -54,7 +54,8 @@ // ... and set the new mode. if(mode == V3270_COPY_DEFAULT) { - mode = (lib3270_get_toggle(v3270_get_session(widget),LIB3270_TOGGLE_SMART_PASTE) ? V3270_COPY_FORMATTED : V3270_COPY_TEXT); +// mode = (lib3270_get_toggle(v3270_get_session(widget),LIB3270_TOGGLE_SMART_PASTE) ? V3270_COPY_FORMATTED : V3270_COPY_TEXT); + mode = V3270_COPY_FORMATTED; } terminal->selection.format = mode; diff --git a/src/selection/linux/paste.c b/src/selection/linux/paste.c index 30a2257..f015af7 100644 --- a/src/selection/linux/paste.c +++ b/src/selection/linux/paste.c @@ -176,13 +176,15 @@ static void formatted_received(GtkClipboard *clipboard, GtkSelectionData *select } -static void targets_received(GtkClipboard *clipboard, GdkAtom *atoms, gint n_atoms, GtkWidget *widget) -{ +static void targets_received(GtkClipboard *clipboard, GdkAtom *atoms, gint n_atoms, GtkWidget *widget) { // If smart paste is enabled try to get formatted clipboard. - debug("%s: Smart paste is %s", __FUNCTION__, (lib3270_get_toggle(GTK_V3270(widget)->host,LIB3270_TOGGLE_SMART_PASTE) ? "enabled" : "disabled")); - if(lib3270_get_toggle(GTK_V3270(widget)->host,LIB3270_TOGGLE_SMART_PASTE) && has_target(GTK_V3270_GET_CLASS(widget)->clipboard_formatted,atoms,n_atoms)) - { + gboolean screen_paste = ((GTK_V3270(widget)->selection.options & V3270_SELECTION_SCREEN_PASTE) != 0); + + debug("%s: Screen paste is %s", __FUNCTION__, screen_paste ? "enabled" : "disabled"); + + if(screen_paste && has_target(GTK_V3270_GET_CLASS(widget)->clipboard_formatted,atoms,n_atoms)) { + debug("Clipboard as TN3270 \"%s\" data",gdk_atom_name(GTK_V3270_GET_CLASS(widget)->clipboard_formatted)); gtk_clipboard_request_contents( @@ -225,7 +227,6 @@ LIB3270_EXPORT void v3270_clipboard_get_from_url(GtkWidget *widget, const gchar (GtkClipboardTextReceivedFunc) text_received, (gpointer) widget ); - } else if(g_str_has_prefix(url,"file://")) { @@ -234,6 +235,15 @@ LIB3270_EXPORT void v3270_clipboard_get_from_url(GtkWidget *widget, const gchar v3270_load_dialog_run(dialog); gtk_widget_destroy(dialog); } + else if(g_str_has_prefix(url,"screen://")) + { + gtk_clipboard_request_contents( + clipboard, + GTK_V3270_GET_CLASS(widget)->clipboard_formatted, + (GtkClipboardReceivedFunc) formatted_received, + (gpointer) widget + ); + } } diff --git a/src/terminal/actions/action.c b/src/terminal/actions/action.c index 2b8ce43..5823355 100644 --- a/src/terminal/actions/action.c +++ b/src/terminal/actions/action.c @@ -248,7 +248,7 @@ } - void set_property(GObject G_GNUC_UNUSED(*object), guint G_GNUC_UNUSED(prop_id), const GValue G_GNUC_UNUSED(*value), GParamSpec *pspec) { + void set_property(GObject G_GNUC_UNUSED(*object), guint G_GNUC_UNUSED(prop_id), const GValue G_GNUC_UNUSED(*value), GParamSpec G_GNUC_UNUSED(*pspec)) { // g_message("Action %s property %s is read-only",g_action_get_name(G_ACTION(object)),pspec->name); } diff --git a/src/terminal/actions/clipboard.c b/src/terminal/actions/clipboard.c index 524c59e..18f74d8 100644 --- a/src/terminal/actions/clipboard.c +++ b/src/terminal/actions/clipboard.c @@ -50,7 +50,6 @@ int fire_paste_accelerator(GtkWidget *widget, const V3270_ACTION * action) { - switch((int) action->flags) { case 0: // Default paste. @@ -65,6 +64,10 @@ v3270_clipboard_get_from_url(widget,"file://"); break; + case 3: // screen paste. + v3270_clipboard_get_from_url(widget,"screen://"); + break; + default: g_warning("Unexpected paste flags %u",(unsigned int) action->flags); } diff --git a/src/terminal/actions/table.c b/src/terminal/actions/table.c index 177331d..3f36ad4 100644 --- a/src/terminal/actions/table.c +++ b/src/terminal/actions/table.c @@ -193,6 +193,17 @@ .activate = fire_paste_accelerator }, + { + .flags = 3, + .group = LIB3270_ACTION_GROUP_ONLINE, + .name = "paste-screen", + .label = N_("Paste formatted screen"), + .summary = N_("Search clipboard for a similar screen, if found paste unprotected fields and restore cursor position"), + .key = 'v', + .mods = GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_ALT_MASK, + .activate = fire_paste_accelerator + }, + { .flags = 0, .group = LIB3270_ACTION_GROUP_ONLINE, -- libgit2 0.21.2