if (!doc.isWritable()) { msg.append("[RO] ");
if ((handler.getArgFlags() & CommandHandler.WRITABLE) > 0 && !editor.getDocument().isWritable()) { VimPlugin.indicateError(); return result | RES_READONLY;
if (type.isWrite() && !editor.getDocument().isWritable()) { VimPlugin.indicateError(); reset(editor);
@Override public void editorCreated(@NotNull EditorFactoryEvent event) { final Editor editor = event.getEditor(); isBlockCursor = editor.getSettings().isBlockCursor(); isAnimatedScrolling = editor.getSettings().isAnimatedScrolling(); isRefrainFromScrolling = editor.getSettings().isRefrainFromScrolling(); EditorData.initializeEditor(editor); DocumentManager.getInstance().addListeners(editor.getDocument()); VimPlugin.getKey().registerRequiredShortcutKeys(editor); if (VimPlugin.isEnabled()) { initLineNumbers(editor); // Turn on insert mode if editor doesn't have any file if (!EditorData.isFileEditor(editor) && editor.getDocument().isWritable() && !CommandState.inInsertMode(editor)) { KeyHandler.getInstance().handleKey(editor, KeyStroke.getKeyStroke('i'), new EditorDataContext(editor)); } editor.getSettings().setBlockCursor(!CommandState.inInsertMode(editor)); editor.getSettings().setAnimatedScrolling(ANIMATED_SCROLLING_VIM_VALUE); editor.getSettings().setRefrainFromScrolling(REFRAIN_FROM_SCROLLING_VIM_VALUE); } }
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { // Replace this position with the same value, we have to trigger a reparse somehow Document document = file.getViewProvider().getDocument(); if (document != null && document.isWritable()) { PsiElement replacement = BashPsiElementFactory.createComposedVar(project, variableName); startElement.replace(replacement); } } }
@Override public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (ApplicationManager.getApplication().isUnitTestMode()) { // builds 163.x set the read-only flag for unknown reasons, work around it in tests return true; } Document document = file.getViewProvider().getDocument(); return document != null && document.isWritable(); }
private Result skipWithResultQ(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return Result.Continue; } if (!file.getViewProvider().getLanguages().contains(MathematicaLanguage.INSTANCE)) { return Result.Continue; } if (editor.isViewer()) { return Result.Continue; } final Document document = editor.getDocument(); if (!document.isWritable()) { return Result.Continue; } if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) { return Result.Continue; } PsiDocumentManager.getInstance(project).commitDocument(document); int caret = editor.getCaretModel().getOffset(); if (caret == 0) { return Result.DefaultSkipIndent; } if (caret <= 0) { return Result.Continue; } return null; }
private Result skipWithResultQ(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final DataContext dataContext) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); if (project == null) { return Result.Continue; } if (!file.getViewProvider().getLanguages().contains(MathematicaLanguage.INSTANCE)) { return Result.Continue; } if (editor.isViewer()) { return Result.Continue; } final Document document = editor.getDocument(); if (!document.isWritable()) { return Result.Continue; } if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) { return Result.Continue; } PsiDocumentManager.getInstance(project).commitDocument(document); int caret = editor.getCaretModel().getOffset(); if (caret == 0) { return Result.DefaultSkipIndent; } if (caret <= 0) { return Result.Continue; } return null; }
@Nullable @Override public TextRange surroundElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements) throws IncorrectOperationException { int selectionStart; int selectionEnd; final SelectionModel selectionModel = editor.getSelectionModel(); if (elements.length > 0) { selectionStart = elements[0].getTextOffset(); selectionEnd = elements[elements.length - 1].getTextRange().getEndOffset(); } else { return null; } final Document document = editor.getDocument(); if (document.isWritable()) { final String expr = document.getText(TextRange.create(selectionStart, selectionEnd)); document.replaceString(selectionStart, selectionEnd, getOpening() + expr + getClosing()); modifySelection(TextRange.create(selectionStart, selectionEnd), selectionModel); } return null; }
@Override public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement elm = descriptor.getPsiElement(); if (!FileModificationService.getInstance().prepareFileForWrite(elm.getContainingFile())) return; final PsiDocumentManager manager = PsiDocumentManager.getInstance(project); final Document doc = manager.getDocument(elm.getContainingFile()); if (doc != null && doc.isWritable()) { doc.insertString(descriptor.getTextRangeInElement().getEndOffset(), ";"); } else { LOG.warn("Document was null or not writable!"); } } }
public void saveChanges(final String content) { if (hasErrors()) { return; } ApplicationManager.getApplication().invokeLater(() -> { if (!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)); }); }