Search in sources :

Example 21 with DialogAction

use of com.mucommander.ui.dialog.DialogAction in project mucommander by mucommander.

the class BasicFileEditor method trySaveAs.

private void trySaveAs() {
    JFileChooser fileChooser = new JFileChooser();
    AbstractFile currentFile = getCurrentFile();
    // Sets selected file in JFileChooser to current file
    if (currentFile.getURL().getScheme().equals(LocalFile.SCHEMA)) {
        fileChooser.setSelectedFile(new java.io.File(currentFile.getAbsolutePath()));
    }
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    int ret = fileChooser.showSaveDialog(getFrame());
    if (ret == JFileChooser.APPROVE_OPTION) {
        AbstractFile destFile;
        try {
            destFile = FileFactory.getFile(fileChooser.getSelectedFile().getAbsolutePath(), true);
        } catch (IOException e) {
            InformationDialog.showErrorDialog(getFrame(), Translator.get("write_error"), Translator.get("file_editor.cannot_write"));
            return;
        }
        // Check for file collisions, i.e. if the file already exists in the destination
        int collision = FileCollisionChecker.checkForCollision(null, destFile);
        if (collision != FileCollisionChecker.NO_COLLISION) {
            // File already exists in destination, ask the user what to do (cancel, overwrite,...) but
            // do not offer the multiple files mode options such as 'skip' and 'apply to all'.
            DialogAction action = new FileCollisionDialog(getFrame(), getFrame(), /*mainFrame*/
            collision, null, destFile, false, false).getActionValue();
            // User chose to overwrite the file
            if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
            // Do nothing, simply continue and file will be overwritten
            } else // User chose to cancel or closed the dialog
            {
                return;
            }
        }
        if (trySave(destFile)) {
            setCurrentFile(destFile);
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileCollisionDialog(com.mucommander.ui.dialog.file.FileCollisionDialog) JFileChooser(javax.swing.JFileChooser) DialogAction(com.mucommander.ui.dialog.DialogAction) IOException(java.io.IOException)

Example 22 with DialogAction

use of com.mucommander.ui.dialog.DialogAction in project mucommander by mucommander.

the class BasicFileEditor method askSave.

// Returns true if the file does not have any unsaved change or if the user refused to save the changes,
// false if the user canceled the dialog or the save failed.
public boolean askSave() {
    if (!saveNeeded) {
        return true;
    }
    QuestionDialog dialog = new QuestionDialog(getFrame(), null, Translator.get("file_editor.save_warning"), getFrame(), Arrays.asList(BasicFileAction.YES, BasicFileAction.NO, BasicFileAction.CANCEL), 0);
    DialogAction ret = dialog.getActionValue();
    if (ret == BasicFileAction.YES && trySave(getCurrentFile()) || ret == BasicFileAction.NO) {
        setSaveNeeded(false);
        return true;
    }
    // User canceled or the file couldn't be properly saved
    return false;
}
Also used : QuestionDialog(com.mucommander.ui.dialog.QuestionDialog) DialogAction(com.mucommander.ui.dialog.DialogAction)

Aggregations

DialogAction (com.mucommander.ui.dialog.DialogAction)22 IOException (java.io.IOException)13 AbstractFile (com.mucommander.commons.file.AbstractFile)10 FileCollisionDialog (com.mucommander.ui.dialog.file.FileCollisionDialog)7 QuestionDialog (com.mucommander.ui.dialog.QuestionDialog)6 JFileChooser (javax.swing.JFileChooser)3 InformationPane (com.mucommander.ui.layout.InformationPane)2 MainFrame (com.mucommander.ui.main.MainFrame)2 WarnUserException (com.mucommander.viewer.WarnUserException)2 Cursor (java.awt.Cursor)2 Frame (java.awt.Frame)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 JCheckBox (javax.swing.JCheckBox)2 VersionChecker (com.mucommander.VersionChecker)1 CredentialsMapping (com.mucommander.auth.CredentialsMapping)1 AuthException (com.mucommander.commons.file.AuthException)1 AuthenticationType (com.mucommander.commons.file.AuthenticationType)1 FileURL (com.mucommander.commons.file.FileURL)1 UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)1