com.intellij.openapi.vfs.ReadonlyStatusHandler Java Examples

The following examples show how to use com.intellij.openapi.vfs.ReadonlyStatusHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CsvTableEditor.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void saveChanges(final String content) {
    if (hasErrors()) {
        return;
    }
    ApplicationManager.getApplication().invokeLater(() -> {
        if (project == null || project.isDisposed() ||
                (!this.document.isWritable() && ReadonlyStatusHandler.getInstance(this.project).ensureFilesWritable(this.file).hasReadonlyFiles())) {
            return;
        }
        ApplicationManager.getApplication().runWriteAction(() ->
                CommandProcessor.getInstance().executeCommand(this.project, () -> {
                    this.document.setText(content);
                    this.initialState = dataManagement.getCurrentState();
                }, "Csv Table Editor changes", null));
    });
}
 
Example #2
Source File: LivePreviewController.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void performReplaceAll(Editor e) {
  Project project = mySearchResults.getProject();
  if (!ReadonlyStatusHandler.ensureDocumentWritable(project, e.getDocument())) {
    return;
  }
  if (mySearchResults.getFindModel() != null) {
    final FindModel copy = new FindModel();
    copy.copyFrom(mySearchResults.getFindModel());

    final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();

    final int offset;
    if (!selectionModel.hasSelection() || copy.isGlobal()) {
      copy.setGlobal(true);
      offset = 0;
    }
    else {
      offset = selectionModel.getBlockSelectionStarts()[0];
    }
    FindUtil.replace(project, e, offset, copy, this);
  }
}
 
Example #3
Source File: ReplaceInProjectManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean ensureUsagesWritable(ReplaceContext replaceContext, Collection<? extends Usage> selectedUsages) {
  Set<VirtualFile> readOnlyFiles = null;
  for (final Usage usage : selectedUsages) {
    final VirtualFile file = ((UsageInFile)usage).getFile();

    if (file != null && !file.isWritable()) {
      if (readOnlyFiles == null) readOnlyFiles = new HashSet<>();
      readOnlyFiles.add(file);
    }
  }

  if (readOnlyFiles != null) {
    ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(readOnlyFiles);
  }

  if (hasReadOnlyUsages(selectedUsages)) {
    int result = Messages.showOkCancelDialog(replaceContext.getUsageView().getComponent(), FindBundle.message("find.replace.occurrences.in.read.only.files.prompt"),
                                             FindBundle.message("find.replace.occurrences.in.read.only.files.title"), Messages.getWarningIcon());
    if (result != Messages.OK) {
      return false;
    }
  }
  return true;
}
 
Example #4
Source File: QuickEditHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void commitToOriginal(final DocumentEvent e) {
  VirtualFile origVirtualFile = PsiUtilCore.getVirtualFile(myNewFile.getContext());
  myCommittingToOriginal = true;
  try {
    if (origVirtualFile == null || !ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(origVirtualFile).hasReadonlyFiles()) {
      PostprocessReformattingAspect.getInstance(myProject).disablePostprocessFormattingInside(new Runnable() {
        @Override
        public void run() {
          if (myAltFullRange != null) {
            altCommitToOriginal(e);
            return;
          }
          commitToOriginalInner();
        }
      });
      PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(myOrigDocument);
    }
  }
  finally {
    myCommittingToOriginal = false;
  }
}
 
Example #5
Source File: WrapWithCustomTemplateAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final Document document = myEditor.getDocument();
  final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
  if (file != null) {
    ReadonlyStatusHandler.getInstance(myFile.getProject()).ensureFilesWritable(file);
  }

  String selection = myEditor.getSelectionModel().getSelectedText(true);

  if (selection != null) {
    selection = selection.trim();
    PsiDocumentManager.getInstance(myFile.getProject()).commitAllDocuments();
    myTemplate.wrap(selection, new CustomTemplateCallback(myEditor, myFile));
  }
}
 
Example #6
Source File: CodeInsightUtilBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean preparePsiElementsForWrite(@Nonnull Collection<? extends PsiElement> elements) {
  if (elements.isEmpty()) return true;
  Set<VirtualFile> files = new THashSet<VirtualFile>();
  Project project = null;
  for (PsiElement element : elements) {
    if (element == null) continue;
    PsiFile file = element.getContainingFile();
    if (file == null || !file.isPhysical()) continue;
    project = file.getProject();
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) continue;
    files.add(virtualFile);
  }
  if (!files.isEmpty()) {
    VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(files);
    ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(virtualFiles);
    return !status.hasReadonlyFiles();
  }
  return true;
}
 
Example #7
Source File: CodeInsightUtilBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean prepareFileForWrite(@Nullable final PsiFile psiFile) {
  if (psiFile == null) return false;
  final VirtualFile file = psiFile.getVirtualFile();
  final Project project = psiFile.getProject();

  if (ReadonlyStatusHandler.ensureFilesWritable(project, file)) {
    return true;
  }
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file), true);
      if (editor != null && editor.getComponent().isDisplayable()) {
        HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("error.hint.file.is.readonly", file.getPresentableUrl()));
      }
    }
  }, project.getDisposed());

  return false;
}
 
Example #8
Source File: AbstractFileProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void handleFiles(final List<PsiFile> files) {
  final List<VirtualFile> vFiles = new ArrayList<VirtualFile>();
  for (PsiFile psiFile : files) {
    vFiles.add(psiFile.getVirtualFile());
  }
  if (!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtil.toVirtualFileArray(vFiles)).hasReadonlyFiles()) {
    if (!files.isEmpty()) {
      final Runnable[] resultRunnable = new Runnable[1];
      execute(new Runnable() {
                public void run() {
                  resultRunnable[0] = prepareFiles(files);
                }
              }, new Runnable() {
                public void run() {
                  if (resultRunnable[0] != null) {
                    resultRunnable[0].run();
                  }
                }
              }
      );
    }
  }
}
 
Example #9
Source File: PatchApplier.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
protected ApplyPatchStatus executeWritable() {
  final ReadonlyStatusHandler.OperationStatus readOnlyFilesStatus = getReadOnlyFilesStatus(myVerifier.getWritableFiles());
  if (readOnlyFilesStatus.hasReadonlyFiles()) {
    showError(myProject, readOnlyFilesStatus.getReadonlyFilesMessage(), true);
    return ApplyPatchStatus.ABORT;
  }
  myFailedPatches.addAll(myVerifier.filterBadFileTypePatches());
  ApplyPatchStatus result = myFailedPatches.isEmpty() ? null : ApplyPatchStatus.FAILURE;
  final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches = myVerifier.getTextPatches();
  try {
    markInternalOperation(textPatches, true);
    return ApplyPatchStatus.and(result, actualApply(textPatches, myVerifier.getBinaryPatches(), myCommitContext));
  }
  finally {
    markInternalOperation(textPatches, false);
  }
}
 
Example #10
Source File: Change.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Applies the text from the original marker to the target marker.
 * @return the resulting TextRange from the target document, or null if the document if not writable.
 */
@Nullable
private static TextRange modifyDocument(@Nonnull Project project, @Nonnull RangeMarker original, @Nonnull RangeMarker target) {
  Document document = target.getDocument();
  if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document)) { return null; }
  if (DocumentUtil.isEmpty(original)) {
    int offset = target.getStartOffset();
    document.deleteString(offset, target.getEndOffset());
  }
  String text = DocumentUtil.getText(original);
  int startOffset = target.getStartOffset();
  if (DocumentUtil.isEmpty(target)) {
    document.insertString(startOffset, text);
  } else {
    document.replaceString(startOffset, target.getEndOffset(), text);
  }
  return new TextRange(startOffset, startOffset + text.length());
}
 
Example #11
Source File: EncodingUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
static void saveIn(@Nonnull final Document document, final Editor editor, @Nonnull final VirtualFile virtualFile, @Nonnull final Charset charset) {
  FileDocumentManager documentManager = FileDocumentManager.getInstance();
  documentManager.saveDocument(document);
  final Project project = ProjectLocator.getInstance().guessProjectForFile(virtualFile);
  boolean writable = project == null ? virtualFile.isWritable() : ReadonlyStatusHandler.ensureFilesWritable(project, virtualFile);
  if (!writable) {
    CommonRefactoringUtil.showErrorHint(project, editor, "Cannot save the file " + virtualFile.getPresentableUrl(), "Unable to Save", null);
    return;
  }

  EncodingProjectManagerImpl.suppressReloadDuring(() -> {
    EncodingManager.getInstance().setEncoding(virtualFile, charset);
    try {
      ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Object, IOException>)() -> {
        virtualFile.setCharset(charset);
        LoadTextUtil.write(project, virtualFile, virtualFile, document.getText(), document.getModificationStamp());
        return null;
      });
    }
    catch (IOException io) {
      Messages.showErrorDialog(project, io.getMessage(), "Error Writing File");
    }
  });
}
 
Example #12
Source File: DocImpl.java    From floobits-intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void save() {
    if (context.project == null) {
        Flog.info("Document: %s can not be saved.", document);
        return;
    }
    if (!ReadonlyStatusHandler.ensureDocumentWritable(context.project, document)) {
        Flog.info("Document: %s is not writable, can not save.", document);
        return;
    }
    setReadOnly(false);
    try {
        FileDocumentManager.getInstance().saveDocument(document);
    } catch (Throwable e) {
        Flog.error(e);
    }
}
 
Example #13
Source File: DocGenerateAction.java    From CodeMaker with Apache License 2.0 5 votes vote down vote up
/**
 * Check files access.
 *
 * @param beforeElement the before element
 */
private void checkFilesAccess(@NotNull PsiElement beforeElement) {
    PsiFile containingFile = beforeElement.getContainingFile();
    if (containingFile == null || !containingFile.isValid()) {
        throw new IllegalStateException("File cannot be used to generate javadocs");
    }
    OperationStatus status = ReadonlyStatusHandler.getInstance(beforeElement.getProject()).
            ensureFilesWritable(Collections.singletonList(containingFile.getVirtualFile()));
    if (status.hasReadonlyFiles()) {
        throw new IllegalStateException(status.getReadonlyFilesMessage());
    }
}
 
Example #14
Source File: ReadOnlyStatusDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void setToBeShown(boolean value, boolean onOk) {
  if (onOk) {
    ReadonlyStatusHandlerImpl.State state = ((ReadonlyStatusHandlerImpl)ReadonlyStatusHandler.getInstance(myProject)).getState();
    if (state != null) {
      state.SHOW_DIALOG = value;
    }
  }
}
 
Example #15
Source File: MergeOperations.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void perform(final Project project) {
  if (myPerformed) return;
  myPerformed = true;
  if (!myDocument.isWritable()) {
    final VirtualFile file = FileDocumentManager.getInstance().getFile(myDocument);
    final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file);
    if (status.hasReadonlyFiles()) return;
  }
  ApplicationManager.getApplication().runWriteAction(new Runnable(){
    public void run() {
      CommandProcessor.getInstance().executeCommand(project, myModification, getName(), null);
    }
  });
}
 
Example #16
Source File: ProjectStoreImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected final void doSave(@Nullable List<SaveSession> saveSessions, @Nonnull List<Pair<SaveSession, File>> readonlyFiles) {
  ProjectStorageUtil.UnableToSaveProjectNotification[] notifications = NotificationsManager.getNotificationsManager().getNotificationsOfType(ProjectStorageUtil.UnableToSaveProjectNotification.class, myProject);
  if (notifications.length > 0) {
    throw new SaveCancelledException();
  }

  beforeSave(readonlyFiles);

  super.doSave(saveSessions, readonlyFiles);

  if (!readonlyFiles.isEmpty()) {
    ReadonlyStatusHandler.OperationStatus status = AccessRule.read(() -> {
      List<File> filesList = getFilesList(readonlyFiles);
      VirtualFile[] files = filesList.stream().map(file -> LocalFileSystem.getInstance().findFileByIoFile(file)).toArray(VirtualFile[]::new);
      return ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(files);
    });

    if (status.hasReadonlyFiles()) {
      ProjectStorageUtil.dropUnableToSaveProjectNotification(myProject, VfsUtil.virtualToIoFiles(Arrays.asList(status.getReadonlyFiles())));
      throw new SaveCancelledException();
    }
    else {
      List<Pair<SaveSession, File>> oldList = new ArrayList<>(readonlyFiles);
      readonlyFiles.clear();
      for (Pair<SaveSession, File> entry : oldList) {
        executeSave(entry.first, readonlyFiles);
      }

      if (!readonlyFiles.isEmpty()) {
        ProjectStorageUtil.dropUnableToSaveProjectNotification(myProject, getFilesList(readonlyFiles));
        throw new SaveCancelledException();
      }
    }
  }
}
 
Example #17
Source File: LivePreviewController.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public TextRange performReplace(final FindResult occurrence, final String replacement, final Editor editor) {
  Project project = mySearchResults.getProject();
  if (myReplaceDenied || !ReadonlyStatusHandler.ensureDocumentWritable(project, editor.getDocument())) return null;
  FindModel findModel = mySearchResults.getFindModel();
  CommandProcessor.getInstance().runUndoTransparentAction(() -> getEditor().getCaretModel().moveToOffset(occurrence.getEndOffset()));
  TextRange result = FindUtil.doReplace(project, editor.getDocument(), findModel, new FindResultImpl(occurrence.getStartOffset(), occurrence.getEndOffset()), replacement, true, new ArrayList<>());
  mySearchResults.updateThreadSafe(findModel, true, result, mySearchResults.getStamp());
  return result;
}
 
Example #18
Source File: InjectTextAction.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
private void injectText(PsiFile psiFile) {
    ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(psiFile.getVirtualFile());
    if (status.hasReadonlyFiles()) {
        ReportHelper.setState(ExecutionState.FAILED);
        ReportHelper.putReport(new FailedActionReport(this, Localizer.get("error.ReadOnlyFile"), "InjectTextAction ReadOnlyFile"));
        Logger.log("InjectTextAction ReadOnlyFile");
        return;
    }

    Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
    if (document == null) {
        ReportHelper.setState(ExecutionState.FAILED);
        ReportHelper.putReport(new FailedActionReport(this, Localizer.get("error.internalError"), "InjectTextAction document==nul"));
        Logger.log("InjectTextAction document==nul");
        return;
    }

    int offset = getOffset(document, textInjection.getInjectDirection());
    if (offset == -1) {
        return;
    }

    String textToInsert = fromVelocity(textInjection.getTextToInject());
    if (textToInsert == null) {
        return;
    }

    // Replace
    if (textInjection.getInjectDirection() == InjectDirection.REPLACE) {
        doReplace(document, textToInsert);
    }
    // Insert
    else {
        document.insertString(offset, textToInsert);
    }
}
 
Example #19
Source File: CommonRefactoringUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean checkReadOnlyStatus(@Nonnull Project project,
                                           @Nonnull Collection<? extends PsiElement> recursive,
                                           @Nonnull Collection<? extends PsiElement> flat,
                                           @Nonnull String messagePrefix,
                                           boolean notifyOnFail) {
  Collection<VirtualFile> readonly = new THashSet<>();  // not writable, but could be checked out
  Collection<VirtualFile> failed = new THashSet<>();  // those located in read-only filesystem

  boolean seenNonWritablePsiFilesWithoutVirtualFile =
          checkReadOnlyStatus(flat, false, readonly, failed) || checkReadOnlyStatus(recursive, true, readonly, failed);

  ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(readonly);
  ContainerUtil.addAll(failed, status.getReadonlyFiles());

  if (notifyOnFail && (!failed.isEmpty() || seenNonWritablePsiFilesWithoutVirtualFile && readonly.isEmpty())) {
    StringBuilder message = new StringBuilder(messagePrefix).append('\n');
    int i = 0;
    for (VirtualFile virtualFile : failed) {
      String subj = RefactoringBundle.message(virtualFile.isDirectory() ? "directory.description" : "file.description", virtualFile.getPresentableUrl());
      if (virtualFile.getFileSystem().isReadOnly()) {
        message.append(RefactoringBundle.message("0.is.located.in.a.archive.file", subj)).append('\n');
      }
      else {
        message.append(RefactoringBundle.message("0.is.read.only", subj)).append('\n');
      }
      if (i++ > 20) {
        message.append("...\n");
        break;
      }
    }
    showErrorMessage(RefactoringBundle.message("error.title"), message.toString(), null, project);
    return false;
  }

  return failed.isEmpty();
}
 
Example #20
Source File: AbstractIntention.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
protected static boolean isFileReadOnly( @NotNull Project project, @NotNull PsiFile file )
{
    VirtualFile virtualFile = file.getVirtualFile();
    ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance( project );
    ReadonlyStatusHandler.OperationStatus operationStatus =
        readonlyStatusHandler.ensureFilesWritable( virtualFile );
    return operationStatus.hasReadonlyFiles();
}
 
Example #21
Source File: InvokeTemplateAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void perform() {
  final Document document = myEditor.getDocument();
  final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
  if (file != null) {
    ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(file);
  }

  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      myEditor.getCaretModel().runForEachCaret(new CaretAction() {
        @Override
        public void perform(Caret caret) {
          // adjust the selection so that it starts with a non-whitespace character (to make sure that the template is inserted
          // at a meaningful position rather than at indent 0)
          if (myEditor.getSelectionModel().hasSelection() && myTemplate.isToReformat()) {
            int offset = myEditor.getSelectionModel().getSelectionStart();
            int selectionEnd = myEditor.getSelectionModel().getSelectionEnd();
            int lineEnd = document.getLineEndOffset(document.getLineNumber(offset));
            while (offset < lineEnd && offset < selectionEnd &&
                   (document.getCharsSequence().charAt(offset) == ' ' || document.getCharsSequence().charAt(offset) == '\t')) {
              offset++;
            }
            // avoid extra line break after $SELECTION$ in case when selection ends with a complete line
            if (selectionEnd == document.getLineStartOffset(document.getLineNumber(selectionEnd))) {
              selectionEnd--;
            }
            if (offset < lineEnd && offset < selectionEnd) {  // found non-WS character in first line of selection
              myEditor.getSelectionModel().setSelection(offset, selectionEnd);
            }
          }
          String selectionString = myEditor.getSelectionModel().getSelectedText();
          TemplateManager.getInstance(myProject).startTemplate(myEditor, selectionString, myTemplate);
        }
      });
    }
  }, "Wrap with template", "Wrap with template " + myTemplate.getKey());
}
 
Example #22
Source File: QuickFixAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return true if immediate UI update needed.
 */
protected boolean applyFix(@Nonnull RefEntity[] refElements) {
  Set<VirtualFile> readOnlyFiles = getReadOnlyFiles(refElements);
  if (!readOnlyFiles.isEmpty()) {
    final Project project = refElements[0].getRefManager().getProject();
    final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(
      VfsUtilCore.toVirtualFileArray(readOnlyFiles));
    if (operationStatus.hasReadonlyFiles()) return false;
  }
  return true;
}
 
Example #23
Source File: DocImpl.java    From floobits-intellij with Apache License 2.0 5 votes vote down vote up
@Override
public boolean makeWritable() {
    if (!document.isWritable()) {
        document.setReadOnly(false);
    }

    try {
        return ReadonlyStatusHandler.ensureDocumentWritable(context.project, document);
    } catch (Throwable e) {
        Flog.error(e);
    }
    return false;
}
 
Example #24
Source File: DiffUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
public static boolean makeWritable(@Nullable Project project, @Nonnull VirtualFile file) {
  if (project == null) project = ProjectManager.getInstance().getDefaultProject();
  return !ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file).hasReadonlyFiles();
}
 
Example #25
Source File: FileUtils.java    From EclipseCodeFormatter with Apache License 2.0 4 votes vote down vote up
public static boolean isWritable(@NotNull VirtualFile file, @NotNull Project project) {
	return !ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file).hasReadonlyFiles();
}
 
Example #26
Source File: CodeInsightUtilBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean prepareVirtualFilesForWrite(@Nonnull Project project, @Nonnull Collection<VirtualFile> files) {
  ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
  return !status.hasReadonlyFiles();
}
 
Example #27
Source File: PatchApplier.java    From consulo with Apache License 2.0 4 votes vote down vote up
private ReadonlyStatusHandler.OperationStatus getReadOnlyFilesStatus(@Nonnull final List<VirtualFile> filesToMakeWritable) {
  final VirtualFile[] fileArray = VfsUtilCore.toVirtualFileArray(filesToMakeWritable);
  return ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(fileArray);
}
 
Example #28
Source File: UsageViewImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean checkReadonlyUsages() {
  final Set<VirtualFile> readOnlyUsages = getReadOnlyUsagesFiles();

  return readOnlyUsages.isEmpty() || !ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(readOnlyUsages).hasReadonlyFiles();
}
 
Example #29
Source File: VcsGeneralConfigurationPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private ReadonlyStatusHandlerImpl getReadOnlyStatusHandler() {
  return ((ReadonlyStatusHandlerImpl)ReadonlyStatusHandler.getInstance(myProject));
}
 
Example #30
Source File: CommonRefactoringUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean checkReadOnlyStatus(@Nonnull PsiElement element) {
  final VirtualFile file = element.getContainingFile().getVirtualFile();
  return file != null && !ReadonlyStatusHandler.getInstance(element.getProject()).ensureFilesWritable(file).hasReadonlyFiles();
}