Search in sources :

Example 1 with RcvrCannotUndoRedoException

use of edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException in project cogtool by cogtool.

the class DefaultController method save.

/**
     * Perform a Save operation, using a stored save location.
     *
     * @return true if file was saved, false otherwise
     * @throws RcvrIOException if the save operation fails
     */
protected boolean save() {
    try {
        // Save to this file's original location.
        project.setBuildVersion(CogTool.getVersion());
        persist.save(project, null);
        // Tell undo manager(s) that a save has just occurred
        try {
            UndoManager.markSavePoint(project);
        } catch (IllegalStateException ex) {
            throw new RcvrCannotUndoRedoException("Marking save point", ex);
        }
        return true;
    } catch (IOException e) {
        throw new RcvrIOSaveException("Error persisting project: " + e.getMessage(), e);
    }
}
Also used : RcvrCannotUndoRedoException(edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)

Example 2 with RcvrCannotUndoRedoException

use of edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException in project cogtool by cogtool.

the class DefaultController method saveAs.

/**
     * Perform a Save As... operation, prompting for a save location.
     *
     * @return true if file was saved, false otherwise
     * @throws RcvrIOException if the save operation fails
     */
protected boolean saveAs() {
    Interaction stdInteraction = getUI().getStandardInteraction();
    try {
        boolean nameIsInUse;
        File saveLoc;
        do {
            // Request a new file name, using the project's current name
            // as the default.
            // TODO: It is "evil" that the test for existing files is
            //       hidden within this call; separate at some point (mlh)
            saveLoc = stdInteraction.selectFileDest(project.getName());
            // If the save dialog was canceled, do nothing.
            if (saveLoc == null) {
                return false;
            }
            // If saveLoc is already open, refuse to save there.
            nameIsInUse = persist.isRegistered(saveLoc, project);
            if (nameIsInUse) {
                switch(stdInteraction.protestBeingEdited(saveLoc)) {
                    case Interaction.SAVE:
                        {
                            nameIsInUse = false;
                            break;
                        }
                    case Interaction.NO_SAVE:
                        {
                            // Simply loop to ask for a new name
                            break;
                        }
                    case Interaction.CANCEL:
                        {
                            return false;
                        }
                }
            }
        } while (nameIsInUse);
        CogToolPref.setRecent(saveLoc.getCanonicalPath());
        // Set the title BEFORE saving the project.
        String name = saveLoc.getName();
        // Remove the .cgt, if it is there.
        int periodIndex = name.lastIndexOf('.');
        if (periodIndex > 0) {
            name = name.substring(0, periodIndex);
        }
        project.setName(name);
        // Save to the selected location.
        project.setBuildVersion(CogTool.getVersion());
        persist.save(project, saveLoc);
        // Tell undo manager(s) that a save has just occurred
        try {
            UndoManager.markSavePoint(project);
        } catch (IllegalStateException ex) {
            throw new RcvrCannotUndoRedoException("Marking save point", ex);
        }
        return true;
    } catch (IOException e) {
        throw new RcvrIOSaveException("Error persisting project: " + e.getMessage(), e);
    }
}
Also used : RcvrCannotUndoRedoException(edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException) Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) File(java.io.File) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)

Aggregations

RcvrCannotUndoRedoException (edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException)2 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)2 RcvrIOSaveException (edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)2 IOException (java.io.IOException)2 Interaction (edu.cmu.cs.hcii.cogtool.ui.Interaction)1 File (java.io.File)1