Changeset 2025 in josm for trunk/src/org/openstreetmap/josm/Main.java
- Timestamp:
- 2009-09-02T21:17:52+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r2017 r2025 2 2 package org.openstreetmap.josm; 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.trn; 4 5 5 6 import java.awt.BorderLayout; … … 12 13 import java.net.URI; 13 14 import java.net.URISyntaxException; 15 import java.util.ArrayList; 14 16 import java.util.Collection; 17 import java.util.List; 15 18 import java.util.Map; 16 19 import java.util.StringTokenizer; … … 22 25 import javax.swing.JComponent; 23 26 import javax.swing.JFrame; 27 import javax.swing.JLabel; 24 28 import javax.swing.JOptionPane; 25 29 import javax.swing.JPanel; … … 45 49 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 46 50 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; 51 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 47 52 import org.openstreetmap.josm.gui.layer.Layer; 48 53 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 393 398 } 394 399 395 public static boolean breakBecauseUnsavedChanges() { 400 public static boolean saveUnsavedModifications() { 401 if (map == null) return true; 402 SaveLayersDialog dialog = new SaveLayersDialog(Main.parent); 403 List<OsmDataLayer> layersWithUnmodifiedChanges = new ArrayList<OsmDataLayer>(); 404 for (OsmDataLayer l: Main.map.mapView.getLayersOfType(OsmDataLayer.class)) { 405 if (l.requiresSaveToFile() || l.requiresUploadToServer()) { 406 layersWithUnmodifiedChanges.add(l); 407 } 408 } 409 dialog.prepareForSavingAndUpdatingLayersBeforeExit(); 410 if (!layersWithUnmodifiedChanges.isEmpty()) { 411 dialog.getModel().populate(layersWithUnmodifiedChanges); 412 dialog.setVisible(true); 413 switch(dialog.getUserAction()) { 414 case CANCEL: return false; 415 case PROCEED: return true; 416 default: return false; 417 } 418 } 419 return true; 420 } 421 422 /** 423 * Saves all {@see OsmDataLayer}s with an associated file and with unsaved 424 * data modifications. 425 * 426 * @return true, if the save operation was successful; false, otherwise 427 */ 428 public static boolean saveUnsavedModifications_old() { 396 429 Shortcut.savePrefs(); 397 if (map != null) { 398 boolean modified = false; 399 boolean uploadedModified = false; 400 for (final Layer l : map.mapView.getAllLayers()) { 401 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 402 modified = true; 403 uploadedModified = ((OsmDataLayer)l).uploadedModified; 404 break; 405 } 406 } 407 if (modified) { 408 final String msg = uploadedModified ? "\n" 409 +tr("Hint: Some changes came from uploading new data to the server.") : ""; 410 int result = new ExtendedDialog(parent, tr("Unsaved Changes"), 411 new javax.swing.JLabel(tr("There are unsaved changes. Discard the changes and continue?")+msg), 412 new String[] {tr("Save and Exit"), tr("Discard and Exit"), tr("Cancel")}, 413 new String[] {"save.png", "exit.png", "cancel.png"}).getValue(); 414 415 // Save before exiting 416 if(result == 1) { 417 Boolean savefailed = false; 418 for (final Layer l : map.mapView.getAllLayers()) { 419 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 420 SaveAction save = new SaveAction(); 421 if(!save.doSave(l)) { 422 savefailed = true; 423 } 424 } 425 } 426 return savefailed; 427 } 428 else if(result != 2) // Cancel exiting unless the 2nd button was clicked 429 return true; 430 } 431 } 432 return false; 430 if (map == null) 431 return true; // nothing to save, return success 432 433 int numUnsavedLayers = 0; 434 for (final OsmDataLayer l : map.mapView.getLayersOfType(OsmDataLayer.class)) { 435 if (l.requiresSaveToFile()) { 436 numUnsavedLayers++; 437 } 438 } 439 if (numUnsavedLayers == 0) 440 return true; // nothing to save, return success 441 442 String msg = trn( 443 "There are unsaved changes in {0} layer. Discard the changes and continue?", 444 "There are unsaved changes in {0} layers. Discard the changes and continue?", 445 numUnsavedLayers, 446 numUnsavedLayers 447 ); 448 int result = new ExtendedDialog(parent, tr("Unsaved Changes"), 449 new JLabel(msg), 450 new String[] {tr("Save and Exit"), tr("Discard and Exit"), tr("Cancel")}, 451 new String[] {"save.png", "exit.png", "cancel.png"}).getValue(); 452 453 switch(result) { 454 case 2: /* discard and exit */ return true; 455 case 3: /* cancel */ return false; 456 } 457 boolean savefailed = false; 458 for (OsmDataLayer l : map.mapView.getLayersOfType(OsmDataLayer.class)) { 459 if(!new SaveAction().doSave(l)) { 460 savefailed = true; 461 } 462 } 463 return !savefailed; 433 464 } 434 465
Note:
See TracChangeset
for help on using the changeset viewer.