|
8 | 8 | #include "clFileName.hpp" |
9 | 9 | #include "clINIParser.hpp" |
10 | 10 | #include "clWorkspaceManager.h" |
| 11 | +#include "cl_aui_tool_stickness.h" |
11 | 12 | #include "codelite_events.h" |
12 | 13 | #include "environmentconfig.h" |
13 | 14 | #include "event_notifier.h" |
|
23 | 24 | #include <wx/choicdlg.h> |
24 | 25 | #include <wx/dir.h> |
25 | 26 | #include <wx/frame.h> |
| 27 | +#include <wx/menu.h> |
26 | 28 | #include <wx/sizer.h> |
27 | 29 | #include <wx/xrc/xmlres.h> |
28 | 30 |
|
@@ -54,6 +56,9 @@ std::map<wxString, wxString> LocateDefaultTerminals() |
54 | 56 | clBuiltinTerminalPane::clBuiltinTerminalPane(wxWindow* parent, wxWindowID id) |
55 | 57 | : wxPanel(parent, id) |
56 | 58 | { |
| 59 | + // Load saved settings |
| 60 | + m_safeDrawingEnabled = clConfig::Get().Read("terminal/safe_drawing", false); |
| 61 | + |
57 | 62 | SetSizer(new wxBoxSizer(wxVERTICAL)); |
58 | 63 | m_book = new Notebook(this, |
59 | 64 | wxID_ANY, |
@@ -82,18 +87,22 @@ clBuiltinTerminalPane::clBuiltinTerminalPane(wxWindow* parent, wxWindowID id) |
82 | 87 | #endif |
83 | 88 |
|
84 | 89 | m_toolbar->AddSeparator(); |
85 | | - |
86 | 90 | // Get list of terminals |
87 | 91 | m_choice_themes = new wxChoice(m_toolbar, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(200), wxNOT_FOUND)); |
88 | 92 | m_toolbar->AddControl(m_choice_themes); |
89 | 93 | m_choice_themes->SetToolTip(_("Choose terminal theme")); |
90 | 94 | m_choice_themes->Bind(wxEVT_CHOICE, &clBuiltinTerminalPane::OnChoiceTheme, this); |
91 | 95 | UpdateFont(); |
| 96 | + m_toolbar->AddSeparator(); |
92 | 97 |
|
| 98 | + m_toolbar->AddTool( |
| 99 | + wxID_PREFERENCES, _("Settings"), image_list->LoadBitmap("cog"), _("Terminal Settings"), wxITEM_NORMAL); |
| 100 | + m_toolbar->SetToolDropDown(wxID_PREFERENCES, true); |
93 | 101 | m_toolbar->Realize(); |
94 | 102 |
|
95 | 103 | m_toolbar->Bind(wxEVT_TOOL, &clBuiltinTerminalPane::OnNew, this, wxID_NEW); |
96 | 104 | m_toolbar->Bind(wxEVT_TOOL, &clBuiltinTerminalPane::OnScanForTerminals, this, wxID_REFRESH); |
| 105 | + m_toolbar->Bind(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &clBuiltinTerminalPane::OnSettingsMenu, this, wxID_PREFERENCES); |
97 | 106 |
|
98 | 107 | GetSizer()->Fit(this); |
99 | 108 | m_book->Bind(wxEVT_BOOK_PAGE_CHANGED, &clBuiltinTerminalPane::OnPageChanged, this); |
@@ -147,6 +156,9 @@ void clBuiltinTerminalPane::OnNew(wxCommandEvent& event) |
147 | 156 | TerminalView* ctrl = new TerminalView(m_book, cmd, env); |
148 | 157 | ctrl->SetTheme(m_activeTheme.has_value() ? *m_activeTheme : wxTerminalTheme::MakeDarkTheme()); |
149 | 158 | m_book->AddPage(ctrl, cmd, true); |
| 159 | + |
| 160 | + // Apply safe drawing setting to the new terminal |
| 161 | + ctrl->EnableSafeDrawing(m_safeDrawingEnabled); |
150 | 162 | m_book->SetPageToolTip(m_book->GetPageCount() - 1, cmd); |
151 | 163 |
|
152 | 164 | ctrl->Bind(wxEVT_TERMINAL_TITLE_CHANGED, [ctrl, this](wxTerminalEvent& event) { |
@@ -540,6 +552,43 @@ void clBuiltinTerminalPane::OnChoiceTheme(wxCommandEvent& event) |
540 | 552 | ApplyThemeChanges(); |
541 | 553 | } |
542 | 554 |
|
| 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 | + |
543 | 592 | void clBuiltinTerminalPane::ApplyThemeChanges() |
544 | 593 | { |
545 | 594 | if (!m_activeTheme.has_value()) { |
|
0 commit comments