From cb74c47e3bcfd8b7349da1f25b1f8685db1bca46 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 8 Nov 2022 17:39:30 +0000 Subject: [PATCH] JAL-1988 JAL-3772 Fixes highlighted by tests --- src/jalview/gui/JvOptionPane.java | 15 +++++++++++++++ src/jalview/gui/QuitHandler.java | 21 +++++++++++---------- src/jalview/project/Jalview2XML.java | 12 ++++++++++-- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/jalview/gui/JvOptionPane.java b/src/jalview/gui/JvOptionPane.java index b58ea41..6e89fe2 100644 --- a/src/jalview/gui/JvOptionPane.java +++ b/src/jalview/gui/JvOptionPane.java @@ -793,6 +793,7 @@ public class JvOptionPane extends JOptionPane if (!isInteractiveMode()) { handleResponse(getMockResponse()); + return; } // two uses: // @@ -1002,6 +1003,10 @@ public class JvOptionPane extends JOptionPane public static int showDialogOnTop(String label, String actionString, int JOPTIONPANE_OPTION, int JOPTIONPANE_MESSAGETYPE) { + if (!isInteractiveMode()) + { + return (int) getMockResponse(); + } // Ensure Jalview window is brought to front (primarily for Quit // confirmation window to be visible) @@ -1047,6 +1052,11 @@ public class JvOptionPane extends JOptionPane int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options, Object initialValue, boolean modal, JButton[] buttons) { + if (!isInteractiveMode()) + { + handleResponse(getMockResponse()); + return; + } // Ensure Jalview window is brought to front (primarily for Quit // confirmation window to be visible) @@ -1131,6 +1141,11 @@ public class JvOptionPane extends JOptionPane Object[] options, Object initialValue, boolean modal, JButton[] buttons) { + if (!isInteractiveMode()) + { + handleResponse(getMockResponse()); + return null; + } JButton[] optionsButtons = null; Object initialValueButton = null; JOptionPane joptionpane = new JOptionPane(); diff --git a/src/jalview/gui/QuitHandler.java b/src/jalview/gui/QuitHandler.java index e90a2d5..77eed81 100644 --- a/src/jalview/gui/QuitHandler.java +++ b/src/jalview/gui/QuitHandler.java @@ -29,10 +29,12 @@ import jalview.util.Platform; public class QuitHandler { - private static final int MIN_WAIT_FOR_SAVE = 3000; + private static final int MIN_WAIT_FOR_SAVE = 1000; private static final int MAX_WAIT_FOR_SAVE = 20000; + private static boolean interactive = true; + public static enum QResponse { NULL, QUIT, CANCEL_QUIT, FORCE_QUIT @@ -67,7 +69,7 @@ public class QuitHandler private static QResponse gotQuitResponse = QResponse.NULL; - private static QResponse setResponse(QResponse qresponse) + protected static QResponse setResponse(QResponse qresponse) { gotQuitResponse = qresponse; return qresponse; @@ -81,7 +83,7 @@ public class QuitHandler public static final Callable defaultCancelQuit = () -> { Console.debug("QuitHandler: (default) Quit action CANCELLED by user"); // reset - setResponse(QResponse.NULL); + setResponse(QResponse.CANCEL_QUIT); return null; }; @@ -105,8 +107,6 @@ public class QuitHandler defaultCancelQuit); } - private static boolean interactive = true; - public static QResponse getQuitResponse(boolean ui, Callable okQuit, Callable forceQuit, Callable cancelQuit) { @@ -147,14 +147,14 @@ public class QuitHandler { JvOptionPane.newOptionDialog() .setResponseHandler(JOptionPane.YES_OPTION, defaultOkQuit) - .setResponseHandler(JOptionPane.NO_OPTION, defaultCancelQuit) + .setResponseHandler(JOptionPane.NO_OPTION, cancelQuit) .showDialogOnTopAsync( new StringBuilder(MessageManager .getString("label.quit_jalview")) - .append("\n") - .append(MessageManager.getString( - "label.unsaved_changes")) - .toString(), + .append("\n") + .append(MessageManager + .getString("label.unsaved_changes")) + .toString(), MessageManager.getString("action.quit"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] @@ -168,6 +168,7 @@ public class QuitHandler if (got == QResponse.CANCEL_QUIT) { // reset + Console.debug("Cancelling quit. Resetting response to NULL"); setResponse(QResponse.NULL); // but return cancel return QResponse.CANCEL_QUIT; diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 9cec063..c8f9be6 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -625,7 +625,7 @@ public class Jalview2XML if (Cache.getDefault("DEBUG_DELAY_SAVE", false)) { - int n = 20; + int n = debugDelaySave; int i = 0; while (i < n) { @@ -791,7 +791,7 @@ public class Jalview2XML if (Cache.getDefault("DEBUG_DELAY_SAVE", false)) { - int n = 20; + int n = debugDelaySave; int i = 0; while (i < n) { @@ -6614,4 +6614,12 @@ public class Jalview2XML } return true; } + + // used for debugging and tests + private static int debugDelaySave = 20; + + public static void setDebugDelaySave(int n) + { + debugDelaySave = n; + } } -- 1.7.10.2