List of usage examples for com.intellij.openapi.vfs ReadonlyStatusHandler ensureDocumentWritable
public static boolean ensureDocumentWritable(@NotNull Project project, @NotNull Document document)
From source file:com.intellij.diff.util.DiffUtil.java
License:Apache License
@RequiredDispatchThread public static boolean makeWritable(@Nullable Project project, @NotNull Document document) { if (document.isWritable()) return true; if (project == null) return false; return ReadonlyStatusHandler.ensureDocumentWritable(project, document); }
From source file:com.intellij.find.impl.livePreview.LivePreviewController.java
License:Apache License
@Nullable public TextRange performReplace(final FindResult occurrence, final String replacement, final Editor editor) { if (myReplaceDenied || !ReadonlyStatusHandler.ensureDocumentWritable(editor.getProject(), editor.getDocument())) return null; FindModel findModel = mySearchResults.getFindModel(); TextRange result = FindUtil.doReplace(editor.getProject(), editor.getDocument(), findModel, new FindResultImpl(occurrence.getStartOffset(), occurrence.getEndOffset()), replacement, true, new ArrayList<Pair<TextRange, String>>()); myLivePreview.inSmartUpdate();/*from w w w . j ava 2 s .com*/ mySearchResults.updateThreadSafe(findModel, true, result, mySearchResults.getStamp()); return result; }
From source file:com.intellij.find.impl.livePreview.LivePreviewController.java
License:Apache License
public void performReplaceAll(Editor e) { if (!ReadonlyStatusHandler.ensureDocumentWritable(e.getProject(), e.getDocument())) return;//from ww w . j a va 2 s. c o m 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() && !selectionModel.hasBlockSelection()) || copy.isGlobal()) { copy.setGlobal(true); offset = 0; } else { offset = selectionModel.getBlockSelectionStarts()[0]; } FindUtil.replace(e.getProject(), e, offset, copy, this); } }
From source file:com.jetbrains.lang.dart.ide.actions.DartSortMembersAction.java
License:Apache License
protected void runOverEditor(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile psiFile) { final Document document = editor.getDocument(); if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document)) return;/*from w w w . ja v a2 s .com*/ final String path = psiFile.getVirtualFile().getPath(); final DartAnalysisServerService service = DartAnalysisServerService.getInstance(project); service.updateFilesContent(); final SourceFileEdit fileEdit = service.edit_sortMembers(path); if (fileEdit == null) { showHintLater(editor, DartBundle.message("dart.sort.members.hint.failed"), true); LOG.warn("Unexpected response from edit_sortMembers, fileEdit is null"); return; } final List<SourceEdit> edits = fileEdit.getEdits(); if (edits == null || edits.size() == 0) { showHintLater(editor, DartBundle.message("dart.sort.members.hint.already.good"), false); return; } final Runnable runnable = () -> { AssistUtils.applySourceEdits(project, psiFile.getVirtualFile(), document, edits, Collections.emptySet()); showHintLater(editor, DartBundle.message("dart.sort.members.hint.success"), false); }; ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance() .executeCommand(project, runnable, DartBundle.message("dart.sort.members.action.name"), null)); }