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:
drdev
2013-10-09 05:10:59 +00:00
parent c05d299fe4
commit 4c1f670147
5 changed files with 29 additions and 15 deletions

View File

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

View File

@@ -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?",

View File

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

View File

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

View File

@@ -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) {
setSelectedTab(tab);
return;
return tab;
}
}
setSelectedTab(addNavigationTab(data)); //if tab not found, add and select it
return null;
}
public void ensureTabActive(INavigationTabData data) {
NavigationTab tab = getTab(data);
if (tab != null && !tab.selected) {
setSelectedTab(tab);
Singletons.getControl().changeStateAutoFixLayout(data.getTabDestScreen(), tab.getText());
}
}
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) {
closeTab(tab);
return;
}
NavigationTab tab = getTab(data);
if (tab != null) {
closeTab(tab);
}
}