X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FStructureViewerBase.java;h=01a3c2db0bf3b95e761f5ee2e5d5f1cd0242a83d;hb=9b943e6d79fd92f78a61916a6f6eb047ba0a9755;hp=6c3f6d8a279152dca86a95a2850e94f3272ef719;hpb=c1f5dd54ab8caa7e76ca50f9c3a85f2731b66862;p=jalview.git diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 6c3f6d8..01a3c2d 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -26,6 +26,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.beans.PropertyVetoException; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -1251,6 +1252,20 @@ public abstract class StructureViewerBase extends GStructureViewer return session; } + private static boolean quitClose = false; + + public static void setQuitClose(boolean b) + { + quitClose = b; + } + + @Override + public boolean stillRunning() + { + AAStructureBindingModel binding = getBinding(); + return binding != null && binding.isViewerRunning(); + } + /** * Close down this instance of Jalview's Chimera viewer, giving the user the * option to close the associated Chimera window (process). They may wish to @@ -1263,24 +1278,48 @@ public abstract class StructureViewerBase extends GStructureViewer public void closeViewer(boolean forceClose) { AAStructureBindingModel binding = getBinding(); - if (binding != null && binding.isViewerRunning()) + if (stillRunning()) { if (!forceClose) { String viewerName = getViewerName(); - String prompt = MessageManager - .formatMessage("label.confirm_close_viewer", new Object[] - { binding.getViewerTitle(viewerName, false), viewerName }); - prompt = JvSwingUtils.wrapTooltip(true, prompt); - int confirm = JvOptionPane.showConfirmDialog(this, prompt, - MessageManager.getString("label.close_viewer"), - JvOptionPane.YES_NO_CANCEL_OPTION); + + int confirm = JvOptionPane.CANCEL_OPTION; + if (QuitHandler.quitting()) + { + // already asked about closing external windows + confirm = quitClose ? JvOptionPane.YES_OPTION + : JvOptionPane.NO_OPTION; + } + else + { + String prompt = MessageManager + .formatMessage("label.confirm_close_viewer", new Object[] + { binding.getViewerTitle(viewerName, false), + viewerName }); + prompt = JvSwingUtils.wrapTooltip(true, prompt); + String title = MessageManager.getString("label.close_viewer"); + confirm = showCloseDialog(title, prompt); + } + /* * abort closure if user hits escape or Cancel */ if (confirm == JvOptionPane.CANCEL_OPTION || confirm == JvOptionPane.CLOSED_OPTION) { + // abort possible quit handling if CANCEL chosen + if (confirm == JvOptionPane.CANCEL_OPTION) + { + try + { + // this is a bit futile + this.setClosed(false); + } catch (PropertyVetoException e) + { + } + QuitHandler.abortQuit(); + } return; } forceClose = confirm == JvOptionPane.YES_OPTION; @@ -1300,6 +1339,16 @@ public abstract class StructureViewerBase extends GStructureViewer dispose(); } + private int showCloseDialog(final String title, final String prompt) + { + int confirmResponse = JvOptionPane.CANCEL_OPTION; + confirmResponse = JvOptionPane.showConfirmDialog(this, prompt, + MessageManager.getString("label.close_viewer"), + JvOptionPane.YES_NO_CANCEL_OPTION, + JvOptionPane.WARNING_MESSAGE); + return confirmResponse; + } + @Override public void showHelp_actionPerformed() { @@ -1330,4 +1379,5 @@ public abstract class StructureViewerBase extends GStructureViewer && viewerActionMenu.getItemCount() > 0 && viewerActionMenu.isVisible(); } + }