Changeset 18135 in josm


Ignore:
Timestamp:
2021-08-20T14:18:17+02:00 (3 years ago)
Author:
Don-vip
Message:

see #16709 - fix #20755 - Display a notification while/after saving session files

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
3 edited

Legend:

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

    r16553 r18135  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.util.Collection;
     
    79import javax.swing.filechooser.FileFilter;
    810
     11import org.openstreetmap.josm.gui.Notification;
     12import org.openstreetmap.josm.gui.util.GuiHelper;
    913import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    1014import org.openstreetmap.josm.gui.widgets.FileChooserManager;
     15import org.openstreetmap.josm.tools.ImageProvider;
    1116import org.openstreetmap.josm.tools.Shortcut;
    1217
     
    137142                .openFileChooser();
    138143    }
     144
     145    /**
     146     * Show "saving file ..." notification and returns it, for future replacement.
     147     * @param filename filename of file to save
     148     * @return {@link Notification} to provide to {@link #showSavedNotification} once saving is successful
     149     * @since 18135
     150     */
     151    protected static Notification showSavingNotification(String filename) {
     152        Notification savingNotification = new Notification(tr("Saving file {0}...", filename)).setIcon(ImageProvider.get("save"));
     153        GuiHelper.runInEDT(savingNotification::show);
     154        return savingNotification;
     155    }
     156
     157    /**
     158     * Show "Successfully saved file" notification and returns it.
     159     * @param savingNotification {@link Notification} returned by {@link #showSavingNotification}
     160     * @param filename filename of file saved
     161     * @return {@code Notification} displayed
     162     * @since 18135
     163     */
     164    protected static Notification showSavedNotification(Notification savingNotification, String filename) {
     165        Notification doneNotification = new Notification(tr("Successfully saved file {0}", filename)).setIcon(ImageProvider.get("save"));
     166        GuiHelper.runInEDT(() -> doneNotification.replaceExisting(savingNotification));
     167        return doneNotification;
     168    }
    139169}
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r17628 r18135  
    1212import java.util.List;
    1313
    14 import javax.swing.ImageIcon;
    1514import javax.swing.JFileChooser;
    1615import javax.swing.JOptionPane;
     
    2726import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    2827import org.openstreetmap.josm.spi.preferences.Config;
    29 import org.openstreetmap.josm.tools.ImageProvider;
    3028import org.openstreetmap.josm.tools.Logging;
    3129import org.openstreetmap.josm.tools.Shortcut;
     
    137135            return false;
    138136
    139         ImageIcon icon = ImageProvider.get("save");
    140         Notification savingNotification = new Notification(tr("Saving file {0}...", file.getName())).setIcon(icon);
    141         GuiHelper.runInEDT(savingNotification::show);
     137        Notification savingNotification = showSavingNotification(file.getName());
    142138        try {
    143139            boolean exported = false;
     
    175171        }
    176172        addToFileOpenHistory(file);
    177         Notification doneNotification = new Notification(tr("Successfully saved file {0}", file.getName())).setIcon(icon);
    178         GuiHelper.runInEDT(() -> doneNotification.replaceExisting(savingNotification));
     173        showSavedNotification(savingNotification, file.getName());
    179174        return true;
    180175    }
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r18133 r18135  
    3838import org.openstreetmap.josm.gui.MapFrame;
    3939import org.openstreetmap.josm.gui.MapFrameListener;
     40import org.openstreetmap.josm.gui.Notification;
    4041import org.openstreetmap.josm.gui.layer.Layer;
    4142import org.openstreetmap.josm.gui.util.WindowGeometry;
     
    166167        SessionWriter sw = new SessionWriter(layersOut, active, exporters, dependencies, zip);
    167168        try {
     169            Notification savingNotification = showSavingNotification(file.getName());
    168170            sw.write(file);
    169171            SaveActionBase.addToFileOpenHistory(file);
     172            showSavedNotification(savingNotification, file.getName());
    170173        } catch (IOException ex) {
    171174            Logging.error(ex);
Note: See TracChangeset for help on using the changeset viewer.