/** * Defines whether a file can be chosen. */ public boolean isFileSelectable(VirtualFile file) { if (file == null) return false; if (file.is(VFileProperty.SYMLINK) && file.getCanonicalPath() == null) { return false; } if (file.isDirectory() && myChooseFolders) { return true; } if (acceptAsJarFile(file)) { return true; } if (acceptAsGeneralFile(file)) { return true; } if (myFileFilter != null && !file.isDirectory() && myFileFilter.value(file)) { return true; } return false; }
private boolean checkAndScheduleFileTypeChange(@NotNull VirtualFile parent, @NotNull VirtualFile child, @NotNull FileAttributes childAttributes) { boolean currentIsDirectory = child.isDirectory(); boolean currentIsSymlink = child.is(VFileProperty.SYMLINK); boolean currentIsSpecial = child.is(VFileProperty.SPECIAL); boolean upToDateIsDirectory = childAttributes.isDirectory(); boolean upToDateIsSymlink = childAttributes.isSymLink(); boolean upToDateIsSpecial = childAttributes.isSpecial(); if (currentIsDirectory != upToDateIsDirectory || currentIsSymlink != upToDateIsSymlink || currentIsSpecial != upToDateIsSpecial) { scheduleDeletion(child); scheduleCreation(parent, child.getName(), upToDateIsDirectory, true); return true; } return false; }
@Nullable protected PsiFile createFile(@NotNull Project project, @NotNull VirtualFile file, @NotNull FileType fileType) { if (fileType.isBinary() || file.is(VFileProperty.SPECIAL)) { return new PsiBinaryFileImpl((PsiManagerImpl)getManager(), this); } if (!isTooLargeForIntelligence(file)) { final PsiFile psiFile = createFile(getBaseLanguage()); if (psiFile != null) return psiFile; } if (isTooLargeForContentLoading(file)) { return new PsiLargeFileImpl((PsiManagerImpl)getManager(), this); } return new PsiPlainTextFileImpl(this); }
public boolean processFile(NewVirtualFile file) { if (file.isDirectory() || file.is(VFileProperty.SPECIAL)) { return true; } try { DataInputStream stream = FSRecords.readContent(file.getId()); if (stream == null) return true; byte[] bytes = FileUtil.loadBytes(stream); totalSize.addAndGet(bytes.length); count.incrementAndGet(); ProgressManager.getInstance().getProgressIndicator().setText(file.getPresentableUrl()); } catch (IOException e) { LOG.error(e); } return true; }
protected Icon patchIcon(Icon original, VirtualFile file) { Icon icon = original; final Bookmark bookmarkAtFile = BookmarkManager.getInstance(myProject).findFileBookmark(file); if (bookmarkAtFile != null) { final RowIcon composite = new RowIcon(2, RowIcon.Alignment.CENTER); composite.setIcon(icon, 0); composite.setIcon(bookmarkAtFile.getIcon(), 1); icon = composite; } if (!file.isWritable()) { icon = LayeredIcon.create(icon, PlatformIcons.LOCKED_ICON); } if (file.is(VFileProperty.SYMLINK)) { icon = LayeredIcon.create(icon, PlatformIcons.SYMLINK_ICON); } return icon; }
@Override protected void updateImpl(PresentationData data) { PsiFile value = getValue(); data.setPresentableText(value.getName()); data.setIcon(value.getIcon(Iconable.ICON_FLAG_READ_STATUS)); VirtualFile file = getVirtualFile(); if (file != null && file.is(VFileProperty.SYMLINK)) { String target = file.getCanonicalPath(); if (target == null) { data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES); data.setTooltip(CommonBundle.message("vfs.broken.link")); } else { data.setTooltip(FileUtil.toSystemDependentName(target)); } } }
private boolean checkAndScheduleAttributesChange(@NotNull VirtualFile parent, @NotNull VirtualFile child, @NotNull FileAttributes childAttributes) { boolean currentIsDirectory = child.isDirectory(); boolean currentIsSymlink = child.is(VFileProperty.SYMLINK); boolean currentIsSpecial = child.is(VFileProperty.SPECIAL); boolean upToDateIsDirectory = childAttributes.isDirectory(); boolean upToDateIsSymlink = childAttributes.isSymLink(); boolean upToDateIsSpecial = childAttributes.isSpecial(); if (currentIsDirectory != upToDateIsDirectory || currentIsSymlink != upToDateIsSymlink || currentIsSpecial != upToDateIsSpecial) { scheduleDeletion(child); scheduleReCreation(parent, child.getName(), upToDateIsDirectory); return true; } return false; }
/** * Defines whether file can be chosen or not */ @RequiredDispatchThread public boolean isFileSelectable(VirtualFile file) { if (file == null) return false; if (file.is(VFileProperty.SYMLINK) && file.getCanonicalPath() == null) { return false; } if (file.isDirectory() && myChooseFolders) { return true; } if (myFileFilter != null && !file.isDirectory()) { return myFileFilter.value(file); } return acceptAsJarFile(file) || acceptAsGeneralFile(file); }
@Nullable public static NewVirtualFile findFileByPath(@Nonnull NewVirtualFileSystem vfs, @Nonnull String path) { Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path); if (data == null) return null; NewVirtualFile file = data.first; for (String pathElement : data.second) { if (pathElement.isEmpty() || ".".equals(pathElement)) continue; if ("..".equals(pathElement)) { if (file.is(VFileProperty.SYMLINK)) { final NewVirtualFile canonicalFile = file.getCanonicalFile(); file = canonicalFile != null ? canonicalFile.getParent() : null; } else { file = file.getParent(); } } else { file = file.findChild(pathElement); } if (file == null) return null; } return file; }
private boolean checkAndScheduleFileTypeChange(@Nonnull VirtualFile parent, @Nonnull VirtualFile child, @Nonnull FileAttributes childAttributes) { boolean currentIsDirectory = child.isDirectory(); boolean currentIsSymlink = child.is(VFileProperty.SYMLINK); boolean currentIsSpecial = child.is(VFileProperty.SPECIAL); boolean upToDateIsDirectory = childAttributes.isDirectory(); boolean upToDateIsSymlink = childAttributes.isSymLink(); boolean upToDateIsSpecial = childAttributes.isSpecial(); if (currentIsDirectory != upToDateIsDirectory || currentIsSymlink != upToDateIsSymlink || currentIsSpecial != upToDateIsSpecial) { scheduleDeletion(child); scheduleCreation(parent, child.getName(), upToDateIsDirectory, true); return true; } return false; }
@Nullable protected PsiFile createFile(@Nonnull Project project, @Nonnull VirtualFile file, @Nonnull FileType fileType) { if (fileType.isBinary() || file.is(VFileProperty.SPECIAL)) { return SingleRootFileViewProvider.isTooLargeForContentLoading(file) ? new PsiLargeBinaryFileImpl((PsiManagerImpl)getManager(), this) : new PsiBinaryFileImpl((PsiManagerImpl)getManager(), this); } if (!SingleRootFileViewProvider.isTooLargeForIntelligence(file)) { final PsiFile psiFile = createFile(getBaseLanguage()); if (psiFile != null) return psiFile; } if (SingleRootFileViewProvider.isTooLargeForContentLoading(file)) { return new PsiLargeTextFileImpl(this); } return new PsiPlainTextFileImpl(this); }
@RequiredReadAction @Override public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int flags) { if (element instanceof PsiFile) { if (iconDescriptor.getMainIcon() == null) { FileType fileType = ((PsiFile)element).getFileType(); iconDescriptor.setMainIcon(fileType.getIcon()); } VirtualFile virtualFile = ((PsiFile)element).getVirtualFile(); if (virtualFile != null && virtualFile.is(VFileProperty.SYMLINK)) { iconDescriptor.addLayerIcon(AllIcons.Nodes.Symlink); } } else { Icon languageElementIcon = LanguageElementIcons.INSTANCE.forLanguage(element.getLanguage()); if (languageElementIcon == null) { return; } iconDescriptor.addLayerIcon(languageElementIcon); } }
public boolean processFile(NewVirtualFile file) { if (file.isDirectory() || file.is(VFileProperty.SPECIAL)) return true; try { DataInputStream stream = FSRecords.readContent(file.getId()); if (stream == null) return true; byte[] bytes = FileUtil.loadBytes(stream); totalSize.addAndGet(bytes.length); count.incrementAndGet(); ProgressManager.getInstance().getProgressIndicator().setText(file.getPresentableUrl()); } catch (IOException e1) { LOG.error(e1); } return true; }
protected Icon patchIcon(Icon original, VirtualFile file) { Icon icon = original; final Bookmark bookmarkAtFile = BookmarkManager.getInstance(myProject).findFileBookmark(file); if (bookmarkAtFile != null) { final RowIcon composite = new RowIcon(2, RowIcon.Alignment.CENTER); composite.setIcon(icon, 0); composite.setIcon(bookmarkAtFile.getIcon(), 1); icon = composite; } if (!file.isWritable()) { icon = LayeredIcon.create(icon, AllIcons.Nodes.Locked); } if (file.is(VFileProperty.SYMLINK)) { icon = LayeredIcon.create(icon, AllIcons.Nodes.Symlink); } return icon; }
@Override protected void updateImpl(PresentationData data) { PsiFile value = getValue(); data.setPresentableText(value.getName()); data.setIcon(IconDescriptorUpdaters.getIcon(value, Iconable.ICON_FLAG_READ_STATUS)); VirtualFile file = getVirtualFile(); if (file != null && file.is(VFileProperty.SYMLINK)) { String target = file.getCanonicalPath(); if (target == null) { data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES); data.setTooltip(CommonBundle.message("vfs.broken.link")); } else { data.setTooltip(FileUtil.toSystemDependentName(target)); } } }
private static VirtualFile findMetadataFile(VirtualFile root) { if (!root.is(VFileProperty.SYMLINK)) { //noinspection UnsafeVfsRecursion for (VirtualFile child : asList(root.getChildren())) { if (child.getName().equals("spring-configuration-metadata.json")) { return child; } VirtualFile matchedFile = findMetadataFile(child); if (matchedFile != null) { return matchedFile; } } } return null; }
@Override protected void modifyRoots(@NotNull VirtualFile vFile, @NotNull ContentEntry entry) { VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { if (file.isDirectory() && file.is(VFileProperty.SYMLINK)) { entry.addExcludeFolder(file); return false; } else { return true; } } }); }
/** * Defines whether a file is visible in the tree. */ public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { if (file.is(VFileProperty.SYMLINK) && file.getCanonicalPath() == null) { return false; } if (!file.isDirectory()) { if (FileElement.isArchive(file)) { if (!myChooseJars && !myChooseJarContents) { return false; } } else if (!myChooseFiles) { return false; } if (myFileFilter != null && !myFileFilter.value(file)) { return false; } } if (isHideIgnored() && FileTypeManager.getInstance().isFileIgnored(file)) { return false; } if (!showHiddenFiles && FileElement.isFileHidden(file)) { return false; } return true; }
@Nullable public static NewVirtualFile findFileByPath(@NotNull NewVirtualFileSystem vfs, @NotNull @NonNls String path) { Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path); if (data == null) { return null; } NewVirtualFile file = data.first; for (String pathElement : data.second) { if (pathElement.isEmpty() || ".".equals(pathElement)) continue; if ("..".equals(pathElement)) { if (file.is(VFileProperty.SYMLINK)) { final NewVirtualFile canonicalFile = file.getCanonicalFile(); file = canonicalFile != null ? canonicalFile.getParent() : null; } else { file = file.getParent(); } } else { file = file.findChild(pathElement); } if (file == null) return null; } return file; }
@Nullable public static NewVirtualFile findFileByPathIfCached(@NotNull NewVirtualFileSystem vfs, @NotNull @NonNls String path) { Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path); if (data == null) { return null; } NewVirtualFile file = data.first; for (String pathElement : data.second) { if (pathElement.isEmpty() || ".".equals(pathElement)) continue; if ("..".equals(pathElement)) { if (file.is(VFileProperty.SYMLINK)) { final String canonicalPath = file.getCanonicalPath(); final NewVirtualFile canonicalFile = canonicalPath != null ? findFileByPathIfCached(vfs, canonicalPath) : null; file = canonicalFile != null ? canonicalFile.getParent() : null; } else { file = file.getParent(); } } else { file = file.findChildIfCached(pathElement); } if (file == null) return null; } return file; }
@Nullable public static NewVirtualFile refreshAndFindFileByPath(@NotNull NewVirtualFileSystem vfs, @NotNull @NonNls String path) { Pair<NewVirtualFile, Iterable<String>> data = prepare(vfs, path); if (data == null) { return null; } NewVirtualFile file = data.first; for (String pathElement : data.second) { if (pathElement.isEmpty() || ".".equals(pathElement)) continue; if ("..".equals(pathElement)) { if (file.is(VFileProperty.SYMLINK)) { final String canonicalPath = file.getCanonicalPath(); final NewVirtualFile canonicalFile = canonicalPath != null ? refreshAndFindFileByPath(vfs, canonicalPath) : null; file = canonicalFile != null ? canonicalFile.getParent() : null; } else { file = file.getParent(); } } else { file = file.refreshAndFindChild(pathElement); } if (file == null) return null; } return file; }
void updateLinkStatus() { boolean isSymLink = is(VFileProperty.SYMLINK); if (isSymLink) { String target = getParent().getFileSystem().resolveSymLink(this); setLinkTarget(target != null ? FileUtil.toSystemIndependentName(target) : null); } setFlagInt(HAS_SYMLINK_FLAG, isSymLink || getParent().getFlagInt(HAS_SYMLINK_FLAG)); }
@Override public boolean is(@NotNull VFileProperty property) { if (property == VFileProperty.SPECIAL) return getFlagInt(IS_SPECIAL_FLAG); if (property == VFileProperty.HIDDEN) return getFlagInt(IS_HIDDEN_FLAG); if (property == VFileProperty.SYMLINK) return getFlagInt(IS_SYMLINK_FLAG); return super.is(property); }
@Override public String getCanonicalPath() { if (getFlagInt(HAS_SYMLINK_FLAG)) { if (is(VFileProperty.SYMLINK)) { return getUserData(SYMLINK_TARGET); } VirtualFileSystemEntry parent = getParent(); if (parent != null) { return parent.getCanonicalPath() + "/" + getName(); } return getName(); } return getPath(); }
public static boolean canNavigate(PsiElement element) { if (element == null || !element.isValid()) { return false; } VirtualFile file = PsiUtilCore.getVirtualFile(element.getNavigationElement()); return file != null && file.isValid() && !file.is(VFileProperty.SPECIAL) && !VfsUtilCore.isBrokenLink(file); }
@Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = getEventProject(e); VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); if (project != null && file != null && file.is(VFileProperty.SYMLINK)) { VirtualFile target = file.getCanonicalFile(); if (target != null) { PsiManager psiManager = PsiManager.getInstance(project); PsiFileSystemItem psiFile = target.isDirectory() ? psiManager.findDirectory(target) : psiManager.findFile(target); if (psiFile != null) { ProjectView.getInstance(project).select(psiFile, target, false); } } } }
public static void smartVisit(VirtualFile file, LinkedList<VirtualFile> fileList) { if (file.isDirectory() && !file.getName().startsWith(".") && !file.is(VFileProperty.SYMLINK) && file.getChildren() != null) { for (VirtualFile childFile : file.getChildren()) { smartVisit(childFile, fileList); } } else if (!file.isDirectory()) { fileList.add(file); } }
@NotNull @Override public FileType detectFileTypeFromContent(@NotNull VirtualFile file) { if (file.isDirectory() || !file.isValid() || file.is(VFileProperty.SPECIAL)) { return UnknownFileType.INSTANCE; } FileType fileType = file.getUserData(DETECTED_FROM_CONTENT_FILE_TYPE_KEY); if (fileType == null) { fileType = detectFromContent(file); file.putUserData(DETECTED_FROM_CONTENT_FILE_TYPE_KEY, fileType); } return fileType; }
private void updateLinkStatus() { boolean isSymLink = is(VFileProperty.SYMLINK); if (isSymLink) { String target = myParent.getFileSystem().resolveSymLink(this); putUserData(SYMLINK_TARGET, target != null ? FileUtil.toSystemIndependentName(target) : target); } setFlagInt(HAS_SYMLINK_FLAG, isSymLink || myParent.getFlagInt(HAS_SYMLINK_FLAG)); }
@Override public String getCanonicalPath() { if (getFlagInt(HAS_SYMLINK_FLAG)) { if (is(VFileProperty.SYMLINK)) { return getUserData(SYMLINK_TARGET); } VirtualDirectoryImpl parent = myParent; if (parent != null) { return parent.getCanonicalPath() + "/" + getName(); } return getName(); } return getPath(); }
@Override @RequiredReadAction public Icon fun(final AnyIconKey<VirtualFile> key) { final VirtualFile file = key.getObject(); final int flags = key.getFlags(); Project project = key.getProject(); if (!file.isValid() || project != null && (project.isDisposed() || !wasEverInitialized(project))) return null; boolean processedDescriptors = false; // disable on webservice native icon IconDescriptor iconDescriptor = new IconDescriptor(VirtualFilePresentation.getIcon(file)); if (project != null) { PsiManager manager = PsiManager.getInstance(project); final PsiElement element = file.isDirectory() ? manager.findDirectory(file) : manager.findFile(file); if (element != null) { IconDescriptorUpdaters.processExistingDescriptor(iconDescriptor, element, flags); processedDescriptors = true; } } // if descriptors not processed - we need add layer icon obviously if (!processedDescriptors && file.is(VFileProperty.SYMLINK)) { iconDescriptor.addLayerIcon(AllIcons.Nodes.Symlink); } if (BitUtil.isSet(flags, Iconable.ICON_FLAG_READ_STATUS)) { final boolean isLocked = !file.isWritable() || !WritingAccessProvider.isPotentiallyWritable(file, project); if (isLocked) { iconDescriptor.addLayerIcon(AllIcons.Nodes.Locked); } } Icon icon = iconDescriptor.toIcon(); Iconable.LastComputedIcon.put(file, icon, flags); return icon; }