Enabling and disabling collections is now handled better.

This commit is contained in:
Leon Styhre 2021-01-02 12:33:27 +01:00
parent d6ca413945
commit 145cbf8df7
3 changed files with 45 additions and 7 deletions

View file

@ -84,8 +84,6 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(
setNeedsSaving(); setNeedsSaving();
setNeedsReloading(); setNeedsReloading();
setNeedsCollectionsUpdate(); setNeedsCollectionsUpdate();
if (!mAddedCustomCollection)
setNeedsGoToSystem(SystemData::sSystemVector.front());
} }
}); });
@ -130,7 +128,7 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(
addedCustomSystems.push_back(system); addedCustomSystems.push_back(system);
} }
} }
if (!addedCustomSystems.empty()) { if (!mAddedCustomCollection && !addedCustomSystems.empty()) {
for (std::string system : addedCustomSystems) for (std::string system : addedCustomSystems)
CollectionSystemsManager::get()-> CollectionSystemsManager::get()->
repopulateCollection(customSystems.find(system)->second.system); repopulateCollection(customSystems.find(system)->second.system);
@ -138,8 +136,7 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(
setNeedsSaving(); setNeedsSaving();
setNeedsReloading(); setNeedsReloading();
setNeedsCollectionsUpdate(); setNeedsCollectionsUpdate();
if (!mAddedCustomCollection) setNeedsGoToGroupedCollections();
setNeedsGoToSystem(SystemData::sSystemVector.front());
} }
} }
}); });
@ -259,6 +256,7 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(
Settings::getInstance()->setString("CollectionSystemsCustom", Settings::getInstance()->setString("CollectionSystemsCustom",
collectionsConfigEntry); collectionsConfigEntry);
setNeedsSaving(); setNeedsSaving();
setNeedsGoToStart();
setNeedsGoToSystem(SystemData::sSystemVector.front()); setNeedsGoToSystem(SystemData::sSystemVector.front());
} }
CollectionSystemsManager::get()->deleteCustomCollection(name); CollectionSystemsManager::get()->deleteCustomCollection(name);
@ -356,6 +354,11 @@ void GuiCollectionSystemsOptions::createCustomCollection(std::string inName)
collection_systems_custom->add(collectionName, collectionName, true); collection_systems_custom->add(collectionName, collectionName, true);
mAddedCustomCollection = true; mAddedCustomCollection = true;
setNeedsGoToStart();
if (Settings::getInstance()->getBool("UseCustomCollectionsSystem"))
setNeedsGoToGroupedCollections();
else
setNeedsGoToSystem(newCollection); setNeedsGoToSystem(newCollection);
Window* window = mWindow; Window* window = mWindow;

View file

@ -30,7 +30,8 @@ GuiSettings::GuiSettings(
mNeedsSortingCollections(false), mNeedsSortingCollections(false),
mGoToSystem(nullptr), mGoToSystem(nullptr),
mNeedsGoToStart(false), mNeedsGoToStart(false),
mNeedsGoToSystem(false) mNeedsGoToSystem(false),
mNeedsGoToGroupedCollections(false)
{ {
addChild(&mMenu); addChild(&mMenu);
mMenu.addButton("BACK", "back", [this] { delete this; }); mMenu.addButton("BACK", "back", [this] { delete this; });
@ -82,6 +83,38 @@ void GuiSettings::save()
if (mNeedsGoToSystem) if (mNeedsGoToSystem)
ViewController::get()->goToSystem(mGoToSystem, false); ViewController::get()->goToSystem(mGoToSystem, false);
if (mNeedsGoToGroupedCollections) {
for (SystemData* system : SystemData::sSystemVector) {
if (system->getThemeFolder() == "custom-collections") {
ViewController::get()->goToSystem(system, false);
continue;
}
}
}
if (mNeedsCollectionsUpdate) {
auto state = ViewController::get()->getState();
// If we're in any view other than the grouped custom collections, always jump to the
// system view in case of any collection updates. This is overkill in some instances but
// these views can behave a bit strange during collection changes so it's better to be on
// the safe side.
if (state.getSystem()->isCollection() &&
state.getSystem()->getThemeFolder() != "custom-collections") {
ViewController::get()->goToStart();
ViewController::get()->goToSystem(SystemData::sSystemVector.front(), false);
// We don't want to invalidate the cached background when there has been a collection
// systen change as that may show a black screen in some circumstances.
return;
}
// If the last displayed custom collection was just disabled, then go to start (to the
// system view).
if (std::find(SystemData::sSystemVector.begin(), SystemData::sSystemVector.end(),
state.getSystem()) == SystemData::sSystemVector.end()) {
ViewController::get()->goToStart();
return;
}
}
if (mNeedsSaving || mNeedsCollectionsUpdate || mNeedsReloading || mNeedsSorting || if (mNeedsSaving || mNeedsCollectionsUpdate || mNeedsReloading || mNeedsSorting ||
mNeedsGoToStart || mNeedsGoToSystem) mNeedsGoToStart || mNeedsGoToSystem)
mWindow->invalidateCachedBackground(); mWindow->invalidateCachedBackground();

View file

@ -41,6 +41,7 @@ public:
void setNeedsGoToStart() { mNeedsGoToStart = true; }; void setNeedsGoToStart() { mNeedsGoToStart = true; };
void setNeedsGoToSystem(SystemData* goToSystem) void setNeedsGoToSystem(SystemData* goToSystem)
{ mNeedsGoToSystem = true; mGoToSystem = goToSystem; }; { mNeedsGoToSystem = true; mGoToSystem = goToSystem; };
void setNeedsGoToGroupedCollections() { mNeedsGoToGroupedCollections = true; };
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
std::vector<HelpPrompt> getHelpPrompts() override; std::vector<HelpPrompt> getHelpPrompts() override;
@ -56,6 +57,7 @@ private:
bool mNeedsSortingCollections; bool mNeedsSortingCollections;
bool mNeedsGoToStart; bool mNeedsGoToStart;
bool mNeedsGoToSystem; bool mNeedsGoToSystem;
bool mNeedsGoToGroupedCollections;
SystemData* mGoToSystem; SystemData* mGoToSystem;
}; };