mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Fix so saving a deck multiple time works
Fix so adding/removing decks in All Decks pane updates deck choosers on home screen Fix so saving a deck in Deck Editor updates All Decks pane right away Fix so typing in deck title field marks deck as having changes to save
This commit is contained in:
@@ -239,6 +239,7 @@ public class FDeckChooser extends JPanel implements IDecksComboBoxListener {
|
||||
}
|
||||
else {
|
||||
removeAll();
|
||||
restoreSavedState(); //ensure decks refreshed and state restored in case any deleted or added since last loaded
|
||||
}
|
||||
this.setLayout(new MigLayout("insets 0, gap 0"));
|
||||
decksComboBox.addTo(this, "w 100%, h 30px!, gapbottom 5px, spanx 2, wrap");
|
||||
|
||||
@@ -3,7 +3,9 @@ package forge.gui.deckeditor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.gui.deckeditor.controllers.CAllDecks;
|
||||
import forge.gui.deckeditor.controllers.DeckController;
|
||||
import forge.gui.deckeditor.views.VAllDecks;
|
||||
import forge.gui.deckeditor.views.VCurrentDeck;
|
||||
import forge.gui.framework.FScreen;
|
||||
import forge.gui.toolbox.FOptionPane;
|
||||
@@ -14,7 +16,6 @@ import forge.gui.toolbox.FOptionPane;
|
||||
* <br><br><i>(S at beginning of class name denotes a static factory.)</i>
|
||||
*/
|
||||
public class SEditorIO {
|
||||
|
||||
/**
|
||||
* Saves the current deck, with various prompts depending on the
|
||||
* current save environment.
|
||||
@@ -34,18 +35,28 @@ public class SEditorIO {
|
||||
// Confirm if overwrite
|
||||
else if (controller.fileExists(name)) {
|
||||
boolean confirmResult = true;
|
||||
if ( !StringUtils.equals(name, controller.getModelName()) ) { // prompt only if name was changed
|
||||
if (!StringUtils.equals(name, controller.getModelName())) { // prompt only if name was changed
|
||||
confirmResult = FOptionPane.showConfirmDialog(
|
||||
"There is already a deck named '" + name + "'. Overwrite?",
|
||||
"Overwrite Deck?");
|
||||
}
|
||||
|
||||
if (confirmResult) { controller.save(); }
|
||||
if (confirmResult) {
|
||||
controller.save();
|
||||
DeckProxy deck = VAllDecks.SINGLETON_INSTANCE.getLstDecks().stringToItem(controller.getModelPath() + "/" + name);
|
||||
if (deck != null) { //reload DeckProxy to pull changes into deck list
|
||||
deck.reloadFromStorage();
|
||||
VAllDecks.SINGLETON_INSTANCE.getLstDecks().setSelectedItem(deck);
|
||||
VAllDecks.SINGLETON_INSTANCE.getLstDecks().repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Confirm if a new deck will be created
|
||||
else if (FOptionPane.showConfirmDialog("This will create a new deck named '" +
|
||||
name + "'. Continue?", "Create Deck?")) {
|
||||
controller.saveAs(name);
|
||||
CAllDecks.SINGLETON_INSTANCE.refresh(); //pull new deck into deck list and select it
|
||||
VAllDecks.SINGLETON_INSTANCE.getLstDecks().setSelectedString(controller.getModelPath() + "/" + name);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -31,6 +31,10 @@ public enum CAllDecks implements ICDoc {
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
VAllDecks.SINGLETON_INSTANCE.getLstDecks().setPool(DeckProxy.getAllConstructedDecks(Singletons.getModel().getDecks().getConstructed()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package forge.gui.deckeditor.controllers;
|
||||
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
@@ -111,6 +113,14 @@ public enum CCurrentDeck implements ICDoc {
|
||||
importDeck();
|
||||
}
|
||||
});
|
||||
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (Character.isLetterOrDigit(e.getKeyChar())) {
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController().notifyModelChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,6 +37,7 @@ public class DeckController<T extends DeckBase> {
|
||||
private boolean modelInStorage;
|
||||
private final IStorage<T> rootFolder;
|
||||
private IStorage<T> currentFolder;
|
||||
private String modelPath;
|
||||
private final ACEditorBase<?, T> view;
|
||||
private final Supplier<T> newModelCreator;
|
||||
|
||||
@@ -54,6 +55,7 @@ public class DeckController<T extends DeckBase> {
|
||||
this.model = null;
|
||||
this.saved = true;
|
||||
this.modelInStorage = false;
|
||||
this.modelPath = "";
|
||||
this.newModelCreator = newModelCreator0;
|
||||
}
|
||||
|
||||
@@ -66,6 +68,10 @@ public class DeckController<T extends DeckBase> {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
public String getModelPath() {
|
||||
return this.modelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the model.
|
||||
*
|
||||
@@ -82,7 +88,7 @@ public class DeckController<T extends DeckBase> {
|
||||
CProbabilities.SINGLETON_INSTANCE.update();
|
||||
|
||||
if (this.isModelInSyncWithFolder()) {
|
||||
_setSaved(true);
|
||||
this.setSaved(true);
|
||||
}
|
||||
else {
|
||||
this.notifyModelChanged();
|
||||
@@ -119,10 +125,12 @@ public class DeckController<T extends DeckBase> {
|
||||
* Notify model changed.
|
||||
*/
|
||||
public void notifyModelChanged() {
|
||||
_setSaved(false);
|
||||
if (saved) {
|
||||
this.setSaved(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void _setSaved(boolean val) {
|
||||
private void setSaved(boolean val) {
|
||||
saved = val;
|
||||
updateCaptions();
|
||||
}
|
||||
@@ -147,6 +155,7 @@ public class DeckController<T extends DeckBase> {
|
||||
else {
|
||||
currentFolder = rootFolder.tryGetFolder(path);
|
||||
}
|
||||
modelPath = path;
|
||||
load(name);
|
||||
}
|
||||
|
||||
@@ -155,13 +164,14 @@ public class DeckController<T extends DeckBase> {
|
||||
*
|
||||
* @param name the name
|
||||
*/
|
||||
@SuppressWarnings("unchecked") private void load(final String name) {
|
||||
@SuppressWarnings("unchecked")
|
||||
private void load(final String name) {
|
||||
T newModel = this.currentFolder.get(name);
|
||||
if (newModel != null) {
|
||||
this.setModel((T) newModel.copyTo(name), true);
|
||||
}
|
||||
else {
|
||||
_setSaved(true);
|
||||
this.setSaved(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,11 +184,10 @@ public class DeckController<T extends DeckBase> {
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentFolder.add(this.model);
|
||||
// copy to new instance which will be edited and left if unsaved
|
||||
this.model = (T)this.model.copyTo(this.model.getName());
|
||||
// copy to new instance before adding to current folder so further changes are auto-saved
|
||||
this.currentFolder.add((T) this.model.copyTo(this.model.getName()));
|
||||
this.modelInStorage = true;
|
||||
_setSaved(true);
|
||||
this.setSaved(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,6 +200,7 @@ public class DeckController<T extends DeckBase> {
|
||||
this.model = (T)this.model.copyTo(name0);
|
||||
this.modelInStorage = false;
|
||||
this.save();
|
||||
this.view.resetTables(); //ensure pool updated in CCurrentDeck
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +248,7 @@ public class DeckController<T extends DeckBase> {
|
||||
*/
|
||||
public void newModel() {
|
||||
this.model = this.newModelCreator.get();
|
||||
_setSaved(true);
|
||||
this.setSaved(true);
|
||||
this.view.resetTables();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,8 @@ public enum VAllDecks implements IVDoc<CAllDecks> {
|
||||
*/
|
||||
@Override
|
||||
public void populate() {
|
||||
CAllDecks.SINGLETON_INSTANCE.refresh(); //ensure decks refreshed in case any deleted or added since last loaded
|
||||
|
||||
JPanel parentBody = parentCell.getBody();
|
||||
parentBody.setLayout(new MigLayout("insets 5, gap 0, wrap, hidemode 3"));
|
||||
parentBody.add(new ItemManagerContainer(lstDecks), "push, grow");
|
||||
|
||||
@@ -397,7 +397,6 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
this.setPool(ItemPool.createFrom(items, this.genericType), false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Sets the item pool.
|
||||
@@ -420,7 +419,7 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
* @param pool0
|
||||
* @param infinite
|
||||
*/
|
||||
protected void setPoolImpl(final ItemPool<T> pool0, boolean infinite) {
|
||||
private void setPoolImpl(final ItemPool<T> pool0, boolean infinite) {
|
||||
this.model.clear();
|
||||
this.pool = pool0;
|
||||
this.model.addItems(this.pool);
|
||||
@@ -506,6 +505,35 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
return this.table.setSelectedItems(items);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* stringToItem.
|
||||
*
|
||||
* @param str - String to get item corresponding to
|
||||
*/
|
||||
public T stringToItem(String str) {
|
||||
for (Entry<T, Integer> itemEntry : this.pool) {
|
||||
if (itemEntry.getKey().toString().equals(str)) {
|
||||
return itemEntry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* setSelectedString.
|
||||
*
|
||||
* @param str - String to select
|
||||
*/
|
||||
public boolean setSelectedString(String str) {
|
||||
T item = stringToItem(str);
|
||||
if (item != null) {
|
||||
return this.setSelectedItem(item);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* setSelectedStrings.
|
||||
@@ -514,12 +542,10 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
||||
*/
|
||||
public boolean setSelectedStrings(Iterable<String> strings) {
|
||||
List<T> items = new ArrayList<T>();
|
||||
for (String itemName : strings) {
|
||||
for (Entry<T, Integer> itemEntry : this.pool) {
|
||||
if (itemEntry.getKey().toString().equals(itemName)) {
|
||||
items.add(itemEntry.getKey());
|
||||
break;
|
||||
}
|
||||
for (String str : strings) {
|
||||
T item = stringToItem(str);
|
||||
if (item != null) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
return this.setSelectedItems(items);
|
||||
|
||||
Reference in New Issue
Block a user