diff --git a/src/musikcube/Main.cpp b/src/musikcube/Main.cpp index 28493deb3..21fb838e2 100644 --- a/src/musikcube/Main.cpp +++ b/src/musikcube/Main.cpp @@ -168,7 +168,6 @@ int main(int argc, char* argv[]) { /* theme */ std::string colorTheme = prefs->GetString(musik::cube::prefs::keys::ColorTheme); if (colorTheme.size()) { - colorTheme = GetApplicationDirectory() + "/themes/" + colorTheme + ".json"; app.SetColorTheme(colorTheme); } diff --git a/src/musikcube/app/layout/SettingsLayout.cpp b/src/musikcube/app/layout/SettingsLayout.cpp index cc1106e39..afc498e7b 100755 --- a/src/musikcube/app/layout/SettingsLayout.cpp +++ b/src/musikcube/app/layout/SettingsLayout.cpp @@ -115,6 +115,15 @@ static std::string getOutputDeviceName() { return deviceName; } +static std::string resolveThemeName(const std::string& themePath) { + const boost::filesystem::path p(themePath); + if (p.has_extension() && p.extension().string() == ".json") { + std::string fn = p.filename().string(); + return fn.substr(0, fn.rfind(".")); + } + return _TSTR("settings_default_theme_name"); +} + SettingsLayout::SettingsLayout( cursespp::App& app, musik::core::ILibraryPtr library, @@ -564,7 +573,9 @@ void SettingsLayout::LoadPreferences() { colorTheme = _TSTR("settings_8color_theme_name"); } - this->themeDropdown->SetText(arrow + _TSTR("settings_color_theme") + colorTheme); + this->themeDropdown->SetText( + arrow + _TSTR("settings_color_theme") + + resolveThemeName(colorTheme)); #ifdef ENABLE_256_COLOR_OPTION this->paletteCheckbox->CheckChanged.disconnect(this); diff --git a/src/musikcube/app/overlay/ColorThemeOverlay.cpp b/src/musikcube/app/overlay/ColorThemeOverlay.cpp index 1a9b06574..ebbcf8931 100644 --- a/src/musikcube/app/overlay/ColorThemeOverlay.cpp +++ b/src/musikcube/app/overlay/ColorThemeOverlay.cpp @@ -58,6 +58,11 @@ using namespace boost::filesystem; using Callback = std::function; +struct ThemeInfo { + std::string name; + std::string path; +}; + static void showNeedsRestart(Callback cb = Callback()) { std::shared_ptr dialog(new DialogOverlay()); @@ -73,8 +78,23 @@ static void showNeedsRestart(Callback cb = Callback()) { App::Overlays().Push(dialog); } -static std::string ThemesDirectory() { - return musik::core::GetApplicationDirectory() + "/themes/"; +static void indexThemes( + const std::string& directory, + std::shared_ptr> themes) +{ + path colorPath(directory); + if (exists(colorPath)) { + directory_iterator end; + for (directory_iterator file(colorPath); file != end; file++) { + const path& p = file->path(); + + if (p.has_extension() && p.extension().string() == ".json") { + std::string fn = p.filename().string(); + std::string name = fn.substr(0, fn.rfind(".")); + themes->push_back({ name, p.string() }); + } + } + } } ColorThemeOverlay::ColorThemeOverlay() { @@ -96,27 +116,21 @@ void ColorThemeOverlay::Show(std::function callback) { adapter->AddEntry(_TSTR("settings_default_theme_name")); adapter->AddEntry(_TSTR("settings_8color_theme_name")); - std::shared_ptr> themes(new std::vector()); + std::shared_ptr> themes(new std::vector()); + indexThemes(musik::core::GetApplicationDirectory() + "/themes/", themes); + indexThemes(musik::core::GetDataDirectory() + "/themes/", themes); - path colorPath(ThemesDirectory()); - if (exists(colorPath)) { - int i = 2; - directory_iterator end; - for (directory_iterator file(colorPath); file != end; file++) { - const path& p = file->path(); + std::sort( + themes->begin(), + themes->end(), + [](const ThemeInfo& a, const ThemeInfo& b) -> bool { + return a.name < b.name; + }); - if (p.has_extension() && p.extension().string() == ".json") { - std::string fn = p.filename().string(); - fn = fn.substr(0, fn.rfind(".")); - themes->push_back(fn); - adapter->AddEntry(fn); - - if (currentTheme == fn) { - selectedIndex = i; - } - - ++i; - } + for (size_t i = 0; i < themes->size(); i++) { + adapter->AddEntry(themes->at(i).name); + if (themes->at(i).path == currentTheme) { + selectedIndex = i + 2; } } @@ -149,11 +163,11 @@ void ColorThemeOverlay::Show(std::function callback) { } } else { - std::string selected = themes->at(index - 2).c_str(); + std::string selected = themes->at(index - 2).path; if (selected != currentTheme) { prefs->SetString(cube::prefs::keys::ColorTheme, selected.c_str()); prefs->SetBool(cube::prefs::keys::DisableCustomColors, false); - Colors::SetTheme(ThemesDirectory() + selected + ".json"); + Colors::SetTheme(selected); if (disableCustomColors) { showNeedsRestart();