/** * Iterates through the ancestors returned by {@link #getAncestor()} until the top-most ancestor is reached and * returns it. If this file has no ancestor, <code>this</code> will be returned. * * @return returns the top-most ancestor of this file, <code>this</code> if this file has no ancestor */ public final AbstractFile getTopAncestor() { AbstractFile topAncestor = this; while(topAncestor.hasAncestor()) topAncestor = topAncestor.getAncestor(); return topAncestor; }
/** * Convenience method that returns the parent {@link AbstractArchiveFile} that contains this file. If this file * is an {@link AbstractArchiveFile} or an ancestor of {@link AbstractArchiveFile}, <code>this</code> is returned. * If this file is neither contained by an archive nor is an archive, <code>null</code> is returned. * * <p> * <b>Important note:</b> the returned {@link AbstractArchiveFile}, if any, may not necessarily be an * archive, as specified by {@link #isArchive()}. This is the case for files that were resolved as * {@link AbstractArchiveFile} instances based on their path, but that do not yet exist or were created as * directories. On the contrary, an existing archive will necessarily return a non-null value. * </p> * * @return the parent {@link AbstractArchiveFile} that contains this file */ public final AbstractArchiveFile getParentArchive() { if(hasAncestor(AbstractArchiveFile.class)) return getAncestor(AbstractArchiveFile.class); else if(hasAncestor(AbstractArchiveEntryFile.class)) return getAncestor(AbstractArchiveEntryFile.class).getArchiveFile(); return null; }
private void tryCopyFileTypeAndCreator(AbstractFile sourceFile, AbstractFile destFile) { if (OsFamily.MAC_OS_X.isCurrent() && sourceFile.hasAncestor(LocalFile.class) && destFile.hasAncestor(LocalFile.class)) { String sourcePath = sourceFile.getAbsolutePath(); try { FileManager.setFileTypeAndCreator(destFile.getAbsolutePath(), FileManager.getFileType(sourcePath), FileManager.getFileCreator(sourcePath)); } catch(IOException e) { // Swallow the exception and do not interrupt the transfer LOGGER.debug("Error while setting Mac OS X file type and creator on destination", e); } } }
if(target[0] instanceof AbstractFile && ((AbstractFile)target[0]).hasAncestor(LocalFile.class)) return (AbstractFile)target[0];
@Override protected void toggleEnabledState() { AbstractFile currentFolder = mainFrame.getActivePanel().getCurrentFolder(); setEnabled(currentFolder.getURL().getScheme().equals(FileProtocols.FILE) && !currentFolder.isArchive() && !currentFolder.hasAncestor(AbstractArchiveEntryFile.class) ); }
@Override protected void acceptListItem(AbstractFile item) { MainFrame mainFrame = WindowManager.getCurrentMainFrame(); if(item.getURL().getScheme().equals(FileProtocols.FILE) && (item.hasAncestor(LocalFile.class))) { try { DesktopManager.open(item); } catch(IOException e) {} } // Copies non-local file in a temporary local file and opens them using their native association. else { ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying")); TempExecJob job = new TempExecJob(progressDialog, mainFrame, item); progressDialog.start(job); } }
if(!currentDirectory.hasAncestor(LocalFile.class)) { currentDirectory = FileFactory.getFile(System.getProperty("user.home"), true);
&& isSingleFile && singleFile.hasAncestor(LocalFile.class)) { String comment = OSXFileUtils.getSpotlightComment(singleFile); JLabel commentLabel = new JLabel(Translator.get("comment")+":");
if(currentFolder.hasAncestor(LocalFile.class)) { tokens[tokens.length - 1] = command; commandTokens = tokens;
if(currentFolder.hasAncestor(AbstractArchiveEntryFile.class)) javaIoFile = currentFolder.getParentArchive().getUnderlyingFileObject(); else
@Override public void performAction() { AbstractFile selectedFile = mainFrame.getActiveTable().getSelectedFile(true, true); if(selectedFile==null) return; // Copy file to a temporary local file and execute it with native file associations if // file is not on a local filesystem or file is an archive entry if(!FileProtocols.FILE.equals(selectedFile.getURL().getScheme()) || selectedFile.hasAncestor(AbstractArchiveEntryFile.class)) { ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying")); TempExecJob job = new TempExecJob(progressDialog, mainFrame, selectedFile); progressDialog.start(job); } else { // Tries to execute file with native file associations try { DesktopManager.open(selectedFile); RecentExecutedFilesQL.addFile(selectedFile); } catch(IOException e) { InformationDialog.showErrorDialog(mainFrame); } } }
@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(FileProtocols.FILE) && (selectedFiles.getBaseFolder().hasAncestor(LocalFile.class))) { try {ProcessRunner.execute(command.getTokens(selectedFiles), selectedFiles.getBaseFolder());} catch(Exception e) { InformationDialog.showErrorDialog(mainFrame); LOGGER.debug("Failed to execute command: " + command.getCommand(), e); } } // Otherwise, copies the files locally before running the command. else { 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)); } }
if(file.hasAncestor(LocalFile.class)) { try {ProcessRunner.execute(customCommand.getTokens(file), file);} catch(Exception e) {
!file.hasAncestor(LocalFile.class) || !destFile.hasAncestor(LocalFile.class))) { return true;
else if(resolvedFile.getURL().getScheme().equals(FileProtocols.FILE) && (resolvedFile.hasAncestor(LocalFile.class))) { try { DesktopManager.open(resolvedFile);