Search in sources :

Example 1 with TempOpenWithJob

use of com.mucommander.job.impl.TempOpenWithJob in project mucommander by mucommander.

the class CommandAction method performAction.

// - Action code -----------------------------------------------------------
// -------------------------------------------------------------------------
@Override
public void performAction() {
    FileSet selectedFiles;
    // Retrieves the current selection.
    selectedFiles = mainFrame.getActiveTable().getSelectedFiles();
    // If no files are either selected or marked, aborts.
    if (command.hasSelectedFileKeyword() && selectedFiles.size() == 0)
        return;
    // If we're working with local files, go ahead and runs the command.
    if (selectedFiles.getBaseFolder().getURL().getScheme().equals(LocalFile.SCHEMA) && (selectedFiles.getBaseFolder().hasAncestor(LocalFile.class))) {
        try {
            InformationDialog.showErrorDialogIfNeeded(getMainFrame(), ProcessRunner.executeAsync(command.getTokens(selectedFiles), selectedFiles.getBaseFolder()));
        } catch (Exception e) {
            InformationDialog.showErrorDialog(mainFrame);
            LOGGER.debug("Failed to execute command: " + command.getCommand(), e);
        }
    } else // Otherwise, copies the files locally before running the command.
    {
        ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying"));
        progressDialog.start(new TempOpenWithJob(new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying")), mainFrame, selectedFiles, command));
    }
}
Also used : FileSet(com.mucommander.commons.file.util.FileSet) ProgressDialog(com.mucommander.ui.dialog.file.ProgressDialog) TempOpenWithJob(com.mucommander.job.impl.TempOpenWithJob)

Example 2 with TempOpenWithJob

use of com.mucommander.job.impl.TempOpenWithJob in project mucommander by mucommander.

the class AbstractViewerAction method performAction.

// - AbstractAction implementation ---------------------------------------------------
// -----------------------------------------------------------------------------------
/**
 * Edits the currently selected file.
 */
@Override
public synchronized void performAction() {
    AbstractFile file;
    Command customCommand;
    file = mainFrame.getActiveTable().getSelectedFile(false, true);
    // viewer/editor implementations will decide whether they allow a particular file or not.
    if (file != null) {
        customCommand = getCustomCommand();
        // If we're using a custom command...
        if (customCommand != null) {
            // If it's local, run the custom editor on it.
            if (file.hasAncestor(LocalFile.class)) {
                try {
                    InformationDialog.showErrorDialogIfNeeded(getMainFrame(), ProcessRunner.executeAsync(customCommand.getTokens(file), file));
                } catch (Exception e) {
                    InformationDialog.showErrorDialog(mainFrame);
                }
            } else // If it's distant, copies it locally before running the custom editor on it.
            {
                ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying"));
                TempOpenWithJob job = new TempOpenWithJob(progressDialog, mainFrame, file, customCommand);
                progressDialog.start(job);
            }
        } else
            // If we're not using a custom editor, this action behaves exactly like its parent.
            performInternalAction(file);
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) Command(com.mucommander.command.Command) ProgressDialog(com.mucommander.ui.dialog.file.ProgressDialog) TempOpenWithJob(com.mucommander.job.impl.TempOpenWithJob)

Aggregations

TempOpenWithJob (com.mucommander.job.impl.TempOpenWithJob)2 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)2 Command (com.mucommander.command.Command)1 AbstractFile (com.mucommander.commons.file.AbstractFile)1 FileSet (com.mucommander.commons.file.util.FileSet)1