Changeset 8913 in josm


Ignore:
Timestamp:
2015-10-19T23:30:55+02:00 (9 years ago)
Author:
simon04
Message:

fix #9115 - Offer to save session when closing editor with unsaved changes

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r8802 r8913  
    6464    @Override
    6565    public void actionPerformed(ActionEvent e) {
     66        try {
     67            saveSession();
     68        } catch (CancelException ignore) {
     69        }
     70    }
     71
     72    /**
     73     * Denotes that the user has cancelled the save process.
     74     * @since 8913
     75     */
     76    public static class CancelException extends Exception {
     77    }
     78
     79    /**
     80     * Attempts to save the session.
     81     * @throws CancelException when the user has cancelled the save process.
     82     * @since 8913
     83     */
     84    public void saveSession() throws CancelException {
    6685        if (!isEnabled()) {
    6786            return;
     
    7089        SessionSaveAsDialog dlg = new SessionSaveAsDialog();
    7190        dlg.showDialog();
    72         if (dlg.getValue() != 1) return;
     91        if (dlg.getValue() != 1) {
     92            throw new CancelException();
     93        }
    7394
    7495        boolean zipRequired = false;
     
    93114        }
    94115
    95         if (fc == null)
    96             return;
     116        if (fc == null) {
     117            throw new CancelException();
     118        }
    97119
    98120        File file = fc.getSelectedFile();
     
    116138        if (fn.indexOf('.') == -1) {
    117139            file = new File(file.getPath() + (zip ? ".joz" : ".jos"));
    118             if (!SaveActionBase.confirmOverwrite(file))
    119                 return;
     140            if (!SaveActionBase.confirmOverwrite(file)) {
     141                throw new CancelException();
     142            }
    120143        }
    121144
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r8912 r8913  
    4242
    4343import org.openstreetmap.josm.Main;
     44import org.openstreetmap.josm.actions.SessionSaveAsAction;
    4445import org.openstreetmap.josm.actions.UploadAction;
    4546import org.openstreetmap.josm.gui.ExceptionDialogUtil;
     
    6768
    6869    private SaveAndProceedAction saveAndProceedAction;
     70    private SaveSessionAction saveSessionAction;
    6971    private DiscardAndProceedAction discardAndProceedAction;
    7072    private CancelAction cancelAction;
     
    105107        saveAndProceedAction = new SaveAndProceedAction();
    106108        model.addPropertyChangeListener(saveAndProceedAction);
    107         pnl.add(saveAndProceedActionButton = new JButton(saveAndProceedAction), GBC.std().insets(5, 5, 5, 5).fill(GBC.HORIZONTAL));
     109        pnl.add(saveAndProceedActionButton = new JButton(saveAndProceedAction), GBC.std(0, 0).insets(5, 5, 0, 0).fill(GBC.HORIZONTAL));
     110
     111        saveSessionAction = new SaveSessionAction();
     112        pnl.add(new JButton(saveSessionAction), GBC.std(1, 0).insets(5, 5, 5, 0). fill(GBC.HORIZONTAL));
    108113
    109114        discardAndProceedAction = new DiscardAndProceedAction();
    110115        model.addPropertyChangeListener(discardAndProceedAction);
    111         pnl.add(new JButton(discardAndProceedAction), GBC.std().insets(0, 0, 5, 0).fill(GBC.HORIZONTAL));
     116        pnl.add(new JButton(discardAndProceedAction), GBC.std(0, 1).insets(5, 5, 0, 5).fill(GBC.HORIZONTAL));
    112117
    113118        cancelAction = new CancelAction();
    114         pnl.add(new JButton(cancelAction), GBC.std().insets(0, 0, 5, 0).fill(GBC.HORIZONTAL));
     119        pnl.add(new JButton(cancelAction), GBC.std(1, 1).insets(5, 5, 5, 5). fill(GBC.HORIZONTAL));
    115120
    116121        JPanel pnl2 = new JPanel();
     
    363368    }
    364369
     370    class SaveSessionAction extends SessionSaveAsAction {
     371        @Override
     372        public void actionPerformed(ActionEvent e) {
     373            try {
     374                saveSession();
     375                setUserAction(UserAction.PROCEED);
     376                closeDialog();
     377            } catch (CancelException ignore) {
     378            }
     379        }
     380    }
     381
    365382    final class SaveAndProceedAction extends AbstractAction implements PropertyChangeListener {
    366383        private static final int is = 24; // icon size
Note: See TracChangeset for help on using the changeset viewer.