Java 类com.intellij.openapi.vfs.WritingAccessProvider 实例源码

项目:intellij-ce-playground    文件:NonProjectFileAccessTest.java   
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;
}
项目:intellij-ce-playground    文件:DeleteHandler.java   
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;
}
项目:tools-idea    文件:DeleteHandler.java   
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;
}
项目:consulo    文件:VfsIconUtil.java   
@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;
}
项目:consulo    文件:LockedIconDescriptorUpdater.java   
@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);
    }
  }
}
项目:consulo    文件:DeleteHandler.java   
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;
}