Better control on Deck save and editor state set + FIX set deck name

the loadDeck method now has a better handling of the deck (model) status, also wrt. the state of the UI editor.
If the deck is Stored, the editor will be in "modified - not saved" state.
This commit is contained in:
leriomaggio
2021-10-28 23:20:31 +01:00
parent c31d4cbb1f
commit 35eca6f038

View File

@@ -91,17 +91,21 @@ public class DeckController<T extends DeckBase> {
} }
public void loadDeck(Deck deck, boolean substituteCurrentDeck) { public void loadDeck(Deck deck, boolean substituteCurrentDeck) {
boolean isStored;
if (view.getCatalogManager().isInfinite()) { if (view.getCatalogManager().isInfinite()) {
Deck currentDeck = view.getHumanDeck(); Deck currentDeck = view.getHumanDeck();
if (substituteCurrentDeck || currentDeck.isEmpty()) { if (substituteCurrentDeck || currentDeck.isEmpty()) {
newModel(); newModel();
} isStored = false;
} else
isStored = !this.modelPath.equals("");
} else { } else {
CardPool catalogClone = new CardPool(view.getInitialCatalog()); CardPool catalogClone = new CardPool(view.getInitialCatalog());
deck = pickFromCatalog(deck, catalogClone); deck = pickFromCatalog(deck, catalogClone);
ItemPool<PaperCard> catalogPool = view.getCatalogManager().getPool(); ItemPool<PaperCard> catalogPool = view.getCatalogManager().getPool();
catalogPool.clear(); catalogPool.clear();
catalogPool.addAll(catalogClone); catalogPool.addAll(catalogClone);
isStored = false;
} }
Deck currentDeck = view.getHumanDeck(); Deck currentDeck = view.getHumanDeck();
@@ -112,9 +116,9 @@ public class DeckController<T extends DeckBase> {
} }
} }
// Allow to specify the name of Deck in DeckImporter // Allow to specify the name of Deck in DeckImporter
if ((deck.hasName()) && (!currentDeck.hasName())) if (deck.hasName())
view.getHumanDeck().setName(deck.getName()); currentDeck.setName(deck.getName());
onModelChanged(false); this.setModel((T) currentDeck, isStored);
} }
private Deck pickFromCatalog(Deck deck, CardPool catalog) { private Deck pickFromCatalog(Deck deck, CardPool catalog) {
@@ -237,7 +241,7 @@ public class DeckController<T extends DeckBase> {
} else { //TODO: Make this smarter } else { //TODO: Make this smarter
currentFolder = rootFolder; currentFolder = rootFolder;
modelPath = ""; modelPath = "";
setSaved(true); setSaved(this.model.isEmpty());
} }
} }