File selectedFile = null;
/**
- * On user selecting a file to save to, this response is run to check if the
- * file already exists, and if so show a dialog to prompt for confirmation of
- * overwrite.
- */
- RunResponse overwriteCheck = new RunResponse(JalviewFileChooser.APPROVE_OPTION)
- {
- @Override
- public void run()
- {
- selectedFile = getSelectedFile();
-
- if (selectedFile == null)
- {
- // Workaround for Java 9,10 on OSX - no selected file, but there is a
- // filename typed in
- // TODO is this needed in Java 8 or 11?
- try
- {
- String filename = ((BasicFileChooserUI) getUI()).getFileName();
- if (filename != null && filename.length() > 0)
- {
- selectedFile = new File(getCurrentDirectory(), filename);
- }
- } catch (Throwable x)
- {
- System.err.println(
- "Unexpected exception when trying to get filename.");
- x.printStackTrace();
- }
- }
- if (selectedFile == null)
- {
- setReturnValue(JalviewFileChooser.CANCEL_OPTION);
- return;
- }
- // JBP Note - this code was executed regardless of 'SAVE' being pressed
- // need to see if there were side effects
- if (getFileFilter() instanceof JalviewFileFilter)
- {
- JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();
-
- if (!jvf.accept(getSelectedFile()))
- {
- String withExtension = getSelectedFile() + "."
- + jvf.getAcceptableExtension();
- setSelectedFile(new File(withExtension));
- }
- }
- // All good, so we continue to save
- setReturnValue(JalviewFileChooser.APPROVE_OPTION);
-
- // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE
- // USER PROMPTED FOR A NEW FILENAME
- if (!Jalview.isJS())
- {
- if (getSelectedFile().exists())
- {
- // JAL-3048 - may not need to raise this for browser saves
- // yes/no cancel
- int confirm = JvOptionPane.showConfirmDialog(JalviewFileChooser.this,
- MessageManager.getString("label.overwrite_existing_file"),
- MessageManager.getString("label.file_already_exists"),
- JvOptionPane.YES_NO_OPTION);
-
- if (confirm != JvOptionPane.YES_OPTION)
- {
- setReturnValue(JalviewFileChooser.CANCEL_OPTION);
- }
- }
- }
- };
- };
-
- /**
* Factory method to return a file chooser that offers readable alignment file
* formats
*
}
@Override
- public DialogRunnerI addResponse(RunResponse action)
+ public DialogRunnerI addResponse(Object response, RunResponse action)
{
- return runner.addResponse(action);
+ return runner.addResponse(response, action);
}
/**