Search in sources :

Example 6 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class EditorTextFieldControl method setValue.

@Override
protected void setValue(final String value) {
    CommandProcessor.getInstance().runUndoTransparentAction(() -> new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final T component = getComponent();
            final Document document = getEditorTextField(component).getDocument();
            document.replaceString(0, document.getTextLength(), value == null ? "" : value);
        }
    }.execute());
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 7 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class MavenTestCase method createModule.

protected Module createModule(final String name, final ModuleType type) throws IOException {
    return new WriteCommandAction<Module>(myProject) {

        @Override
        protected void run(@NotNull Result<Module> moduleResult) throws Throwable {
            VirtualFile f = createProjectSubFile(name + "/" + name + ".iml");
            Module module = ModuleManager.getInstance(myProject).newModule(f.getPath(), type.getId());
            PsiTestUtil.addContentRoot(module, f.getParent());
            moduleResult.setResult(module);
        }
    }.execute().getResultObject();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 8 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class DomNamespacesTest method testCopyFromHonorsNamespaces.

public void testCopyFromHonorsNamespaces() throws Throwable {
    final MyElement element = createElement("<a xmlns=\"foo\" xmlns:bar=\"bar\"/>", MyElement.class);
    registerNamespacePolicies(element);
    final MyElement element2 = createElement("<f:a xmlns:f=\"foo1\" xmlns:b=\"bar1\" xmlns=\"foo1\">" + "<foo-child/>" + "<b:bar-child/>" + "<f:some-child/>" + "<f:foo-element attr-2=\"239\" attr=\"42\"/>" + "<f:foo-element/>" + "<f:bool/>" + "<sys:aaa/>" + "</f:a>", MyElement.class);
    registerNamespacePolicies(element2, "foo1", "bar1");
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            element.copyFrom(element2);
        }
    }.execute();
    assertEquals("<a xmlns=\"foo\" xmlns:bar=\"bar\">" + "<bar:bar-child/>" + "<bool/>" + "<foo-child/>" + "<some-child/>" + "<sys:aaa/>" + "<foo-element attr=\"42\" attr-2=\"239\"/>" + "<foo-element/>" + "</a>", element.getXmlTag().getText());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Result(com.intellij.openapi.application.Result)

Example 9 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class DefaultAddAction method performElementAddition.

@Nullable
protected T performElementAddition() {
    final DomElement parent = getParentDomElement();
    final DomManager domManager = parent.getManager();
    final TypeChooser[] oldChoosers = new TypeChooser[] { null };
    final Type[] aClass = new Type[] { null };
    final StableElement<T> result = new WriteCommandAction<StableElement<T>>(domManager.getProject(), DomUtil.getFile(parent)) {

        @Override
        protected void run(@NotNull Result<StableElement<T>> result) throws Throwable {
            final DomElement parentDomElement = getParentDomElement();
            final T t = (T) getDomCollectionChildDescription().addValue(parentDomElement, getElementType());
            tuneNewValue(t);
            aClass[0] = parent.getGenericInfo().getCollectionChildDescription(t.getXmlElementName()).getType();
            oldChoosers[0] = domManager.getTypeChooserManager().getTypeChooser(aClass[0]);
            final SmartPsiElementPointer pointer = SmartPointerManager.getInstance(getProject()).createSmartPsiElementPointer(t.getXmlTag());
            domManager.getTypeChooserManager().registerTypeChooser(aClass[0], new TypeChooser() {

                @Override
                public Type chooseType(final XmlTag tag) {
                    if (tag == pointer.getElement()) {
                        return getElementType();
                    }
                    return oldChoosers[0].chooseType(tag);
                }

                @Override
                public void distinguishTag(final XmlTag tag, final Type aClass) throws IncorrectOperationException {
                    oldChoosers[0].distinguishTag(tag, aClass);
                }

                @Override
                public Type[] getChooserTypes() {
                    return oldChoosers[0].getChooserTypes();
                }
            });
            result.setResult((StableElement<T>) t.createStableCopy());
        }
    }.execute().getResultObject();
    if (result != null) {
        domManager.getTypeChooserManager().registerTypeChooser(aClass[0], oldChoosers[0]);
        return result.getWrappedElement();
    }
    return null;
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) Type(java.lang.reflect.Type) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class DomFileDescriptionTest method testCheckDtdPublicId.

public void testCheckDtdPublicId() throws Throwable {
    getDomManager().registerFileDescription(new DomFileDescription<NamespacedElement>(NamespacedElement.class, "xxx", "bar") {

        @Override
        protected void initializeFileDescription() {
            registerNamespacePolicy("foo", "bar");
        }
    }, myDisposable);
    final PsiFile file = createFile("xxx.xml", "<xxx/>");
    assertFalse(getDomManager().isDomFile(file));
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final Document document = getDocument(file);
            document.insertString(0, "<!DOCTYPE xxx PUBLIC \"bar\" \"http://java.sun.com/dtd/ejb-jar_2_0.dtd\">\n");
            commitDocument(document);
        }
    }.execute();
    assertTrue(getDomManager().isDomFile(file));
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)278 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)177 NotNull (org.jetbrains.annotations.NotNull)111 WriteAction (com.intellij.openapi.application.WriteAction)87 VirtualFile (com.intellij.openapi.vfs.VirtualFile)76 Project (com.intellij.openapi.project.Project)55 File (java.io.File)30 Document (com.intellij.openapi.editor.Document)28 Module (com.intellij.openapi.module.Module)28 XmlFile (com.intellij.psi.xml.XmlFile)28 IOException (java.io.IOException)26 PsiFile (com.intellij.psi.PsiFile)25 XmlTag (com.intellij.psi.xml.XmlTag)24 Nullable (org.jetbrains.annotations.Nullable)16 ArrayList (java.util.ArrayList)15 ReadAction (com.intellij.openapi.application.ReadAction)14 Editor (com.intellij.openapi.editor.Editor)12 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)10 TextRange (com.intellij.openapi.util.TextRange)10