Ignore:
Timestamp:
2021-10-19T01:26:15+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #20913 - fix handling of GPX files in sessions (patch by Bjoeni)

  • revert r17659 (except for unit tests) - see #20233
    • don't save GPX track and marker colors in session file anymore, but in the GPX files as extensions (like before)
    • don't ask to save unmodified GPX file
    • don't override global color settings when individual track doesn't have a color
  • ask user to save changes to GPX file when any drawing settings or marker colors have changed (currently only happens for track colors)
  • save marker color values to session even when corresponding GPX layer has already been deleted
  • save alpha values for GPX marker colors
  • added explanation to the "overwrite GPX file" dialog
  • inform user if not all files referenced by the session file are saved yet
  • allow user to save all files that are not included in the *.jos/*.joz but are only referenced in the session file
  • display * next to GPX layers that need to be saved (move isDirty() logic from OsmDataLayer to AbstractModifiableLayer)
Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

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

    r16913 r18287  
    1515import javax.swing.SwingConstants;
    1616
    17 import org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeListener;
     17import org.openstreetmap.josm.data.gpx.GpxConstants;
    1818import org.openstreetmap.josm.gui.ExtendedDialog;
    1919import org.openstreetmap.josm.gui.MainApplication;
     20import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    2021import org.openstreetmap.josm.gui.layer.GpxLayer;
    2122import org.openstreetmap.josm.gui.layer.Layer;
    2223import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    2324import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    24 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2525import org.openstreetmap.josm.gui.layer.SaveToFile;
    2626import org.openstreetmap.josm.gui.util.GuiHelper;
     
    3838
    3939    private final PropertyChangeListener updateOnRequireSaveChange = evt -> {
    40         if (OsmDataLayer.REQUIRES_SAVE_TO_DISK_PROP.equals(evt.getPropertyName())) {
     40        if (AbstractModifiableLayer.REQUIRES_SAVE_TO_DISK_PROP.equals(evt.getPropertyName())) {
    4141            updateEnabledState();
    4242        }
    4343    };
    44 
    45     private final GpxDataChangeListener updateOnRequireSaveChangeGpx = evt -> updateEnabledState();
    4644
    4745    /**
     
    6967            public void layerAdded(LayerAddEvent e) {
    7068                Layer l = e.getAddedLayer();
    71                 if (l instanceof OsmDataLayer) {
     69                if (l instanceof AbstractModifiableLayer) {
    7270                    l.addPropertyChangeListener(updateOnRequireSaveChange);
    73                 }
    74                 if (l instanceof GpxLayer) {
    75                     ((GpxLayer) l).data.addWeakChangeListener(updateOnRequireSaveChangeGpx);
    7671                }
    7772                super.layerAdded(e);
     
    8176            public void layerRemoving(LayerRemoveEvent e) {
    8277                Layer l = e.getRemovedLayer();
    83                 if (l instanceof OsmDataLayer) {
     78                if (l instanceof AbstractModifiableLayer) {
    8479                    l.removePropertyChangeListener(updateOnRequireSaveChange);
    85                 }
    86                 if (l instanceof GpxLayer) {
    87                     ((GpxLayer) l).data.removeChangeListener(updateOnRequireSaveChangeGpx);
    8880                }
    8981                super.layerRemoving(e);
     
    114106
    115107        // Ask for overwrite in case of GpxLayer
    116         if (f != null && layer instanceof GpxLayer && !Config.getPref().getBoolean("gpx.export.overwrite", false)) {
     108        if (f != null
     109                && layer instanceof GpxLayer
     110                && (((GpxLayer) layer).data == null
     111                || !GpxConstants.JOSM_CREATOR_NAME.equals(((GpxLayer) layer).data.creator))
     112                && !Config.getPref().getBoolean("gpx.export.overwrite", false)) {
     113
    117114            JPanel p = new JPanel(new GridBagLayout());
    118             JLabel label = new JLabel(tr("File {0} exists. Overwrite?", f.getName()));
     115            JLabel label = new JLabel("<html>"
     116                    + tr("The file \"{0}\" will be modified.<br>Would you like to overwrite the existing file?", f.getName())
     117                    + "</html>");
    119118            label.setHorizontalAlignment(SwingConstants.CENTER);
    120             JCheckBox remember = new JCheckBox(tr("Remember choice"));
     119            JCheckBox remember = new JCheckBox(tr("Always overwrite GPX files without asking"));
    121120            remember.setHorizontalAlignment(SwingConstants.CENTER);
    122121            p.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 10));
     
    125124                    MainApplication.getMainFrame(),
    126125                    tr("Overwrite"),
    127                     tr("Overwrite"), tr("Cancel"))
    128                 .setButtonIcons("save_as", "cancel")
     126                    tr("Overwrite"), tr("Save As..."), tr("Cancel"))
     127                .setButtonIcons("save", "save_as", "cancel")
    129128                .setContent(p);
    130             if (dialog.showDialog().getValue() != 1) {
     129            int val = dialog.showDialog().getValue();
     130            if (val == 1) {
     131                Config.getPref().putBoolean("gpx.export.overwrite", remember.isSelected());
     132            } else if (val == 2) {
    131133                f = null;
    132             } else if (remember.isSelected()) {
    133                 Config.getPref().putBoolean("gpx.export.overwrite", true);
     134            } else {
     135                return null;
    134136            }
    135137        }
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r18135 r18287  
    2020import java.util.Set;
    2121import java.util.stream.Collectors;
     22import java.util.stream.Stream;
    2223
    2324import javax.swing.BorderFactory;
     
    3334import javax.swing.filechooser.FileFilter;
    3435
     36import org.openstreetmap.josm.data.preferences.BooleanProperty;
    3537import org.openstreetmap.josm.gui.ExtendedDialog;
    3638import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    3941import org.openstreetmap.josm.gui.MapFrameListener;
    4042import org.openstreetmap.josm.gui.Notification;
     43import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    4144import org.openstreetmap.josm.gui.layer.Layer;
    4245import org.openstreetmap.josm.gui.util.WindowGeometry;
     
    6164    private transient MultiMap<Layer, Layer> dependencies;
    6265
     66    private static final BooleanProperty SAVE_LOCAL_FILES_PROPERTY = new BooleanProperty("session.savelocal", true);
     67
    6368    /**
    6469     * Constructs a new {@code SessionSaveAsAction}.
     
    158163                .filter(layer -> exporters.get(layer) != null && exporters.get(layer).shallExport())
    159164                .collect(Collectors.toList());
     165
     166        Stream<Layer> layersToSaveStream = layersOut.stream()
     167                .filter(layer -> layer.isSavable()
     168                        && layer instanceof AbstractModifiableLayer
     169                        && ((AbstractModifiableLayer) layer).requiresSaveToFile()
     170                        && exporters.get(layer) != null
     171                        && !exporters.get(layer).requiresZip());
     172
     173        if (SAVE_LOCAL_FILES_PROPERTY.get()) {
     174            // individual files must be saved before the session file as the location may change
     175            if (layersToSaveStream
     176                .map(layer -> SaveAction.getInstance().doSave(layer, true))
     177                .collect(Collectors.toList()) // force evaluation of all elements
     178                .contains(false)) {
     179
     180                new Notification(tr("Not all local files referenced by the session file could be saved."
     181                        + "<br>Make sure you save them before closing JOSM."))
     182                    .setIcon(JOptionPane.WARNING_MESSAGE)
     183                    .setDuration(Notification.TIME_LONG)
     184                    .show();
     185            }
     186        } else if (layersToSaveStream.anyMatch(l -> true)) {
     187            new Notification(tr("Not all local files referenced by the session file are saved yet."
     188                    + "<br>Make sure you save them before closing JOSM."))
     189                .setIcon(JOptionPane.INFORMATION_MESSAGE)
     190                .setDuration(Notification.TIME_LONG)
     191                .show();
     192        }
    160193
    161194        int active = -1;
     
    251284
    252285        protected final Component build() {
     286            JPanel op = new JPanel(new GridBagLayout());
    253287            JPanel ip = new JPanel(new GridBagLayout());
    254288            for (Layer layer : layers) {
     
    273307            final JTabbedPane tabs = new JTabbedPane();
    274308            tabs.addTab(tr("Layers"), p);
    275             return tabs;
     309            op.add(tabs, GBC.eol().fill());
     310            JCheckBox chkSaveLocal = new JCheckBox(tr("Save all local files to disk"), SAVE_LOCAL_FILES_PROPERTY.get());
     311            chkSaveLocal.addChangeListener(l -> {
     312                SAVE_LOCAL_FILES_PROPERTY.put(chkSaveLocal.isSelected());
     313            });
     314            op.add(chkSaveLocal);
     315            return op;
    276316        }
    277317
Note: See TracChangeset for help on using the changeset viewer.