| 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others |
|---|
| 2 | package org.openstreetmap.josm.actions; |
|---|
| 3 | |
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
|---|
| 5 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht; |
|---|
| 6 | |
|---|
| 7 | import java.awt.event.KeyEvent; |
|---|
| 8 | import java.io.File; |
|---|
| 9 | |
|---|
| 10 | import org.openstreetmap.josm.Main; |
|---|
| 11 | import org.openstreetmap.josm.gui.ExtendedDialog; |
|---|
| 12 | import org.openstreetmap.josm.gui.layer.GpxLayer; |
|---|
| 13 | import org.openstreetmap.josm.gui.layer.Layer; |
|---|
| 14 | import org.openstreetmap.josm.tools.Shortcut; |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * Export the data as an OSM xml file. |
|---|
| 18 | * |
|---|
| 19 | * @author imi |
|---|
| 20 | */ |
|---|
| 21 | public class SaveAction extends SaveActionBase { |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * Construct the action with "Save" as label. |
|---|
| 25 | * @param layer Save this layer. |
|---|
| 26 | */ |
|---|
| 27 | public 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.GROUP_MENU)); |
|---|
| 30 | putValue("help", ht("/Action/Save")); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | @Override public File getFile(Layer layer) { |
|---|
| 34 | File f = layer.getAssociatedFile(); |
|---|
| 35 | if(f != null && ! f.exists()) { |
|---|
| 36 | f=null; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | // Ask for overwrite in case of GpxLayer: GpxLayers usually are imports |
|---|
| 40 | // and modifying is an error most of the time. |
|---|
| 41 | if(f != null && layer instanceof GpxLayer) { |
|---|
| 42 | ExtendedDialog dialog = new ExtendedDialog( |
|---|
| 43 | Main.parent, |
|---|
| 44 | tr("Overwrite"), |
|---|
| 45 | new String[] {tr("Overwrite"), tr("Cancel")} |
|---|
| 46 | ); |
|---|
| 47 | dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"}); |
|---|
| 48 | dialog.setContent(tr("File {0} exists. Overwrite?", f.getName())); |
|---|
| 49 | dialog.showDialog(); |
|---|
| 50 | int ret = dialog.getValue(); |
|---|
| 51 | if (ret != 1) { |
|---|
| 52 | f = null; |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | return f == null ? openFileDialog(layer) : f; |
|---|
| 56 | } |
|---|
| 57 | } |
|---|