From 97e07093b2b540cc15c0e573e37e9bbae9424d11 Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Tue, 13 Jul 2021 22:20:29 +0700 Subject: [PATCH] Change terminal menu option 'Select All' -> 'Copy All' Adds copy_all() function to terminal node which returns all of the screen's text. --- .../editor_plugins/terminal/terminal_panel.gd | 4 +++- .../editor_plugins/terminal/terminal_panel.tscn | 2 +- addons/godot_xterm/native/src/terminal.cpp | 9 +++++++++ addons/godot_xterm/native/src/terminal.h | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd b/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd index 885182a..b756cf3 100644 --- a/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd +++ b/addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd @@ -16,7 +16,7 @@ enum TerminalPopupMenuOptions { NEW_TERMINAL = 0, COPY = 2, PASTE = 3, - SELECT_ALL = 4, + COPY_ALL = 4, CLEAR = 6, KILL_TERMINAL = 7, } @@ -216,6 +216,8 @@ func _on_TerminalPopupMenu_id_pressed(id): event.unicode = ord(OS.clipboard[i]) event.pressed = true terminal._gui_input(event) + TerminalPopupMenuOptions.COPY_ALL: + OS.clipboard = terminal.copy_all() TerminalPopupMenuOptions.CLEAR: terminal.clear() TerminalPopupMenuOptions.KILL_TERMINAL: diff --git a/addons/godot_xterm/editor_plugins/terminal/terminal_panel.tscn b/addons/godot_xterm/editor_plugins/terminal/terminal_panel.tscn index 4fe7c0a..0be2690 100644 --- a/addons/godot_xterm/editor_plugins/terminal/terminal_panel.tscn +++ b/addons/godot_xterm/editor_plugins/terminal/terminal_panel.tscn @@ -107,7 +107,7 @@ margin_right = 193.0 margin_bottom = 160.0 size_flags_horizontal = 0 size_flags_vertical = 0 -items = [ "New Terminal", null, 0, false, false, 0, 0, null, "", false, "", null, 0, false, true, 1, 0, null, "", true, "Copy", null, 0, false, false, 2, 0, null, "", false, "Paste", null, 0, false, false, 3, 0, null, "", false, "Select All", null, 0, false, true, 4, 0, null, "", false, "", null, 0, false, false, 5, 0, null, "", true, "Clear", null, 0, false, false, 6, 0, null, "", false, "Kill Terminal", null, 0, false, false, 7, 0, null, "", false ] +items = [ "New Terminal", null, 0, false, false, 0, 0, null, "", false, "", null, 0, false, true, 1, 0, null, "", true, "Copy", null, 0, false, false, 2, 0, null, "", false, "Paste", null, 0, false, false, 3, 0, null, "", false, "Copy All", null, 0, false, false, 4, 0, null, "", false, "", null, 0, false, false, 5, 0, null, "", true, "Clear", null, 0, false, false, 6, 0, null, "", false, "Kill Terminal", null, 0, false, false, 7, 0, null, "", false ] __meta__ = { "_edit_use_anchors_": false } diff --git a/addons/godot_xterm/native/src/terminal.cpp b/addons/godot_xterm/native/src/terminal.cpp index 296cafa..ce3c9a3 100644 --- a/addons/godot_xterm/native/src/terminal.cpp +++ b/addons/godot_xterm/native/src/terminal.cpp @@ -295,6 +295,7 @@ void Terminal::_register_methods() { register_method("select_to_pointer", &Terminal::select_to_pointer); register_method("reset_selection", &Terminal::reset_selection); register_method("copy_selection", &Terminal::copy_selection); + register_method("copy_all", &Terminal::copy_all); register_method("_update_theme", &Terminal::update_theme); register_method("_update_size", &Terminal::update_theme); @@ -626,3 +627,11 @@ String Terminal::copy_selection() { std::free(out); return result; } + +String Terminal::copy_all() { + char *out = nullptr; + int len = tsm_screen_copy_all(screen, &out); + String result = String(out); + std::free(out); + return result; +} \ No newline at end of file diff --git a/addons/godot_xterm/native/src/terminal.h b/addons/godot_xterm/native/src/terminal.h index 656e6d9..7757bd3 100644 --- a/addons/godot_xterm/native/src/terminal.h +++ b/addons/godot_xterm/native/src/terminal.h @@ -64,6 +64,7 @@ public: void select_to_pointer(Vector2 position); void reset_selection(); String copy_selection(); + String copy_all(); enum UpdateMode { DISABLED,