private Set<VirtualFile> registerWriteAccessProvider(final VirtualFile... filesToDeny) { final Set<VirtualFile> requested = new LinkedHashSet<VirtualFile>(); PlatformTestUtil.registerExtension(Extensions.getArea(getProject()), WritingAccessProvider.EP_NAME, new WritingAccessProvider() { @NotNull @Override public Collection<VirtualFile> requestWriting(VirtualFile... files) { Collections.addAll(requested, files); HashSet<VirtualFile> denied = new HashSet<VirtualFile>(Arrays.asList(filesToDeny)); denied.retainAll(Arrays.asList(files)); return denied; } @Override public boolean isPotentiallyWritable(@NotNull VirtualFile file) { return true; } }, myTestRootDisposable); return requested; }
public static boolean shouldEnableDeleteAction(PsiElement[] elements) { if (elements == null || elements.length == 0) return false; for (PsiElement element : elements) { VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element); if (virtualFile == null) { return false; } if (!WritingAccessProvider.isPotentiallyWritable(virtualFile, element.getProject())) { return false; } } return true; }
@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; }
@RequiredReadAction @Override public void updateIcon(@Nonnull IconDescriptor iconDescriptor, @Nonnull PsiElement element, int flags) { if (BitUtil.isSet(flags, Iconable.ICON_FLAG_READ_STATUS)) { VirtualFile file = PsiUtilCore.getVirtualFile(element); final boolean isLocked = !element.isWritable() || !WritingAccessProvider.isPotentiallyWritable(file, element.getProject()); if (isLocked) { iconDescriptor.addLayerIcon(AllIcons.Nodes.Locked); } } }