From 8edfa1b958977f36b229b2dc2869315b7b0a257c Mon Sep 17 00:00:00 2001 From: Eran Ifrah Date: Fri, 27 Dec 2024 12:08:05 +0200 Subject: [PATCH] Improvements to the new build output view - Added context menu - Copying text strips any ANSI code embedded in the text Signed-off-by: Eran Ifrah --- LiteEditor/BuildTabView.cpp | 71 +++++++++++++++++++++++++++++++++++++ LiteEditor/BuildTabView.hpp | 3 ++ LiteEditor/quickfindbar.h | 2 -- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/LiteEditor/BuildTabView.cpp b/LiteEditor/BuildTabView.cpp index be94685858..a3028bf3fb 100644 --- a/LiteEditor/BuildTabView.cpp +++ b/LiteEditor/BuildTabView.cpp @@ -62,14 +62,40 @@ constexpr int LINE_MARKER = 7; constexpr int NUMBER_MARGIN_ID = 1; constexpr int SYMBOLS_MARGIN_SEP_ID = 4; +/// Provide a helper that strips ANSI codes from the text +class MyEventsHandler : public clEditEventsHandler +{ +public: + MyEventsHandler(wxStyledTextCtrl* ctrl) + : clEditEventsHandler(ctrl) + { + } + + void OnCopy(wxCommandEvent& event) override + { + if (!m_stc->CanCopy()) { + return; + } + + auto text = ::clGetVisibleSelection(m_stc); + if (text.empty()) { + return; + } + ::CopyToClipboard(text); + } +}; + } // namespace BuildTabView::BuildTabView(wxWindow* parent) : wxStyledTextCtrl(parent) { InitialiseView(); + m_editEvents.reset(new MyEventsHandler(this)); + Bind(wxEVT_LEFT_DOWN, &BuildTabView::OnLeftDown, this); Bind(wxEVT_LEFT_UP, &BuildTabView::OnLeftUp, this); + Bind(wxEVT_CONTEXT_MENU, &BuildTabView::OnContextMenu, this); wxTheApp->Bind(wxEVT_MENU, &BuildTabView::OnNextBuildError, this, XRCID("next_build_error")); wxTheApp->Bind(wxEVT_UPDATE_UI, &BuildTabView::OnNextBuildErrorUI, this, XRCID("next_build_error")); @@ -86,6 +112,7 @@ BuildTabView::~BuildTabView() { Unbind(wxEVT_LEFT_DOWN, &BuildTabView::OnLeftDown, this); Unbind(wxEVT_LEFT_UP, &BuildTabView::OnLeftUp, this); + Unbind(wxEVT_CONTEXT_MENU, &BuildTabView::OnContextMenu, this); wxTheApp->Unbind(wxEVT_MENU, &BuildTabView::OnNextBuildError, this, XRCID("next_build_error")); wxTheApp->Unbind(wxEVT_UPDATE_UI, &BuildTabView::OnNextBuildErrorUI, this, XRCID("next_build_error")); @@ -110,7 +137,9 @@ void BuildTabView::InitialiseView() SetScrollWidthTracking(true); SetWordChars(R"#(\:~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$/.-+@)#"); SetEditable(false); + UsePopUp(0); } + #define PROCESSBUFFER_FMT_LINES_MAX 8192 #define PROCESSBUFFER_FLUSH_TIME 200 // ms @@ -465,3 +494,45 @@ void BuildTabView::OnThemeChanged(wxCommandEvent& e) e.Skip(); InitialiseView(); } + +void BuildTabView::OnContextMenu(wxContextMenuEvent& e) +{ + e.Skip(); + wxMenu menu; + + menu.Append(XRCID("buildtabview_copy"), _("Copy")); + menu.Append(XRCID("buildtabview_select_all"), _("Select All")); + menu.AppendSeparator(); + menu.Append(XRCID("buildtabview_clear_all"), _("Clear")); + + menu.Bind( + wxEVT_MENU, + [this](wxCommandEvent& e) { + wxUnusedVar(e); + auto text = ::clGetVisibleSelection(this); + ::CopyToClipboard(text); + }, + XRCID("buildtabview_copy")); + menu.Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& e) { e.Enable(HasSelection()); }, XRCID("buildtabview_copy")); + + menu.Bind( + wxEVT_MENU, + [this](wxCommandEvent& e) { + wxUnusedVar(e); + SelectAll(); + }, + XRCID("buildtabview_select_all")); + menu.Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& e) { e.Enable(!IsEmpty()); }, XRCID("buildtabview_select_all")); + + menu.Bind( + wxEVT_MENU, + [this](wxCommandEvent& e) { + wxUnusedVar(e); + SetEditable(true); + ClearAll(); + SetEditable(false); + }, + XRCID("buildtabview_clear_all")); + menu.Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& e) { e.Enable(!IsEmpty()); }, XRCID("buildtabview_clear_all")); + PopupMenu(&menu); +} diff --git a/LiteEditor/BuildTabView.hpp b/LiteEditor/BuildTabView.hpp index 5503a91868..edff43800e 100644 --- a/LiteEditor/BuildTabView.hpp +++ b/LiteEditor/BuildTabView.hpp @@ -1,5 +1,6 @@ #pragma once +#include "clEditorEditEventsHandler.h" #include "compiler.h" #include @@ -51,6 +52,7 @@ class BuildTabView : public wxStyledTextCtrl void SelectFirstErrorOrWarning(size_t from, bool errors_only); protected: + void OnContextMenu(wxContextMenuEvent& e); void OnLeftDown(wxMouseEvent& e); void OnLeftUp(wxMouseEvent& e); void DoPatternClicked(const wxString& pattern, int pattern_line); @@ -74,4 +76,5 @@ class BuildTabView : public wxStyledTextCtrl wxString m_currentProject; int m_indicatorStartPos = wxNOT_FOUND; int m_indicatorEndPos = wxNOT_FOUND; + clEditEventsHandler::Ptr_t m_editEvents; }; diff --git a/LiteEditor/quickfindbar.h b/LiteEditor/quickfindbar.h index c4a642b70e..4755fdb72c 100644 --- a/LiteEditor/quickfindbar.h +++ b/LiteEditor/quickfindbar.h @@ -24,10 +24,8 @@ ////////////////////////////////////////////////////////////////////////////// #pragma once -#include "clEditorEditEventsHandler.h" #include "clTerminalHistory.h" #include "quickfindbarbase.h" -#include "wxCustomStatusBar.h" #include #include