Java Code Examples for com.intellij.openapi.vfs.ReadonlyStatusHandler#ensureDocumentWritable()
The following examples show how to use
com.intellij.openapi.vfs.ReadonlyStatusHandler#ensureDocumentWritable() .
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: DocImpl.java From floobits-intellij with Apache License 2.0 | 6 votes |
@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 2
Source File: Change.java From consulo with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: LivePreviewController.java From consulo with Apache License 2.0 | 6 votes |
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 4
Source File: DocImpl.java From floobits-intellij with Apache License 2.0 | 5 votes |
@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 5
Source File: LivePreviewController.java From consulo with Apache License 2.0 | 5 votes |
@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; }