Skip to content

Commit 2a27f0b

Browse files
committed
Add Safe Drawing Toggle To Builtin Terminal
Persist and expose a new terminal “Safe Drawing” setting from the builtin terminal pane. The toolbar now includes a settings dropdown that lets users toggle the feature, and the choice is saved to configuration so it survives restart. When the setting changes, it is applied immediately to all open terminal views and to newly created terminals as they are opened. * Terminal pane toolbar * Terminal view initialization * Configuration persistence **Generated by CodeLite** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent a022255 commit 2a27f0b

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

Plugin/wxTerminalCtrl/clBuiltinTerminalPane.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "clFileName.hpp"
99
#include "clINIParser.hpp"
1010
#include "clWorkspaceManager.h"
11+
#include "cl_aui_tool_stickness.h"
1112
#include "codelite_events.h"
1213
#include "environmentconfig.h"
1314
#include "event_notifier.h"
@@ -23,6 +24,7 @@
2324
#include <wx/choicdlg.h>
2425
#include <wx/dir.h>
2526
#include <wx/frame.h>
27+
#include <wx/menu.h>
2628
#include <wx/sizer.h>
2729
#include <wx/xrc/xmlres.h>
2830

@@ -54,6 +56,9 @@ std::map<wxString, wxString> LocateDefaultTerminals()
5456
clBuiltinTerminalPane::clBuiltinTerminalPane(wxWindow* parent, wxWindowID id)
5557
: wxPanel(parent, id)
5658
{
59+
// Load saved settings
60+
m_safeDrawingEnabled = clConfig::Get().Read("terminal/safe_drawing", false);
61+
5762
SetSizer(new wxBoxSizer(wxVERTICAL));
5863
m_book = new Notebook(this,
5964
wxID_ANY,
@@ -82,18 +87,22 @@ clBuiltinTerminalPane::clBuiltinTerminalPane(wxWindow* parent, wxWindowID id)
8287
#endif
8388

8489
m_toolbar->AddSeparator();
85-
8690
// Get list of terminals
8791
m_choice_themes = new wxChoice(m_toolbar, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(200), wxNOT_FOUND));
8892
m_toolbar->AddControl(m_choice_themes);
8993
m_choice_themes->SetToolTip(_("Choose terminal theme"));
9094
m_choice_themes->Bind(wxEVT_CHOICE, &clBuiltinTerminalPane::OnChoiceTheme, this);
9195
UpdateFont();
96+
m_toolbar->AddSeparator();
9297

98+
m_toolbar->AddTool(
99+
wxID_PREFERENCES, _("Settings"), image_list->LoadBitmap("cog"), _("Terminal Settings"), wxITEM_NORMAL);
100+
m_toolbar->SetToolDropDown(wxID_PREFERENCES, true);
93101
m_toolbar->Realize();
94102

95103
m_toolbar->Bind(wxEVT_TOOL, &clBuiltinTerminalPane::OnNew, this, wxID_NEW);
96104
m_toolbar->Bind(wxEVT_TOOL, &clBuiltinTerminalPane::OnScanForTerminals, this, wxID_REFRESH);
105+
m_toolbar->Bind(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &clBuiltinTerminalPane::OnSettingsMenu, this, wxID_PREFERENCES);
97106

98107
GetSizer()->Fit(this);
99108
m_book->Bind(wxEVT_BOOK_PAGE_CHANGED, &clBuiltinTerminalPane::OnPageChanged, this);
@@ -147,6 +156,9 @@ void clBuiltinTerminalPane::OnNew(wxCommandEvent& event)
147156
TerminalView* ctrl = new TerminalView(m_book, cmd, env);
148157
ctrl->SetTheme(m_activeTheme.has_value() ? *m_activeTheme : wxTerminalTheme::MakeDarkTheme());
149158
m_book->AddPage(ctrl, cmd, true);
159+
160+
// Apply safe drawing setting to the new terminal
161+
ctrl->EnableSafeDrawing(m_safeDrawingEnabled);
150162
m_book->SetPageToolTip(m_book->GetPageCount() - 1, cmd);
151163

152164
ctrl->Bind(wxEVT_TERMINAL_TITLE_CHANGED, [ctrl, this](wxTerminalEvent& event) {
@@ -540,6 +552,43 @@ void clBuiltinTerminalPane::OnChoiceTheme(wxCommandEvent& event)
540552
ApplyThemeChanges();
541553
}
542554

555+
void clBuiltinTerminalPane::OnSettingsMenu(wxCommandEvent& event)
556+
{
557+
wxUnusedVar(event);
558+
559+
wxMenu menu;
560+
wxMenuItem* safeDrawingItem = menu.AppendCheckItem(wxID_ANY, _("Enable Safe Drawing"));
561+
safeDrawingItem->Check(m_safeDrawingEnabled);
562+
563+
menu.Bind(
564+
wxEVT_MENU,
565+
[this](wxCommandEvent& e) {
566+
m_safeDrawingEnabled = !m_safeDrawingEnabled;
567+
clDEBUG() << "Safe Drawing:" << (m_safeDrawingEnabled ? "Enabled" : "Disabled") << endl;
568+
569+
// Persist the setting
570+
clConfig::Get().Write("terminal/safe_drawing", m_safeDrawingEnabled);
571+
clConfig::Get().Save();
572+
573+
// Apply to all terminals
574+
for (size_t i = 0; i < m_book->GetPageCount(); ++i) {
575+
auto terminal = dynamic_cast<TerminalView*>(m_book->GetPage(i));
576+
if (terminal) {
577+
terminal->EnableSafeDrawing(m_safeDrawingEnabled);
578+
terminal->Refresh();
579+
}
580+
}
581+
},
582+
safeDrawingItem->GetId());
583+
584+
wxRect rect = m_toolbar->GetToolRect(wxID_PREFERENCES);
585+
wxPoint pt = m_toolbar->ClientToScreen(rect.GetBottomLeft());
586+
pt = ScreenToClient(pt);
587+
588+
clAuiToolStickness st{m_toolbar, event.GetId()};
589+
PopupMenu(&menu, pt);
590+
}
591+
543592
void clBuiltinTerminalPane::ApplyThemeChanges()
544593
{
545594
if (!m_activeTheme.has_value()) {

Plugin/wxTerminalCtrl/clBuiltinTerminalPane.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class WXDLLIMPEXP_SDK clBuiltinTerminalPane : public wxPanel
5757
void OnChoiceTheme(wxCommandEvent& event);
5858
void ApplyThemeChanges();
5959
void UpdateFont();
60+
void OnSettingsMenu(wxCommandEvent& event);
61+
void OnToggleSafeDrawing(wxCommandEvent& event);
6062

6163
private:
6264
static std::optional<wxTerminalTheme> FromTOML(const wxFileName& filepath);
@@ -71,6 +73,7 @@ class WXDLLIMPEXP_SDK clBuiltinTerminalPane : public wxPanel
7173
std::map<wxString, wxTerminalTheme> m_themes;
7274
std::optional<wxTerminalTheme> m_activeTheme{std::nullopt};
7375
wxFont m_activeFont;
76+
bool m_safeDrawingEnabled = false;
7477
};
7578

7679
#endif // CLBUILTINTERMINALPANE_HPP

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ BUGS
3939
- AI: Unable to restart the client once a single "Confirm" bar was shown.
4040
- AI: Replace the "Confirm" dialog with a free text, allowing the user to interrupt the model.
4141
- AI: Extend all the tools with a "Purpose" mandatory field, so each model will be forced to report the reason for the invocation.
42-
42+
- AI: Add a system-message that instruct the model to NEVER create a summary file

0 commit comments

Comments
 (0)