* @param exit {@code true} if JOSM is exiting, {@code false} otherwise.
* @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations. {@code false} if the user cancels.
* @since 5519
*/
public static boolean saveUnsavedModifications(Iterable<? extends Layer> selectedLayers, boolean exit) {
SaveLayersDialog dialog = new SaveLayersDialog(parent);
List<ModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>();
for (Layer l: selectedLayers) {
if (!(l instanceof ModifiableLayer)) {
continue;
}
ModifiableLayer odl = (ModifiableLayer)l;
if ((odl.requiresSaveToFile() || (odl.requiresUploadToServer() && !odl.isUploadDiscouraged())) && odl.isModified()) {
layersWithUnmodifiedChanges.add(odl);
}
}
if (exit) {
dialog.prepareForSavingAndUpdatingLayersBeforeExit();
} else {
dialog.prepareForSavingAndUpdatingLayersBeforeDelete();
}
if (!layersWithUnmodifiedChanges.isEmpty()) {
dialog.getModel().populate(layersWithUnmodifiedChanges);
dialog.setVisible(true);
switch(dialog.getUserAction()) {
case CANCEL: return false;
case PROCEED: return true;
default: return false;
}
}