Changeset 5459 in josm for trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
- Timestamp:
- 2012-08-20T01:11:45+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r5457 r5459 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.conflict.ConflictCollection;19 import org.openstreetmap.josm.data.osm.OsmPrimitive;20 18 import org.openstreetmap.josm.gui.ExtendedDialog; 21 import org.openstreetmap.josm.gui.layer.GpxLayer;22 19 import org.openstreetmap.josm.gui.layer.Layer; 23 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 21 import org.openstreetmap.josm.io.FileExporter; 25 import org.openstreetmap.josm.io.GpxImporter;26 22 import org.openstreetmap.josm.tools.Shortcut; 27 23 … … 44 40 45 41 public boolean doSave() { 46 Layer layer = null; 47 if (Main.isDisplayingMapView() && (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 48 || Main.map.mapView.getActiveLayer() instanceof GpxLayer)) { 49 layer = Main.map.mapView.getActiveLayer(); 42 if (Main.isDisplayingMapView()) { 43 Layer layer = Main.map.mapView.getActiveLayer(); 44 if (layer != null && layer.isSavable()) { 45 return doSave(layer); 46 } 50 47 } 51 if (layer == null) 52 return false; 53 return doSave(layer); 48 return false; 54 49 } 55 50 56 51 public boolean doSave(Layer layer) { 57 if(!checkSaveConditions( layer))52 if(!layer.checkSaveConditions()) 58 53 return false; 59 54 file = getFile(layer); … … 62 57 63 58 public static boolean doSave(Layer layer, File file) { 64 if(!checkSaveConditions( layer))59 if(!layer.checkSaveConditions()) 65 60 return false; 66 61 return doInternalSave(layer, file); … … 101 96 102 97 /** 103 * Checks whether it is ok to launch a save (whether we have data,104 * there is no conflict etc.)105 * @return <code>true</code>, if it is safe to save.106 */107 public static boolean checkSaveConditions(Layer layer) {108 if (layer instanceof GpxLayer)109 return ((GpxLayer)layer).data != null;110 else if (layer instanceof OsmDataLayer) {111 if (isDataSetEmpty((OsmDataLayer)layer)) {112 ExtendedDialog dialog = new ExtendedDialog(113 Main.parent,114 tr("Empty document"),115 new String[] {tr("Save anyway"), tr("Cancel")}116 );117 dialog.setContent(tr("The document contains no data."));118 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"});119 dialog.showDialog();120 if (dialog.getValue() != 1) return false;121 }122 123 ConflictCollection conflicts = ((OsmDataLayer)layer).getConflicts();124 if (conflicts != null && !conflicts.isEmpty()) {125 ExtendedDialog dialog = new ExtendedDialog(126 Main.parent,127 /* I18N: Display title of the window showing conflicts */128 tr("Conflicts"),129 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}130 );131 dialog.setContent(tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"));132 dialog.setButtonIcons(new String[] {"save.png", "cancel.png"});133 dialog.showDialog();134 if (dialog.getValue() != 1) return false;135 }136 return true;137 }138 return false;139 }140 141 public static File openFileDialog(Layer layer) {142 if (layer instanceof OsmDataLayer)143 return createAndOpenSaveFileChooser(tr("Save OSM file"), "osm");144 else if (layer instanceof GpxLayer)145 return createAndOpenSaveFileChooser(tr("Save GPX file"), GpxImporter.FILE_FILTER);146 return createAndOpenSaveFileChooser(tr("Save Layer"), "lay");147 }148 149 /**150 * Check the data set if it would be empty on save. It is empty, if it contains151 * no objects (after all objects that are created and deleted without being152 * transferred to the server have been removed).153 *154 * @return <code>true</code>, if a save result in an empty data set.155 */156 private static boolean isDataSetEmpty(OsmDataLayer layer) {157 for (OsmPrimitive osm : layer.data.allNonDeletedPrimitives())158 if (!osm.isDeleted() || !osm.isNewOrUndeleted())159 return false;160 return true;161 }162 163 /**164 98 * Refreshes the enabled state 165 99 * … … 179 113 } 180 114 Layer layer = Main.map.mapView.getActiveLayer(); 181 setEnabled(layer instanceof OsmDataLayer || layer instanceof GpxLayer);115 setEnabled(layer != null && layer.isSavable()); 182 116 } 183 117
Note:
See TracChangeset
for help on using the changeset viewer.
