From b8ae2878ad8adc9f707395df2a7537601b215bed Mon Sep 17 00:00:00 2001 From: Blake-Madden Date: Sat, 9 Sep 2023 13:03:34 -0400 Subject: [PATCH] Add support for C++ to code editor --- src/ui/controls/codeeditor.cpp | 51 +++++++++++++++++++++++++++------- src/ui/controls/codeeditor.h | 5 ++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/ui/controls/codeeditor.cpp b/src/ui/controls/codeeditor.cpp index b0929c27..a8f8cf33 100644 --- a/src/ui/controls/codeeditor.cpp +++ b/src/ui/controls/codeeditor.cpp @@ -107,18 +107,49 @@ void CodeEditor::SetLanguage(const int lang) SetFileFilter(_(L"Lua Script (*.lua)|*.lua")); SetLibraryAccessor(L'.'); SetObjectAccessor(L':'); - } - // highlighting for all supported languages - StyleSetForeground(wxSTC_LUA_WORD, m_keywordColor); - StyleSetForeground(wxSTC_LUA_WORD2, m_keywordColor); - StyleSetForeground(wxSTC_LUA_STRING, m_stringColor); - StyleSetForeground(wxSTC_LUA_OPERATOR, m_operatorColor); - StyleSetForeground(wxSTC_LUA_COMMENTLINE, m_commentColor); + // highlighting for all supported languages + StyleSetForeground(wxSTC_LUA_WORD, m_keywordColor); + StyleSetForeground(wxSTC_LUA_WORD2, m_keywordColor); + StyleSetForeground(wxSTC_LUA_STRING, m_stringColor); + StyleSetForeground(wxSTC_LUA_OPERATOR, m_operatorColor); + StyleSetForeground(wxSTC_LUA_COMMENTLINE, m_commentColor); - StyleSetBold(wxSTC_LUA_WORD, true); - StyleSetBold(wxSTC_LUA_WORD2, true); - StyleSetBold(wxSTC_LUA_OPERATOR, true); + StyleSetBold(wxSTC_LUA_WORD, true); + StyleSetBold(wxSTC_LUA_WORD2, true); + StyleSetBold(wxSTC_LUA_OPERATOR, true); + } + if (wxSTC_LEX_CPP == lang || + wxSTC_LEX_CPPNOCASE == lang) + { + // core language keywords + SetLexer(lang); + SetKeyWords(0, + _DT(L"alignas alignof and and_eq asm atomic_cancel atomic_commit atomic_noexcept auto bitand " + "bitor bool break case catch char char8_t char16_t " + "char32_t class compl concept const consteval constexpr constinit const_cast continue co_await co_return co_yield decltype default delete " + "do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new noexcept " + "not not_eq nullptr operator or or_eq private protected public reflexpr register reinterpret_cast requires return short signed " + "sizeof static static_assert static_cast struct switch synchronized template this thread_local throw true try typedef typeid typename " + "union unsigned using virtual void volatile wchar_t while xor xor_eq final override import module")); + // other language settings + SetFileFilter(_(L"C++ Source Files (*.cpp)|*.cpp")); + SetLibraryAccessor(L':'); + SetObjectAccessor(L'.'); + + // highlighting for all supported languages + StyleSetForeground(wxSTC_C_WORD, m_keywordColor); + StyleSetForeground(wxSTC_C_WORD2, m_keywordColor); + StyleSetForeground(wxSTC_C_STRING, m_stringColor); + StyleSetForeground(wxSTC_C_OPERATOR, m_operatorColor); + StyleSetForeground(wxSTC_C_COMMENTLINE, m_commentColor); + StyleSetForeground(wxSTC_C_COMMENT, m_commentColor); + + StyleSetBold(wxSTC_C_WORD, true); + StyleSetBold(wxSTC_C_WORD2, true); + StyleSetBold(wxSTC_C_OPERATOR, true); + } + } //------------------------------------------------------------- diff --git a/src/ui/controls/codeeditor.h b/src/ui/controls/codeeditor.h index 3c43bef0..c12520c6 100644 --- a/src/ui/controls/codeeditor.h +++ b/src/ui/controls/codeeditor.h @@ -83,7 +83,8 @@ namespace Wisteria::UI CodeEditor& operator=(const CodeEditor&) = delete; /** @brief Sets the language used in this editor. - @param lang The language. @c wxSTC_LEX_LUA is currently supported.*/ + @param lang The language.\n + @c wxSTC_LEX_LUA, @c wxSTC_LEX_CPP, and @c wxSTC_LEX_CPPNOCASE are currently supported.*/ void SetLanguage(const int lang); /** @brief Adds a library and its functions/classes. This information is used for autocompletion. @@ -237,7 +238,7 @@ namespace Wisteria::UI wchar_t m_libraryAccessor{ L'.' }; wchar_t m_objectAccessor{ L':' }; - wxColour m_commentColor{ 49, 250, 65 }; + wxColour m_commentColor{ L"#008000" }; wxColour m_keywordColor{ L"#0000FF" }; wxColour m_operatorColor{ L"#B928C1" }; wxColour m_stringColor{ L"#A31515" };