Index: /trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java	(revision 1646)
@@ -6,4 +6,5 @@
 import java.io.File;
 import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.gui.ExtendedDialog;
@@ -20,5 +21,5 @@
     }
 
-    protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
+    public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
         String curDir = Main.pref.get("lastDirectory");
         if (curDir.equals(""))
@@ -55,3 +56,50 @@
         return fc;
     }
+
+    public static File createAndOpenSaveFileChooser(String title,
+    String extension)
+    {
+        String curDir = Main.pref.get("lastDirectory");
+        if (curDir.equals(""))
+            curDir = ".";
+        JFileChooser fc = new JFileChooser(new File(curDir));
+        if (title != null)
+            fc.setDialogTitle(title);
+
+        fc.setMultiSelectionEnabled(false);
+        for (FileImporter imExporter: ExtensionFileFilter.importers) {
+            fc.addChoosableFileFilter(imExporter.filter);
+        }
+
+        fc.setAcceptAllFileFilterUsed(true);
+
+        int answer = fc.showSaveDialog(Main.parent);
+        if (answer != JFileChooser.APPROVE_OPTION)
+            return null;
+
+        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
+            Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
+
+        File file = fc.getSelectedFile();
+        if(extension != null)
+        {
+            String fn = file.getPath();
+            if(fn.indexOf('.') == -1)
+            {
+                FileFilter ff = fc.getFileFilter();
+                if (ff instanceof ExtensionFileFilter)
+                    fn += "." + ((ExtensionFileFilter)ff).defaultExtension;
+                else
+                    fn += extension;
+                file = new File(fn);
+            }
+        }
+        if(file == null || (file.exists() && 1 != new ExtendedDialog(Main.parent,
+        tr("Overwrite"), tr("File exists. Overwrite?"),
+        new String[] {tr("Overwrite"), tr("Cancel")},
+        new String[] {"save_as.png", "cancel.png"}).getValue()))
+            return null;
+        return file;
+    }
+
 }
Index: /trunk/src/org/openstreetmap/josm/actions/RenameLayerAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/RenameLayerAction.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/actions/RenameLayerAction.java	(revision 1646)
@@ -82,5 +82,5 @@
                 File newFile = new File(newname);
                 if (file.renameTo(newFile)) {
-                    layer.associatedFile = newFile;
+                    layer.setAssociatedFile(newFile);
                     nameText = newFile.getName();
                 } else {
Index: /trunk/src/org/openstreetmap/josm/actions/SaveAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/SaveAction.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/actions/SaveAction.java	(revision 1646)
@@ -8,6 +8,4 @@
 
 import org.openstreetmap.josm.gui.layer.Layer;
-import org.openstreetmap.josm.gui.layer.GpxLayer;
-import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -29,17 +27,6 @@
 
     @Override public File getFile(Layer layer) {
-        if (layer instanceof OsmDataLayer) {
-            File f = ((OsmDataLayer)layer).associatedFile;
-            if (f != null) {
-                return f;
-            }
-        }
-        if (layer instanceof GpxLayer) {
-            File f = ((GpxLayer)layer).data.storageFile;
-            if (f != null) {
-                return f;
-            }
-        }
-        return openFileDialog(layer);
+        File f = layer.getAssociatedFile();
+        return f == null ? openFileDialog(layer) : f;
     }
 }
Index: /trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java	(revision 1646)
@@ -14,5 +14,4 @@
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
-import javax.swing.filechooser.FileFilter;
 
 import org.openstreetmap.josm.Main;
@@ -60,5 +59,5 @@
 
         layer.name = file.getName();
-        layer.associatedFile = file;
+        layer.setAssociatedFile(file);
         Main.parent.repaint();
         return true;
@@ -101,22 +100,9 @@
 
     public static File openFileDialog(Layer layer) {
-        JFileChooser fc = createAndOpenFileChooser(false, false, layer instanceof GpxLayer ? tr("Save GPX file") : tr("Save OSM file"));
-        if (fc == null)
-            return null;
-
-        File file = fc.getSelectedFile();
-
-        String fn = file.getPath();
-        if (fn.indexOf('.') == -1) {
-            FileFilter ff = fc.getFileFilter();
-            if (ff instanceof ExtensionFileFilter)
-                fn += "." + ((ExtensionFileFilter)ff).defaultExtension;
-            else if (layer instanceof GpxLayer)
-                fn += ".gpx";
-            else
-                fn += ".osm";
-            file = new File(fn);
-        }
-        return file;
+        if (layer instanceof OsmDataLayer)
+            return createAndOpenSaveFileChooser(tr("Save OSM file"), ".osm");
+        else if (layer instanceof GpxLayer)
+            return createAndOpenSaveFileChooser(tr("Save GPX file"), ".gpx");
+        return createAndOpenSaveFileChooser(tr("Save Layer"), ".lay");
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 1646)
@@ -175,5 +175,5 @@
                                 namedTrackPoints.waypoints.add(point);
 
-                MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), associatedFile, me);
+                MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), getAssociatedFile(), me);
                 if (ml.data.size() > 0) {
                     Main.main.addLayer(ml);
@@ -203,5 +203,5 @@
                         Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath());
 
-                    MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), associatedFile, me);
+                    MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name), getAssociatedFile(), me);
                     File sel[] = fc.getSelectedFiles();
                     if(sel != null) {
@@ -270,5 +270,5 @@
                 new JMenuItem(new ConvertToDataLayerAction()),
                 new JSeparator(),
-                new JMenuItem(new RenameLayerAction(associatedFile, this)),
+                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
                 new JSeparator(),
                 new JMenuItem(new LayerListPopup.InfoAction(this))};
@@ -287,5 +287,5 @@
             new JMenuItem(new DownloadAlongTrackAction()),
             new JSeparator(),
-            new JMenuItem(new RenameLayerAction(associatedFile, this)),
+            new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
             new JSeparator(),
             new JMenuItem(new LayerListPopup.InfoAction(this))};
@@ -680,8 +680,11 @@
             }
             Main.main.addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", GpxLayer.this.name),
-                        data.storageFile));
+                        getAssociatedFile()));
             Main.main.removeLayer(GpxLayer.this);
         }
     }
+
+    public File getAssociatedFile() { return data.storageFile; }
+    public void setAssociatedFile(File file) { data.storageFile = file; }
 
     /**
@@ -932,5 +935,5 @@
             double duration = AudioUtil.getCalibratedDuration(wavFile);
             double startTime = lastModified - duration;
-            startTime = firstStartTime + (startTime - firstStartTime) /  
+            startTime = firstStartTime + (startTime - firstStartTime) /
                 Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
             WayPoint w1 = null;
@@ -949,5 +952,5 @@
                     if (w2 != null) break;
                 }
-            }    
+            }
 
             if (w1 == null || w2 == null) {
@@ -964,7 +967,7 @@
                 wayPointFromTimeStamp.attr.put("name", name);
                 waypoints.add(wayPointFromTimeStamp);
-            }            
-        }
-        
+            }
+        }
+
         // (e) analyse audio for spoken markers here, in due course
 
@@ -1013,6 +1016,6 @@
                     name, uri, ml, w.time, offset);
             /* timeFromAudio intended for future use to shift markers of this type on synchronization */
-            if (w == wayPointFromTimeStamp) { 
-                am.timeFromAudio = true; 
+            if (w == wayPointFromTimeStamp) {
+                am.timeFromAudio = true;
             }
             ml.data.add(am);
Index: /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/Layer.java	(revision 1646)
@@ -65,5 +65,5 @@
      * If a file is associated with this layer, this variable should be set to it.
      */
-    public File associatedFile;
+    private File associatedFile;
 
     /**
@@ -120,3 +120,6 @@
      */
     public void destroy() {}
+
+    public File getAssociatedFile() { return associatedFile; }
+    public void setAssociatedFile(File file) { associatedFile = file; }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java	(revision 1646)
@@ -152,5 +152,5 @@
         super(name);
         this.data = data;
-        this.associatedFile = associatedFile;
+        this.setAssociatedFile(associatedFile);
     }
 
@@ -217,6 +217,7 @@
         tool += undeletedSize(data.ways)+" "+trn("way", "ways", undeletedSize(data.ways));
         if (data.version != null) tool += ", " + tr("version {0}", data.version);
-        if (associatedFile != null)
-            tool = "<html>"+tool+"<br>"+associatedFile.getPath()+"</html>";
+        File f = getAssociatedFile();
+        if (f != null)
+            tool = "<html>"+tool+"<br>"+f.getPath()+"</html>";
         return tool;
     }
@@ -307,9 +308,10 @@
 
         // update the modified flag
-        if (associatedFile != null && processed != null && !dataAdded)
+        boolean b = (getAssociatedFile() != null && processed != null);
+        if (b && !dataAdded)
             return; // do nothing when uploading non-harmful changes.
 
         // modified if server changed the data (esp. the id).
-        uploadedModified = associatedFile != null && processed != null && dataAdded;
+        uploadedModified = b && dataAdded;
         setModified(uploadedModified);
     }
@@ -378,5 +380,5 @@
                     new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
                     new JSeparator(),
-                    new JMenuItem(new RenameLayerAction(associatedFile, this)),
+                    new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
                     new JSeparator(),
                     new JMenuItem(new LayerListPopup.InfoAction(this))};
@@ -391,5 +393,5 @@
                 new JMenuItem(new ConvertToGpxLayerAction()),
                 new JSeparator(),
-                new JMenuItem(new RenameLayerAction(associatedFile, this)),
+                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
                 new JSeparator(),
                 new JMenuItem(new LayerListPopup.InfoAction(this))};
@@ -454,5 +456,5 @@
 
     public GpxData toGpxData() {
-        return toGpxData(data, associatedFile);
+        return toGpxData(data, getAssociatedFile());
     }
 
Index: /trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java	(revision 1646)
@@ -107,5 +107,5 @@
         super(name);
         this.fromServer = fromServer;
-        this.associatedFile = associatedFile;
+        setAssociatedFile(associatedFile);
         this.data = data;
         Main.pref.listener.add(this);
@@ -151,6 +151,7 @@
         String tool = data.size()+" "+trn("track", "tracks", data.size())
         +" "+points+" "+trn("point", "points", points);
-        if (associatedFile != null)
-            tool = "<html>"+tool+"<br>"+associatedFile.getPath()+"</html>";
+        File f = getAssociatedFile();
+        if (f != null)
+            tool = "<html>"+tool+"<br>"+f.getPath()+"</html>";
         return tool;
     }
@@ -242,5 +243,5 @@
                 new JMenuItem(new ConvertToDataLayerAction()),
                 new JSeparator(),
-                new JMenuItem(new RenameLayerAction(associatedFile, this)),
+                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
                 new JSeparator(),
                 new JMenuItem(new LayerListPopup.InfoAction(this))};
@@ -254,5 +255,5 @@
                 new JMenuItem(new ConvertToDataLayerAction()),
                 new JSeparator(),
-                new JMenuItem(new RenameLayerAction(associatedFile, this)),
+                new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
                 new JSeparator(),
                 new JMenuItem(new LayerListPopup.InfoAction(this))};
Index: /trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java	(revision 1645)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java	(revision 1646)
@@ -71,5 +71,5 @@
 
         super(name);
-        this.associatedFile = associatedFile;
+        this.setAssociatedFile(associatedFile);
         this.data = new ArrayList<Marker>();
         this.fromLayer = fromLayer;
@@ -258,5 +258,5 @@
             components.add (moveaudio);
         }
-        components.add(new JMenuItem(new RenameLayerAction(associatedFile, this)));
+        components.add(new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)));
         components.add(new JSeparator());
         components.add(new JMenuItem(new LayerListPopup.InfoAction(this)));
