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