Skip to content

Commit de92fe6

Browse files
committed
Improvements to new settings system
1 parent 3db692e commit de92fe6

File tree

7 files changed

+35
-49
lines changed

7 files changed

+35
-49
lines changed

Source/Components/SuggestionComponent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class SuggestionComponent final : public Component
629629
if (!_this || !_this->currentObject)
630630
return;
631631

632-
if (!SettingsFile::getInstance()->getLibrariesTree().contains("Gem")) {
632+
if (!SettingsFile::getInstance()->getProperty<VarArray>("libraries").contains("Gem")) {
633633
StringArray noGemObjects;
634634
for (auto& object : toFilter) {
635635
if (object.startsWith("Gem/") || !library->isGemObject(object)) // Don't suggest Gem objects without "Gem/" prefix unless gem library is loaded

Source/Dialogs/PathsSettingsPanel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class SearchPathPanel final : public Component
272272
{
273273
paths.clear();
274274

275-
for (auto& child : SettingsFile::getInstance()->getPathsTree()) {
275+
for (auto& child : SettingsFile::getInstance()->getProperty<VarArray>("paths")) {
276276
paths.add(child);
277277
}
278278

@@ -283,7 +283,7 @@ class SearchPathPanel final : public Component
283283
}
284284
void internalChange()
285285
{
286-
auto& pathsTree = SettingsFile::getInstance()->getPathsTree();
286+
auto& pathsTree = SettingsFile::getInstance()->getProperty<VarArray>("paths");
287287
pathsTree.clear();
288288

289289
for (auto const& path : paths) {
@@ -573,7 +573,7 @@ class LibraryLoadPanel final : public Component
573573
{
574574
librariesToLoad.clear();
575575

576-
for (auto& child : SettingsFile::getInstance()->getLibrariesTree()) {
576+
for (auto& child : SettingsFile::getInstance()->getProperty<VarArray>("libraries")) {
577577
librariesToLoad.addIfNotAlreadyThere(child.toString());
578578
}
579579

@@ -584,7 +584,7 @@ class LibraryLoadPanel final : public Component
584584
}
585585
void internalChange()
586586
{
587-
auto& librariesTree = SettingsFile::getInstance()->getLibrariesTree();
587+
auto& librariesTree = SettingsFile::getInstance()->getProperty<VarArray>("libraries");
588588
librariesTree.clear();
589589

590590
for (auto const& name : librariesToLoad) {

Source/Dialogs/ThemeSettingsPanel.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class ThemeSettingsPanel final : public SettingsDialogPanel
274274
if (newThemeName.isEmpty())
275275
return;
276276

277-
SettingsFile::getInstance()->getActiveThemes().getReference(themeSlot) = newThemeName;
277+
SettingsFile::getInstance()->getProperty<VarArray>("active_themes").getReference(themeSlot) = newThemeName;
278278
PlugDataLook::selectedThemes.set(themeSlot, newThemeName);
279279

280280
updateThemeNames(primaryThemeSelector->getText(), secondaryThemeSelector->getText());
@@ -310,7 +310,7 @@ class ThemeSettingsPanel final : public SettingsDialogPanel
310310
DynamicObject::Ptr newTheme = theme->clone().release();
311311
newTheme->setProperty("name", name);
312312

313-
SettingsFile::getInstance()->getThemeTree().add(var(newTheme.get()));
313+
SettingsFile::getInstance()->getProperty<VarArray>("themes").add(var(newTheme.get()));
314314
updateSwatches();
315315
};
316316

@@ -352,7 +352,7 @@ class ThemeSettingsPanel final : public SettingsDialogPanel
352352
themeName = finalThemeName;
353353
}
354354
themeObj->setProperty("name", themeName);
355-
SettingsFile::getInstance()->getThemeTree().add(themeJson);
355+
SettingsFile::getInstance()->getProperty<VarArray>("themes").add(themeJson);
356356
}
357357
updateSwatches();
358358
},
@@ -403,11 +403,11 @@ class ThemeSettingsPanel final : public SettingsDialogPanel
403403
if (result < 1)
404404
return;
405405

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

410-
SettingsFile::getInstance()->getThemeTree().remove(result - 1);
410+
SettingsFile::getInstance()->getProperty<VarArray>("themes").remove(result - 1);
411411
if (selectedThemes[0].toString() == themeName) {
412412
selectedThemes.set(0, "light");
413413
PlugDataLook::selectedThemes.set(0, "light");
@@ -560,7 +560,7 @@ class ThemeSettingsPanel final : public SettingsDialogPanel
560560
return;
561561
}
562562

563-
auto const themeTree = SettingsFile::getInstance()->getThemeTree();
563+
auto const themeTree = SettingsFile::getInstance()->getProperty<VarArray>("themes");
564564
bool isInTheme = false;
565565
bool ioletGeometryNeedsUpdate = false;
566566
for (auto theme : PlugDataLook::selectedThemes) {
@@ -656,8 +656,8 @@ class ThemeSettingsPanel final : public SettingsDialogPanel
656656
primaryThemeSelector->setSelectedItem(firstThemes.indexOf(PlugDataLook::selectedThemes[0]));
657657
secondaryThemeSelector->setSelectedItem(secondThemes.indexOf(PlugDataLook::selectedThemes[1]));
658658

659-
SettingsFile::getInstance()->getActiveThemes().set(0, "light");
660-
SettingsFile::getInstance()->getActiveThemes().set(1, "dark");
659+
SettingsFile::getInstance()->getProperty<VarArray>("active_themes").set(0, "light");
660+
SettingsFile::getInstance()->getProperty<VarArray>("active_themes").set(1, "dark");
661661
SettingsFile::getInstance()->setProperty("theme", "light");
662662

663663
updateSwatches();

Source/LookAndFeel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ void PlugDataLook::setTheme(DynamicObject::Ptr themeTree)
14111411

14121412
StringArray PlugDataLook::getAllThemes()
14131413
{
1414-
auto const themeTree = SettingsFile::getInstance()->getThemeTree();
1414+
auto const themeTree = SettingsFile::getInstance()->getProperty<VarArray>("themes");
14151415
StringArray allThemes;
14161416
for (auto& theme : themeTree) {
14171417
allThemes.add(theme.getDynamicObject()->getProperty("name").toString());

Source/PluginProcessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ bool PluginProcessor::initialiseFilesystem()
519519
void PluginProcessor::updateSearchPaths()
520520
{
521521
// Reload pd search paths from settings
522-
auto const& pathTree = settingsFile->getPathsTree();
522+
auto const& pathTree = settingsFile->getProperty<VarArray>("paths");
523523

524524
setThis();
525525

@@ -542,7 +542,7 @@ void PluginProcessor::updateSearchPaths()
542542
libpd_add_to_search_path(path.replace("\\", "/").toRawUTF8());
543543
}
544544

545-
auto librariesTree = settingsFile->getLibrariesTree();
545+
auto librariesTree = settingsFile->getProperty<VarArray>("libraries");
546546

547547
for (auto& library : librariesTree) {
548548
if (library.toString().isEmpty()) {

Source/Utility/SettingsFile.cpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ SettingsFile* SettingsFile::initialise()
190190

191191
isInitialised = true;
192192

193+
FileSystemWatcher::addGlobalIgnorePath(lockFile);
194+
193195
// Check if settings file exists, if not, create the default
194196
// This is expected behaviour for first run / deleting plugdata folder
195197
// No need to alert the user to this
@@ -216,7 +218,7 @@ SettingsFile* SettingsFile::initialise()
216218

217219
auto settingsFileToUse = settingsFile;
218220
bool xmlSettings = false;
219-
if (oldSettingsFile.existsAsFile()) {
221+
if (oldSettingsFile.existsAsFile() && !settingsFile.existsAsFile()) {
220222
settingsFileToUse = oldSettingsFile;
221223
xmlSettings = true;
222224
}
@@ -317,26 +319,6 @@ String SettingsFile::getKeyMap() const
317319
return memOut.toString();
318320
}
319321

320-
Array<var>& SettingsFile::getThemeTree() const
321-
{
322-
return getProperty<VarArray>("themes");
323-
}
324-
325-
Array<var>& SettingsFile::getPathsTree() const
326-
{
327-
return getProperty<VarArray>("paths");
328-
}
329-
330-
Array<var>& SettingsFile::getActiveThemes() const
331-
{
332-
return getProperty<VarArray>("active_themes");
333-
}
334-
335-
Array<var>& SettingsFile::getLibrariesTree() const
336-
{
337-
return getProperty<VarArray>("libraries");
338-
}
339-
340322
DynamicObject::Ptr SettingsFile::getTheme(String const& name) const
341323
{
342324
for (auto& theme : getProperty<VarArray>("themes")) {
@@ -386,7 +368,7 @@ void SettingsFile::initialisePathsTree()
386368
HeapArray<File> currentPaths;
387369
currentPaths.reserve(10);
388370

389-
auto& pathTree = getPathsTree();
371+
auto& pathTree = getProperty<VarArray>("paths");
390372

391373
// on iOS, the containerisation of apps leads to problems with custom search paths
392374
// So we completely reset them every time
@@ -474,7 +456,7 @@ bool SettingsFile::wantsNativeDialog() const
474456
void SettingsFile::initialiseThemesTree()
475457
{
476458
// Initialise selected themes tree
477-
auto selectedThemes = getActiveThemes();
459+
auto selectedThemes = getProperty<VarArray>("active_themes");
478460
auto currentTheme = getProperty<String>("theme");
479461

480462
if(!getTheme(currentTheme))
@@ -580,6 +562,7 @@ void SettingsFile::reloadSettings()
580562
if (acquireFileLock()) {
581563
auto const newSettings = settingsFile.loadFileAsString();
582564
auto const contentHash = newSettings.hashCode64();
565+
583566
if (contentHash == lastContentHash) {
584567
releaseFileLock();
585568
return;
@@ -591,6 +574,16 @@ void SettingsFile::reloadSettings()
591574
return;
592575
}
593576

577+
for (auto& [name, var] : defaultSettings) {
578+
if(name == "themes")
579+
{
580+
settings["themes"] = JSON::fromString(PlugDataLook::defaultThemesJSON);
581+
loadThemeFromDiff(*var.getArray());
582+
continue;
583+
}
584+
settings[name] = var;
585+
}
586+
594587
auto* jsonObject = settingsToLoad.getDynamicObject();
595588
for (auto& var : jsonObject->getProperties()) {
596589
if(var.name == Identifier("themes"))
@@ -610,11 +603,9 @@ void SettingsFile::reloadSettings()
610603
}
611604
}
612605

613-
void SettingsFile::fileChanged(File const file, FileSystemWatcher::FileSystemEvent fileEvent)
606+
void SettingsFile::filesystemChanged()
614607
{
615-
if (file == settingsFile) {
616-
reloadSettings();
617-
}
608+
reloadSettings();
618609
}
619610

620611
void SettingsFile::triggerSettingsChange(String const& name)

Source/Utility/SettingsFile.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ class SettingsFile final
3939
void setKeyMap(String const& keymap);
4040
String getKeyMap() const;
4141

42-
Array<var>& getThemeTree() const;
43-
Array<var>& getPathsTree() const;
44-
Array<var>& getActiveThemes() const;
45-
Array<var>& getLibrariesTree() const;
46-
4742
DynamicObject::Ptr getTheme(String const& name) const;
4843
DynamicObject::Ptr getCurrentTheme() const;
4944

@@ -60,7 +55,7 @@ class SettingsFile final
6055

6156
void reloadSettings();
6257

63-
void fileChanged(File file, FileSystemWatcher::FileSystemEvent fileEvent) override;
58+
void filesystemChanged() override;
6459

6560
void triggerSettingsChange(String const&);
6661
void valueChanged(Value& v) override;

0 commit comments

Comments
 (0)