diff --git a/Plugin/wxTerminalCtrl/wxTerminalCtrl.h b/Plugin/wxTerminalCtrl/wxTerminalCtrl.h index f7c48b1fe7..23a8a52de3 100644 --- a/Plugin/wxTerminalCtrl/wxTerminalCtrl.h +++ b/Plugin/wxTerminalCtrl/wxTerminalCtrl.h @@ -60,7 +60,7 @@ class WXDLLIMPEXP_SDK wxTerminalCtrl : public wxPanel const wxString& GetShellCommand() const { return m_shellCommand; } /** - * @brief execute a command in the temrinal + * @brief execute a command in the terminal * @param command */ void Run(const wxString& command); diff --git a/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp b/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp index ed126e6b3b..bf25d4b044 100644 --- a/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp +++ b/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.cpp @@ -18,6 +18,7 @@ #include "wxTerminalInputCtrl.hpp" #include +#include #include #include #include @@ -41,6 +42,24 @@ class MyEventsHandler : public clEditEventsHandler CHECK_PTR_RET(m_input_ctrl); m_input_ctrl->Paste(); } + + void OnCopy(wxCommandEvent& event) override + { + CHECK_FOCUS_WINDOW(); + CHECK_PTR_RET(m_stc); + if (!m_stc->CanCopy()) { + return; + } + + wxString text = m_stc->GetSelectedText(); + if (text.empty()) { + return; + } + wxString modbuffer; + StringUtils::StripTerminalColouring(text, modbuffer); + + ::CopyToClipboard(modbuffer); + } }; struct EditorEnabler { @@ -62,8 +81,11 @@ wxTerminalOutputCtrl::wxTerminalOutputCtrl(wxWindow* parent, wxWindowID winid) m_editEvents = std::make_unique(nullptr, m_ctrl); } -wxTerminalOutputCtrl::wxTerminalOutputCtrl(wxTerminalCtrl* parent, wxWindowID winid, const wxFont& font, - const wxColour& bg_colour, const wxColour& text_colour) +wxTerminalOutputCtrl::wxTerminalOutputCtrl(wxTerminalCtrl* parent, + wxWindowID winid, + const wxFont& font, + const wxColour& bg_colour, + const wxColour& text_colour) : wxWindow(parent, winid) , m_terminal(parent) { @@ -87,7 +109,8 @@ void wxTerminalOutputCtrl::Initialise(const wxFont& font, const wxColour& bg_col m_ctrl->SetMarginWidth(i, 0); } - m_ctrl->UsePopUp(1); + m_ctrl->UsePopUp(0); + m_ctrl->Bind(wxEVT_CONTEXT_MENU, &wxTerminalOutputCtrl::OnMenu, this); m_ctrl->SetLexer(wxSTC_LEX_CONTAINER); m_ctrl->SetWrapMode(wxSTC_WRAP_CHAR); m_ctrl->SetEditable(false); @@ -414,3 +437,56 @@ void wxTerminalOutputCtrl::DoPatternClicked(const wxString& pattern) }; clGetManager()->OpenFileAndAsyncExecute(file, std::move(cb)); } + +void wxTerminalOutputCtrl::OnMenu(wxContextMenuEvent& event) +{ + wxUnusedVar(event); + wxMenu menu; + menu.Append(wxID_COPY); + menu.Append(XRCID("copy-with-ansi-colors"), _("Copy with Terminal Colours")); + menu.AppendSeparator(); + menu.Append(wxID_SELECTALL); + menu.AppendSeparator(); + menu.Append(wxID_CLEAR); + + menu.Bind( + wxEVT_MENU, + [this](wxCommandEvent& event) { + wxUnusedVar(event); + wxString text = m_ctrl->GetSelectedText(); + if (text.empty()) { + return; + } + + wxString modbuffer; + StringUtils::StripTerminalColouring(text, modbuffer); + ::CopyToClipboard(modbuffer); + }, + wxID_COPY); + menu.Bind( + wxEVT_MENU, + [this](wxCommandEvent& event) { + wxUnusedVar(event); + wxString text = m_ctrl->GetSelectedText(); + if (text.empty()) { + return; + } + ::CopyToClipboard(text); + }, + XRCID("copy-with-ansi-colors")); + menu.Bind( + wxEVT_MENU, + [this](wxCommandEvent& event) { + wxUnusedVar(event); + m_ctrl->SelectAll(); + }, + wxID_SELECTALL); + menu.Bind( + wxEVT_MENU, + [this](wxCommandEvent& event) { + wxUnusedVar(event); + Clear(); + }, + wxID_CLEAR); + PopupMenu(&menu); +} diff --git a/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.hpp b/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.hpp index b06825364a..8060e1153c 100644 --- a/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.hpp +++ b/Plugin/wxTerminalCtrl/wxTerminalOutputCtrl.hpp @@ -81,17 +81,21 @@ class WXDLLIMPEXP_SDK wxTerminalOutputCtrl : public wxWindow void OnLeftUp(wxMouseEvent& event); void ApplyTheme(); void OnKeyDown(wxKeyEvent& event); - void Initialise(const wxFont& font = wxNullFont, const wxColour& bg_colour = *wxBLACK, + void Initialise(const wxFont& font = wxNullFont, + const wxColour& bg_colour = *wxBLACK, const wxColour& text_colour = *wxWHITE); void ClearIndicators(); void ProcessIdle(); void OnEnterWindow(wxMouseEvent& event); void OnLeaveWindow(wxMouseEvent& event); void DoPatternClicked(const wxString& pattern); + void OnMenu(wxContextMenuEvent& event); public: - explicit wxTerminalOutputCtrl(wxTerminalCtrl* parent, wxWindowID winid = wxNOT_FOUND, - const wxFont& font = wxNullFont, const wxColour& bg_colour = *wxBLACK, + explicit wxTerminalOutputCtrl(wxTerminalCtrl* parent, + wxWindowID winid = wxNOT_FOUND, + const wxFont& font = wxNullFont, + const wxColour& bg_colour = *wxBLACK, const wxColour& text_colour = *wxWHITE); explicit wxTerminalOutputCtrl(wxWindow* parent, wxWindowID winid = wxNOT_FOUND); virtual ~wxTerminalOutputCtrl();