Changeset 18287 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2021-10-19T01:26:15+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SaveAction.java
r16913 r18287 15 15 import javax.swing.SwingConstants; 16 16 17 import org.openstreetmap.josm.data.gpx.Gpx Data.GpxDataChangeListener;17 import org.openstreetmap.josm.data.gpx.GpxConstants; 18 18 import org.openstreetmap.josm.gui.ExtendedDialog; 19 19 import org.openstreetmap.josm.gui.MainApplication; 20 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer; 20 21 import org.openstreetmap.josm.gui.layer.GpxLayer; 21 22 import org.openstreetmap.josm.gui.layer.Layer; 22 23 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 23 24 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer;25 25 import org.openstreetmap.josm.gui.layer.SaveToFile; 26 26 import org.openstreetmap.josm.gui.util.GuiHelper; … … 38 38 39 39 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())) { 41 41 updateEnabledState(); 42 42 } 43 43 }; 44 45 private final GpxDataChangeListener updateOnRequireSaveChangeGpx = evt -> updateEnabledState();46 44 47 45 /** … … 69 67 public void layerAdded(LayerAddEvent e) { 70 68 Layer l = e.getAddedLayer(); 71 if (l instanceof OsmDataLayer) {69 if (l instanceof AbstractModifiableLayer) { 72 70 l.addPropertyChangeListener(updateOnRequireSaveChange); 73 }74 if (l instanceof GpxLayer) {75 ((GpxLayer) l).data.addWeakChangeListener(updateOnRequireSaveChangeGpx);76 71 } 77 72 super.layerAdded(e); … … 81 76 public void layerRemoving(LayerRemoveEvent e) { 82 77 Layer l = e.getRemovedLayer(); 83 if (l instanceof OsmDataLayer) {78 if (l instanceof AbstractModifiableLayer) { 84 79 l.removePropertyChangeListener(updateOnRequireSaveChange); 85 }86 if (l instanceof GpxLayer) {87 ((GpxLayer) l).data.removeChangeListener(updateOnRequireSaveChangeGpx);88 80 } 89 81 super.layerRemoving(e); … … 114 106 115 107 // 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 117 114 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>"); 119 118 label.setHorizontalAlignment(SwingConstants.CENTER); 120 JCheckBox remember = new JCheckBox(tr(" Remember choice"));119 JCheckBox remember = new JCheckBox(tr("Always overwrite GPX files without asking")); 121 120 remember.setHorizontalAlignment(SwingConstants.CENTER); 122 121 p.add(label, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 10)); … … 125 124 MainApplication.getMainFrame(), 126 125 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") 129 128 .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) { 131 133 f = null; 132 } else if (remember.isSelected()){133 Config.getPref().putBoolean("gpx.export.overwrite", true);134 } else { 135 return null; 134 136 } 135 137 } -
trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java
r18135 r18287 20 20 import java.util.Set; 21 21 import java.util.stream.Collectors; 22 import java.util.stream.Stream; 22 23 23 24 import javax.swing.BorderFactory; … … 33 34 import javax.swing.filechooser.FileFilter; 34 35 36 import org.openstreetmap.josm.data.preferences.BooleanProperty; 35 37 import org.openstreetmap.josm.gui.ExtendedDialog; 36 38 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 39 41 import org.openstreetmap.josm.gui.MapFrameListener; 40 42 import org.openstreetmap.josm.gui.Notification; 43 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer; 41 44 import org.openstreetmap.josm.gui.layer.Layer; 42 45 import org.openstreetmap.josm.gui.util.WindowGeometry; … … 61 64 private transient MultiMap<Layer, Layer> dependencies; 62 65 66 private static final BooleanProperty SAVE_LOCAL_FILES_PROPERTY = new BooleanProperty("session.savelocal", true); 67 63 68 /** 64 69 * Constructs a new {@code SessionSaveAsAction}. … … 158 163 .filter(layer -> exporters.get(layer) != null && exporters.get(layer).shallExport()) 159 164 .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 } 160 193 161 194 int active = -1; … … 251 284 252 285 protected final Component build() { 286 JPanel op = new JPanel(new GridBagLayout()); 253 287 JPanel ip = new JPanel(new GridBagLayout()); 254 288 for (Layer layer : layers) { … … 273 307 final JTabbedPane tabs = new JTabbedPane(); 274 308 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; 276 316 } 277 317
Note:
See TracChangeset
for help on using the changeset viewer.