Skip to content

Commit

Permalink
Added UI for changing syntax highlighting colours in Preferences, rep…
Browse files Browse the repository at this point in the history
…laced a run-time map with a compile-time map
  • Loading branch information
mikekazakov committed Jun 16, 2024
1 parent b854355 commit 63404b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@
#include <charconv>
#include <fmt/core.h>
#include <ranges>
#include <ranges>
#include <algorithm>
#include <frozen/string.h>
#include <frozen/unordered_map.h>

namespace nc {

static const auto g_NameKey = "themeName";

[[clang::no_destroy]] static std::shared_ptr<const Theme> g_CurrentTheme;

using TMN = ThemesManager::Notifications;
template <size_t size, typename T, size_t... indexes>
static constexpr auto make_array_n_impl(T &&value, std::index_sequence<indexes...>)
{
return std::array<std::decay_t<T>, size>{(static_cast<void>(indexes), value)..., std::forward<T>(value)};
}

using NotificationsMapping =
robin_hood::unordered_flat_map<std::string, uint64_t, RHTransparentStringHashEqual, RHTransparentStringHashEqual>;
template <size_t size, typename T>
static constexpr auto make_array_n(T &&value)
{
return make_array_n_impl<size>(std::forward<T>(value), std::make_index_sequence<size - 1>{});
}

[[clang::no_destroy]] static const NotificationsMapping g_EntryToNotificationMapping = {
using TMN = ThemesManager::Notifications;
static constexpr std::pair<const char *, uint64_t> g_EntryToNotificationMappingTable[] = {
{"themeAppearance", TMN::Appearance},
{"filePanelsColoringRules_v1", TMN::FilePanelsGeneral},
{"filePanelsGeneralDropBorderColor", TMN::FilePanelsGeneral},
Expand Down Expand Up @@ -93,10 +104,26 @@
{"viewerFont", TMN::Viewer},
{"viewerOverlayColor", TMN::Viewer},
{"viewerTextColor", TMN::Viewer},
{"viewerTextSyntaxCommentColor", TMN::Viewer},
{"viewerTextSyntaxPreprocessorColor", TMN::Viewer},
{"viewerTextSyntaxKeywordColor", TMN::Viewer},
{"viewerTextSyntaxOperatorColor", TMN::Viewer},
{"viewerTextSyntaxIdentifierColor", TMN::Viewer},
{"viewerTextSyntaxNumberColor", TMN::Viewer},
{"viewerTextSyntaxStringColor", TMN::Viewer},
{"viewerSelectionColor", TMN::Viewer},
{"viewerBackgroundColor", TMN::Viewer},
};

static constinit const auto g_EntryToNotificationMapping = [] {
auto items = make_array_n<std::size(g_EntryToNotificationMappingTable)>(
std::pair<frozen::string, uint64_t>(frozen::string(""), 0));
for( size_t i = 0; i < std::size(g_EntryToNotificationMappingTable); ++i )
items[i] = std::pair<frozen::string, uint64_t>(g_EntryToNotificationMappingTable[i].first,
g_EntryToNotificationMappingTable[i].second);
return frozen::make_unordered_map(items);
}();

static std::string MigrateThemeName(const std::string &_name);
static std::optional<std::string> ExtractThemeNameAppearance(const nc::config::Value &_doc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ - (instancetype)initWithTitle:(NSString *)_title andChildren:(NSArray *)_childre
SpawnFontNode(@"Text font", "viewerFont"),
SpawnColorNode(@"Overlay color", "viewerOverlayColor"),
SpawnColorNode(@"Foreground color", "viewerTextColor"),
SpawnColorNode(@"Syntax color - keyword", "viewerTextSyntaxKeywordColor"),
SpawnColorNode(@"Syntax color - operator", "viewerTextSyntaxOperatorColor"),
SpawnColorNode(@"Syntax color - identifier", "viewerTextSyntaxIdentifierColor"),
SpawnColorNode(@"Syntax color - number", "viewerTextSyntaxNumberColor"),
SpawnColorNode(@"Syntax color - string", "viewerTextSyntaxStringColor"),
SpawnColorNode(@"Syntax color - comment", "viewerTextSyntaxCommentColor"),
SpawnColorNode(@"Syntax color - preprocessor", "viewerTextSyntaxPreprocessorColor"),
SpawnColorNode(@"Selection color", "viewerSelectionColor"),
SpawnColorNode(@"Background color", "viewerBackgroundColor")
];
Expand Down

0 comments on commit 63404b9

Please sign in to comment.