Skip to content

Commit 280f72b

Browse files
committed
Make sure themes are intact
1 parent 5f01f39 commit 280f72b

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

Source/Dialogs/ThemeSettingsPanel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,20 @@ class ThemeSettingsPanel final : public SettingsDialogPanel
406406

407407
auto& selectedThemes = SettingsFile::getInstance()->getActiveThemes();
408408
auto const& themeName = allThemes[result - 1];
409+
auto currentTheme = SettingsFile::getInstance()->getProperty<String>("theme");
409410

410411
SettingsFile::getInstance()->getThemeTree().remove(result - 1);
411412
if (selectedThemes[0].toString() == themeName) {
412413
selectedThemes.set(0, "light");
413414
PlugDataLook::selectedThemes.set(0, "light");
415+
if(themeName == currentTheme)
416+
SettingsFile::getInstance()->setProperty("theme", "light");
414417
}
415418
if (selectedThemes[1].toString() == themeName) {
416419
selectedThemes.set(1, "dark");
417420
PlugDataLook::selectedThemes.set(1, "dark");
421+
if(themeName == currentTheme)
422+
SettingsFile::getInstance()->setProperty("theme", "dark");
418423
}
419424

420425
updateSwatches();

Source/LookAndFeel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ void PlugDataLook::setTheme(DynamicObject::Ptr themeTree)
13421342
UnorderedMap<PlugDataColour, Colour> colours;
13431343

13441344
// Quick check if this tree is valid
1345-
if (!themeTree->hasProperty("name"))
1345+
if (!themeTree || !themeTree->hasProperty("name"))
13461346
return;
13471347

13481348
for (auto const& [colourId, colourNames] : PlugDataColourNames) {

Source/PluginProcessor.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,14 +1591,11 @@ void PluginProcessor::setTheme(String themeToUse, bool const force)
15911591
auto themeTree = settingsFile->getTheme(themeToUse);
15921592
// Check if theme name is valid
15931593
if (!themeTree) {
1594-
themeToUse = PlugDataLook::selectedThemes[0];
1594+
themeToUse = "light";
15951595
themeTree = settingsFile->getTheme(themeToUse);
1596+
SettingsFile::getInstance()->setProperty("theme", themeToUse);
15961597
}
15971598

1598-
// TODO: do we need this?
1599-
// if (!force && oldThemeTree && themeTree.isEquivalentTo(oldThemeTree))
1600-
// return;
1601-
16021599
lnf->setTheme(themeTree);
16031600

16041601
updateAllEditorsLNF();

Source/Utility/SettingsFile.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,20 @@ void SettingsFile::initialiseThemesTree()
519519
// Initialise selected themes tree
520520
auto selectedThemes = getActiveThemes();
521521
auto currentTheme = getProperty<String>("theme");
522+
523+
if(!getTheme(currentTheme))
524+
{
525+
currentTheme = "light";
526+
setProperty("theme", selectedThemes[0].toString());
527+
}
528+
if(!getTheme(selectedThemes[0]))
529+
{
530+
selectedThemes.set(0, "light");
531+
}
532+
if(!getTheme(selectedThemes[1]))
533+
{
534+
selectedThemes.set(1, "dark");
535+
}
522536
if (selectedThemes[0].toString() != currentTheme && selectedThemes[1].toString() != currentTheme) {
523537
setProperty("theme", selectedThemes[0].toString());
524538
}

0 commit comments

Comments
 (0)