diff --git a/LiteEditor/ContextJavaScript.cpp b/LiteEditor/ContextJavaScript.cpp index 53e880fde6..6567670c71 100644 --- a/LiteEditor/ContextJavaScript.cpp +++ b/LiteEditor/ContextJavaScript.cpp @@ -177,8 +177,6 @@ wxMenu* ContextJavaScript::GetMenu() { return ContextBase::GetMenu(); } TagEntryPtr ContextJavaScript::GetTagAtCaret(bool scoped, bool impl) { return NULL; } -void ContextJavaScript::GotoPreviousDefintion() {} - bool ContextJavaScript::IsCommentOrString(long pos) { int style = GetCtrl().GetStyleAt(pos); @@ -187,7 +185,10 @@ bool ContextJavaScript::IsCommentOrString(long pos) bool ContextJavaScript::IsDefaultContext() const { return false; } -ContextBase* ContextJavaScript::NewInstance(clEditor* container) { return new ContextJavaScript(container); } +std::shared_ptr ContextJavaScript::NewInstance(clEditor* container) +{ + return std::make_shared(container); +} void ContextJavaScript::OnCallTipClick(wxStyledTextEvent& event) {} @@ -199,8 +200,6 @@ void ContextJavaScript::OnDbgDwellStart(wxStyledTextEvent& event) {} void ContextJavaScript::OnDwellEnd(wxStyledTextEvent& event) {} -void ContextJavaScript::OnDwellStart(wxStyledTextEvent& event) {} - void ContextJavaScript::OnEnterHit() {} void ContextJavaScript::OnFileSaved() {} @@ -249,7 +248,7 @@ void ContextJavaScript::SemicolonShift() void ContextJavaScript::SetActive() {} -bool ContextJavaScript::IsComment(long pos) +bool ContextJavaScript::IsComment(long pos) const { int style = GetCtrl().GetStyleAt(pos); return style == wxSTC_C_COMMENT || style == wxSTC_C_COMMENTDOC || style == wxSTC_C_COMMENTDOCKEYWORD || diff --git a/LiteEditor/ContextJavaScript.h b/LiteEditor/ContextJavaScript.h index 09387cb89e..59a7dc12a9 100644 --- a/LiteEditor/ContextJavaScript.h +++ b/LiteEditor/ContextJavaScript.h @@ -31,40 +31,39 @@ class ContextJavaScript : public ContextBase { public: ContextJavaScript(); - ContextJavaScript(clEditor* Editor); - virtual ~ContextJavaScript() = default; + explicit ContextJavaScript(clEditor* Editor); + ~ContextJavaScript() override = default; public: - virtual int GetActiveKeywordSet() const; - virtual int DoGetCalltipParamterIndex(); - virtual wxMenu* GetMenu(); - virtual void AddMenuDynamicContent(wxMenu* menu); - virtual void ApplySettings(); - virtual void AutoIndent(const wxChar&); - virtual wxString CallTipContent(); - virtual wxString GetCurrentScopeName(); - virtual TagEntryPtr GetTagAtCaret(bool scoped, bool impl); - virtual void GotoPreviousDefintion(); - virtual bool IsComment(long pos); - virtual bool IsCommentOrString(long pos); - virtual bool IsDefaultContext() const; - virtual ContextBase* NewInstance(clEditor* container); - virtual void OnCallTipClick(wxStyledTextEvent& event); - virtual void OnCalltipCancel(); - virtual void OnDbgDwellEnd(wxStyledTextEvent& event); - virtual void OnDbgDwellStart(wxStyledTextEvent& event); - virtual void OnDwellEnd(wxStyledTextEvent& event); - virtual void OnDwellStart(wxStyledTextEvent& event); - virtual void OnEnterHit(); - virtual void OnFileSaved(); - virtual void OnKeyDown(wxKeyEvent& event); - virtual void OnSciUpdateUI(wxStyledTextEvent& event); - virtual void RemoveMenuDynamicContent(wxMenu* menu); - virtual void RetagFile(); - virtual void SemicolonShift(); - virtual void SetActive(); - virtual bool IsAtBlockComment() const; - virtual bool IsAtLineComment() const; + int GetActiveKeywordSet() const override; + int DoGetCalltipParamterIndex() override; + wxMenu* GetMenu() override; + void AddMenuDynamicContent(wxMenu* menu) override; + void ApplySettings() override; + void AutoIndent(const wxChar&) override; + wxString CallTipContent() override; + wxString GetCurrentScopeName() override; + TagEntryPtr GetTagAtCaret(bool scoped, bool impl) override; + bool IsCommentOrString(long pos) override; + bool IsDefaultContext() const override; + std::shared_ptr NewInstance(clEditor* container) override; + void OnCallTipClick(wxStyledTextEvent& event) override; + void OnCalltipCancel() override; + void OnDbgDwellEnd(wxStyledTextEvent& event) override; + void OnDbgDwellStart(wxStyledTextEvent& event) override; + void OnDwellEnd(wxStyledTextEvent& event) override; + void OnEnterHit() override; + void OnFileSaved() override; + void OnKeyDown(wxKeyEvent& event) override; + void OnSciUpdateUI(wxStyledTextEvent& event) override; + void RemoveMenuDynamicContent(wxMenu* menu) override; + void RetagFile() override; + void SemicolonShift() override; + void SetActive() override; + bool IsAtBlockComment() const override; + bool IsAtLineComment() const override; + + bool IsComment(long pos) const; }; #endif // CONTEXTJAVASCRIPT_H diff --git a/LiteEditor/ContextPhp.cpp b/LiteEditor/ContextPhp.cpp index 705e7beed6..3f84642a75 100644 --- a/LiteEditor/ContextPhp.cpp +++ b/LiteEditor/ContextPhp.cpp @@ -220,8 +220,6 @@ wxMenu* ContextPhp::GetMenu() { return ContextBase::GetMenu(); } TagEntryPtr ContextPhp::GetTagAtCaret(bool scoped, bool impl) { return NULL; } -void ContextPhp::GotoPreviousDefintion() {} - bool ContextPhp::IsCommentOrString(long pos) { int style = GetCtrl().GetStyleAt(pos); @@ -236,7 +234,10 @@ bool ContextPhp::IsCommentOrString(long pos) bool ContextPhp::IsDefaultContext() const { return false; } -ContextBase* ContextPhp::NewInstance(clEditor* container) { return new ContextPhp(container); } +std::shared_ptr ContextPhp::NewInstance(clEditor* container) +{ + return std::make_shared(container); +} void ContextPhp::OnCallTipClick(wxStyledTextEvent& event) {} @@ -248,8 +249,6 @@ void ContextPhp::OnDbgDwellStart(wxStyledTextEvent& event) {} void ContextPhp::OnDwellEnd(wxStyledTextEvent& event) {} -void ContextPhp::OnDwellStart(wxStyledTextEvent& event) {} - void ContextPhp::OnEnterHit() {} void ContextPhp::OnFileSaved() {} @@ -299,7 +298,7 @@ void ContextPhp::SemicolonShift() void ContextPhp::SetActive() {} -bool ContextPhp::IsComment(long pos) +bool ContextPhp::IsComment(long pos) const { int style = GetCtrl().GetStyleAt(pos); return style == wxSTC_H_COMMENT || style == wxSTC_H_XCCOMMENT || style == wxSTC_H_SGML_COMMENT || diff --git a/LiteEditor/ContextPhp.h b/LiteEditor/ContextPhp.h index 4fbd57577a..834a9ca55e 100644 --- a/LiteEditor/ContextPhp.h +++ b/LiteEditor/ContextPhp.h @@ -32,43 +32,41 @@ class ContextPhp : public ContextGeneric { public: ContextPhp(); - ContextPhp(clEditor *Editor); - virtual ~ContextPhp() = default; + explicit ContextPhp(clEditor *Editor); + ~ContextPhp() override = default; public: - bool IsStringTriggerCodeComplete(const wxString& str) const; - virtual int GetActiveKeywordSet() const; - virtual int DoGetCalltipParamterIndex(); - virtual wxMenu* GetMenu(); - virtual void AddMenuDynamicContent(wxMenu* menu); - virtual void ApplySettings(); - virtual void AutoIndent(const wxChar&); - virtual wxString CallTipContent(); - virtual wxString GetCurrentScopeName(); - virtual TagEntryPtr GetTagAtCaret(bool scoped, bool impl); - virtual void GotoPreviousDefintion(); - virtual bool IsComment(long pos); - virtual bool IsCommentOrString(long pos); - virtual bool IsDefaultContext() const; - virtual ContextBase* NewInstance(clEditor* container); - virtual void OnCallTipClick(wxStyledTextEvent& event); - virtual void OnCalltipCancel(); - virtual void OnDbgDwellEnd(wxStyledTextEvent& event); - virtual void OnDbgDwellStart(wxStyledTextEvent& event); - virtual void OnDwellEnd(wxStyledTextEvent& event); - virtual void OnDwellStart(wxStyledTextEvent& event); - virtual void OnEnterHit(); - virtual void OnFileSaved(); - virtual void OnKeyDown(wxKeyEvent& event); - virtual void OnSciUpdateUI(wxStyledTextEvent& event); - virtual void RemoveMenuDynamicContent(wxMenu* menu); - virtual void RetagFile(); - virtual void SemicolonShift(); - virtual void SetActive(); - virtual bool IsAtBlockComment() const; - virtual bool IsAtLineComment() const; - void ProcessIdleActions(); - + bool IsStringTriggerCodeComplete(const wxString& str) const override; + int GetActiveKeywordSet() const override; + int DoGetCalltipParamterIndex() override; + wxMenu* GetMenu() override; + void AddMenuDynamicContent(wxMenu* menu) override; + void ApplySettings() override; + void AutoIndent(const wxChar&) override; + wxString CallTipContent() override; + wxString GetCurrentScopeName() override; + TagEntryPtr GetTagAtCaret(bool scoped, bool impl) override; + bool IsCommentOrString(long pos) override; + bool IsDefaultContext() const override; + std::shared_ptr NewInstance(clEditor* container) override; + void OnCallTipClick(wxStyledTextEvent& event) override; + void OnCalltipCancel() override; + void OnDbgDwellEnd(wxStyledTextEvent& event) override; + void OnDbgDwellStart(wxStyledTextEvent& event) override; + void OnDwellEnd(wxStyledTextEvent& event) override; + void OnEnterHit() override; + void OnFileSaved() override; + void OnKeyDown(wxKeyEvent& event) override; + void OnSciUpdateUI(wxStyledTextEvent& event) override; + void RemoveMenuDynamicContent(wxMenu* menu) override; + void RetagFile() override; + void SemicolonShift() override; + void SetActive() override; + bool IsAtBlockComment() const override; + bool IsAtLineComment() const override; + void ProcessIdleActions() override; + + bool IsComment(long pos) const; }; #endif // CONTEXTPHP_H diff --git a/LiteEditor/ContextPython.cpp b/LiteEditor/ContextPython.cpp index 55910264d9..1a3f636739 100644 --- a/LiteEditor/ContextPython.cpp +++ b/LiteEditor/ContextPython.cpp @@ -2,10 +2,8 @@ #include "ColoursAndFontsManager.h" #include "cl_editor.h" -#include "editor_config.h" #include "lexer_configuration.h" -#include #include #include #include @@ -55,7 +53,10 @@ void ContextPython::ApplySettings() DoApplySettings(lexPtr); } -ContextBase* ContextPython::NewInstance(clEditor* container) { return new ContextPython(container); } +std::shared_ptr ContextPython::NewInstance(clEditor* container) +{ + return std::make_shared(container); +} void ContextPython::OnCommentSelection(wxCommandEvent& event) { diff --git a/LiteEditor/ContextPython.hpp b/LiteEditor/ContextPython.hpp index 514cb766ab..80e66865e2 100644 --- a/LiteEditor/ContextPython.hpp +++ b/LiteEditor/ContextPython.hpp @@ -3,7 +3,6 @@ #include "generic_context.h" -class clEditor; class ContextPython : public ContextGeneric { protected: @@ -20,10 +19,10 @@ class ContextPython : public ContextGeneric public: ContextPython(); - ContextPython(clEditor* container); - virtual ~ContextPython(); + explicit ContextPython(clEditor* container); + ~ContextPython() override; void ApplySettings() override; - ContextBase* NewInstance(clEditor* container) override; + std::shared_ptr NewInstance(clEditor* container) override; bool IsAtBlockComment() const override; bool IsAtLineComment() const override; }; diff --git a/LiteEditor/ContextRust.cpp b/LiteEditor/ContextRust.cpp index 859eff0947..18a5a764ca 100644 --- a/LiteEditor/ContextRust.cpp +++ b/LiteEditor/ContextRust.cpp @@ -130,8 +130,6 @@ wxMenu* ContextRust::GetMenu() { return ContextBase::GetMenu(); } TagEntryPtr ContextRust::GetTagAtCaret(bool scoped, bool impl) { return NULL; } -void ContextRust::GotoPreviousDefintion() {} - bool ContextRust::IsCommentOrString(long pos) { static std::unordered_set string_styles = { wxSTC_RUST_BYTECHARACTER, wxSTC_RUST_BYTESTRING, @@ -143,7 +141,10 @@ bool ContextRust::IsCommentOrString(long pos) bool ContextRust::IsDefaultContext() const { return false; } -ContextBase* ContextRust::NewInstance(clEditor* container) { return new ContextRust(container); } +std::shared_ptr ContextRust::NewInstance(clEditor* container) +{ + return std::make_shared(container); +} void ContextRust::OnCallTipClick(wxStyledTextEvent& event) { wxUnusedVar(event); } @@ -155,8 +156,6 @@ void ContextRust::OnDbgDwellStart(wxStyledTextEvent& event) { wxUnusedVar(event) void ContextRust::OnDwellEnd(wxStyledTextEvent& event) { wxUnusedVar(event); } -void ContextRust::OnDwellStart(wxStyledTextEvent& event) { wxUnusedVar(event); } - void ContextRust::OnEnterHit() {} void ContextRust::OnFileSaved() {} @@ -200,7 +199,7 @@ void ContextRust::SemicolonShift() void ContextRust::SetActive() {} -bool ContextRust::IsComment(long pos) +bool ContextRust::IsComment(long pos) const { static std::unordered_set comment_styles = { wxSTC_RUST_COMMENTBLOCK, wxSTC_RUST_COMMENTLINE, wxSTC_RUST_COMMENTBLOCKDOC, wxSTC_RUST_COMMENTLINEDOC }; diff --git a/LiteEditor/ContextRust.hpp b/LiteEditor/ContextRust.hpp index a57dce56e3..fa19722e20 100644 --- a/LiteEditor/ContextRust.hpp +++ b/LiteEditor/ContextRust.hpp @@ -8,46 +8,45 @@ class ContextRust : public ContextGeneric public: ContextRust(); - ContextRust(clEditor* Editor); - virtual ~ContextRust(); + explicit ContextRust(clEditor* Editor); + ~ContextRust() override; protected: void OnCommentSelection(wxCommandEvent& event); void OnCommentLine(wxCommandEvent& event); public: - bool IsStringTriggerCodeComplete(const wxString& str) const; - virtual int GetActiveKeywordSet() const; - virtual int DoGetCalltipParamterIndex(); - virtual wxMenu* GetMenu(); - virtual void AddMenuDynamicContent(wxMenu* menu); - virtual void ApplySettings(); - virtual void AutoIndent(const wxChar&); - virtual wxString CallTipContent(); - virtual wxString GetCurrentScopeName(); - virtual TagEntryPtr GetTagAtCaret(bool scoped, bool impl); - virtual void GotoPreviousDefintion(); - virtual bool IsComment(long pos); - virtual bool IsCommentOrString(long pos); - virtual bool IsDefaultContext() const; - virtual ContextBase* NewInstance(clEditor* container); - virtual void OnCallTipClick(wxStyledTextEvent& event); - virtual void OnCalltipCancel(); - virtual void OnDbgDwellEnd(wxStyledTextEvent& event); - virtual void OnDbgDwellStart(wxStyledTextEvent& event); - virtual void OnDwellEnd(wxStyledTextEvent& event); - virtual void OnDwellStart(wxStyledTextEvent& event); - virtual void OnEnterHit(); - virtual void OnFileSaved(); - virtual void OnKeyDown(wxKeyEvent& event); - virtual void OnSciUpdateUI(wxStyledTextEvent& event); - virtual void RemoveMenuDynamicContent(wxMenu* menu); - virtual void RetagFile(); - virtual void SemicolonShift(); - virtual void SetActive(); - virtual bool IsAtBlockComment() const; - virtual bool IsAtLineComment() const; - void ProcessIdleActions(); + bool IsStringTriggerCodeComplete(const wxString& str) const override; + int GetActiveKeywordSet() const override; + int DoGetCalltipParamterIndex() override; + wxMenu* GetMenu() override; + void AddMenuDynamicContent(wxMenu* menu) override; + void ApplySettings() override; + void AutoIndent(const wxChar&) override; + wxString CallTipContent() override; + wxString GetCurrentScopeName() override; + TagEntryPtr GetTagAtCaret(bool scoped, bool impl) override; + bool IsCommentOrString(long pos) override; + bool IsDefaultContext() const override; + std::shared_ptr NewInstance(clEditor* container) override; + void OnCallTipClick(wxStyledTextEvent& event) override; + void OnCalltipCancel() override; + void OnDbgDwellEnd(wxStyledTextEvent& event) override; + void OnDbgDwellStart(wxStyledTextEvent& event) override; + void OnDwellEnd(wxStyledTextEvent& event) override; + void OnEnterHit() override; + void OnFileSaved() override; + void OnKeyDown(wxKeyEvent& event) override; + void OnSciUpdateUI(wxStyledTextEvent& event) override; + void RemoveMenuDynamicContent(wxMenu* menu) override; + void RetagFile() override; + void SemicolonShift() override; + void SetActive() override; + bool IsAtBlockComment() const override; + bool IsAtLineComment() const override; + void ProcessIdleActions() override; + + bool IsComment(long pos) const; }; #endif // CONTEXTRUST_HPP diff --git a/LiteEditor/context_base.h b/LiteEditor/context_base.h index f317ac293f..08dd483018 100644 --- a/LiteEditor/context_base.h +++ b/LiteEditor/context_base.h @@ -30,9 +30,7 @@ #include "macros.h" #include -#include #include -#include #include #include @@ -77,10 +75,10 @@ class ContextBase : public wxEvtHandler public: // ctor-dtor - ContextBase(clEditor* container); - ContextBase(const wxString& name); + explicit ContextBase(clEditor* container); + explicit ContextBase(const wxString& name); - virtual ~ContextBase() = default; + ~ContextBase() override = default; /** * @brief user typed '@' inside a block comment. Code complete possible keywords @@ -110,7 +108,7 @@ class ContextBase : public wxEvtHandler const wxString& GetName() const { return m_name; } // every Context derived class must implement the following methods - virtual ContextBase* NewInstance(clEditor* container) = 0; + virtual std::shared_ptr NewInstance(clEditor* container) = 0; virtual void ApplySettings() = 0; // functions with default implementation: diff --git a/LiteEditor/context_cpp.cpp b/LiteEditor/context_cpp.cpp index c271dde6f1..4ca54e9872 100644 --- a/LiteEditor/context_cpp.cpp +++ b/LiteEditor/context_cpp.cpp @@ -26,11 +26,11 @@ #include "context_cpp.h" #include "AddFunctionsImpDlg.h" -#include "CTags.hpp" #include "CompletionHelper.hpp" +#include "Cxx/FlexLexer.h" +#include "Cxx/cpp_scanner.h" #include "Debugger/debuggermanager.h" #include "LSP/LSPManager.hpp" -#include "SelectProjectsDlg.h" #include "addincludefiledlg.h" #include "clEditorStateLocker.h" #include "clFileSystemEvent.h" @@ -40,7 +40,6 @@ #include "codelite_events.h" #include "commentconfigdata.h" #include "ctags_manager.h" -#include "drawingutils.h" #include "editor_config.h" #include "event_notifier.h" #include "file_logger.h" @@ -49,21 +48,18 @@ #include "fileview.h" #include "frame.h" #include "globals.h" -#include "language.h" #include "macromanager.h" #include "manager.h" #include "movefuncimpldlg.h" #include "new_quick_watch_dlg.h" -#include "pluginmanager.h" #include "precompiled_header.h" #include "resources/clXmlResource.hpp" #include "setters_getters_dlg.h" +#include "variable.h" #include "workspacetab.h" -#include #include #include -#include #include #include #include @@ -181,7 +177,10 @@ ContextCpp::~ContextCpp() wxDELETE(m_rclickMenu); } -ContextBase* ContextCpp::NewInstance(clEditor* container) { return new ContextCpp(container); } +std::shared_ptr ContextCpp::NewInstance(clEditor* container) +{ + return std::make_shared(container); +} void ContextCpp::OnDwellEnd(wxStyledTextEvent& event) { @@ -1680,7 +1679,7 @@ void ContextCpp::AutoAddComment() rCtrl.ChooseCaretX(); // set new column as "current" column } -bool ContextCpp::IsComment(long pos) +bool ContextCpp::IsComment(long pos) const { int style; style = GetCtrl().GetStyleAt(pos); diff --git a/LiteEditor/context_cpp.h b/LiteEditor/context_cpp.h index 68f55f406c..55a301572f 100644 --- a/LiteEditor/context_cpp.h +++ b/LiteEditor/context_cpp.h @@ -26,7 +26,6 @@ #define CONTEXT_CPP_H #include "LSP/LSPEvent.h" -#include "Cxx/cpptoken.h" #include "cl_command_event.h" #include "context_base.h" #include "ctags_manager.h" @@ -70,19 +69,18 @@ class ContextCpp : public ContextBase * @return */ bool IsAtLineComment() const override; - ContextCpp(clEditor* container); + explicit ContextCpp(clEditor* container); bool IsDefaultContext() const override; - virtual ~ContextCpp(); + ~ContextCpp() override; ContextCpp(); - ContextBase* NewInstance(clEditor* container) override; + std::shared_ptr NewInstance(clEditor* container) override; bool CompleteWord() override; bool CodeComplete(long pos = wxNOT_FOUND) override; bool GotoDefinition() override; wxString GetCurrentScopeName() override; void AutoIndent(const wxChar&) override; bool IsCommentOrString(long pos) override; - virtual bool IsComment(long pos); void AddMenuDynamicContent(wxMenu* menu) override; void RemoveMenuDynamicContent(wxMenu* menu) override; void ApplySettings() override; @@ -92,6 +90,7 @@ class ContextCpp : public ContextBase void SemicolonShift() override; void ProcessIdleActions() override; + bool IsComment(long pos) const; // override swapfiles features virtual void SwapFiles(const wxFileName& fileName); diff --git a/LiteEditor/context_diff.cpp b/LiteEditor/context_diff.cpp index ab41d2c937..bac46d27d7 100644 --- a/LiteEditor/context_diff.cpp +++ b/LiteEditor/context_diff.cpp @@ -22,12 +22,9 @@ ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// #include "context_diff.h" + #include "cl_editor.h" #include "editor_config.h" -#include "frame.h" -#include "manager.h" -#include -#include ContextDiff::ContextDiff() : ContextBase(wxT("Diff")) @@ -41,7 +38,10 @@ ContextDiff::ContextDiff(clEditor* container) ApplySettings(); } -ContextBase* ContextDiff::NewInstance(clEditor* container) { return new ContextDiff(container); } +std::shared_ptr ContextDiff::NewInstance(clEditor* container) +{ + return std::make_shared(container); +} void ContextDiff::ApplySettings() { diff --git a/LiteEditor/context_diff.h b/LiteEditor/context_diff.h index 6dc1a94418..cd700f4ea1 100644 --- a/LiteEditor/context_diff.h +++ b/LiteEditor/context_diff.h @@ -31,11 +31,11 @@ class ContextDiff : public ContextBase { public: ContextDiff(); - ContextDiff(clEditor* container); - virtual ~ContextDiff() = default; + explicit ContextDiff(clEditor* container); + ~ContextDiff() override = default; - virtual void ApplySettings(); - virtual ContextBase* NewInstance(clEditor* container); + void ApplySettings() override; + std::shared_ptr NewInstance(clEditor* container) override; }; #endif // __contextdiff__ diff --git a/LiteEditor/context_html.cpp b/LiteEditor/context_html.cpp index a24af53659..ea631f3282 100644 --- a/LiteEditor/context_html.cpp +++ b/LiteEditor/context_html.cpp @@ -198,8 +198,6 @@ TagEntryPtr ContextHtml::GetTagAtCaret(bool scoped, bool impl) { return NULL; } bool ContextHtml::GotoDefinition() { return false; } -void ContextHtml::GotoPreviousDefintion() {} - bool ContextHtml::IsCommentOrString(long pos) { int style = GetCtrl().GetStyleAt(pos); @@ -214,7 +212,10 @@ bool ContextHtml::IsCommentOrString(long pos) bool ContextHtml::IsDefaultContext() const { return false; } -ContextBase* ContextHtml::NewInstance(clEditor* container) { return new ContextHtml(container); } +std::shared_ptr ContextHtml::NewInstance(clEditor* container) +{ + return std::make_shared(container); +} void ContextHtml::OnCallTipClick(wxStyledTextEvent& event) {} @@ -226,8 +227,6 @@ void ContextHtml::OnDbgDwellStart(wxStyledTextEvent& event) {} void ContextHtml::OnDwellEnd(wxStyledTextEvent& event) {} -void ContextHtml::OnDwellStart(wxStyledTextEvent& event) {} - void ContextHtml::OnEnterHit() {} void ContextHtml::OnFileSaved() {} @@ -275,7 +274,7 @@ void ContextHtml::SemicolonShift() void ContextHtml::SetActive() {} -bool ContextHtml::IsComment(long pos) +bool ContextHtml::IsComment(long pos) const { int style = GetCtrl().GetStyleAt(pos); return style == wxSTC_H_COMMENT || style == wxSTC_H_XCCOMMENT || style == wxSTC_H_SGML_COMMENT || diff --git a/LiteEditor/context_html.h b/LiteEditor/context_html.h index 89e275be83..78cd1565da 100644 --- a/LiteEditor/context_html.h +++ b/LiteEditor/context_html.h @@ -32,42 +32,40 @@ class ContextHtml : public ContextBase { public: ContextHtml(); - ContextHtml(clEditor *Editor); - virtual ~ContextHtml() = default; + explicit ContextHtml(clEditor *Editor); + ~ContextHtml() override = default; public: - virtual int GetActiveKeywordSet() const; - virtual int DoGetCalltipParamterIndex(); - virtual wxMenu* GetMenu(); - virtual void AddMenuDynamicContent(wxMenu* menu); - virtual void ApplySettings(); - virtual void AutoIndent(const wxChar&); - virtual wxString CallTipContent(); - virtual wxString GetCurrentScopeName(); - virtual TagEntryPtr GetTagAtCaret(bool scoped, bool impl); - virtual bool GotoDefinition(); - virtual void GotoPreviousDefintion(); - virtual bool IsComment(long pos); - virtual bool IsCommentOrString(long pos); - virtual bool IsDefaultContext() const; - virtual ContextBase* NewInstance(clEditor* container); - virtual void OnCallTipClick(wxStyledTextEvent& event); - virtual void OnCalltipCancel(); - virtual void OnDbgDwellEnd(wxStyledTextEvent& event); - virtual void OnDbgDwellStart(wxStyledTextEvent& event); - virtual void OnDwellEnd(wxStyledTextEvent& event); - virtual void OnDwellStart(wxStyledTextEvent& event); - virtual void OnEnterHit(); - virtual void OnFileSaved(); - virtual void OnKeyDown(wxKeyEvent& event); - virtual void OnSciUpdateUI(wxStyledTextEvent& event); - virtual void RemoveMenuDynamicContent(wxMenu* menu); - virtual void RetagFile(); - virtual void SemicolonShift(); - virtual void SetActive(); - virtual bool IsAtBlockComment() const; - virtual bool IsAtLineComment() const; - + int GetActiveKeywordSet() const override; + int DoGetCalltipParamterIndex() override; + wxMenu* GetMenu() override; + void AddMenuDynamicContent(wxMenu* menu) override; + void ApplySettings() override; + void AutoIndent(const wxChar&) override; + wxString CallTipContent() override; + wxString GetCurrentScopeName() override; + TagEntryPtr GetTagAtCaret(bool scoped, bool impl) override; + bool GotoDefinition() override; + bool IsCommentOrString(long pos) override; + bool IsDefaultContext() const override; + std::shared_ptr NewInstance(clEditor* container) override; + void OnCallTipClick(wxStyledTextEvent& event) override; + void OnCalltipCancel() override; + void OnDbgDwellEnd(wxStyledTextEvent& event) override; + void OnDbgDwellStart(wxStyledTextEvent& event) override; + void OnDwellEnd(wxStyledTextEvent& event) override; + void OnEnterHit() override; + void OnFileSaved() override; + void OnKeyDown(wxKeyEvent& event) override; + void OnSciUpdateUI(wxStyledTextEvent& event) override; + void RemoveMenuDynamicContent(wxMenu* menu) override; + void RetagFile() override; + void SemicolonShift() override; + void SetActive() override; + bool IsAtBlockComment() const override; + bool IsAtLineComment() const override; + + bool IsComment(long pos) const; }; #endif // CONTEXTHTML_H diff --git a/LiteEditor/context_manager.cpp b/LiteEditor/context_manager.cpp index 6911cb4fc5..76be55a6ca 100644 --- a/LiteEditor/context_manager.cpp +++ b/LiteEditor/context_manager.cpp @@ -33,13 +33,32 @@ #include "context_cpp.h" #include "context_diff.h" #include "context_html.h" -#include "editor_config.h" #include "generic_context.h" -#include -#include +ContextManager::ContextManager() +{ + // register available contexts + m_contextPool = {{"c++", std::make_shared()}, + {"diff", std::make_shared()}, + {"html", std::make_shared()}, + {"php", std::make_shared()}, + {"javascript", std::make_shared()}, + {"python", std::make_shared()}, + {"rust", std::make_shared()}}; + + // load generic lexers + wxArrayString names = ColoursAndFontsManager::Get().GetAllLexersNames(); + for (const auto& name : names) { + if (m_contextPool.count(name) == 0) { + m_contextPool.insert({name, std::make_shared(name)}); + } + } -ContextManager::ContextManager() { Initialize(); } + // make sure there is a "fallback" lexer for unrecognized file types + if (m_contextPool.find("text") == m_contextPool.end()) { + m_contextPool[wxT("text")] = std::make_shared(wxT("text")); + } +} ContextBasePtr ContextManager::NewContext(clEditor* parent, const wxString& lexerName) { @@ -48,10 +67,10 @@ ContextBasePtr ContextManager::NewContext(clEditor* parent, const wxString& lexe lex_name.MakeLower(); auto iter = m_contextPool.find(lex_name); if (iter == m_contextPool.end()) { - return ContextBasePtr(m_contextPool["text"]->NewInstance(parent)); + return m_contextPool["text"]->NewInstance(parent); } - return ContextBasePtr(iter->second->NewInstance((clEditor*)parent)); + return iter->second->NewInstance(parent); } ContextBasePtr ContextManager::NewContextByFileName(clEditor* parent, const wxFileName& fileName) @@ -63,31 +82,3 @@ ContextBasePtr ContextManager::NewContextByFileName(clEditor* parent, const wxFi } return ContextManager::Get()->NewContext(parent, lexer->GetName()); } - -void ContextManager::Initialize() -{ - // Populate the contexts available - m_contextPool.clear(); - - // register available contexts - m_contextPool["c++"] = std::make_shared(); - m_contextPool["diff"] = std::make_shared(); - m_contextPool["html"] = std::make_shared(); - m_contextPool["php"] = std::make_shared(); - m_contextPool["javascript"] = std::make_shared(); - m_contextPool["python"] = std::make_shared(); - m_contextPool["rust"] = std::make_shared(); - - // load generic lexers - wxArrayString names = ColoursAndFontsManager::Get().GetAllLexersNames(); - for (const auto& name : names) { - if (m_contextPool.count(name) == 0) { - m_contextPool.insert({ name, std::make_shared(name) }); - } - } - - // make sure there is a "fallback" lexer for unrecognized file types - if (m_contextPool.find("text") == m_contextPool.end()) { - m_contextPool[wxT("text")] = std::make_shared(wxT("text")); - } -} diff --git a/LiteEditor/context_manager.h b/LiteEditor/context_manager.h index 629bbb1e96..3d524e5a25 100644 --- a/LiteEditor/context_manager.h +++ b/LiteEditor/context_manager.h @@ -29,15 +29,12 @@ #include "singleton.h" #include +#include #include -#include - -class ContextManager; class ContextManager : public Singleton { - friend class Singleton; - std::unordered_map m_contextPool; + friend Singleton; public: /** @@ -48,10 +45,12 @@ class ContextManager : public Singleton */ ContextBasePtr NewContext(clEditor* parent, const wxString& lexerName); ContextBasePtr NewContextByFileName(clEditor* parent, const wxFileName& fileName); - void Initialize(); private: ContextManager(); - virtual ~ContextManager() = default; + ~ContextManager() override = default; + +private: + std::unordered_map m_contextPool; }; #endif // CONTEXT_MANAGER_H diff --git a/LiteEditor/generic_context.cpp b/LiteEditor/generic_context.cpp index df3fc30b89..a27a10ae38 100644 --- a/LiteEditor/generic_context.cpp +++ b/LiteEditor/generic_context.cpp @@ -28,7 +28,6 @@ #include "clEditorColouriseLocker.h" #include "clEditorWordCharsLocker.h" #include "cl_editor.h" -#include "editor_config.h" #include "file_logger.h" ContextGeneric::ContextGeneric(clEditor* container, const wxString& name) @@ -38,7 +37,10 @@ ContextGeneric::ContextGeneric(clEditor* container, const wxString& name) ApplySettings(); } -ContextBase* ContextGeneric::NewInstance(clEditor* container) { return new ContextGeneric(container, GetName()); } +std::shared_ptr ContextGeneric::NewInstance(clEditor* container) +{ + return std::make_shared(container, GetName()); +} void ContextGeneric::ApplySettings() { diff --git a/LiteEditor/generic_context.h b/LiteEditor/generic_context.h index dc924fe6b6..f814445b1f 100644 --- a/LiteEditor/generic_context.h +++ b/LiteEditor/generic_context.h @@ -53,19 +53,19 @@ class ContextGeneric : public ContextBase : ContextBase(wxT("Text")) { } - ContextGeneric(const wxString& name) + explicit ContextGeneric(const wxString& name) : ContextBase(name) { } - virtual ~ContextGeneric() = default; - virtual ContextBase* NewInstance(clEditor* container); + ~ContextGeneric() override = default; + std::shared_ptr NewInstance(clEditor* container) override; //--------------------------------------- // Operations //--------------------------------------- virtual void ApplySettings(); - + void ProcessIdleActions(); }; #endif // CONTEXT_GENERIC_H