Search in sources :

Example 71 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction in project android by JetBrains.

the class WidgetConstraintPanel method setAttribute.

private void setAttribute(String nameSpace, String attribute, String value) {
    if (mConfiguringUI) {
        return;
    }
    NlModel model = mComponent.getModel();
    AttributesTransaction transaction = mComponent.startAttributeTransaction();
    transaction.setAttribute(nameSpace, attribute, value);
    transaction.apply();
    model.requestLayout(false);
    myTimer.setRepeats(false);
    Project project = model.getProject();
    XmlFile file = model.getFile();
    String label = "Change Widget";
    myWriteAction = new WriteCommandAction(project, label, file) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            AttributesTransaction transaction = mComponent.startAttributeTransaction();
            transaction.setAttribute(nameSpace, attribute, value);
            transaction.commit();
        }
    };
    myTimer.restart();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 72 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction in project android by JetBrains.

the class ConstraintComponentUtilities method clearAttributes.

public static void clearAttributes(SceneComponent component) {
    AttributesTransaction transaction = component.getNlComponent().startAttributeTransaction();
    clearAllAttributes(component, transaction);
    transaction.apply();
    NlModel nlModel = component.getNlComponent().getModel();
    Project project = nlModel.getProject();
    XmlFile file = nlModel.getFile();
    String label = "Cleared all constraints";
    WriteCommandAction action = new WriteCommandAction(project, label, file) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            transaction.commit();
        }
    };
    action.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 73 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction in project android by JetBrains.

the class ConstraintComponentUtilities method updateOnDelete.

public static void updateOnDelete(NlComponent component, String targetId) {
    AttributesTransaction transaction = null;
    transaction = updateOnDelete(component, ourLeftAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourTopAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourRightAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourBottomAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourBaselineAttributes, transaction, targetId);
    if (transaction != null) {
        transaction.apply();
        NlModel nlModel = component.getModel();
        Project project = nlModel.getProject();
        XmlFile file = nlModel.getFile();
        String label = "Remove constraints pointing to a deleted component";
        AttributesTransaction finalTransaction = transaction;
        WriteCommandAction action = new WriteCommandAction(project, label, file) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                finalTransaction.commit();
            }
        };
        action.execute();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 74 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction in project intellij-plugins by JetBrains.

the class CucumberPsiTreeListenerTest method deleteStepDefinition.

private void deleteStepDefinition(@NotNull final String stepDefName) {
    final PsiClass psiClass = getStepDefClass();
    final PsiFile psiFile = psiClass.getContainingFile();
    new WriteCommandAction(getProject(), psiFile) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            for (PsiMethod method : psiClass.getAllMethods()) {
                if (method.getName().equals(stepDefName)) {
                    method.delete();
                    break;
                }
            }
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Result(com.intellij.openapi.application.Result)

Example 75 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction in project android by JetBrains.

the class NewAndroidComponentDialog method addSetContentViewStatement.

private static void addSetContentViewStatement(final PsiCodeBlock body, final String layoutFieldRef) {
    final Project project = body.getProject();
    final PsiElement lastBodyElement = body.getLastBodyElement();
    if (lastBodyElement != null) {
        new WriteCommandAction(project, body.getContainingFile()) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                final PsiStatement newStatement = PsiElementFactory.SERVICE.getInstance(project).createStatementFromText("setContentView(" + layoutFieldRef + ");", body);
                body.addAfter(newStatement, lastBodyElement);
                JavaCodeStyleManager.getInstance(project).shortenClassReferences(body);
                CodeStyleManager.getInstance(project).reformat(body);
            }
        }.execute();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) Result(com.intellij.openapi.application.Result)

Aggregations

WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)176 Result (com.intellij.openapi.application.Result)175 NotNull (org.jetbrains.annotations.NotNull)62 Project (com.intellij.openapi.project.Project)45 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 XmlFile (com.intellij.psi.xml.XmlFile)28 XmlTag (com.intellij.psi.xml.XmlTag)23 Document (com.intellij.openapi.editor.Document)22 PsiFile (com.intellij.psi.PsiFile)16 Module (com.intellij.openapi.module.Module)14 Nullable (org.jetbrains.annotations.Nullable)12 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)10 Editor (com.intellij.openapi.editor.Editor)10 TextRange (com.intellij.openapi.util.TextRange)8 XmlAttribute (com.intellij.psi.xml.XmlAttribute)8 File (java.io.File)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)7