Search in sources :

Example 11 with AttributesTransaction

use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.

the class ResizeTarget method mouseRelease.

@Override
public void mouseRelease(int x, int y, @Nullable Target closestTarget) {
    NlComponent component = myComponent.getNlComponent();
    AttributesTransaction attributes = component.startAttributeTransaction();
    updateAttributes(attributes, x, y);
    attributes.apply();
    NlModel nlModel = component.getModel();
    Project project = nlModel.getProject();
    XmlFile file = nlModel.getFile();
    String label = "Constraint";
    WriteCommandAction action = new WriteCommandAction(project, label, file) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            attributes.commit();
        }
    };
    action.execute();
    myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) 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 12 with AttributesTransaction

use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.

the class DragDndTarget method mouseRelease.

public void mouseRelease(int x, int y, @NotNull NlComponent component) {
    if (myComponent.getParent() != null) {
        AttributesTransaction attributes = component.startAttributeTransaction();
        int dx = x - myOffsetX;
        int dy = y - myOffsetY;
        if (myCurrentNotchX != null) {
            dx = myCurrentNotchX.apply(dx);
            if (myComponent.allowsAutoConnect()) {
                myCurrentNotchX.apply(attributes);
            }
            myCurrentNotchX = null;
        }
        if (myCurrentNotchY != null) {
            dy = myCurrentNotchY.apply(dy);
            if (myComponent.allowsAutoConnect()) {
                myCurrentNotchY.apply(attributes);
            }
            myCurrentNotchY = null;
        }
        updateAttributes(attributes, dx, dy);
        cleanup(attributes);
        attributes.apply();
        attributes.commit();
    }
    if (myChangedComponent) {
        myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
    }
}
Also used : AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction)

Example 13 with AttributesTransaction

use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.

the class DragTarget method mouseRelease.

@Override
public void mouseRelease(int x, int y, @Nullable Target closestTarget) {
    if (myComponent.getParent() != null) {
        boolean commitChanges = true;
        if (Math.abs(x - myFirstMouseX) <= 1 && Math.abs(y - myFirstMouseY) <= 1) {
            commitChanges = false;
        }
        NlComponent component = myComponent.getNlComponent();
        AttributesTransaction attributes = component.startAttributeTransaction();
        int dx = x - myOffsetX;
        int dy = y - myOffsetY;
        if (myCurrentNotchX != null) {
            dx = myCurrentNotchX.apply(dx);
            if (myComponent.allowsAutoConnect()) {
                myCurrentNotchX.apply(attributes);
            }
            myCurrentNotchX = null;
        }
        if (myCurrentNotchY != null) {
            dy = myCurrentNotchY.apply(dy);
            if (myComponent.allowsAutoConnect()) {
                myCurrentNotchY.apply(attributes);
            }
            myCurrentNotchY = null;
        }
        updateAttributes(attributes, dx, dy);
        cleanup(attributes);
        attributes.apply();
        if (commitChanges) {
            NlModel nlModel = component.getModel();
            Project project = nlModel.getProject();
            XmlFile file = nlModel.getFile();
            String label = "Component dragged";
            WriteCommandAction action = new WriteCommandAction(project, label, file) {

                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    attributes.commit();
                }
            };
            action.execute();
        }
    }
    if (myChangedComponent) {
        myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) 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 14 with AttributesTransaction

use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.

the class DragTarget method mouseDrag.

@Override
public void mouseDrag(int x, int y, @Nullable Target closestTarget) {
    if (myComponent.getParent() == null) {
        return;
    }
    NlComponent component = myComponent.getNlComponent();
    AttributesTransaction attributes = component.startAttributeTransaction();
    int dx = x - myOffsetX;
    int dy = y - myOffsetY;
    dx = snapX(dx);
    dy = snapY(dy);
    updateAttributes(attributes, dx, dy);
    cleanup(attributes);
    attributes.apply();
    component.fireLiveChangeEvent();
    myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
    myChangedComponent = true;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction)

Example 15 with AttributesTransaction

use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.

the class AnchorTarget method revertToPreviousState.

/**
   * Revert to the original (on mouse down) state.
   */
private void revertToPreviousState() {
    NlComponent component = myComponent.getNlComponent();
    AttributesTransaction attributes = component.startAttributeTransaction();
    attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_BASELINE_TO_BASELINE_OF, null);
    for (String key : mPreviousAttributes.keySet()) {
        if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_X)) {
            attributes.setAttribute(SdkConstants.TOOLS_URI, key, mPreviousAttributes.get(key));
        } else if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_Y)) {
            attributes.setAttribute(SdkConstants.TOOLS_URI, key, mPreviousAttributes.get(key));
        } else if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_MARGIN_TOP)) {
            attributes.setAttribute(SdkConstants.ANDROID_URI, key, mPreviousAttributes.get(key));
        } else if (key.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_MARGIN_BOTTOM)) {
            attributes.setAttribute(SdkConstants.ANDROID_URI, key, mPreviousAttributes.get(key));
        } else {
            attributes.setAttribute(SdkConstants.SHERPA_URI, key, mPreviousAttributes.get(key));
        }
    }
    attributes.apply();
    myComponent.getScene().needsLayout(Scene.ANIMATED_LAYOUT);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction)

Aggregations

AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)17 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 XmlFile (com.intellij.psi.xml.XmlFile)11 Result (com.intellij.openapi.application.Result)10 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)10 Project (com.intellij.openapi.project.Project)10 NotNull (org.jetbrains.annotations.NotNull)10 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)9 ResourceFolderType (com.android.resources.ResourceFolderType)1 ModelListener (com.android.tools.idea.uibuilder.model.ModelListener)1 Scene (com.android.tools.idea.uibuilder.scene.Scene)1 SceneComponent (com.android.tools.idea.uibuilder.scene.SceneComponent)1 XmlTag (com.intellij.psi.xml.XmlTag)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1