Search in sources :

Example 1 with AttributeSnapshot

use of com.android.tools.idea.rendering.AttributeSnapshot in project android by JetBrains.

the class NlDropListener method morphReceiverIntoViewGroup.

/**
   * Morph the receiver into a constraint layout and add the dragged component to it.
   *
   * @param model      {@link NlComponentTree#getDesignerModel()}
   */
private void morphReceiverIntoViewGroup(@NotNull NlModel model) {
    final AttributesTransaction transaction = myDragReceiver.startAttributeTransaction();
    for (AttributeSnapshot attribute : myDragReceiver.getAttributes()) {
        if (!TOOLS_PREFIX.equals(attribute.prefix) && !ourCopyableAttributes.contains(attribute.name) && attribute.namespace != null) {
            transaction.removeAttribute(attribute.namespace, attribute.name);
        }
    }
    new WriteCommandAction(model.getProject(), model.getFile()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final XmlTag tag = myDragReceiver.getTag();
            tag.setName(CONSTRAINT_LAYOUT);
            myDragReceiver.setTag(tag);
            transaction.commit();
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) AttributeSnapshot(com.android.tools.idea.rendering.AttributeSnapshot) Result(com.intellij.openapi.application.Result) XmlTag(com.intellij.psi.xml.XmlTag)

Example 2 with AttributeSnapshot

use of com.android.tools.idea.rendering.AttributeSnapshot in project android by JetBrains.

the class NlPropertiesSorter method getModifiedAttributes.

@NotNull
public static Set<String> getModifiedAttributes(@NotNull List<NlComponent> components) {
    List<AttributeSnapshot> attrs = components.get(0).getAttributes();
    Set<String> modifiedAttrs = Sets.newHashSetWithExpectedSize(attrs.size());
    for (NlComponent component : components) {
        attrs = component.getAttributes();
        for (AttributeSnapshot snapshot : attrs) {
            modifiedAttrs.add(snapshot.name);
        }
    }
    return modifiedAttrs;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AttributeSnapshot(com.android.tools.idea.rendering.AttributeSnapshot) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AttributeSnapshot

use of com.android.tools.idea.rendering.AttributeSnapshot in project android by JetBrains.

the class GenerateLayoutTestSkeletonAction method appendComponent.

private static void appendComponent(@NotNull NlComponent component, int indent, @NotNull StringBuilder builder) {
    builder.append(StringUtil.repeat(" ", indent)).append("component(").append(getTagSymbol(component.getTagName())).append(")\n").append(StringUtil.repeat(" ", indent + 2)).append(makeBounds(component)).append("\n");
    for (AttributeSnapshot attribute : component.getAttributes()) {
        appendAttribute(attribute, indent + 4, builder);
    }
    if (component.getChildCount() > 0) {
        builder.append(StringUtil.repeat(" ", indent + 2)).append(".children(\n");
        for (NlComponent child : component.getChildren()) {
            appendComponent(child, indent + 4, builder);
            // Replace last \n with a comma separator:
            builder.replace(builder.length() - 1, builder.length(), ",\n\n");
        }
        // Replace last comma separator with end paren
        builder.replace(builder.length() - 3, builder.length(), ")\n");
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AttributeSnapshot(com.android.tools.idea.rendering.AttributeSnapshot)

Aggregations

AttributeSnapshot (com.android.tools.idea.rendering.AttributeSnapshot)3 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 XmlTag (com.intellij.psi.xml.XmlTag)1 NotNull (org.jetbrains.annotations.NotNull)1