mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Set dialog default to Yes when exiting Forge without game active
Ensure Deck Editor visible if and when "Save Changes?" dialog would appear
This commit is contained in:
@@ -140,7 +140,7 @@ public enum FControl implements KeyEventDispatcher {
|
||||
if (this.game != null) {
|
||||
userPrompt = "A game is currently active. " + userPrompt;
|
||||
}
|
||||
if (!MenuUtil.getUserConfirmation(userPrompt, "Exit Forge")) {
|
||||
if (!MenuUtil.getUserConfirmation(userPrompt, "Exit Forge", this.game == null)) { //default Yes if no game active
|
||||
return false;
|
||||
}
|
||||
if (!CDeckEditorUI.SINGLETON_INSTANCE.canExit()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.controllers.DeckController;
|
||||
import forge.gui.deckeditor.views.VCurrentDeck;
|
||||
@@ -82,8 +83,8 @@ public class SEditorIO {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean confirmSaveChanges() {
|
||||
if (!((DeckController<DeckBase>) CDeckEditorUI
|
||||
.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController()).isSaved()) {
|
||||
if (!((DeckController<DeckBase>) CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController()).isSaved()) {
|
||||
Singletons.getView().getNavigationBar().ensureTabActive(CDeckEditorUI.SINGLETON_INSTANCE); //ensure Deck Editor is active before showing dialog
|
||||
final int choice = JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(),
|
||||
"Save changes to current deck?",
|
||||
"Save Changes?",
|
||||
|
||||
@@ -83,7 +83,7 @@ public final class GameMenu {
|
||||
String userPrompt =
|
||||
"This will end the current game and you will not be able to resume.\n\n" +
|
||||
"Concede anyway?";
|
||||
if (MenuUtil.getUserConfirmation(userPrompt, "Concede Game?")) {
|
||||
if (MenuUtil.getUserConfirmation(userPrompt, "Concede Game?", false)) {
|
||||
controller.concede();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class MenuUtil {
|
||||
return KeyStroke.getKeyStroke(key, DEFAULT_MenuShortcutKeyMask);
|
||||
}
|
||||
|
||||
public static boolean getUserConfirmation(String prompt, String dialogTitle) {
|
||||
public static boolean getUserConfirmation(String prompt, String dialogTitle, boolean defaultYes) {
|
||||
Object[] options = {"Yes", "No"};
|
||||
int reply = JOptionPane.showOptionDialog(
|
||||
JOptionPane.getRootFrame(),
|
||||
@@ -44,7 +44,7 @@ public final class MenuUtil {
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[1]);
|
||||
options[defaultYes ? 0 : 1]);
|
||||
return (reply == JOptionPane.YES_OPTION);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,14 +101,29 @@ public class FNavigationBar extends FTitleBarBase {
|
||||
return tab;
|
||||
}
|
||||
|
||||
public void setSelectedTab(INavigationTabData data) {
|
||||
private NavigationTab getTab(INavigationTabData data) {
|
||||
for (NavigationTab tab : tabs) {
|
||||
if (tab.data == data) {
|
||||
return tab;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ensureTabActive(INavigationTabData data) {
|
||||
NavigationTab tab = getTab(data);
|
||||
if (tab != null && !tab.selected) {
|
||||
setSelectedTab(tab);
|
||||
return;
|
||||
Singletons.getControl().changeStateAutoFixLayout(data.getTabDestScreen(), tab.getText());
|
||||
}
|
||||
}
|
||||
setSelectedTab(addNavigationTab(data)); //if tab not found, add and select it
|
||||
|
||||
public void setSelectedTab(INavigationTabData data) {
|
||||
NavigationTab tab = getTab(data);
|
||||
if (tab == null) {
|
||||
tab = addNavigationTab(data); //if tab not found, add and select it
|
||||
}
|
||||
setSelectedTab(tab);
|
||||
}
|
||||
|
||||
private void setSelectedTab(NavigationTab tab) {
|
||||
@@ -122,11 +137,9 @@ public class FNavigationBar extends FTitleBarBase {
|
||||
}
|
||||
|
||||
public void closeTab(INavigationTabData data) {
|
||||
for (NavigationTab tab : tabs) {
|
||||
if (tab.data == data) {
|
||||
NavigationTab tab = getTab(data);
|
||||
if (tab != null) {
|
||||
closeTab(tab);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user