consulo.annotation.access.RequiredWriteAction Java Examples
The following examples show how to use
consulo.annotation.access.RequiredWriteAction.
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: DefaultProjectFactoryImpl.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Nullable @Override public Element getState() { assert myDefaultProject != null; myDefaultProject.save(); Element stateElement = myDefaultProject.getStateElement(); if (stateElement == null) { // we are not ready to save return null; } Element element = new Element("state"); stateElement.detach(); element.addContent(stateElement); return element; }
Example #2
Source File: ConvertIndentsActionBase.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void executeWriteAction(final Editor editor, @Nullable Caret caret, DataContext dataContext) { final SelectionModel selectionModel = editor.getSelectionModel(); int changedLines = 0; if (selectionModel.hasSelection()) { changedLines = performAction(editor, new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())); } else { changedLines += performAction(editor, new TextRange(0, editor.getDocument().getTextLength())); } if (changedLines == 0) { HintManager.getInstance().showInformationHint(editor, "All lines already have requested indentation"); } else { HintManager.getInstance().showInformationHint(editor, "Changed indentation in " + changedLines + (changedLines == 1 ? " line" : " lines")); } }
Example #3
Source File: ShaderLabElementColorProvider.java From consulo-unity3d with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void setColorTo(@Nonnull PsiElement element, @Nonnull ColorValue color) { float[] colorComponents = color.toRGB().getFloatValues(); StringBuilder builder = new StringBuilder(); builder.append("("); for(int i = 0; i < (colorComponents[3] == 1 ? colorComponents.length - 1 : colorComponents.length); i++) { if(i != 0) { builder.append(", "); } builder.append(colorComponents[i]); } builder.append(")"); ShaderPropertyValue value = createValue(element.getProject(), builder.toString()); element.replace(value); }
Example #4
Source File: KillToWordStartAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { CaretModel caretModel = editor.getCaretModel(); int caretOffset = caretModel.getOffset(); if (caretOffset <= 0) { return; } boolean camel = editor.getSettings().isCamelWords(); for (int i = caretOffset - 1; i >= 0; i--) { if (EditorActionUtil.isWordOrLexemeStart(editor, i, camel)) { KillRingUtil.cut(editor, i, caretOffset); return; } } KillRingUtil.cut(editor, 0, caretOffset); }
Example #5
Source File: UnityCSharpStaticElementColor32Provider.java From consulo-unity3d with Apache License 2.0 | 6 votes |
@Override @RequiredWriteAction public void setColorTo(@Nonnull PsiElement element, @Nonnull ColorValue color) { CSharpNewExpression newExpression = PsiTreeUtil.getParentOfType(element, CSharpNewExpression.class); assert newExpression != null; DotNetType newType = newExpression.getNewType(); assert newType != null; StringBuilder builder = new StringBuilder().append("new ").append(newType.getText()).append("("); consulo.ui.shared.RGBColor rgbColor = color.toRGB(); builder.append(rgbColor.getRed()).append(", "); builder.append(rgbColor.getGreen()).append(", "); builder.append(rgbColor.getBlue()).append(", "); builder.append((int) (rgbColor.getAlpha() * 255f)); builder.append(")"); CSharpNewExpression expression = (CSharpNewExpression) CSharpFileFactory.createExpression(element.getProject(), builder.toString()); newExpression.getParameterList().replace(expression.getParameterList()); }
Example #6
Source File: DuplicateLinesAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { if (editor.getSelectionModel().hasSelection()) { int selStart = editor.getSelectionModel().getSelectionStart(); int selEnd = editor.getSelectionModel().getSelectionEnd(); VisualPosition rangeStart = editor.offsetToVisualPosition(Math.min(selStart, selEnd)); VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd)); final Pair<Integer,Integer> copiedRange = DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), rangeStart, rangeEnd); if (copiedRange != null) { editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second); } } else { VisualPosition caretPos = editor.getCaretModel().getVisualPosition(); DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), caretPos, caretPos); } }
Example #7
Source File: ModifiableModelCommitter.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction public static void multiCommit(ModifiableRootModel[] rootModels, ModifiableModuleModel moduleModel) { ApplicationManager.getApplication().assertWriteAccessAllowed(); final List<RootModelImpl> modelsToCommit = getSortedChangedModels(rootModels, moduleModel); final List<ModifiableRootModel> modelsToDispose = new ArrayList<ModifiableRootModel>(Arrays.asList(rootModels)); modelsToDispose.removeAll(modelsToCommit); ModuleManagerImpl.commitModelWithRunnable(moduleModel, new Runnable() { @Override public void run() { for (RootModelImpl rootModel : modelsToCommit) { rootModel.doCommitAndDispose(true); } for (ModifiableRootModel model : modelsToDispose) { model.dispose(); } } }); }
Example #8
Source File: UnifiedDiffViewer.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction public void replaceChange(@Nonnull UnifiedDiffChange change, @Nonnull Side sourceSide) { Side outputSide = sourceSide.other(); Document document1 = getDocument(Side.LEFT); Document document2 = getDocument(Side.RIGHT); LineFragment lineFragment = change.getLineFragment(); DiffUtil.applyModification(outputSide.select(document1, document2), outputSide.getStartLine(lineFragment), outputSide.getEndLine(lineFragment), sourceSide.select(document1, document2), sourceSide.getStartLine(lineFragment), sourceSide.getEndLine(lineFragment)); // no need to mark myStateIsOutOfDate - it will be made by DocumentListener // TODO: we can apply change manually, without marking state out-of-date. But we'll have to schedule rediff anyway. }
Example #9
Source File: XBreakpointManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nullable @RequiredWriteAction <T extends XBreakpointProperties> XLineBreakpoint<T> copyLineBreakpoint(@Nonnull XLineBreakpoint<T> source, @Nonnull String fileUrl, int line) { ApplicationManager.getApplication().assertWriteAccessAllowed(); if (!(source instanceof XLineBreakpointImpl<?>)) { return null; } myDependentBreakpointManager.saveState(); final LineBreakpointState sourceState = ((XLineBreakpointImpl<?>)source).getState(); final LineBreakpointState newState = XmlSerializer.deserialize(XmlSerializer.serialize(sourceState, SERIALIZATION_FILTER), LineBreakpointState.class); newState.setLine(line); newState.setFileUrl(fileUrl); //noinspection unchecked final XLineBreakpointImpl<T> breakpoint = (XLineBreakpointImpl<T>)createBreakpoint(newState); if (breakpoint != null) { addBreakpoint(breakpoint, false, true); final XBreakpoint<?> masterBreakpoint = myDependentBreakpointManager.getMasterBreakpoint(source); if (masterBreakpoint != null) { myDependentBreakpointManager.setMasterBreakpoint(breakpoint, masterBreakpoint, sourceState.getDependencyState().isLeaveEnabled()); } } return breakpoint; }
Example #10
Source File: DeleteSelectionHandler.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) { if (caret == null ? editor.getSelectionModel().hasSelection(true) : caret.hasSelection()) { EditorUIUtil.hideCursorInEditor(editor); CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP); CopyPasteManager.getInstance().stopKillRings(); CaretAction action = c -> EditorModificationUtil.deleteSelectedText(editor); if (caret == null) { editor.getCaretModel().runForEachCaret(action); } else { action.perform(caret); } } else { myOriginalHandler.execute(editor, caret, dataContext); } }
Example #11
Source File: LineStatusTrackerBase.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction private void runBulkRollback(@Nonnull Runnable task) { myApplication.assertWriteAccessAllowed(); if (!tryValidate()) return; synchronized (LOCK) { try { myDuringRollback = true; task.run(); } catch (Error | RuntimeException e) { reinstallRanges(); throw e; } finally { myDuringRollback = false; } } }
Example #12
Source File: SdkTableImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override @RequiredWriteAction public void updateSdk(@Nonnull Sdk originalSdk, @Nonnull Sdk modifiedSdk) { myApplication.assertWriteAccessAllowed(); final String previousName = originalSdk.getName(); final String newName = modifiedSdk.getName(); boolean nameChanged = !previousName.equals(newName); if (nameChanged) { myApplication.getMessageBus().syncPublisher(SDK_TABLE_TOPIC).beforeSdkNameChanged(originalSdk, previousName); } ((SdkImpl)modifiedSdk).copyTo((SdkImpl)originalSdk); if (nameChanged) { myApplication.getMessageBus().syncPublisher(SDK_TABLE_TOPIC).sdkNameChanged(originalSdk, previousName); } }
Example #13
Source File: CS0227.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override @RequiredWriteAction public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(file); if(moduleForPsiElement == null) { return; } ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForPsiElement); final ModifiableRootModel modifiableModel = moduleRootManager.getModifiableModel(); CSharpSimpleMutableModuleExtension cSharpModuleExtension = modifiableModel.getExtension(CSharpSimpleMutableModuleExtension.class); if(cSharpModuleExtension != null) { cSharpModuleExtension.setAllowUnsafeCode(true); } modifiableModel.commit(); }
Example #14
Source File: CS0017.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override @RequiredWriteAction public void invoke(@Nonnull Project project, Editor editor, @Nonnull PsiElement element) throws IncorrectOperationException { DotNetModuleExtension<?> extension = ModuleUtilCore.getExtension(element, DotNetModuleExtension.class); if(extension == null || extension.getMainType() != null) { return; } ModuleRootManager rootManager = ModuleRootManager.getInstance(extension.getModule()); ModifiableRootModel modifiableModel = rootManager.getModifiableModel(); final DotNetMutableModuleExtension<?> mutable = modifiableModel.getExtension(DotNetMutableModuleExtension.class); assert mutable != null; mutable.setMainType(myVmQName); modifiableModel.commit(); }
Example #15
Source File: ComponentStoreImpl.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void saveAsync(@Nonnull UIAccess uiAccess, @Nonnull List<Pair<SaveSession, File>> readonlyFiles) { ExternalizationSession externalizationSession = myComponents.isEmpty() ? null : getStateStorageManager().startExternalization(); if (externalizationSession != null) { String[] names = ArrayUtil.toStringArray(myComponents.keySet()); Arrays.sort(names); for (String name : names) { StateComponentInfo<?> componentInfo = myComponents.get(name); commitComponentInsideSingleUIWriteThread(componentInfo, externalizationSession); } } for (SettingsSavingComponent settingsSavingComponent : mySettingsSavingComponents) { try { settingsSavingComponent.save(); } catch (Throwable e) { LOG.error(e); } } doSave(externalizationSession == null ? null : externalizationSession.createSaveSessions(), readonlyFiles); }
Example #16
Source File: ModuleDataService.java From consulo with Apache License 2.0 | 6 votes |
@Override public void removeData(@Nonnull final Collection<? extends Module> modules, @Nonnull final Project project, boolean synchronous) { if (modules.isEmpty()) { return; } ExternalSystemApiUtil.executeProjectChangeAction(synchronous, new DisposeAwareProjectChange(project) { @RequiredUIAccess @Override @RequiredWriteAction public void execute() { ModuleManager moduleManager = ModuleManager.getInstance(project); for (Module module : modules) { if (module.isDisposed()) continue; moduleManager.disposeModule(module); } } }); }
Example #17
Source File: CutLineBackwardAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, DataContext dataContext) { final Document document = editor.getDocument(); int caretOffset = editor.getCaretModel().getOffset(); if (caretOffset <= 0) { return; } // The main idea is to kill everything between the current line start and caret and the whole previous line. final int caretLine = document.getLineNumber(caretOffset); int start; if (caretLine <= 0) { start = 0; } else { start = document.getLineStartOffset(caretLine - 1); } KillRingUtil.cut(editor, start, caretOffset); }
Example #18
Source File: TabAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) { if (caret == null) { caret = editor.getCaretModel().getPrimaryCaret(); } CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.EDIT_COMMAND_GROUP); CommandProcessor.getInstance().setCurrentCommandName(EditorBundle.message("typing.command.name")); Project project = dataContext.getData(CommonDataKeys.PROJECT); insertTabAtCaret(editor, caret, project); }
Example #19
Source File: SimpleDiffViewer.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction public void appendChange(@Nonnull SimpleDiffChange change, @Nonnull final Side sourceSide) { if (!change.isValid()) return; if (change.getStartLine(sourceSide) == change.getEndLine(sourceSide)) return; Side outputSide = sourceSide.other(); DiffUtil.applyModification(getEditor(outputSide).getDocument(), change.getEndLine(outputSide), change.getEndLine(outputSide), getEditor(sourceSide).getDocument(), change.getStartLine(sourceSide), change.getEndLine(sourceSide)); change.destroyHighlighter(); myDiffChanges.remove(change); }
Example #20
Source File: StartNewLineBeforeAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { editor.getSelectionModel().removeSelection(); LogicalPosition caretPosition = editor.getCaretModel().getLogicalPosition(); final int line = caretPosition.line; int lineStartOffset = editor.getDocument().getLineStartOffset(line); editor.getCaretModel().moveToOffset(lineStartOffset); getHandler(IdeActions.ACTION_EDITOR_ENTER).execute(editor, caret, dataContext); editor.getCaretModel().moveToOffset(editor.getDocument().getLineStartOffset(line)); getHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END).execute(editor, caret, dataContext); }
Example #21
Source File: BackspaceHandler.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { if (!handleBackspace(editor, caret, dataContext, false)) { myOriginalHandler.execute(editor, caret, dataContext); } }
Example #22
Source File: EditorWriteActionHandler.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) { if (inExecution) { return; } try { inExecution = true; //noinspection deprecation executeWriteAction(editor, dataContext); } finally { inExecution = false; } }
Example #23
Source File: TextMergeViewer.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable @RequiredWriteAction private static CharSequence getChunkContent(@Nonnull TextMergeChange change, @Nonnull List<Document> documents, @Nonnull ThreeSide side) { int startLine = change.getStartLine(side); int endLine = change.getEndLine(side); return startLine != endLine ? DiffUtil.getLinesContent(side.select(documents), startLine, endLine) : null; }
Example #24
Source File: UnifiedDiffViewer.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction public void appendChange(@Nonnull UnifiedDiffChange change, @Nonnull final Side sourceSide) { Side outputSide = sourceSide.other(); Document document1 = getDocument(Side.LEFT); Document document2 = getDocument(Side.RIGHT); LineFragment lineFragment = change.getLineFragment(); if (sourceSide.getStartLine(lineFragment) == sourceSide.getEndLine(lineFragment)) return; DiffUtil.applyModification(outputSide.select(document1, document2), outputSide.getEndLine(lineFragment), outputSide.getEndLine(lineFragment), sourceSide.select(document1, document2), sourceSide.getStartLine(lineFragment), sourceSide.getEndLine(lineFragment)); }
Example #25
Source File: ProjectRootManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction protected void beforeRootsChanged() { if (myBatchLevel == 0 || !myChanged) { if (fireBeforeRootsChanged(myFileTypes)) { myChanged = true; } } }
Example #26
Source File: CS0120.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredWriteAction public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { CSharpReferenceExpressionEx element = myReferenceExpressionPointer.getElement(); if(element == null) { return; } PsiElement qualifier = element.getQualifier(); if(qualifier == null) { return; } PsiElement resolvedElement = element.resolve(); if(resolvedElement == null) { return; } PsiElement parent = resolvedElement.getParent(); assert parent instanceof PsiNameIdentifierOwner; DotNetExpression expression = CSharpFileFactory.createExpression(project, ((PsiNameIdentifierOwner) parent).getName()); qualifier.replace(expression); }
Example #27
Source File: CallChain.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public <SubNewValue> Link<NewValue, SubNewValue> linkWrite(@RequiredWriteAction @Nonnull Runnable function) { return linkAsync(oldValue -> AccessRule.writeAsync(() -> { function.run(); return null; })); }
Example #28
Source File: DeleteAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction @Override public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { EditorUIUtil.hideCursorInEditor(editor); CommandProcessor.getInstance().setCurrentCommandGroupId(EditorActionUtil.DELETE_COMMAND_GROUP); CopyPasteManager.getInstance().stopKillRings(); if (editor.getInlayModel().hasInlineElementAt(editor.getCaretModel().getVisualPosition())) { editor.getCaretModel().moveCaretRelatively(1, 0, false, false, EditorUtil.isCurrentCaretPrimary(editor)); } else { deleteCharAtCaret(editor); } }
Example #29
Source File: CallChain.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public <SubNewValue> Link<NewValue, SubNewValue> linkRead(@RequiredWriteAction @Nonnull Runnable function) { return linkAsync(oldValue -> AccessRule.readAsync(() -> { function.run(); return null; })); }
Example #30
Source File: PsiBinaryFileImpl.java From consulo with Apache License 2.0 | 5 votes |
@RequiredWriteAction @Override public PsiElement setName(@Nonnull String name) throws IncorrectOperationException { checkSetName(name); if (isCopy()) { myName = name; return this; // not absolutely correct - might change type } return PsiFileImplUtil.setName(this, name); }