dlg.showDialog();
if (dlg.getValue() != 1) return;
boolean zipRequired = false;
for (Layer l : layers) {
SessionLayerExporter ex = exporters.get(l);
if (ex != null && ex.requiresZip()) {
zipRequired = true;
break;
}
}
FileFilter joz = new ExtensionFileFilter("joz", "joz", tr("Session file (archive) (*.joz)"));
FileFilter jos = new ExtensionFileFilter("jos", "jos", tr("Session file (*.jos)"));
JFileChooser fc;
if (zipRequired) {
fc = createAndOpenFileChooser(false, false, tr("Save session"), joz, JFileChooser.FILES_ONLY, "lastDirectory");
} else {
fc = createAndOpenFileChooser(false, false, tr("Save session"), Arrays.asList(new FileFilter[]{jos, joz}), jos, JFileChooser.FILES_ONLY, "lastDirectory");
}
if (fc == null)
return;
File file = fc.getSelectedFile();
String fn = file.getName();
boolean zip;
FileFilter ff = fc.getFileFilter();
if (zipRequired) {
zip = true;
} else if (joz.equals(ff)) {
zip = true;
} else if (jos.equals(ff)) {
zip = false;
} else {
if (fn.toLowerCase().endsWith(".joz")) {
zip = true;
} else {
zip = false;
}
}
if (fn.indexOf('.') == -1) {
file = new File(file.getPath() + (zip ? ".joz" : ".jos"));
if (!SaveActionBase.confirmOverwrite(file))
return;
}
List<Layer> layersOut = new ArrayList<>();
for (Layer layer : layers) {
if (exporters.get(layer) == null || !exporters.get(layer).shallExport()) continue;
// TODO: resolve dependencies for layers excluded by the user
layersOut.add(layer);
}
int active = -1;
Layer activeLayer = Main.map.mapView.getActiveLayer();
if (activeLayer != null) {
active = layersOut.indexOf(activeLayer);
}
SessionWriter sw = new SessionWriter(layersOut, active, exporters, dependencies, zip);
try {
sw.write(file);
} catch (IOException ex) {
Main.error(ex);
HelpAwareOptionPane.showMessageDialogInEDT(
Main.parent,
tr("<html>Could not save session file ''{0}''.<br>Error is:<br>{1}</html>", file.getName(), ex.getMessage()),
tr("IO Error"),
JOptionPane.ERROR_MESSAGE,
null
);
}