Search in sources :

Example 6 with RcvrIOSaveException

use of edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException 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)

Example 7 with RcvrIOSaveException

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

the class DefaultController method saveAsFilename.

public void saveAsFilename(String pathname) {
    File f = new File(pathname);
    project.setName(f.getName());
    project.setBuildVersion(CogTool.getVersion());
    try {
        persist.save(project, f);
    } catch (IOException e) {
        throw new RcvrIOSaveException("Error persisting project: " + e.getMessage(), e);
    }
    save();
}
Also used : 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

RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)7 RcvrIOSaveException (edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)7 IOException (java.io.IOException)7 File (java.io.File)6 FileOutputStream (java.io.FileOutputStream)4 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)3 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)3 RcvrCannotUndoRedoException (edu.cmu.cs.hcii.cogtool.util.RcvrCannotUndoRedoException)3 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)3 PrintWriter (java.io.PrintWriter)3 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 RcvrClipboardException (edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException)2 RcvrImageException (edu.cmu.cs.hcii.cogtool.util.RcvrImageException)2 RcvrOutOfMemoryException (edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException)2 RcvrUnimplementedFnException (edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException)2 RecoverableException (edu.cmu.cs.hcii.cogtool.util.RecoverableException)2 BufferedWriter (java.io.BufferedWriter)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2