Ignore:
Timestamp:
2016-10-07T21:55:54+02:00 (8 years ago)
Author:
simon04
Message:

fix #13320 - Use restart text and icon in unsaved changes dialog

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r11092 r11093  
    7777import org.openstreetmap.josm.gui.ProgramArguments.Option;
    7878import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    79 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    8079import org.openstreetmap.josm.gui.layer.Layer;
    8180import org.openstreetmap.josm.gui.layer.MainLayerManager;
     
    795794
    796795    /**
    797      * Asks user to perform "save layer" operations (save on disk and/or upload data to server) for all
    798      * {@link AbstractModifiableLayer} before JOSM exits.
    799      * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations.
    800      *         {@code false} if the user cancels.
    801      * @since 2025
    802      */
    803     public static boolean saveUnsavedModifications() {
    804         if (!isDisplayingMapView()) return true;
    805         return saveUnsavedModifications(getLayerManager().getLayersOfType(AbstractModifiableLayer.class), true);
    806     }
    807 
    808     /**
    809      * Asks user to perform "save layer" operations (save on disk and/or upload data to server) before data layers deletion.
    810      *
    811      * @param selectedLayers The layers to check. Only instances of {@link AbstractModifiableLayer} are considered.
    812      * @param exit {@code true} if JOSM is exiting, {@code false} otherwise.
    813      * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations.
    814      *         {@code false} if the user cancels.
    815      * @since 5519
    816      */
    817     public static boolean saveUnsavedModifications(Iterable<? extends Layer> selectedLayers, boolean exit) {
    818         SaveLayersDialog dialog = new SaveLayersDialog(parent);
    819         List<AbstractModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>();
    820         for (Layer l: selectedLayers) {
    821             if (!(l instanceof AbstractModifiableLayer)) {
    822                 continue;
    823             }
    824             AbstractModifiableLayer odl = (AbstractModifiableLayer) l;
    825             if (odl.isModified() &&
    826                     ((!odl.isSavable() && !odl.isUploadable()) ||
    827                      odl.requiresSaveToFile() ||
    828                      (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) {
    829                 layersWithUnmodifiedChanges.add(odl);
    830             }
    831         }
    832         if (exit) {
    833             dialog.prepareForSavingAndUpdatingLayersBeforeExit();
    834         } else {
    835             dialog.prepareForSavingAndUpdatingLayersBeforeDelete();
    836         }
    837         if (!layersWithUnmodifiedChanges.isEmpty()) {
    838             dialog.getModel().populate(layersWithUnmodifiedChanges);
    839             dialog.setVisible(true);
    840             switch(dialog.getUserAction()) {
    841             case PROCEED: return true;
    842             case CANCEL:
    843             default: return false;
    844             }
    845         }
    846 
    847         return true;
    848     }
    849 
    850     /**
    851796     * Closes JOSM and optionally terminates the Java Virtual Machine (JVM).
    852797     * If there are some unsaved data layers, asks first for user confirmation.
    853798     * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code.
    854799     * @param exitCode The return code
     800     * @param reason the reason for exiting
    855801     * @return {@code true} if JOSM has been closed, {@code false} if the user has cancelled the operation.
    856      * @since 3378
    857      */
    858     public static boolean exitJosm(boolean exit, int exitCode) {
    859         if (Main.saveUnsavedModifications()) {
     802     * @since 11093 (3378 with a different function signature)
     803     */
     804    public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) {
     805        if (SaveLayersDialog.saveUnsavedModifications(getLayerManager().getLayers(), reason != null ? reason : SaveLayersDialog.Reason.EXIT)) {
    860806            if (Main.main != null) {
    861807                Main.main.shutdown();
Note: See TracChangeset for help on using the changeset viewer.