Changeset 11093 in josm for trunk/src/org/openstreetmap


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

Location:
trunk/src/org/openstreetmap/josm
Files:
8 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();
  • trunk/src/org/openstreetmap/josm/actions/DeleteLayerAction.java

    r10436 r11093  
    1010
    1111import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    1213import org.openstreetmap.josm.gui.layer.Layer;
    1314import org.openstreetmap.josm.tools.Shortcut;
     
    3435            return;
    3536        }
    36         if (!Main.saveUnsavedModifications(Collections.singletonList(activeLayer), false)) {
     37        if (!SaveLayersDialog.saveUnsavedModifications(Collections.singletonList(activeLayer), SaveLayersDialog.Reason.DELETE)) {
    3738            return;
    3839        }
  • trunk/src/org/openstreetmap/josm/actions/ExitAction.java

    r6380 r11093  
    2828    @Override
    2929    public void actionPerformed(ActionEvent e) {
    30         Main.exitJosm(true, 0);
     30        Main.exitJosm(true, 0, null);
    3131    }
    3232}
  • trunk/src/org/openstreetmap/josm/actions/RestartAction.java

    r10212 r11093  
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
     19import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    1920import org.openstreetmap.josm.tools.ImageProvider;
    2021import org.openstreetmap.josm.tools.Shortcut;
     
    5960        String scriptRestart = System.getProperty("josm.restart");
    6061        if ("true".equals(scriptRestart)) {
    61             Main.exitJosm(true, 9);
     62            Main.exitJosm(true, 9, SaveLayersDialog.Reason.RESTART);
    6263        }
    6364
     
    8384     */
    8485    public static void restartJOSM() throws IOException {
    85         if (isRestartSupported() && !Main.exitJosm(false, 0)) return;
     86        if (isRestartSupported() && !Main.exitJosm(false, 0, SaveLayersDialog.Reason.RESTART)) return;
    8687        final List<String> cmd;
    8788        // special handling for OSX .app package
  • trunk/src/org/openstreetmap/josm/gui/MainFrame.java

    r10611 r11093  
    9292            @Override
    9393            public void windowClosing(final WindowEvent evt) {
    94                 Main.exitJosm(true, 0);
     94                Main.exitJosm(true, 0, null);
    9595            }
    9696        });
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DeleteLayerAction.java

    r11078 r11093  
    1111import javax.swing.JMenuItem;
    1212
    13 import org.openstreetmap.josm.Main;
    1413import org.openstreetmap.josm.gui.dialogs.IEnabledStateUpdating;
    1514import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
    1615import org.openstreetmap.josm.gui.help.HelpUtil;
     16import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    1717import org.openstreetmap.josm.gui.layer.Layer;
    1818import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
     
    4444        if (selectedLayers.isEmpty())
    4545            return;
    46         if (!Main.saveUnsavedModifications(selectedLayers, false))
     46        if (!SaveLayersDialog.saveUnsavedModifications(selectedLayers, SaveLayersDialog.Reason.DELETE))
    4747            return;
    4848        for (Layer l: selectedLayers) {
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r11017 r11093  
    1919import java.beans.PropertyChangeEvent;
    2020import java.beans.PropertyChangeListener;
     21import java.util.ArrayList;
    2122import java.util.List;
    2223import java.util.concurrent.CancellationException;
     
    4748import org.openstreetmap.josm.gui.io.SaveLayersModel.Mode;
    4849import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
     50import org.openstreetmap.josm.gui.layer.Layer;
    4951import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    5052import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor;
     
    5860
    5961public class SaveLayersDialog extends JDialog implements TableModelListener {
    60     public enum UserAction {
     62
     63    /**
     64     * The cause for requesting an action on unsaved modifications
     65     */
     66    public enum Reason {
     67        /** deleting a layer */
     68        DELETE,
     69        /** exiting JOSM */
     70        EXIT,
     71        /* restarting JOSM */
     72        RESTART
     73    }
     74
     75    private enum UserAction {
    6176        /** save/upload layers was successful, proceed with operation */
    6277        PROCEED,
     
    7691
    7792    private final JButton saveAndProceedActionButton = new JButton(saveAndProceedAction);
     93
     94    /**
     95     * Asks user to perform "save layer" operations (save on disk and/or upload data to server) before data layers deletion.
     96     *
     97     * @param selectedLayers The layers to check. Only instances of {@link AbstractModifiableLayer} are considered.
     98     * @param reason the cause for requesting an action on unsaved modifications
     99     * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations.
     100     *         {@code false} if the user cancels.
     101     * @since 11093
     102     */
     103    public static boolean saveUnsavedModifications(Iterable<? extends Layer> selectedLayers, Reason reason) {
     104        SaveLayersDialog dialog = new SaveLayersDialog(Main.parent);
     105        List<AbstractModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>();
     106        for (Layer l: selectedLayers) {
     107            if (!(l instanceof AbstractModifiableLayer)) {
     108                continue;
     109            }
     110            AbstractModifiableLayer odl = (AbstractModifiableLayer) l;
     111            if (odl.isModified() &&
     112                    ((!odl.isSavable() && !odl.isUploadable()) ||
     113                            odl.requiresSaveToFile() ||
     114                            (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) {
     115                layersWithUnmodifiedChanges.add(odl);
     116            }
     117        }
     118        dialog.prepareForSavingAndUpdatingLayers(reason);
     119        if (!layersWithUnmodifiedChanges.isEmpty()) {
     120            dialog.getModel().populate(layersWithUnmodifiedChanges);
     121            dialog.setVisible(true);
     122            switch(dialog.getUserAction()) {
     123                case PROCEED: return true;
     124                case CANCEL:
     125                default: return false;
     126            }
     127        }
     128
     129        return true;
     130    }
    78131
    79132    /**
     
    131184    }
    132185
    133     public void prepareForSavingAndUpdatingLayersBeforeExit() {
    134         setTitle(tr("Unsaved changes - Save/Upload before exiting?"));
    135         this.saveAndProceedAction.initForSaveAndExit();
    136         this.discardAndProceedAction.initForDiscardAndExit();
    137     }
    138 
    139     public void prepareForSavingAndUpdatingLayersBeforeDelete() {
    140         setTitle(tr("Unsaved changes - Save/Upload before deleting?"));
    141         this.saveAndProceedAction.initForSaveAndDelete();
    142         this.discardAndProceedAction.initForDiscardAndDelete();
     186    public void prepareForSavingAndUpdatingLayers(final Reason reason) {
     187        switch (reason) {
     188            case EXIT:
     189                setTitle(tr("Unsaved changes - Save/Upload before exiting?"));
     190                break;
     191            case DELETE:
     192                setTitle(tr("Unsaved changes - Save/Upload before deleting?"));
     193                break;
     194            case RESTART:
     195                setTitle(tr("Unsaved changes - Save/Upload before restarting?"));
     196                break;
     197        }
     198        this.saveAndProceedAction.initForReason(reason);
     199        this.discardAndProceedAction.initForReason(reason);
    143200    }
    144201
     
    323380    class DiscardAndProceedAction extends AbstractAction implements PropertyChangeListener {
    324381        DiscardAndProceedAction() {
    325             initForDiscardAndExit();
    326         }
    327 
    328         public void initForDiscardAndExit() {
    329             putValue(NAME, tr("Exit now!"));
    330             putValue(SHORT_DESCRIPTION, tr("Exit JOSM without saving. Unsaved changes are lost."));
    331             putValue(SMALL_ICON, ImageProvider.get("exit"));
    332         }
    333 
    334         public void initForDiscardAndDelete() {
    335             putValue(NAME, tr("Delete now!"));
    336             putValue(SHORT_DESCRIPTION, tr("Delete layers without saving. Unsaved changes are lost."));
    337             putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     382            initForReason(Reason.EXIT);
     383        }
     384
     385        public void initForReason(Reason reason) {
     386            switch (reason) {
     387                case EXIT:
     388                    putValue(NAME, tr("Exit now!"));
     389                    putValue(SHORT_DESCRIPTION, tr("Exit JOSM without saving. Unsaved changes are lost."));
     390                    putValue(SMALL_ICON, ImageProvider.get("exit"));
     391                    break;
     392                case RESTART:
     393                    putValue(NAME, tr("Restart now!"));
     394                    putValue(SHORT_DESCRIPTION, tr("Restart JOSM without saving. Unsaved changes are lost."));
     395                    putValue(SMALL_ICON, ImageProvider.get("restart"));
     396                    break;
     397                case DELETE:
     398                    putValue(NAME, tr("Delete now!"));
     399                    putValue(SHORT_DESCRIPTION, tr("Delete layers without saving. Unsaved changes are lost."));
     400                    putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
     401                    break;
     402            }
     403
    338404        }
    339405
     
    385451
    386452        SaveAndProceedAction() {
    387             initForSaveAndExit();
    388         }
    389 
    390         public void initForSaveAndExit() {
    391             putValue(NAME, tr("Perform actions before exiting"));
    392             putValue(SHORT_DESCRIPTION, tr("Exit JOSM with saving. Unsaved changes are uploaded and/or saved."));
    393             putValue(BASE_ICON, ImageProvider.get("exit"));
    394             redrawIcon();
    395         }
    396 
    397         public void initForSaveAndDelete() {
    398             putValue(NAME, tr("Perform actions before deleting"));
    399             putValue(SHORT_DESCRIPTION, tr("Save/Upload layers before deleting. Unsaved changes are not lost."));
    400             putValue(BASE_ICON, ImageProvider.get("dialogs", "delete"));
     453            initForReason(Reason.EXIT);
     454        }
     455
     456        public void initForReason(Reason reason) {
     457            switch (reason) {
     458                case EXIT:
     459                    putValue(NAME, tr("Perform actions before exiting"));
     460                    putValue(SHORT_DESCRIPTION, tr("Exit JOSM with saving. Unsaved changes are uploaded and/or saved."));
     461                    putValue(BASE_ICON, ImageProvider.get("exit"));
     462                    break;
     463                case RESTART:
     464                    putValue(NAME, tr("Perform actions before restarting"));
     465                    putValue(SHORT_DESCRIPTION, tr("Restart JOSM with saving. Unsaved changes are uploaded and/or saved."));
     466                    putValue(BASE_ICON, ImageProvider.get("restart"));
     467                    break;
     468                case DELETE:
     469                    putValue(NAME, tr("Perform actions before deleting"));
     470                    putValue(SHORT_DESCRIPTION, tr("Save/Upload layers before deleting. Unsaved changes are not lost."));
     471                    putValue(BASE_ICON, ImageProvider.get("dialogs", "delete"));
     472                    break;
     473            }
    401474            redrawIcon();
    402475        }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r10627 r11093  
    145145            break;
    146146        case "handleQuitRequestWith":
    147             boolean closed = Main.exitJosm(false, 0);
     147            boolean closed = Main.exitJosm(false, 0, null);
    148148            if (args[1] != null) {
    149149                try {
Note: See TracChangeset for help on using the changeset viewer.