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

Last change on this file since 14306 was 14153, checked in by Don-vip, 6 years ago

see #15229 - deprecate Main.parent and Main itself

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
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.gui.ExtendedDialog;
11import org.openstreetmap.josm.gui.MainApplication;
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 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 MainApplication.getMainFrame(),
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}
Note: See TracBrowser for help on using the repository browser.