X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fjbgui%2FQuitHandler.java;h=15cc37a4a33836c5083b450978ecae7e8289249b;hb=69f09dd6dbf67c00c27fdcfecbbcc932e7eac6a9;hp=56e23aabc9664c267398285f4a1c8ebfebad21c6;hpb=74755239a1beeeaba47c0fee8bfc14f8395e65ac;p=jalview.git diff --git a/src/jalview/jbgui/QuitHandler.java b/src/jalview/jbgui/QuitHandler.java index 56e23aa..15cc37a 100644 --- a/src/jalview/jbgui/QuitHandler.java +++ b/src/jalview/jbgui/QuitHandler.java @@ -1,10 +1,13 @@ package jalview.jbgui; +import java.io.File; + import javax.swing.JFrame; import javax.swing.JOptionPane; import com.formdev.flatlaf.extras.FlatDesktop; +import jalview.io.BackupFiles; import jalview.util.MessageManager; public class QuitHandler @@ -12,37 +15,44 @@ public class QuitHandler public static void setQuitHandler() { FlatDesktop.setQuitHandler(response -> { + // confirm quit if needed and wanted boolean confirmQuit = jalview.bin.Cache .getDefault(jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT, true); - boolean canQuit = !confirmQuit; - int n; + /* + if undostack is empty + confirmQuit = false + */ + int n = confirmQuit ? JOptionPane.CANCEL_OPTION + : JOptionPane.OK_OPTION; + + // if going to confirm, do it before the save in progress check to give + // the save time to finish! if (confirmQuit) { - // ensure Jalview window is brought to front for Quit confirmation - // window to be visible - - // this method of raising the Jalview window is broken in java - // jalviewDesktop.setVisible(true); - // jalviewDesktop.toFront(); - - // a better hack which works instead - JFrame dialogParent = new JFrame(); - dialogParent.setAlwaysOnTop(true); - - n = JOptionPane.showConfirmDialog(dialogParent, - MessageManager.getString("label.quit_jalview"), + n = frameOnTop(MessageManager.getString("label.quit_jalview"), MessageManager.getString("action.quit"), - JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, - null); + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); - dialogParent.setAlwaysOnTop(false); - dialogParent.dispose(); } - else + + if (BackupFiles.hasSavesInProgress()) { - n = JOptionPane.OK_OPTION; + // sleep 1 + // ... + + StringBuilder messageSB = new StringBuilder( + MessageManager.getString("label.save_in_progress")); + for (File file : BackupFiles.savesInProgressFiles()) + { + messageSB.append("\n"); + messageSB.append(file.getName()); + } + n = frameOnTop(messageSB.toString(), + MessageManager.getString("action.force_quit"), + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); } - canQuit = (n == JOptionPane.OK_OPTION); + + boolean canQuit = (n == JOptionPane.OK_OPTION); if (canQuit) { response.performQuit(); @@ -54,4 +64,28 @@ public class QuitHandler }); } + public static int frameOnTop(String label, String actionString, + int JOPTIONPANE_OPTION, int JOPTIONPANE_MESSAGETYPE) + { + // ensure Jalview window is brought to front for Quit confirmation + // window to be visible + + // this method of raising the Jalview window is broken in java + // jalviewDesktop.setVisible(true); + // jalviewDesktop.toFront(); + + // a better hack which works instead + + JFrame dialogParent = new JFrame(); + dialogParent.setAlwaysOnTop(true); + + int n = JOptionPane.showConfirmDialog(dialogParent, label, actionString, + JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE); + + dialogParent.setAlwaysOnTop(false); + dialogParent.dispose(); + + return n; + } + }