mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18: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) {
|
if (this.game != null) {
|
||||||
userPrompt = "A game is currently active. " + userPrompt;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (!CDeckEditorUI.SINGLETON_INSTANCE.canExit()) {
|
if (!CDeckEditorUI.SINGLETON_INSTANCE.canExit()) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import javax.swing.JOptionPane;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import forge.Singletons;
|
||||||
import forge.deck.DeckBase;
|
import forge.deck.DeckBase;
|
||||||
import forge.gui.deckeditor.controllers.DeckController;
|
import forge.gui.deckeditor.controllers.DeckController;
|
||||||
import forge.gui.deckeditor.views.VCurrentDeck;
|
import forge.gui.deckeditor.views.VCurrentDeck;
|
||||||
@@ -82,8 +83,8 @@ public class SEditorIO {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static boolean confirmSaveChanges() {
|
public static boolean confirmSaveChanges() {
|
||||||
if (!((DeckController<DeckBase>) CDeckEditorUI
|
if (!((DeckController<DeckBase>) CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController()).isSaved()) {
|
||||||
.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(),
|
final int choice = JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(),
|
||||||
"Save changes to current deck?",
|
"Save changes to current deck?",
|
||||||
"Save Changes?",
|
"Save Changes?",
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public final class GameMenu {
|
|||||||
String userPrompt =
|
String userPrompt =
|
||||||
"This will end the current game and you will not be able to resume.\n\n" +
|
"This will end the current game and you will not be able to resume.\n\n" +
|
||||||
"Concede anyway?";
|
"Concede anyway?";
|
||||||
if (MenuUtil.getUserConfirmation(userPrompt, "Concede Game?")) {
|
if (MenuUtil.getUserConfirmation(userPrompt, "Concede Game?", false)) {
|
||||||
controller.concede();
|
controller.concede();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public final class MenuUtil {
|
|||||||
return KeyStroke.getKeyStroke(key, DEFAULT_MenuShortcutKeyMask);
|
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"};
|
Object[] options = {"Yes", "No"};
|
||||||
int reply = JOptionPane.showOptionDialog(
|
int reply = JOptionPane.showOptionDialog(
|
||||||
JOptionPane.getRootFrame(),
|
JOptionPane.getRootFrame(),
|
||||||
@@ -44,7 +44,7 @@ public final class MenuUtil {
|
|||||||
JOptionPane.QUESTION_MESSAGE,
|
JOptionPane.QUESTION_MESSAGE,
|
||||||
null,
|
null,
|
||||||
options,
|
options,
|
||||||
options[1]);
|
options[defaultYes ? 0 : 1]);
|
||||||
return (reply == JOptionPane.YES_OPTION);
|
return (reply == JOptionPane.YES_OPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,14 +101,29 @@ public class FNavigationBar extends FTitleBarBase {
|
|||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedTab(INavigationTabData data) {
|
private NavigationTab getTab(INavigationTabData data) {
|
||||||
for (NavigationTab tab : tabs) {
|
for (NavigationTab tab : tabs) {
|
||||||
if (tab.data == data) {
|
if (tab.data == data) {
|
||||||
setSelectedTab(tab);
|
return tab;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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) {
|
private void setSelectedTab(NavigationTab tab) {
|
||||||
@@ -122,11 +137,9 @@ public class FNavigationBar extends FTitleBarBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void closeTab(INavigationTabData data) {
|
public void closeTab(INavigationTabData data) {
|
||||||
for (NavigationTab tab : tabs) {
|
NavigationTab tab = getTab(data);
|
||||||
if (tab.data == data) {
|
if (tab != null) {
|
||||||
closeTab(tab);
|
closeTab(tab);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user