Changeset 17628 in josm


Ignore:
Timestamp:
2021-03-21T17:05:43+01:00 (4 years ago)
Author:
simon04
Message:

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

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

Legend:

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

    r16827 r17628  
    1212import java.util.List;
    1313
     14import javax.swing.ImageIcon;
    1415import javax.swing.JFileChooser;
    1516import javax.swing.JOptionPane;
     
    1920import org.openstreetmap.josm.gui.ExtendedDialog;
    2021import org.openstreetmap.josm.gui.MainApplication;
     22import org.openstreetmap.josm.gui.Notification;
    2123import org.openstreetmap.josm.gui.io.importexport.FileExporter;
    2224import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
     
    2527import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    2628import org.openstreetmap.josm.spi.preferences.Config;
     29import org.openstreetmap.josm.tools.ImageProvider;
    2730import org.openstreetmap.josm.tools.Logging;
    2831import org.openstreetmap.josm.tools.Shortcut;
     
    134137            return false;
    135138
     139        ImageIcon icon = ImageProvider.get("save");
     140        Notification savingNotification = new Notification(tr("Saving file {0}...", file.getName())).setIcon(icon);
     141        GuiHelper.runInEDT(savingNotification::show);
    136142        try {
    137143            boolean exported = false;
     
    169175        }
    170176        addToFileOpenHistory(file);
     177        Notification doneNotification = new Notification(tr("Successfully saved file {0}", file.getName())).setIcon(icon);
     178        GuiHelper.runInEDT(() -> doneNotification.replaceExisting(savingNotification));
    171179        return true;
    172180    }
  • trunk/src/org/openstreetmap/josm/gui/Notification.java

    r16314 r17628  
    214214    }
    215215
     216    /**
     217     * Display the notification by replacing the given queued/displaying notification
     218     * @param oldNotification the notification to replace
     219     * @since 17628
     220     */
     221    public void replaceExisting(Notification oldNotification) {
     222        NotificationManager.getInstance().replaceExistingNotification(oldNotification, this);
     223    }
     224
    216225    private Object getContentTextOrComponent() {
    217226        return content instanceof JTextComponent ? ((JTextComponent) content).getText() : content;
  • trunk/src/org/openstreetmap/josm/gui/NotificationManager.java

    r16913 r17628  
    9292     * @see Notification#show()
    9393     */
    94     public void showNotification(Notification note) {
     94    void showNotification(Notification note) {
    9595        synchronized (queue) {
    9696            if (Objects.equals(note, currentNotification) || Objects.equals(note, queue.peekLast())) {
     
    9999            }
    100100            queue.add(note);
     101            processQueue();
     102        }
     103    }
     104
     105    /**
     106     * Show the given notification by replacing the given queued/displaying notification
     107     * @param oldNotification the notification to replace
     108     * @param newNotification the notification to show
     109     */
     110    void replaceExistingNotification(Notification oldNotification, Notification newNotification) {
     111        synchronized (queue) {
     112            if (Objects.equals(oldNotification, currentNotification)) {
     113                stopHideTimer();
     114            } else {
     115                queue.remove(oldNotification);
     116            }
     117            showNotification(newNotification);
    101118            processQueue();
    102119        }
Note: See TracChangeset for help on using the changeset viewer.