From 68b85e82204fbcb8cbed55f08f3b5ee40b712001 Mon Sep 17 00:00:00 2001 From: Eran Ifrah Date: Fri, 31 May 2024 09:25:00 +0300 Subject: [PATCH] LSP plugin: use native notebook to display the existing language servers --- LanguageServer/LanguageServerPage.cpp | 22 ++++++------- LanguageServer/LanguageServerSettingsDlg.cpp | 31 +++++++++--------- LanguageServer/UI.cpp | 34 +++++++++----------- LanguageServer/UI.h | 6 ++-- LanguageServer/UI.wxcp | 8 ++--- 5 files changed, 49 insertions(+), 52 deletions(-) diff --git a/LanguageServer/LanguageServerPage.cpp b/LanguageServer/LanguageServerPage.cpp index c0a16708a4..8f0fcf21de 100644 --- a/LanguageServer/LanguageServerPage.cpp +++ b/LanguageServer/LanguageServerPage.cpp @@ -3,10 +3,7 @@ #include "ColoursAndFontsManager.h" #include "JSON.h" #include "LSP/LanguageServerProtocol.h" -#include "StringUtils.h" -#include "globals.h" -#include #include #include #include @@ -15,8 +12,9 @@ LanguageServerPage::LanguageServerPage(wxWindow* parent, const LanguageServerEntry& data) : LanguageServerPageBase(parent) { + Hide(); LexerConf::Ptr_t lex = ColoursAndFontsManager::Get().GetLexer("text"); - if(lex) { + if (lex) { lex->ApplySystemColours(m_stcCommand); lex->ApplySystemColours(m_stcInitOptions); } @@ -39,7 +37,7 @@ LanguageServerPage::LanguageServerPage(wxWindow* parent) : LanguageServerPageBase(parent) { LexerConf::Ptr_t lex = ColoursAndFontsManager::Get().GetLexer("text"); - if(lex) { + if (lex) { lex->ApplySystemColours(m_stcCommand); lex->ApplySystemColours(m_stcInitOptions); } @@ -74,19 +72,19 @@ void LanguageServerPage::OnSuggestLanguages(wxCommandEvent& event) { const std::set& langSet = LanguageServerProtocol::GetSupportedLanguages(); wxArrayString arrLang; - for(const wxString& lang : langSet) { + for (const wxString& lang : langSet) { arrLang.Add(lang); } wxArrayInt selections; int count = ::wxGetSelectedChoices(selections, _("Select the supported languages by this server:"), _("CodeLite"), arrLang, GetParent()); - if(count == wxNOT_FOUND) { + if (count == wxNOT_FOUND) { return; } wxString newText; - for(int sel : selections) { + for (int sel : selections) { newText << arrLang.Item(sel) << ";"; } m_textCtrlLanguages->ChangeValue(newText); @@ -98,7 +96,7 @@ void LanguageServerPage::OnBrowseWD(wxCommandEvent& event) wxString path(m_textCtrlWD->GetValue()); wxString new_path = wxDirSelector(_("Select a working directory:"), path, wxDD_DEFAULT_STYLE, wxDefaultPosition, this); - if(new_path.IsEmpty() == false) { + if (new_path.IsEmpty() == false) { m_textCtrlWD->SetValue(new_path); } } @@ -109,17 +107,17 @@ bool LanguageServerPage::ValidateData(wxString* message) const wxString init_options = m_stcInitOptions->GetText(); init_options.Trim().Trim(false); - if(init_options.empty()) { + if (init_options.empty()) { return true; } JSON root{ init_options }; - if(!root.isOk()) { + if (!root.isOk()) { (*message) << m_textCtrlName->GetValue() << ": invalid JSON input in `initializationOptions`"; return false; } - if(!root.toElement().isObject()) { + if (!root.toElement().isObject()) { (*message) << m_textCtrlName->GetValue() << ": `initializationOptions` must be a JSON object"; return false; } diff --git a/LanguageServer/LanguageServerSettingsDlg.cpp b/LanguageServer/LanguageServerSettingsDlg.cpp index 397cacfd34..e723c24587 100644 --- a/LanguageServer/LanguageServerSettingsDlg.cpp +++ b/LanguageServer/LanguageServerSettingsDlg.cpp @@ -19,7 +19,7 @@ LanguageServerSettingsDlg::LanguageServerSettingsDlg(wxWindow* parent, bool trig { DoInitialize(); ::clSetDialogBestSizeAndPosition(this); - if(m_scanOnStartup) { + if (m_scanOnStartup) { CallAfter(&LanguageServerSettingsDlg::DoScan); } } @@ -29,7 +29,8 @@ LanguageServerSettingsDlg::~LanguageServerSettingsDlg() {} void LanguageServerSettingsDlg::OnAddServer(wxCommandEvent& event) { NewLanguageServerDlg dlg(this); - if(dlg.ShowModal() == wxID_OK) { + if (dlg.ShowModal() == wxID_OK) { + wxWindowUpdateLocker lk{ m_notebook }; LanguageServerEntry server = dlg.GetData(); // Update the configuration LanguageServerConfig::Get().AddServer(server); @@ -40,7 +41,7 @@ void LanguageServerSettingsDlg::OnAddServer(wxCommandEvent& event) void LanguageServerSettingsDlg::Save() { LanguageServerConfig& conf = LanguageServerConfig::Get(); - for(size_t i = 0; i < m_notebook->GetPageCount(); ++i) { + for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) { LanguageServerPage* page = dynamic_cast(m_notebook->GetPage(i)); conf.AddServer(page->GetData()); } @@ -51,13 +52,13 @@ void LanguageServerSettingsDlg::Save() void LanguageServerSettingsDlg::OnDeleteLSP(wxCommandEvent& event) { int sel = m_notebook->GetSelection(); - if(sel == wxNOT_FOUND) { + if (sel == wxNOT_FOUND) { return; } wxString serverName = m_notebook->GetPageText(sel); - if(::wxMessageBox(wxString() << _("Are you sure you want to delete '") << serverName << "' ?", "CodeLite", - wxICON_QUESTION | wxCENTRE | wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT, this) != wxYES) { + if (::wxMessageBox(wxString() << _("Are you sure you want to delete '") << serverName << "' ?", "CodeLite", + wxICON_QUESTION | wxCENTRE | wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT, this) != wxYES) { return; } LanguageServerConfig::Get().RemoveServer(serverName); @@ -70,8 +71,8 @@ void LanguageServerSettingsDlg::OnOKUI(wxUpdateUIEvent& event) { event.Enable(tr void LanguageServerSettingsDlg::OnScan(wxCommandEvent& event) { event.Skip(); - if(::wxMessageBox(_("This will reconfigure your language servers\nContinue?"), "CodeLite", - wxICON_QUESTION | wxYES_NO | wxCANCEL | wxYES_DEFAULT) != wxYES) { + if (::wxMessageBox(_("This will reconfigure your language servers\nContinue?"), "CodeLite", + wxICON_QUESTION | wxYES_NO | wxCANCEL | wxYES_DEFAULT) != wxYES) { return; } DoScan(); @@ -79,10 +80,10 @@ void LanguageServerSettingsDlg::OnScan(wxCommandEvent& event) void LanguageServerSettingsDlg::DoInitialize() { - wxWindowUpdateLocker locker{ this }; + wxWindowUpdateLocker locker{ m_notebook }; m_notebook->DeleteAllPages(); const auto& servers = LanguageServerConfig::Get().GetServers(); - for(const auto& [name, server] : servers) { + for (const auto& [name, server] : servers) { m_notebook->AddPage(new LanguageServerPage(m_notebook, server), server.GetName()); } m_checkBoxEnable->SetValue(LanguageServerConfig::Get().IsEnabled()); @@ -94,10 +95,10 @@ void LanguageServerSettingsDlg::DoScan() wxBusyCursor bc; std::vector matches; LSPDetectorManager detector; - if(detector.Scan(matches)) { + if (detector.Scan(matches)) { LanguageServerConfig& conf = LanguageServerConfig::Get(); LanguageServerEntry::Map_t servers; - for(const auto& match : matches) { + for (const auto& match : matches) { LanguageServerEntry entry; match->GetLanguageServerEntry(entry); servers.insert({ entry.GetName(), entry }); @@ -105,7 +106,7 @@ void LanguageServerSettingsDlg::DoScan() conf.SetServers(servers); conf.Save(); DoInitialize(); - if(m_scanOnStartup) { + if (m_scanOnStartup) { m_checkBoxEnable->SetValue(true); } } @@ -113,10 +114,10 @@ void LanguageServerSettingsDlg::DoScan() void LanguageServerSettingsDlg::OnButtonOK(wxCommandEvent& event) { // validate the data - for(size_t i = 0; i < m_notebook->GetPageCount(); ++i) { + for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) { LanguageServerPage* page = dynamic_cast(m_notebook->GetPage(i)); wxString message; - if(!page->ValidateData(&message)) { + if (!page->ValidateData(&message)) { ::wxMessageBox(message, "CodeLite", wxOK | wxCENTRE | wxICON_WARNING, this); event.Skip(false); return; diff --git a/LanguageServer/UI.cpp b/LanguageServer/UI.cpp index 7a5228e089..851815a436 100644 --- a/LanguageServer/UI.cpp +++ b/LanguageServer/UI.cpp @@ -27,7 +27,7 @@ LanguageServerSettingsDlgBase::LanguageServerSettingsDlgBase(wxWindow* parent, w const wxPoint& pos, const wxSize& size, long style) : wxDialog(parent, id, title, pos, size, style) { - if(!bBitmapLoaded) { + if (!bBitmapLoaded) { // We need to initialise the default bitmap handler wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler); wxCrafterCbL3wsInitBitmapResources(); @@ -58,8 +58,7 @@ LanguageServerSettingsDlgBase::LanguageServerSettingsDlgBase(wxWindow* parent, w boxSizer2->Add(boxSizer106, 1, wxEXPAND, WXC_FROM_DIP(5)); - m_notebook = - new Notebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), kNotebook_FixedWidth); + m_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), wxBK_DEFAULT); m_notebook->SetName(wxT("m_notebook")); boxSizer106->Add(m_notebook, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5)); @@ -97,10 +96,10 @@ LanguageServerSettingsDlgBase::LanguageServerSettingsDlgBase(wxWindow* parent, w SetName(wxT("LanguageServerSettingsDlgBase")); SetSize(wxDLG_UNIT(this, wxSize(-1, -1))); - if(GetSizer()) { + if (GetSizer()) { GetSizer()->Fit(this); } - if(GetParent()) { + if (GetParent()) { CentreOnParent(wxBOTH); } else { CentreOnScreen(wxBOTH); @@ -128,7 +127,7 @@ LanguageServerPageBase::LanguageServerPageBase(wxWindow* parent, wxWindowID id, long style) : wxPanel(parent, id, pos, size, style) { - if(!bBitmapLoaded) { + if (!bBitmapLoaded) { // We need to initialise the default bitmap handler wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler); wxCrafterCbL3wsInitBitmapResources(); @@ -178,8 +177,7 @@ LanguageServerPageBase::LanguageServerPageBase(wxWindow* parent, wxWindowID id, flexGridSizer432->Add(boxSizer200, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5)); - m_notebook201 = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), - wxNB_FIXEDWIDTH | wxBK_DEFAULT); + m_notebook201 = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), wxBK_DEFAULT); m_notebook201->SetName(wxT("m_notebook201")); boxSizer200->Add(m_notebook201, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5)); @@ -353,7 +351,7 @@ LanguageServerPageBase::LanguageServerPageBase(wxWindow* parent, wxWindowID id, SetName(wxT("LanguageServerPageBase")); SetSize(wxDLG_UNIT(this, wxSize(-1, -1))); - if(GetSizer()) { + if (GetSizer()) { GetSizer()->Fit(this); } // Connect events @@ -373,7 +371,7 @@ NewLanguageServerDlgBase::NewLanguageServerDlgBase(wxWindow* parent, wxWindowID const wxPoint& pos, const wxSize& size, long style) : wxDialog(parent, id, title, pos, size, style) { - if(!bBitmapLoaded) { + if (!bBitmapLoaded) { // We need to initialise the default bitmap handler wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler); wxCrafterCbL3wsInitBitmapResources(); @@ -397,10 +395,10 @@ NewLanguageServerDlgBase::NewLanguageServerDlgBase(wxWindow* parent, wxWindowID SetName(wxT("NewLanguageServerDlgBase")); SetSize(wxDLG_UNIT(this, wxSize(-1, -1))); - if(GetSizer()) { + if (GetSizer()) { GetSizer()->Fit(this); } - if(GetParent()) { + if (GetParent()) { CentreOnParent(wxBOTH); } else { CentreOnScreen(wxBOTH); @@ -418,7 +416,7 @@ LSPOutlineViewDlgBase::LSPOutlineViewDlgBase(wxWindow* parent, wxWindowID id, co const wxSize& size, long style) : wxDialog(parent, id, title, pos, size, style) { - if(!bBitmapLoaded) { + if (!bBitmapLoaded) { // We need to initialise the default bitmap handler wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler); wxCrafterCbL3wsInitBitmapResources(); @@ -451,15 +449,15 @@ LSPOutlineViewDlgBase::LSPOutlineViewDlgBase(wxWindow* parent, wxWindowID id, co SetName(wxT("LSPOutlineViewDlgBase")); SetSize(wxDLG_UNIT(this, wxSize(500, 300))); - if(GetSizer()) { + if (GetSizer()) { GetSizer()->Fit(this); } - if(GetParent()) { + if (GetParent()) { CentreOnParent(wxBOTH); } else { CentreOnScreen(wxBOTH); } - if(!wxPersistenceManager::Get().Find(this)) { + if (!wxPersistenceManager::Get().Find(this)) { wxPersistenceManager::Get().RegisterAndRestore(this); } else { wxPersistenceManager::Get().Restore(this); @@ -485,7 +483,7 @@ LanguageServerLogViewBase::LanguageServerLogViewBase(wxWindow* parent, wxWindowI const wxSize& size, long style) : wxPanel(parent, id, pos, size, style) { - if(!bBitmapLoaded) { + if (!bBitmapLoaded) { // We need to initialise the default bitmap handler wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler); wxCrafterCbL3wsInitBitmapResources(); @@ -516,7 +514,7 @@ LanguageServerLogViewBase::LanguageServerLogViewBase(wxWindow* parent, wxWindowI SetName(wxT("LanguageServerLogViewBase")); SetSize(wxDLG_UNIT(this, wxSize(500, 300))); - if(GetSizer()) { + if (GetSizer()) { GetSizer()->Fit(this); } } diff --git a/LanguageServer/UI.h b/LanguageServer/UI.h index 4504ee4520..1a97fd0216 100644 --- a/LanguageServer/UI.h +++ b/LanguageServer/UI.h @@ -18,7 +18,6 @@ #include #include #include -#include "Notebook.h" #include #include #include @@ -31,6 +30,7 @@ #include "clThemedTextCtrl.hpp" #include #include "clTerminalViewCtrl.hpp" +#include "Notebook.h" #if wxVERSION_NUMBER >= 2900 #include #include @@ -54,7 +54,7 @@ class LanguageServerSettingsDlgBase : public wxDialog protected: wxCheckBox* m_checkBoxEnable; wxStaticLine* m_staticLine102; - Notebook* m_notebook; + wxNotebook* m_notebook; wxButton* m_buttonScan; wxButton* m_buttonNew; wxButton* m_buttonDelete; @@ -73,7 +73,7 @@ class LanguageServerSettingsDlgBase : public wxDialog public: wxCheckBox* GetCheckBoxEnable() { return m_checkBoxEnable; } wxStaticLine* GetStaticLine102() { return m_staticLine102; } - Notebook* GetNotebook() { return m_notebook; } + wxNotebook* GetNotebook() { return m_notebook; } wxButton* GetButtonScan() { return m_buttonScan; } wxButton* GetButtonNew() { return m_buttonNew; } wxButton* GetButtonDelete() { return m_buttonDelete; } diff --git a/LanguageServer/UI.wxcp b/LanguageServer/UI.wxcp index 0876371e0f..ed653d3ab1 100644 --- a/LanguageServer/UI.wxcp +++ b/LanguageServer/UI.wxcp @@ -434,15 +434,15 @@ }, { "type": "string", "m_label": "Class Name:", - "m_value": "Notebook" + "m_value": "" }, { "type": "string", "m_label": "Include File:", - "m_value": "Notebook.h" + "m_value": "" }, { "type": "string", "m_label": "Style:", - "m_value": "kNotebook_FixedWidth" + "m_value": "" }], "m_events": [], "m_children": [] @@ -1444,7 +1444,7 @@ "border": 5, "gbSpan": "1,1", "gbPosition": "0,0", - "m_styles": ["wxNB_FIXEDWIDTH", "wxBK_DEFAULT"], + "m_styles": ["wxBK_DEFAULT"], "m_sizerFlags": ["wxALL", "wxLEFT", "wxRIGHT", "wxTOP", "wxBOTTOM", "wxEXPAND"], "m_properties": [{ "type": "winid",