Changeset 11093 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-10-07T21:55:54+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r11092 r11093 77 77 import org.openstreetmap.josm.gui.ProgramArguments.Option; 78 78 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 79 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;80 79 import org.openstreetmap.josm.gui.layer.Layer; 81 80 import org.openstreetmap.josm.gui.layer.MainLayerManager; … … 795 794 796 795 /** 797 * Asks user to perform "save layer" operations (save on disk and/or upload data to server) for all798 * {@link AbstractModifiableLayer} before JOSM exits.799 * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations.800 * {@code false} if the user cancels.801 * @since 2025802 */803 public static boolean saveUnsavedModifications() {804 if (!isDisplayingMapView()) return true;805 return saveUnsavedModifications(getLayerManager().getLayersOfType(AbstractModifiableLayer.class), true);806 }807 808 /**809 * Asks user to perform "save layer" operations (save on disk and/or upload data to server) before data layers deletion.810 *811 * @param selectedLayers The layers to check. Only instances of {@link AbstractModifiableLayer} are considered.812 * @param exit {@code true} if JOSM is exiting, {@code false} otherwise.813 * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations.814 * {@code false} if the user cancels.815 * @since 5519816 */817 public static boolean saveUnsavedModifications(Iterable<? extends Layer> selectedLayers, boolean exit) {818 SaveLayersDialog dialog = new SaveLayersDialog(parent);819 List<AbstractModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>();820 for (Layer l: selectedLayers) {821 if (!(l instanceof AbstractModifiableLayer)) {822 continue;823 }824 AbstractModifiableLayer odl = (AbstractModifiableLayer) l;825 if (odl.isModified() &&826 ((!odl.isSavable() && !odl.isUploadable()) ||827 odl.requiresSaveToFile() ||828 (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) {829 layersWithUnmodifiedChanges.add(odl);830 }831 }832 if (exit) {833 dialog.prepareForSavingAndUpdatingLayersBeforeExit();834 } else {835 dialog.prepareForSavingAndUpdatingLayersBeforeDelete();836 }837 if (!layersWithUnmodifiedChanges.isEmpty()) {838 dialog.getModel().populate(layersWithUnmodifiedChanges);839 dialog.setVisible(true);840 switch(dialog.getUserAction()) {841 case PROCEED: return true;842 case CANCEL:843 default: return false;844 }845 }846 847 return true;848 }849 850 /**851 796 * Closes JOSM and optionally terminates the Java Virtual Machine (JVM). 852 797 * If there are some unsaved data layers, asks first for user confirmation. 853 798 * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code. 854 799 * @param exitCode The return code 800 * @param reason the reason for exiting 855 801 * @return {@code true} if JOSM has been closed, {@code false} if the user has cancelled the operation. 856 * @since 3378857 */ 858 public static boolean exitJosm(boolean exit, int exitCode ) {859 if ( Main.saveUnsavedModifications()) {802 * @since 11093 (3378 with a different function signature) 803 */ 804 public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) { 805 if (SaveLayersDialog.saveUnsavedModifications(getLayerManager().getLayers(), reason != null ? reason : SaveLayersDialog.Reason.EXIT)) { 860 806 if (Main.main != null) { 861 807 Main.main.shutdown(); -
trunk/src/org/openstreetmap/josm/actions/DeleteLayerAction.java
r10436 r11093 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 12 13 import org.openstreetmap.josm.gui.layer.Layer; 13 14 import org.openstreetmap.josm.tools.Shortcut; … … 34 35 return; 35 36 } 36 if (! Main.saveUnsavedModifications(Collections.singletonList(activeLayer), false)) {37 if (!SaveLayersDialog.saveUnsavedModifications(Collections.singletonList(activeLayer), SaveLayersDialog.Reason.DELETE)) { 37 38 return; 38 39 } -
trunk/src/org/openstreetmap/josm/actions/ExitAction.java
r6380 r11093 28 28 @Override 29 29 public void actionPerformed(ActionEvent e) { 30 Main.exitJosm(true, 0 );30 Main.exitJosm(true, 0, null); 31 31 } 32 32 } -
trunk/src/org/openstreetmap/josm/actions/RestartAction.java
r10212 r11093 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 19 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 19 20 import org.openstreetmap.josm.tools.ImageProvider; 20 21 import org.openstreetmap.josm.tools.Shortcut; … … 59 60 String scriptRestart = System.getProperty("josm.restart"); 60 61 if ("true".equals(scriptRestart)) { 61 Main.exitJosm(true, 9 );62 Main.exitJosm(true, 9, SaveLayersDialog.Reason.RESTART); 62 63 } 63 64 … … 83 84 */ 84 85 public static void restartJOSM() throws IOException { 85 if (isRestartSupported() && !Main.exitJosm(false, 0 )) return;86 if (isRestartSupported() && !Main.exitJosm(false, 0, SaveLayersDialog.Reason.RESTART)) return; 86 87 final List<String> cmd; 87 88 // special handling for OSX .app package -
trunk/src/org/openstreetmap/josm/gui/MainFrame.java
r10611 r11093 92 92 @Override 93 93 public void windowClosing(final WindowEvent evt) { 94 Main.exitJosm(true, 0 );94 Main.exitJosm(true, 0, null); 95 95 } 96 96 }); -
trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DeleteLayerAction.java
r11078 r11093 11 11 import javax.swing.JMenuItem; 12 12 13 import org.openstreetmap.josm.Main;14 13 import org.openstreetmap.josm.gui.dialogs.IEnabledStateUpdating; 15 14 import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel; 16 15 import org.openstreetmap.josm.gui.help.HelpUtil; 16 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 17 17 import org.openstreetmap.josm.gui.layer.Layer; 18 18 import org.openstreetmap.josm.gui.layer.Layer.LayerAction; … … 44 44 if (selectedLayers.isEmpty()) 45 45 return; 46 if (! Main.saveUnsavedModifications(selectedLayers, false))46 if (!SaveLayersDialog.saveUnsavedModifications(selectedLayers, SaveLayersDialog.Reason.DELETE)) 47 47 return; 48 48 for (Layer l: selectedLayers) { -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r11017 r11093 19 19 import java.beans.PropertyChangeEvent; 20 20 import java.beans.PropertyChangeListener; 21 import java.util.ArrayList; 21 22 import java.util.List; 22 23 import java.util.concurrent.CancellationException; … … 47 48 import org.openstreetmap.josm.gui.io.SaveLayersModel.Mode; 48 49 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer; 50 import org.openstreetmap.josm.gui.layer.Layer; 49 51 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 50 52 import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor; … … 58 60 59 61 public class SaveLayersDialog extends JDialog implements TableModelListener { 60 public enum UserAction { 62 63 /** 64 * The cause for requesting an action on unsaved modifications 65 */ 66 public enum Reason { 67 /** deleting a layer */ 68 DELETE, 69 /** exiting JOSM */ 70 EXIT, 71 /* restarting JOSM */ 72 RESTART 73 } 74 75 private enum UserAction { 61 76 /** save/upload layers was successful, proceed with operation */ 62 77 PROCEED, … … 76 91 77 92 private final JButton saveAndProceedActionButton = new JButton(saveAndProceedAction); 93 94 /** 95 * Asks user to perform "save layer" operations (save on disk and/or upload data to server) before data layers deletion. 96 * 97 * @param selectedLayers The layers to check. Only instances of {@link AbstractModifiableLayer} are considered. 98 * @param reason the cause for requesting an action on unsaved modifications 99 * @return {@code true} if there was nothing to save, or if the user wants to proceed to save operations. 100 * {@code false} if the user cancels. 101 * @since 11093 102 */ 103 public static boolean saveUnsavedModifications(Iterable<? extends Layer> selectedLayers, Reason reason) { 104 SaveLayersDialog dialog = new SaveLayersDialog(Main.parent); 105 List<AbstractModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>(); 106 for (Layer l: selectedLayers) { 107 if (!(l instanceof AbstractModifiableLayer)) { 108 continue; 109 } 110 AbstractModifiableLayer odl = (AbstractModifiableLayer) l; 111 if (odl.isModified() && 112 ((!odl.isSavable() && !odl.isUploadable()) || 113 odl.requiresSaveToFile() || 114 (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) { 115 layersWithUnmodifiedChanges.add(odl); 116 } 117 } 118 dialog.prepareForSavingAndUpdatingLayers(reason); 119 if (!layersWithUnmodifiedChanges.isEmpty()) { 120 dialog.getModel().populate(layersWithUnmodifiedChanges); 121 dialog.setVisible(true); 122 switch(dialog.getUserAction()) { 123 case PROCEED: return true; 124 case CANCEL: 125 default: return false; 126 } 127 } 128 129 return true; 130 } 78 131 79 132 /** … … 131 184 } 132 185 133 public void prepareForSavingAndUpdatingLayersBeforeExit() { 134 setTitle(tr("Unsaved changes - Save/Upload before exiting?")); 135 this.saveAndProceedAction.initForSaveAndExit(); 136 this.discardAndProceedAction.initForDiscardAndExit(); 137 } 138 139 public void prepareForSavingAndUpdatingLayersBeforeDelete() { 140 setTitle(tr("Unsaved changes - Save/Upload before deleting?")); 141 this.saveAndProceedAction.initForSaveAndDelete(); 142 this.discardAndProceedAction.initForDiscardAndDelete(); 186 public void prepareForSavingAndUpdatingLayers(final Reason reason) { 187 switch (reason) { 188 case EXIT: 189 setTitle(tr("Unsaved changes - Save/Upload before exiting?")); 190 break; 191 case DELETE: 192 setTitle(tr("Unsaved changes - Save/Upload before deleting?")); 193 break; 194 case RESTART: 195 setTitle(tr("Unsaved changes - Save/Upload before restarting?")); 196 break; 197 } 198 this.saveAndProceedAction.initForReason(reason); 199 this.discardAndProceedAction.initForReason(reason); 143 200 } 144 201 … … 323 380 class DiscardAndProceedAction extends AbstractAction implements PropertyChangeListener { 324 381 DiscardAndProceedAction() { 325 initForDiscardAndExit(); 326 } 327 328 public void initForDiscardAndExit() { 329 putValue(NAME, tr("Exit now!")); 330 putValue(SHORT_DESCRIPTION, tr("Exit JOSM without saving. Unsaved changes are lost.")); 331 putValue(SMALL_ICON, ImageProvider.get("exit")); 332 } 333 334 public void initForDiscardAndDelete() { 335 putValue(NAME, tr("Delete now!")); 336 putValue(SHORT_DESCRIPTION, tr("Delete layers without saving. Unsaved changes are lost.")); 337 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 382 initForReason(Reason.EXIT); 383 } 384 385 public void initForReason(Reason reason) { 386 switch (reason) { 387 case EXIT: 388 putValue(NAME, tr("Exit now!")); 389 putValue(SHORT_DESCRIPTION, tr("Exit JOSM without saving. Unsaved changes are lost.")); 390 putValue(SMALL_ICON, ImageProvider.get("exit")); 391 break; 392 case RESTART: 393 putValue(NAME, tr("Restart now!")); 394 putValue(SHORT_DESCRIPTION, tr("Restart JOSM without saving. Unsaved changes are lost.")); 395 putValue(SMALL_ICON, ImageProvider.get("restart")); 396 break; 397 case DELETE: 398 putValue(NAME, tr("Delete now!")); 399 putValue(SHORT_DESCRIPTION, tr("Delete layers without saving. Unsaved changes are lost.")); 400 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 401 break; 402 } 403 338 404 } 339 405 … … 385 451 386 452 SaveAndProceedAction() { 387 initForSaveAndExit(); 388 } 389 390 public void initForSaveAndExit() { 391 putValue(NAME, tr("Perform actions before exiting")); 392 putValue(SHORT_DESCRIPTION, tr("Exit JOSM with saving. Unsaved changes are uploaded and/or saved.")); 393 putValue(BASE_ICON, ImageProvider.get("exit")); 394 redrawIcon(); 395 } 396 397 public void initForSaveAndDelete() { 398 putValue(NAME, tr("Perform actions before deleting")); 399 putValue(SHORT_DESCRIPTION, tr("Save/Upload layers before deleting. Unsaved changes are not lost.")); 400 putValue(BASE_ICON, ImageProvider.get("dialogs", "delete")); 453 initForReason(Reason.EXIT); 454 } 455 456 public void initForReason(Reason reason) { 457 switch (reason) { 458 case EXIT: 459 putValue(NAME, tr("Perform actions before exiting")); 460 putValue(SHORT_DESCRIPTION, tr("Exit JOSM with saving. Unsaved changes are uploaded and/or saved.")); 461 putValue(BASE_ICON, ImageProvider.get("exit")); 462 break; 463 case RESTART: 464 putValue(NAME, tr("Perform actions before restarting")); 465 putValue(SHORT_DESCRIPTION, tr("Restart JOSM with saving. Unsaved changes are uploaded and/or saved.")); 466 putValue(BASE_ICON, ImageProvider.get("restart")); 467 break; 468 case DELETE: 469 putValue(NAME, tr("Perform actions before deleting")); 470 putValue(SHORT_DESCRIPTION, tr("Save/Upload layers before deleting. Unsaved changes are not lost.")); 471 putValue(BASE_ICON, ImageProvider.get("dialogs", "delete")); 472 break; 473 } 401 474 redrawIcon(); 402 475 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r10627 r11093 145 145 break; 146 146 case "handleQuitRequestWith": 147 boolean closed = Main.exitJosm(false, 0 );147 boolean closed = Main.exitJosm(false, 0, null); 148 148 if (args[1] != null) { 149 149 try {
Note:
See TracChangeset
for help on using the changeset viewer.