From b37c1d209e3cc2ad778769a4050b568727d49d3f Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 13 Oct 2020 22:53:11 -0300 Subject: [PATCH] Adding "copy-as-html" action. --- src/include/v3270/selection.h | 3 +++ src/selection/linux/copy.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/terminal/actions/table.c | 17 ++++++++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/include/v3270/selection.h b/src/include/v3270/selection.h index 2d44af8..f645594 100644 --- a/src/include/v3270/selection.h +++ b/src/include/v3270/selection.h @@ -59,6 +59,9 @@ LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) G_GNUC_DEPRECATED; LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED; + LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget); + LIB3270_EXPORT void v3270_copy_as_image(GtkWidget *widget); + // Selections LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut); diff --git a/src/selection/linux/copy.c b/src/selection/linux/copy.c index 752a01e..d391270 100644 --- a/src/selection/linux/copy.c +++ b/src/selection/linux/copy.c @@ -193,3 +193,52 @@ void v3270_update_system_clipboard(GtkWidget *widget) } +void v3270_set_copy_target(GtkWidget *widget, const gchar *target, guint flags, guint info) { + + v3270 * terminal = GTK_V3270(widget); + + if(!terminal->selection.blocks) + { + // No clipboard data, return. + v3270_emit_copy_state(widget); + return; + } + + // Has clipboard data, inform system. + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); + + GtkTargetList * list = gtk_target_list_new(NULL,0); + + GtkTargetEntry entry = { + .target = (char *) target, + .flags = flags, + .info = info + }; + + gtk_target_list_add_table(list, &entry, 1); + + int n_targets; + GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); + + if(gtk_clipboard_set_with_owner( + clipboard, + targets, + n_targets, + (GtkClipboardGetFunc) clipboard_get, + (GtkClipboardClearFunc) clipboard_clear, + G_OBJECT(widget) + )) + { + gtk_clipboard_set_can_store(clipboard,targets,1); + } + + gtk_target_table_free(targets, n_targets); + gtk_target_list_unref(list); + v3270_emit_copy_state(widget); +} + +LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget) { + debug("%s(%p)",__FUNCTION__,widget); + v3270_set_copy_target(widget,"text/html", 0, CLIPBOARD_TYPE_HTML); +} + diff --git a/src/terminal/actions/table.c b/src/terminal/actions/table.c index a610006..e491b4c 100644 --- a/src/terminal/actions/table.c +++ b/src/terminal/actions/table.c @@ -36,6 +36,8 @@ // static int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action * action); // static int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action * action); + static int fire_copy_as_html(GtkWidget *widget, const struct _v3270_action * action); + /*--[ Implement ]------------------------------------------------------------------------------------*/ LIB3270_EXPORT const V3270_ACTION * v3270_get_actions() { @@ -71,6 +73,15 @@ }, { + .name = "copy-as-html", + .group = LIB3270_ACTION_GROUP_SELECTION, + .label = N_( "Copy as HTML" ), + .summary = N_("Copy selection in HTML format"), + .description = N_("Replace current clipboard contents with the selected area in HTML format"), + .activate = fire_copy_as_html + }, + + { .name = "copy-append", .keys = "c", .flags = (V3270_ACTION_FLAGS) V3270_COPY_APPEND, @@ -324,6 +335,11 @@ } + static int fire_copy_as_html(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { + v3270_copy_as_html(widget); + return 0; + } + /* int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { @@ -336,7 +352,6 @@ } - int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) -- libgit2 0.21.2