Skip to content

Commit

Permalink
added 3 new themes to the default themes
Browse files Browse the repository at this point in the history
  • Loading branch information
eranif committed Jul 16, 2024
1 parent 112ddb1 commit b3c747d
Show file tree
Hide file tree
Showing 13 changed files with 134,619 additions and 65,772 deletions.
169 changes: 85 additions & 84 deletions CodeLite/JSON.cpp

Large diffs are not rendered by default.

57 changes: 26 additions & 31 deletions Plugin/ThemeImporters/ThemeImporterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,22 @@ LexerConf::Ptr_t ThemeImporterBase::ImportEclipseXML(const wxFileName& theme_fil
return lexer;
}

void ThemeImporterBase::GetEditorVSCodeColour(JSONItem& colours, const wxString& bg_prop, const wxString& fg_prop,
Property& colour)
void ThemeImporterBase::GetEditorVSCodeColour(const std::unordered_map<std::string_view, JSONItem>& colours,
const wxString& bg_prop, const wxString& fg_prop, Property& colour)
{
colour = m_editor;
if (!fg_prop.empty() && colours.hasNamedObject(fg_prop)) {
colour.fg_colour = colours[fg_prop].toString();

std::string str_fg = fg_prop.ToStdString();
std::string str_bg = bg_prop.ToStdString();
std::string_view sv_fg(str_fg.c_str());
std::string_view sv_bg(str_bg.c_str());

if (!fg_prop.empty() && colours.count(sv_fg)) {
colour.fg_colour = colours.find(sv_fg)->second.toString();
}

if (!bg_prop.empty() && colours.hasNamedObject(bg_prop)) {
colour.bg_colour = colours[bg_prop].toString();
if (!bg_prop.empty() && colours.count(sv_bg)) {
colour.bg_colour = colours.find(sv_bg)->second.toString();
}
}

Expand All @@ -303,6 +309,7 @@ void ThemeImporterBase::GetVSCodeColour(const std::unordered_map<wxString, VSCod
for (const wxString& scope : scopes) {
if (lookup.count(scope.Lower())) {
colour.fg_colour = lookup.find(scope.Lower())->second.fg_colour;
break;
}
}
}
Expand Down Expand Up @@ -408,18 +415,6 @@ LexerConf::Ptr_t ThemeImporterBase::ImportAlacrittyThemeToml(const wxFileName& t
colours.cyan = ini_parser[section_name]["cyan"].GetValue();
colours.white = ini_parser[section_name]["white"].GetValue();

#if 0
clSYSTEM() << "black=[" << colours.black << "]" << endl;
clSYSTEM() << "red=[" << colours.red << "]" << endl;
clSYSTEM() << "yellow=[" << colours.yellow << "]" << endl;
clSYSTEM() << "blue=[" << colours.blue << "]" << endl;
clSYSTEM() << "green=[" << colours.green << "]" << endl;
clSYSTEM() << "green=[" << colours.green << "]" << endl;
clSYSTEM() << "magenta=[" << colours.magenta << "]" << endl;
clSYSTEM() << "cyan=[" << colours.cyan << "]" << endl;
clSYSTEM() << "white=[" << colours.white << "]" << endl;
#endif

if (colours.black.empty() || colours.red.empty() || colours.green.empty() || colours.yellow.empty() ||
colours.blue.empty() || colours.magenta.empty() || colours.cyan.empty() || colours.white.empty()) {
clERROR() << "failed to read basic colour" << endl;
Expand Down Expand Up @@ -525,10 +520,11 @@ LexerConf::Ptr_t ThemeImporterBase::ImportVSCodeJSON(const wxFileName& theme_fil

// Build the tokenColoursMap object
auto colours = json["colors"];
auto colours_map = colours.GetAsMap();

// read the base properties
m_editor = {};
GetEditorVSCodeColour(colours, "editor.background", "editor.foreground", m_editor);
GetEditorVSCodeColour(colours_map, "editor.background", "editor.foreground", m_editor);

// in case no fg colour provided, guess it
if (m_editor.fg_colour.empty()) {
Expand Down Expand Up @@ -578,11 +574,11 @@ LexerConf::Ptr_t ThemeImporterBase::ImportVSCodeJSON(const wxFileName& theme_fil
}

for (const wxString& scope : scopes) {
if (token.hasNamedObject("settings") && token["settings"].hasNamedObject("foreground")) {
lookup.insert({ scope.Lower(), VSCodeScope(m_editor, token["settings"]["foreground"].toString()) });
} else {
lookup.insert({ scope.Lower(), VSCodeScope(m_editor, wxEmptyString) });
wxString fg_colour = token["settings"]["foreground"].toString();
if (fg_colour.empty()) {
fg_colour = m_editor.fg_colour;
}
lookup.insert({ scope.Lower(), VSCodeScope(m_editor, fg_colour) });
}
}

Expand All @@ -596,13 +592,13 @@ LexerConf::Ptr_t ThemeImporterBase::ImportVSCodeJSON(const wxFileName& theme_fil

// set the selection colour
SetSelectionColour(m_isDarkTheme, m_selection);
GetEditorVSCodeColour(colours, "editor.background", "editorLineNumber.foreground", m_lineNumber);
GetEditorVSCodeColour(colours_map, "editor.background", "editorLineNumber.foreground", m_lineNumber);

// read the caret colours
GetEditorVSCodeColour(colours, "editorCursor.background", "editorCursor.foreground", m_caret);
GetEditorVSCodeColour(colours_map, "editorCursor.background", "editorCursor.foreground", m_caret);

// active line colours
GetEditorVSCodeColour(colours, "editor.lineHighlightBackground", "editor.foreground", m_lineNumberActive);
GetEditorVSCodeColour(colours_map, "editor.lineHighlightBackground", "editor.foreground", m_lineNumberActive);

// token colours
GetVSCodeColour(lookup, { "comment", "comments" }, m_singleLineComment);
Expand All @@ -617,12 +613,11 @@ LexerConf::Ptr_t ThemeImporterBase::ImportVSCodeJSON(const wxFileName& theme_fil

// search for class names
GetVSCodeColour(lookup,
{ "storage", "storage.type.class", "entity.name.type.class", "entity.name.type.class.cpp",
"entity.name.type.class.php", "meta.block.class.cpp", "entity.name.type.namespace",
"entity.name.type", "entity.name.class", "entity.name.type", "class", "entity.name",
"entity.name.scope-resolution" },
{ "storage.type", "storage", "storage.type.class", "entity.name.type.class",
"entity.name.type.class.cpp", "entity.name.type.class.php", "meta.block.class.cpp",
"entity.name.type.namespace", "entity.name.type", "entity.name.class", "entity.name.type",
"class", "entity.name", "entity.name.scope-resolution" },
m_klass);

GetVSCodeColour(lookup,
{ "entity.name.function", "meta.function-call", "entity.name.function.call.cpp",
"entity.name.function.call.php" },
Expand Down
3 changes: 2 additions & 1 deletion Plugin/ThemeImporters/ThemeImporterBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ class WXDLLIMPEXP_SDK ThemeImporterBase
LexerConf::Ptr_t ImportAlacrittyThemeToml(const wxFileName& theme_file, const wxString& langName, int langId);
void GetVSCodeColour(const std::unordered_map<wxString, VSCodeScope>& lookup, const std::vector<wxString>& scopes,
Property& colour);
void GetEditorVSCodeColour(JSONItem& colours, const wxString& bg_prop, const wxString& fg_prop, Property& colour);
void GetEditorVSCodeColour(const std::unordered_map<std::string_view, JSONItem>& colours, const wxString& bg_prop,
const wxString& fg_prop, Property& colour);

private:
/**
Expand Down
Loading

0 comments on commit b3c747d

Please sign in to comment.