mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
'confirm deck overwrite' dialog will pop only if deck is being saved under a different name, that matches another existing deck name
This commit is contained in:
@@ -22,6 +22,8 @@ import javax.xml.stream.events.Attribute;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.tables.DeckController;
|
||||
import forge.gui.deckeditor.tables.SColumnUtil;
|
||||
@@ -129,14 +131,17 @@ public class SEditorIO {
|
||||
}
|
||||
// Confirm if overwrite
|
||||
else if (controller.fileExists(name)) {
|
||||
final int m = JOptionPane.showConfirmDialog(null,
|
||||
int confirmResult = JOptionPane.YES_OPTION;
|
||||
if ( !StringUtils.equals(name, controller.getModelName()) ) { // prompt only if name was changed
|
||||
confirmResult = JOptionPane.showConfirmDialog(null,
|
||||
limitedDeckMode ? "Would you like to save changes to your deck?"
|
||||
: "There is already a deck named '" + name + "'. Overwrite?",
|
||||
limitedDeckMode ? "Save changes?" : "Overwrite Deck?",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
}
|
||||
|
||||
if (m == JOptionPane.YES_OPTION) { controller.save(); }
|
||||
if (confirmResult == JOptionPane.YES_OPTION) { controller.save(); }
|
||||
}
|
||||
// Confirm if a new deck will be created
|
||||
else {
|
||||
|
||||
@@ -38,6 +38,7 @@ import forge.util.storage.IStorage;
|
||||
public class DeckController<T extends DeckBase> {
|
||||
|
||||
private T model;
|
||||
private String modelName;
|
||||
private boolean saved;
|
||||
private boolean modelInStore;
|
||||
private final IStorage<T> folder;
|
||||
@@ -56,6 +57,7 @@ public class DeckController<T extends DeckBase> {
|
||||
this.folder = folder0;
|
||||
this.view = view0;
|
||||
this.model = null;
|
||||
this.modelName = null;
|
||||
this.saved = true;
|
||||
this.modelInStore = false;
|
||||
this.newModelCreator = newModelCreator0;
|
||||
@@ -88,6 +90,7 @@ public class DeckController<T extends DeckBase> {
|
||||
public void setModel(final T document, final boolean isStored) {
|
||||
this.modelInStore = isStored;
|
||||
this.model = document;
|
||||
this.modelName = document.getName();
|
||||
this.view.resetTables();
|
||||
|
||||
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setText(model.getName());
|
||||
@@ -306,4 +309,8 @@ public class DeckController<T extends DeckBase> {
|
||||
_setSaved(true);
|
||||
this.view.resetTables();
|
||||
}
|
||||
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user