[298] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
[283] | 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[2323] | 5 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
[283] | 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 {
|
---|
[1023] | 22 |
|
---|
[1169] | 23 | /**
|
---|
| 24 | * Construct the action with "Save" as label.
|
---|
| 25 | * @param layer Save this layer.
|
---|
| 26 | */
|
---|
[1808] | 27 | public SaveAction() {
|
---|
[1169] | 28 | super(tr("Save"), "save", tr("Save the current data."),
|
---|
[1808] | 29 | Shortcut.registerShortcut("system:save", tr("File: {0}", tr("Save")), KeyEvent.VK_S, Shortcut.GROUP_MENU));
|
---|
[2323] | 30 | putValue("help", ht("/Action/Save"));
|
---|
[1169] | 31 | }
|
---|
[1023] | 32 |
|
---|
[1169] | 33 | @Override public File getFile(Layer layer) {
|
---|
[1646] | 34 | File f = layer.getAssociatedFile();
|
---|
[1808] | 35 | if(f != null && ! f.exists()) {
|
---|
[1659] | 36 | f=null;
|
---|
[1808] | 37 | }
|
---|
[2070] | 38 |
|
---|
| 39 | // FIXME: why only for GpxLayer?
|
---|
| 40 | if(f != null && layer instanceof GpxLayer) {
|
---|
| 41 | ExtendedDialog dialog = new ExtendedDialog(
|
---|
| 42 | Main.parent,
|
---|
| 43 | tr("Overwrite"),
|
---|
| 44 | new String[] {tr("Overwrite"), tr("Cancel")}
|
---|
| 45 | );
|
---|
| 46 | dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"});
|
---|
| 47 | dialog.setContent(tr("File {0} exists. Overwrite?", f.getName()));
|
---|
| 48 | dialog.showDialog();
|
---|
| 49 | int ret = dialog.getValue();
|
---|
| 50 | if (ret != 1) {
|
---|
| 51 | f = null;
|
---|
| 52 | }
|
---|
[1808] | 53 | }
|
---|
[1646] | 54 | return f == null ? openFileDialog(layer) : f;
|
---|
[1169] | 55 | }
|
---|
[283] | 56 | }
|
---|