[298] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
[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 | */
|
---|
[290] | 21 | public 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 | * @param layer Save this layer.
|
---|
| 27 | */
|
---|
[5014] | 28 | private SaveAction() {
|
---|
[1169] | 29 | super(tr("Save"), "save", tr("Save the current data."),
|
---|
[4982] | 30 | Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.CTRL));
|
---|
[2323] | 31 | putValue("help", ht("/Action/Save"));
|
---|
[1169] | 32 | }
|
---|
[1023] | 33 |
|
---|
[5014] | 34 | public static SaveAction getInstance() {
|
---|
| 35 | return instance;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
[1169] | 39 | @Override public File getFile(Layer layer) {
|
---|
[1646] | 40 | File f = layer.getAssociatedFile();
|
---|
[1808] | 41 | if(f != null && ! f.exists()) {
|
---|
[1659] | 42 | f=null;
|
---|
[1808] | 43 | }
|
---|
[2070] | 44 |
|
---|
[4114] | 45 | // Ask for overwrite in case of GpxLayer: GpxLayers usually are imports
|
---|
| 46 | // and modifying is an error most of the time.
|
---|
[2070] | 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 | }
|
---|
[1808] | 60 | }
|
---|
[1646] | 61 | return f == null ? openFileDialog(layer) : f;
|
---|
[1169] | 62 | }
|
---|
[283] | 63 | }
|
---|