mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-02 11:58:27 +00:00
Fixed bug mentioned in #145 -- themes get reset after upgrade. Added the
ability to put themes in ~/.musikcube/themes/ so they don't get wiped out.
This commit is contained in:
parent
fcc817ab6a
commit
c8ff159056
@ -168,7 +168,6 @@ int main(int argc, char* argv[]) {
|
|||||||
/* theme */
|
/* theme */
|
||||||
std::string colorTheme = prefs->GetString(musik::cube::prefs::keys::ColorTheme);
|
std::string colorTheme = prefs->GetString(musik::cube::prefs::keys::ColorTheme);
|
||||||
if (colorTheme.size()) {
|
if (colorTheme.size()) {
|
||||||
colorTheme = GetApplicationDirectory() + "/themes/" + colorTheme + ".json";
|
|
||||||
app.SetColorTheme(colorTheme);
|
app.SetColorTheme(colorTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,15 @@ static std::string getOutputDeviceName() {
|
|||||||
return deviceName;
|
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(
|
SettingsLayout::SettingsLayout(
|
||||||
cursespp::App& app,
|
cursespp::App& app,
|
||||||
musik::core::ILibraryPtr library,
|
musik::core::ILibraryPtr library,
|
||||||
@ -564,7 +573,9 @@ void SettingsLayout::LoadPreferences() {
|
|||||||
colorTheme = _TSTR("settings_8color_theme_name");
|
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
|
#ifdef ENABLE_256_COLOR_OPTION
|
||||||
this->paletteCheckbox->CheckChanged.disconnect(this);
|
this->paletteCheckbox->CheckChanged.disconnect(this);
|
||||||
|
@ -58,6 +58,11 @@ using namespace boost::filesystem;
|
|||||||
|
|
||||||
using Callback = std::function<void()>;
|
using Callback = std::function<void()>;
|
||||||
|
|
||||||
|
struct ThemeInfo {
|
||||||
|
std::string name;
|
||||||
|
std::string path;
|
||||||
|
};
|
||||||
|
|
||||||
static void showNeedsRestart(Callback cb = Callback()) {
|
static void showNeedsRestart(Callback cb = Callback()) {
|
||||||
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
|
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
|
||||||
|
|
||||||
@ -73,8 +78,23 @@ static void showNeedsRestart(Callback cb = Callback()) {
|
|||||||
App::Overlays().Push(dialog);
|
App::Overlays().Push(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string ThemesDirectory() {
|
static void indexThemes(
|
||||||
return musik::core::GetApplicationDirectory() + "/themes/";
|
const std::string& directory,
|
||||||
|
std::shared_ptr<std::vector<ThemeInfo>> 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() {
|
ColorThemeOverlay::ColorThemeOverlay() {
|
||||||
@ -96,27 +116,21 @@ void ColorThemeOverlay::Show(std::function<void()> callback) {
|
|||||||
adapter->AddEntry(_TSTR("settings_default_theme_name"));
|
adapter->AddEntry(_TSTR("settings_default_theme_name"));
|
||||||
adapter->AddEntry(_TSTR("settings_8color_theme_name"));
|
adapter->AddEntry(_TSTR("settings_8color_theme_name"));
|
||||||
|
|
||||||
std::shared_ptr<std::vector<std::string>> themes(new std::vector<std::string>());
|
std::shared_ptr<std::vector<ThemeInfo>> themes(new std::vector<ThemeInfo>());
|
||||||
|
indexThemes(musik::core::GetApplicationDirectory() + "/themes/", themes);
|
||||||
|
indexThemes(musik::core::GetDataDirectory() + "/themes/", themes);
|
||||||
|
|
||||||
path colorPath(ThemesDirectory());
|
std::sort(
|
||||||
if (exists(colorPath)) {
|
themes->begin(),
|
||||||
int i = 2;
|
themes->end(),
|
||||||
directory_iterator end;
|
[](const ThemeInfo& a, const ThemeInfo& b) -> bool {
|
||||||
for (directory_iterator file(colorPath); file != end; file++) {
|
return a.name < b.name;
|
||||||
const path& p = file->path();
|
});
|
||||||
|
|
||||||
if (p.has_extension() && p.extension().string() == ".json") {
|
for (size_t i = 0; i < themes->size(); i++) {
|
||||||
std::string fn = p.filename().string();
|
adapter->AddEntry(themes->at(i).name);
|
||||||
fn = fn.substr(0, fn.rfind("."));
|
if (themes->at(i).path == currentTheme) {
|
||||||
themes->push_back(fn);
|
selectedIndex = i + 2;
|
||||||
adapter->AddEntry(fn);
|
|
||||||
|
|
||||||
if (currentTheme == fn) {
|
|
||||||
selectedIndex = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,11 +163,11 @@ void ColorThemeOverlay::Show(std::function<void()> callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string selected = themes->at(index - 2).c_str();
|
std::string selected = themes->at(index - 2).path;
|
||||||
if (selected != currentTheme) {
|
if (selected != currentTheme) {
|
||||||
prefs->SetString(cube::prefs::keys::ColorTheme, selected.c_str());
|
prefs->SetString(cube::prefs::keys::ColorTheme, selected.c_str());
|
||||||
prefs->SetBool(cube::prefs::keys::DisableCustomColors, false);
|
prefs->SetBool(cube::prefs::keys::DisableCustomColors, false);
|
||||||
Colors::SetTheme(ThemesDirectory() + selected + ".json");
|
Colors::SetTheme(selected);
|
||||||
|
|
||||||
if (disableCustomColors) {
|
if (disableCustomColors) {
|
||||||
showNeedsRestart();
|
showNeedsRestart();
|
||||||
|
Loading…
Reference in New Issue
Block a user