final Document doc = frame.getDocument();
if ( doc == null ) {
return false;
}
boolean saveDirectly = false;
SaveOptions options = doc.getSaveOptions();
if (options == null) {
if (OtherApplicationShim.shouldSaveDirectly(doc)) {
options = OtherApplicationShim.createExportOptions(doc);
if (options == null) {
// Something went wrong in all the redundant I/O required
// by OtherApplication.
showError(LOCALE.get("DirectSaveError"), null, frame);
return false;
}
doc.setSaveOptions(options);
saveDirectly = true;
}
else {
options = getSaveOptions(doc);
final FileChooser chooser =
Platform.getPlatform().getFileChooser();
File file = options.getFile();
file = chooser.saveFile(file, frame);
if (file == null) {
return false;
}
options.setFile(file);
// We've stopped exposing the multilayer TIFF option to users,
// but the option can slip through via persisted options.
if (options.isMultilayerTiff()) {
// Convert to a single-layer TIFF in this case.
final ImageExportOptions export =
SaveOptions.getExportOptions(options);
options = SaveOptions.createSidecarTiff(export);
}
LastSaveOptions = options;
doc.setSaveOptions(options);
}
} else
saveDirectly = options.shouldSaveDirectly();
frame.showWait(LOCALE.get("SaveMessage"));
final boolean isLzn = options.isLzn();
final File saveFile = options.getFile();
Throwable error = null;
// Throwable error = BlockingExecutor.execute(
// new BlockingExecutor.BlockingRunnable() {
// public void run() throws IOException {
frame.pause();
try {
TemporaryEditorCommitState state = doc.saveStart();
DocumentWriter.save(doc, frame, saveDirectly, null);
doc.saveEnd(state);
if (!isLzn && OtherApplication.isIntegrationEnabled()) {
final OtherApplication app =
(OtherApplication)doc.getSource();
if (app != null) {
app.postSave(
saveFile, saveDirectly, openPending
);
}
}
}
catch (Exception e) {
error = e;
}
finally {
frame.resume();
}
// }
// }
// );
frame.hideWait();
if (error != null) {
final File file = options.getFile();
showError(
LOCALE.get("SaveError", file.getPath()),
error, frame
);
return false;
}
doc.markClean();
// Don't let synthetic writeback options be persisted:
if ( saveDirectly ) {
doc.setSaveOptions(null);
}
final File file = options.getFile();
DocumentDatabase.addDocumentFile(file);
addToRecentFiles(file);
savePrefs();