source: josm/trunk/src/org/openstreetmap/josm/actions/SaveAction.java @ 5241

Revision 5014, 2.0 KB checked in by xeen, 3 months ago (diff)

fix #7429

  • Property svn:eol-style set to native
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.KeyEvent;
8import java.io.File;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.gui.ExtendedDialog;
12import org.openstreetmap.josm.gui.layer.GpxLayer;
13import org.openstreetmap.josm.gui.layer.Layer;
14import org.openstreetmap.josm.tools.Shortcut;
15
16/**
17 * Export the data as an OSM xml file.
18 *
19 * @author imi
20 */
21public class SaveAction extends SaveActionBase {
22    private static SaveAction instance = new SaveAction();
23
24    /**
25     * Construct the action with "Save" as label.
26     * @param layer Save this layer.
27     */
28    private SaveAction() {
29        super(tr("Save"), "save", tr("Save the current data."),
30                Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.CTRL));
31        putValue("help", ht("/Action/Save"));
32    }
33
34    public static SaveAction getInstance() {
35        return instance;
36    }
37
38
39    @Override public File getFile(Layer layer) {
40        File f = layer.getAssociatedFile();
41        if(f != null && ! f.exists()) {
42            f=null;
43        }
44
45        // Ask for overwrite in case of GpxLayer: GpxLayers usually are imports
46        // and modifying is an error most of the time.
47        if(f != null && layer instanceof GpxLayer) {
48            ExtendedDialog dialog = new ExtendedDialog(
49                    Main.parent,
50                    tr("Overwrite"),
51                    new String[] {tr("Overwrite"), tr("Cancel")}
52            );
53            dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"});
54            dialog.setContent(tr("File {0} exists. Overwrite?", f.getName()));
55            dialog.showDialog();
56            int ret = dialog.getValue();
57            if (ret != 1) {
58                f = null;
59            }
60        }
61        return f == null ? openFileDialog(layer) : f;
62    }
63}
Note: See TracBrowser for help on using the repository browser.