mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Prompt to save changes of previous deck before loading another deck
This commit is contained in:
@@ -268,17 +268,17 @@ public enum FControl implements KeyEventDispatcher {
|
||||
/**
|
||||
* Switches between display screens in top level JFrame.
|
||||
*/
|
||||
public void setCurrentScreen(FScreen screen) {
|
||||
setCurrentScreen(screen, false);
|
||||
public boolean setCurrentScreen(FScreen screen) {
|
||||
return setCurrentScreen(screen, false);
|
||||
}
|
||||
public void setCurrentScreen(FScreen screen, boolean previousScreenClosed) {
|
||||
public boolean setCurrentScreen(FScreen screen, boolean previousScreenClosed) {
|
||||
//TODO: Uncomment the line below if this function stops being used to refresh
|
||||
//the current screen in some places (such as Continue and Restart in the match screen)
|
||||
//if (this.currentScreen == screen) { return; }
|
||||
|
||||
//give previous screen a chance to perform special switch handling and/or cancel switching away from screen
|
||||
if (this.currentScreen != screen && !Singletons.getView().getNavigationBar().canSwitch(screen)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.currentScreen == FScreen.MATCH_SCREEN) { //hide targeting overlay and reset image if was on match screen
|
||||
@@ -321,16 +321,17 @@ public enum FControl implements KeyEventDispatcher {
|
||||
}
|
||||
|
||||
Singletons.getView().getNavigationBar().updateSelectedTab();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isMatchBackgroundImageVisible() {
|
||||
return Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_MATCH_IMAGE_VISIBLE);
|
||||
}
|
||||
|
||||
public void ensureScreenActive(FScreen screen) {
|
||||
if (this.currentScreen == screen) { return; }
|
||||
public boolean ensureScreenActive(FScreen screen) {
|
||||
if (this.currentScreen == screen) { return true; }
|
||||
|
||||
setCurrentScreen(screen);
|
||||
return setCurrentScreen(screen);
|
||||
}
|
||||
|
||||
/** @return List<Shortcut> A list of attached keyboard shortcut descriptions and properties. */
|
||||
|
||||
@@ -58,7 +58,11 @@ public class SEditorIO {
|
||||
*/
|
||||
public static boolean confirmSaveChanges(FScreen screen, boolean isClosing) {
|
||||
if (CDeckEditorUI.SINGLETON_INSTANCE.hasChanges()) {
|
||||
Singletons.getControl().ensureScreenActive(screen); //ensure Deck Editor is active before showing dialog
|
||||
//ensure Deck Editor is active before showing dialog
|
||||
if (!Singletons.getControl().ensureScreenActive(screen)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int choice = FOptionPane.showOptionDialog("Save changes to current deck?", "Save Changes?",
|
||||
FOptionPane.QUESTION_ICON, new String[] {"Save", "Don't Save", "Cancel"});
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import forge.deck.DeckBase;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.deckeditor.CDeckEditorUI;
|
||||
import forge.gui.deckeditor.SEditorIO;
|
||||
import forge.gui.deckeditor.controllers.ACEditorBase;
|
||||
import forge.gui.deckeditor.controllers.CEditorLimited;
|
||||
import forge.gui.deckeditor.controllers.CEditorQuest;
|
||||
@@ -454,11 +455,15 @@ public class DeckLister extends JPanel implements ILocalRepaint {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
Singletons.getControl().setCurrentScreen(screen);
|
||||
|
||||
if (!Singletons.getControl().ensureScreenActive(screen)) { return; }
|
||||
|
||||
if (editorCtrl != null) {
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setEditorController(editorCtrl);
|
||||
}
|
||||
|
||||
if (!SEditorIO.confirmSaveChanges(screen, true)) { return; } //ensure previous deck on screen is saved if needed
|
||||
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController().load(d0.getName());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user