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

Last change on this file since 12987 was 12279, checked in by Don-vip, 7 years ago

sonar - squid:S3878 - Arrays should not be created for varargs parameters

  • Property svn:eol-style set to native
File size: 1.9 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.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 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 public static SaveAction getInstance() {
34 return instance;
35 }
36
37 @Override public File getFile(Layer layer) {
38 File f = layer.getAssociatedFile();
39 if (f != null && !f.exists()) {
40 f = null;
41 }
42
43 // Ask for overwrite in case of GpxLayer: GpxLayers usually are imports
44 // and modifying is an error most of the time.
45 if (f != null && layer instanceof GpxLayer) {
46 ExtendedDialog dialog = new ExtendedDialog(
47 Main.parent,
48 tr("Overwrite"),
49 tr("Overwrite"), tr("Cancel"))
50 .setButtonIcons("save_as", "cancel")
51 .setContent(tr("File {0} exists. Overwrite?", f.getName()));
52 if (dialog.showDialog().getValue() != 1) {
53 f = null;
54 }
55 }
56 return f == null ? layer.createAndOpenSaveFileChooser() : f;
57 }
58}
Note: See TracBrowser for help on using the repository browser.