Package com.intellij.openapi.command

Examples of com.intellij.openapi.command.WriteCommandAction


            if (onlyOneReturnStatement(siblings)) {
                returnDeclaration = concatenateElements(siblings);
            }

            final String finalReturnDeclaration = returnDeclaration;
            WriteCommandAction writeCommandAction = new WriteCommandAction(element.getContainingFile().getProject()) {
                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    document.deleteString(rightCurlyPosition, rightCurlyPosition + 1);
                    document.insertString(leftCurlyPosition + 1, "\n" + finalReturnDeclaration + "\n}");
                }
            };
            writeCommandAction.execute();


            flipCondition(document, condition);

            GoSimpleStatement simpleStatement = stmt.getSimpleStatement();
            if (simpleStatement != null) {
                extractSimpleStatement(stmt, document, condition, simpleStatement);
            }
        } else {
            WriteCommandAction writeCommandAction = new WriteCommandAction(element.getContainingFile().getProject()) {
                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    document.insertString(leftCurlyPosition, "{\n} else ");
                }
            };
            writeCommandAction.execute();

            flipCondition(document, condition);
        }

        reformatPositions(file, stmtRange);
View Full Code Here


    private void extractSimpleStatement(final GoIfStatement stmt, final Document document, final GoExpr condition,
                                        final GoSimpleStatement simpleStatement) {
        final String simpleStatementDecl = simpleStatement.getText() + "\n";

        WriteCommandAction writeCommandAction = new WriteCommandAction(condition.getProject()) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {
                document.deleteString(simpleStatement.getTextOffset(), condition.getTextOffset());
                document.insertString(stmt.getTextOffset(), simpleStatementDecl);
            }
        };
        writeCommandAction.execute();
    }
View Full Code Here

        final int innerEnd = inner.getThenBlock().getTextOffset();
        final String simpleStatementAndExpression = getSimpleStatementAndExpression(outer, inner);

        final GoIfStatement finalInner = inner;
        WriteCommandAction writeCommandAction = new WriteCommandAction(element.getContainingFile().getProject()) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {
                document.replaceString(finalInner.getTextOffset(), innerEnd, simpleStatementAndExpression);

                document.deleteString(outerIfRange.getStartOffset(), outerIfRange.getEndOffset());
                document.deleteString(rightCurlyRange.getStartOffset(), rightCurlyRange.getEndOffset());
            }
        };
        writeCommandAction.execute();

        PsiFile file = outer.getContainingFile();
        if (file != null) {
            reformatPositions(file, reformatRange);
        }
View Full Code Here

        final String result = "0" + Integer.toString(value, 8);
        final int start = element.getTextOffset();
        final int end = start + element.getTextLength();

        WriteCommandAction writeCommandAction = new WriteCommandAction(element.getContainingFile().getProject()) {
            @Override
            protected void run(@NotNull Result res) throws Throwable {
                editor.getDocument().replaceString(start, end, result);
            }
        };
        writeCommandAction.execute();
    }
View Full Code Here

        final String result = Integer.toString(value);
        final int start = element.getTextOffset();
        final int end = start + element.getTextLength();

        WriteCommandAction writeCommandAction = new WriteCommandAction(element.getContainingFile().getProject()) {
            @Override
            protected void run(@NotNull Result res) throws Throwable {
                editor.getDocument().replaceString(start, end, result);
            }
        };
        writeCommandAction.execute();
    }
View Full Code Here

        // if there are exactly 2 imports, replace the whole import to import "theOther". i.e. remove parenthesis.
        if (da.length == 2) {
            final PsiElement newImport = getNewImport(da, startElement.getText(), (GoFile) file);
            if (newImport != null) {
                WriteCommandAction writeCommandAction = new WriteCommandAction(file.getProject()) {
                    @Override
                    protected void run(@NotNull Result result) throws Throwable {
                        declarations.replace(newImport);
                    }
                };
                writeCommandAction.execute();
                return;
            }
        }

        // remove the whole declarations, if current one is the only one left.
View Full Code Here

        final PsiElement[] elements = createStatements(goFile, "    return\n");
        if (elements.length == 0) {
            return;
        }

        WriteCommandAction writeCommandAction = new WriteCommandAction(file.getProject(), file) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {
                block.addRangeBefore(elements[0], elements[elements.length - 1], rightCurly);
            }
        };

        writeCommandAction.execute();
        editor.getCaretModel().moveToOffset(doc.getLineEndOffset(lineNumber));
        editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
    }
View Full Code Here

    Assert.assertEquals(reparsedTree, originalTree);
  }

  public static void addLibrary(final Module module, final String libName, final String libPath, final String... jarArr) {
    assert ModuleRootManager.getInstance(module).getContentRoots().length > 0 : "content roots must not be empty";
    new WriteCommandAction(module.getProject()) {
      protected void run(Result result) throws Throwable {
        final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
        final Library library = libraryTable.createLibrary(libName);
        final Library.ModifiableModel libraryModel = library.getModifiableModel();
View Full Code Here

        @Override
        public void onClick(List<TranslationFileModel> files, final String keyName, final String domain, boolean navigateTo) {

            PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());

            new WriteCommandAction(project) {
                @Override
                protected void run(Result result) throws Throwable {
                    String insertString;

                    // check for file context domain
View Full Code Here


                // @TODO: check is last array line on contains eol and indent and move above this line

                final String finalInsertString = insertString;
                new WriteCommandAction(yamlFile.getProject()) {
                    @Override
                    protected void run(Result result) throws Throwable {
                        document.insertString(goToPsi.getYamlKeyValue().getTextRange().getEndOffset(), finalInsertString);
                        manager.doPostponedOperationsAndUnblockDocument(document);
                        manager.commitDocument(document);
View Full Code Here

TOP

Related Classes of com.intellij.openapi.command.WriteCommandAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.