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

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.