Skip to content

Commit

Permalink
widget: Provide a way to copy the selection to clipboard as HTML
Browse files Browse the repository at this point in the history
Currently, copying to HTML is disabled (#if 0) in the code, because
it will generate the potentially huge selection data in both text and
HTML formats.

Instead, provide API to tell vte which format to use.

https://bugzilla.gnome.org/show_bug.cgi?id=365121
  • Loading branch information
Christian Persch committed May 7, 2017
1 parent 64be114 commit 91e9c83
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 209 deletions.
1 change: 1 addition & 0 deletions bindings/vala/app.ui
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Copy</property>
<property name="action_name">win.copy</property>
<property name="action_target">"text"</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="image2">
Expand Down
12 changes: 8 additions & 4 deletions bindings/vala/app.vala
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Window : Gtk.ApplicationWindow
};

private const GLib.ActionEntry[] action_entries = {
{ "copy", action_copy_cb },
{ "copy", action_copy_cb, "s" },
{ "copy-match", action_copy_match_cb, "s" },
{ "paste", action_paste_cb },
{ "reset", action_reset_cb, "b" },
Expand Down Expand Up @@ -564,9 +564,12 @@ class Window : Gtk.ApplicationWindow

/* Callbacks */

private void action_copy_cb()
private void action_copy_cb(GLib.SimpleAction action, GLib.Variant? parameter)
{
terminal.copy_clipboard();
size_t len;
unowned string str = parameter.get_string(out len);

terminal.copy_clipboard_format(str == "html" ? Vte.Format.HTML : Vte.Format.TEXT);
}

private void action_copy_match_cb(GLib.SimpleAction action, GLib.Variant? parameter)
Expand Down Expand Up @@ -625,7 +628,8 @@ class Window : Gtk.ApplicationWindow
return false;

var menu = new GLib.Menu();
menu.append("_Copy", "win.copy");
menu.append("_Copy", "win.copy::text");
menu.append("Copy As _HTML", "win.copy::html");

#if VALA_0_24
if (event != null) {
Expand Down
6 changes: 5 additions & 1 deletion doc/reference/vte-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VteTerminal
VteCursorBlinkMode
VteCursorShape
VteEraseBinding
VteFormat
VteWriteFlags
VteSelectionFunc
vte_terminal_new
Expand All @@ -13,7 +14,7 @@ vte_terminal_feed_child
vte_terminal_feed_child_binary
vte_terminal_select_all
vte_terminal_unselect_all
vte_terminal_copy_clipboard
vte_terminal_copy_clipboard_format
vte_terminal_paste_clipboard
vte_terminal_copy_primary
vte_terminal_paste_primary
Expand Down Expand Up @@ -102,6 +103,8 @@ VTE_TYPE_CURSOR_SHAPE
vte_cursor_shape_get_type
VTE_TYPE_ERASE_BINDING
vte_erase_binding_get_type
VTE_TYPE_FORMAT
vte_format_get_type
VTE_TYPE_WRITE_FLAGS
vte_write_flags_get_type
VTE_TYPE_TERMINAL
Expand All @@ -123,6 +126,7 @@ vte_terminal_get_current_directory_uri
vte_terminal_get_current_file_uri

<SUBSECTION Deprecated>
vte_terminal_copy_clipboard
vte_terminal_match_set_cursor
vte_terminal_match_add_gregex
vte_terminal_search_get_gregex
Expand Down
Loading

0 comments on commit 91e9c83

Please sign in to comment.