'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:
Maxmtg
2013-02-27 05:08:47 +00:00
parent 6a7ed9d213
commit 8146d4c96f
2 changed files with 14 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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;
}
}