Skip to content

Commit

Permalink
Add support for C++ to code editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Sep 9, 2023
1 parent 3abc313 commit b8ae287
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
51 changes: 41 additions & 10 deletions src/ui/controls/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

//-------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/ui/controls/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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" };
Expand Down

0 comments on commit b8ae287

Please sign in to comment.