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