Commit b37c1d209e3cc2ad778769a4050b568727d49d3f
1 parent
bff59301
Exists in
master
and in
1 other branch
Adding "copy-as-html" action.
Showing
3 changed files
with
68 additions
and
1 deletions
Show diff stats
src/include/v3270/selection.h
| @@ -59,6 +59,9 @@ | @@ -59,6 +59,9 @@ | ||
| 59 | LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) G_GNUC_DEPRECATED; | 59 | LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) G_GNUC_DEPRECATED; |
| 60 | LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED; | 60 | LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED; |
| 61 | 61 | ||
| 62 | + LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget); | ||
| 63 | + LIB3270_EXPORT void v3270_copy_as_image(GtkWidget *widget); | ||
| 64 | + | ||
| 62 | // Selections | 65 | // Selections |
| 63 | 66 | ||
| 64 | LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut); | 67 | LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut); |
src/selection/linux/copy.c
| @@ -193,3 +193,52 @@ void v3270_update_system_clipboard(GtkWidget *widget) | @@ -193,3 +193,52 @@ void v3270_update_system_clipboard(GtkWidget *widget) | ||
| 193 | 193 | ||
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | +void v3270_set_copy_target(GtkWidget *widget, const gchar *target, guint flags, guint info) { | ||
| 197 | + | ||
| 198 | + v3270 * terminal = GTK_V3270(widget); | ||
| 199 | + | ||
| 200 | + if(!terminal->selection.blocks) | ||
| 201 | + { | ||
| 202 | + // No clipboard data, return. | ||
| 203 | + v3270_emit_copy_state(widget); | ||
| 204 | + return; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + // Has clipboard data, inform system. | ||
| 208 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | ||
| 209 | + | ||
| 210 | + GtkTargetList * list = gtk_target_list_new(NULL,0); | ||
| 211 | + | ||
| 212 | + GtkTargetEntry entry = { | ||
| 213 | + .target = (char *) target, | ||
| 214 | + .flags = flags, | ||
| 215 | + .info = info | ||
| 216 | + }; | ||
| 217 | + | ||
| 218 | + gtk_target_list_add_table(list, &entry, 1); | ||
| 219 | + | ||
| 220 | + int n_targets; | ||
| 221 | + GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); | ||
| 222 | + | ||
| 223 | + if(gtk_clipboard_set_with_owner( | ||
| 224 | + clipboard, | ||
| 225 | + targets, | ||
| 226 | + n_targets, | ||
| 227 | + (GtkClipboardGetFunc) clipboard_get, | ||
| 228 | + (GtkClipboardClearFunc) clipboard_clear, | ||
| 229 | + G_OBJECT(widget) | ||
| 230 | + )) | ||
| 231 | + { | ||
| 232 | + gtk_clipboard_set_can_store(clipboard,targets,1); | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + gtk_target_table_free(targets, n_targets); | ||
| 236 | + gtk_target_list_unref(list); | ||
| 237 | + v3270_emit_copy_state(widget); | ||
| 238 | +} | ||
| 239 | + | ||
| 240 | +LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget) { | ||
| 241 | + debug("%s(%p)",__FUNCTION__,widget); | ||
| 242 | + v3270_set_copy_target(widget,"text/html", 0, CLIPBOARD_TYPE_HTML); | ||
| 243 | +} | ||
| 244 | + |
src/terminal/actions/table.c
| @@ -36,6 +36,8 @@ | @@ -36,6 +36,8 @@ | ||
| 36 | // static int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action * action); | 36 | // static int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action * action); |
| 37 | // static int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action * action); | 37 | // static int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action * action); |
| 38 | 38 | ||
| 39 | + static int fire_copy_as_html(GtkWidget *widget, const struct _v3270_action * action); | ||
| 40 | + | ||
| 39 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 41 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 40 | 42 | ||
| 41 | LIB3270_EXPORT const V3270_ACTION * v3270_get_actions() { | 43 | LIB3270_EXPORT const V3270_ACTION * v3270_get_actions() { |
| @@ -71,6 +73,15 @@ | @@ -71,6 +73,15 @@ | ||
| 71 | }, | 73 | }, |
| 72 | 74 | ||
| 73 | { | 75 | { |
| 76 | + .name = "copy-as-html", | ||
| 77 | + .group = LIB3270_ACTION_GROUP_SELECTION, | ||
| 78 | + .label = N_( "Copy as HTML" ), | ||
| 79 | + .summary = N_("Copy selection in HTML format"), | ||
| 80 | + .description = N_("Replace current clipboard contents with the selected area in HTML format"), | ||
| 81 | + .activate = fire_copy_as_html | ||
| 82 | + }, | ||
| 83 | + | ||
| 84 | + { | ||
| 74 | .name = "copy-append", | 85 | .name = "copy-append", |
| 75 | .keys = "<Alt>c", | 86 | .keys = "<Alt>c", |
| 76 | .flags = (V3270_ACTION_FLAGS) V3270_COPY_APPEND, | 87 | .flags = (V3270_ACTION_FLAGS) V3270_COPY_APPEND, |
| @@ -324,6 +335,11 @@ | @@ -324,6 +335,11 @@ | ||
| 324 | 335 | ||
| 325 | } | 336 | } |
| 326 | 337 | ||
| 338 | + static int fire_copy_as_html(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { | ||
| 339 | + v3270_copy_as_html(widget); | ||
| 340 | + return 0; | ||
| 341 | + } | ||
| 342 | + | ||
| 327 | /* | 343 | /* |
| 328 | int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { | 344 | int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { |
| 329 | 345 | ||
| @@ -336,7 +352,6 @@ | @@ -336,7 +352,6 @@ | ||
| 336 | 352 | ||
| 337 | } | 353 | } |
| 338 | 354 | ||
| 339 | - | ||
| 340 | int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { | 355 | int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { |
| 341 | 356 | ||
| 342 | if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) | 357 | if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) |