execute method

  1. @override
void execute()
override

Implementation

@override
void execute() {
  // remove from old

  if ( oldParent != null) {
    index = oldParent!.children.indexOf(widget);
    oldParent!.children.remove(widget);

    if ( oldParent != newParent)
      bus.publish(
        "property-changed",
        PropertyChangeEvent(widget: oldParent, source: this),
      );
  }

  // add to new

  widget.parent = newParent;
  widget.cell = newCell;

  if ( newParent != null) {
    if ( newIndex == -1)
      newParent!.children.add(widget);
    else
      newParent!.children.insert(newIndex, widget);

    bus.publish(
      "property-changed",
      PropertyChangeEvent(widget: newParent, source: this),
    );
  }
  else {
    widget.widget = null; // it was deleted

    bus.publish("selection", SelectionEvent(selection: null, source: null));
  }
}