Skip to content

Commit

Permalink
Improvements to the new build output view
Browse files Browse the repository at this point in the history
- Added context menu
- Copying text strips any ANSI code embedded in the text

Signed-off-by: Eran Ifrah <[email protected]>
  • Loading branch information
eranif committed Dec 27, 2024
1 parent 603af24 commit 8edfa1b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
71 changes: 71 additions & 0 deletions LiteEditor/BuildTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand All @@ -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

Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions LiteEditor/BuildTabView.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "clEditorEditEventsHandler.h"
#include "compiler.h"

#include <map>
Expand Down Expand Up @@ -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);
Expand All @@ -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;
};
2 changes: 0 additions & 2 deletions LiteEditor/quickfindbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "clEditorEditEventsHandler.h"
#include "clTerminalHistory.h"
#include "quickfindbarbase.h"
#include "wxCustomStatusBar.h"

#include <vector>
#include <wx/combobox.h>
Expand Down

0 comments on commit 8edfa1b

Please sign in to comment.