use of com.intellij.openapi.vfs.WritingAccessProvider in project intellij-community by JetBrains.
the class NonProjectFileAccessTest method registerWriteAccessProvider.
private Set<VirtualFile> registerWriteAccessProvider(final VirtualFile... filesToDeny) {
final Set<VirtualFile> requested = new LinkedHashSet<>();
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<>(Arrays.asList(filesToDeny));
denied.retainAll(Arrays.asList(files));
return denied;
}
@Override
public boolean isPotentiallyWritable(@NotNull VirtualFile file) {
return true;
}
}, getProject());
return requested;
}
use of com.intellij.openapi.vfs.WritingAccessProvider in project intellij-community by JetBrains.
the class ReadonlyStatusHandlerImpl method ensureFilesWritable.
@Override
public OperationStatus ensureFilesWritable(@NotNull VirtualFile... files) {
if (files.length == 0) {
return new OperationStatusImpl(VirtualFile.EMPTY_ARRAY);
}
checkThreading();
Set<VirtualFile> realFiles = new THashSet<>(files.length);
for (VirtualFile file : files) {
if (file instanceof LightVirtualFile) {
VirtualFile originalFile = ((LightVirtualFile) file).getOriginalFile();
if (originalFile != null) {
file = originalFile;
}
}
if (file instanceof VirtualFileWindow)
file = ((VirtualFileWindow) file).getDelegate();
if (file != null) {
realFiles.add(file);
}
}
files = VfsUtilCore.toVirtualFileArray(realFiles);
for (final WritingAccessProvider accessProvider : myAccessProviders) {
Collection<VirtualFile> denied = ContainerUtil.filter(files, virtualFile -> !accessProvider.isPotentiallyWritable(virtualFile));
if (denied.isEmpty()) {
denied = accessProvider.requestWriting(files);
}
if (!denied.isEmpty()) {
return new OperationStatusImpl(VfsUtilCore.toVirtualFileArray(denied));
}
}
final FileInfo[] fileInfos = createFileInfos(files);
if (fileInfos.length == 0) {
// if all files are already writable
return createResultStatus(files);
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (myClearReadOnlyInTests) {
processFiles(new ArrayList<>(Arrays.asList(fileInfos)), null);
}
return createResultStatus(files);
}
// This event count hack is necessary to allow actions that called this stuff could still get data from their data contexts.
// Otherwise data manager stuff will fire up an assertion saying that event count has been changed (due to modal dialog show-up)
// The hack itself is safe since we guarantee that focus will return to the same component had it before modal dialog have been shown.
final int savedEventCount = IdeEventQueue.getInstance().getEventCount();
if (myState.SHOW_DIALOG) {
new ReadOnlyStatusDialog(myProject, fileInfos).show();
} else {
// the collection passed is modified
processFiles(new ArrayList<>(Arrays.asList(fileInfos)), null);
}
IdeEventQueue.getInstance().setEventCount(savedEventCount);
return createResultStatus(files);
}
Aggregations