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

View file

@ -30,7 +30,8 @@ GuiSettings::GuiSettings(
mNeedsSortingCollections(false),
mGoToSystem(nullptr),
mNeedsGoToStart(false),
mNeedsGoToSystem(false)
mNeedsGoToSystem(false),
mNeedsGoToGroupedCollections(false)
{
addChild(&mMenu);
mMenu.addButton("BACK", "back", [this] { delete this; });
@ -82,6 +83,38 @@ void GuiSettings::save()
if (mNeedsGoToSystem)
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 ||
mNeedsGoToStart || mNeedsGoToSystem)
mWindow->invalidateCachedBackground();

View file

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