Search in sources :

Example 1 with FileTableTabs

use of com.mucommander.ui.main.tabs.FileTableTabs in project mucommander by mucommander.

the class OpenAction method open.

/**
 * Opens the specified file in the specified folder panel.
 * <p>
 * <code>file</code> will be opened using the following rules:
 * <ul>
 *   <li>
 *     If <code>file</code> is {@link com.mucommander.commons.file.AbstractFile#isBrowsable() browsable},
 *     it will be opened in <code>destination</code>.
 *   </li>
 *   <li>
 *     If <code>file</code> is local, it will be opened using its native associations.
 *   </li>
 *   <li>
 *     If <code>file</code> is remote, it will first be copied in a temporary local file and
 *     then opened using its native association.
 *   </li>
 * </ul>
 * </p>
 * @param file        file to open.
 * @param destination if <code>file</code> is browsable, folder panel in which to open the file.
 */
protected void open(AbstractFile file, FolderPanel destination) {
    AbstractFile resolvedFile;
    if (file.isSymlink()) {
        resolvedFile = resolveSymlink(file);
        if (resolvedFile == null) {
            InformationDialog.showErrorDialog(mainFrame, Translator.get("cannot_open_cyclic_symlink"));
            return;
        }
    } else
        resolvedFile = file;
    // Opens browsable files in the destination FolderPanel.
    if (resolvedFile.isBrowsable()) {
        resolvedFile = MuConfigurations.getPreferences().getVariable(MuPreference.CD_FOLLOWS_SYMLINKS, MuPreferences.DEFAULT_CD_FOLLOWS_SYMLINKS) ? resolvedFile : file;
        FileTableTabs tabs = destination.getTabs();
        if (BookmarkManager.isBookmark(resolvedFile.getURL())) {
            String bookmarkLocation = BookmarkManager.getBookmark(resolvedFile.getName()).getLocation();
            FileURL bookmarkURL;
            try {
                bookmarkURL = FileURL.getFileURL(bookmarkLocation);
            } catch (MalformedURLException e) {
                LOGGER.error("Failed to resolve bookmark's location: " + bookmarkLocation);
                return;
            }
            if (tabs.getCurrentTab().isLocked())
                tabs.add(bookmarkURL);
            else
                destination.tryChangeCurrentFolder(bookmarkURL);
        } else {
            if (tabs.getCurrentTab().isLocked())
                tabs.add(resolvedFile);
            else
                destination.tryChangeCurrentFolder(resolvedFile);
        }
    } else // Opens local files using their native associations.
    if (resolvedFile.getURL().getScheme().equals(LocalFile.SCHEMA) && (resolvedFile.hasAncestor(LocalFile.class))) {
        try {
            OpenAction.openFile(getMainFrame(), resolvedFile);
            RecentExecutedFilesQL.addFile(resolvedFile);
        } catch (IOException e) {
            InformationDialog.showErrorDialog(mainFrame);
        }
    } else // Copies non-local file in a temporary local file and opens them using their native association.
    {
        ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying"));
        TempExecJob job = new TempExecJob(progressDialog, mainFrame, resolvedFile);
        progressDialog.start(job);
    }
}
Also used : FileTableTabs(com.mucommander.ui.main.tabs.FileTableTabs) FileURL(com.mucommander.commons.file.FileURL) MalformedURLException(java.net.MalformedURLException) LocalFile(com.mucommander.commons.file.protocol.local.LocalFile) AbstractFile(com.mucommander.commons.file.AbstractFile) TempExecJob(com.mucommander.job.impl.TempExecJob) IOException(java.io.IOException) ProgressDialog(com.mucommander.ui.dialog.file.ProgressDialog)

Aggregations

AbstractFile (com.mucommander.commons.file.AbstractFile)1 FileURL (com.mucommander.commons.file.FileURL)1 LocalFile (com.mucommander.commons.file.protocol.local.LocalFile)1 TempExecJob (com.mucommander.job.impl.TempExecJob)1 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)1 FileTableTabs (com.mucommander.ui.main.tabs.FileTableTabs)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1