use of com.intellij.openapi.application.Result in project android by JetBrains.
the class ConstraintUtilities method saveModelToXML.
/**
* Utility function to commit to the NlModel the current state of all widgets
*
* @param nlModel
* @param commit if false, the changes are only reflected in memory not saved to the XML file.
*/
static void saveModelToXML(@NotNull NlModel nlModel, boolean commit) {
ConstraintModel model = ConstraintModel.getConstraintModel(nlModel);
if (commit) {
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 {
saveXmlWidgets(model, commit);
}
};
action.execute();
} else {
saveXmlWidgets(model, commit);
}
}
use of com.intellij.openapi.application.Result in project android by JetBrains.
the class AnchorTarget method mouseRelease.
/**
* On mouseRelease, we can either disconnect the current anchor (if the mouse release is on ourselve)
* or connect the anchor to a given target. Modifications are applied first in memory then commited
* to the XML model.
*
* @param x
* @param y
* @param closestTarget
*/
@Override
public void mouseRelease(int x, int y, @Nullable Target closestTarget) {
myLastX = -1;
myLastY = -1;
if (myComponent.getParent() != null) {
myComponent.getParent().setExpandTargetArea(false);
}
if (closestTarget != null && closestTarget instanceof AnchorTarget && !(((AnchorTarget) closestTarget).isConnected(this))) {
NlComponent component = myComponent.getNlComponent();
if (closestTarget == this) {
disconnectMe(component);
} else {
String attribute = getAttribute(closestTarget);
if (attribute != null) {
AnchorTarget targetAnchor = (AnchorTarget) closestTarget;
NlComponent targetComponent = targetAnchor.myComponent.getNlComponent();
AttributesTransaction attributes = connectMe(component, attribute, targetComponent);
NlModel nlModel = component.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Constraint Connected";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
attributes.commit();
}
};
action.execute();
myComponent.getScene().needsLayout(Scene.ANIMATED_LAYOUT);
}
}
}
}
use of com.intellij.openapi.application.Result 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();
}
use of com.intellij.openapi.application.Result in project android by JetBrains.
the class GuidelineCycleTarget method mouseRelease.
@Override
public void mouseRelease(int x, int y, @Nullable Target closestTarget) {
AttributesTransaction attributes = myComponent.getNlComponent().startAttributeTransaction();
String begin = attributes.getAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_BEGIN);
String end = attributes.getAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_END);
String percent = attributes.getAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_PERCENT);
SceneComponent parent = myComponent.getParent();
int value = myComponent.getDrawY() - parent.getDrawY();
int dimension = parent.getDrawHeight();
if (!myIsHorizontal) {
value = myComponent.getDrawX() - parent.getDrawX();
dimension = parent.getDrawWidth();
}
if (begin != null) {
setEnd(attributes, dimension - value);
} else if (end != null) {
setPercent(attributes, value / (float) dimension);
} else if (percent != null) {
setBegin(attributes, value);
}
attributes.apply();
NlModel nlModel = myComponent.getNlComponent().getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Cycle Guideline";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
attributes.commit();
}
};
action.execute();
}
use of com.intellij.openapi.application.Result in project intellij-plugins by JetBrains.
the class DartIntroduceHandler method performReplace.
@Nullable
private SmartPsiElementPointer<PsiElement> performReplace(@NotNull final PsiElement declaration, final DartIntroduceOperation operation) {
final DartExpression expression = operation.getInitializer();
final Project project = operation.getProject();
return new WriteCommandAction<SmartPsiElementPointer<PsiElement>>(project, expression.getContainingFile()) {
protected void run(@NotNull final Result<SmartPsiElementPointer<PsiElement>> result) throws Throwable {
final PsiElement createdDeclaration = addDeclaration(operation, declaration);
if (createdDeclaration != null) {
result.setResult(SmartPointerManager.getInstance(project).createSmartPsiElementPointer(createdDeclaration));
modifyDeclaration(createdDeclaration);
}
PsiElement newExpression = createExpression(project, operation.getName());
if (operation.isReplaceAll()) {
List<PsiElement> newOccurrences = new ArrayList<>();
for (PsiElement occurrence : operation.getOccurrences()) {
final PsiElement replaced = replaceExpression(occurrence, newExpression, operation);
if (replaced != null) {
newOccurrences.add(replaced);
}
}
operation.setOccurrences(newOccurrences);
} else {
final PsiElement replaced = replaceExpression(expression, newExpression, operation);
operation.setOccurrences(Collections.singletonList(replaced));
}
postRefactoring(operation.getElement());
}
}.execute().getResultObject();
}
Aggregations