void LayerTree::object_changed(const std::string &key, const grt::ValueRef &value, mforms::TreeNodeRef node) {
  FigureNode *fn = dynamic_cast<FigureNode *>(node->get_data());

  if (key == "name")
    node->set_string(0, fn->object->name());
  else if (key == "layer") {
    model_FigureRef figure(model_FigureRef::cast_from(fn->object));
    if (figure->layer() != value) {
      fn->conn.disconnect();
      node->remove_from_parent();

      if (figure->layer() == _diagram->rootLayer()) {
        int insertion_point = 0;
        // find the last node that's not a layer
        for (int c = count(); insertion_point < c; ++insertion_point) {
          mforms::TreeNodeRef n = node_at_row(insertion_point);
          FigureNode *nn = dynamic_cast<FigureNode *>(n->get_data());
          if (!nn)
            continue;
          if (nn->is_layer)
            break;
        }
        add_figure_node(mforms::TreeNodeRef(), figure, insertion_point);
      } else {
        mforms::TreeNodeRef layer_node = node_with_tag(figure->layer().id());

        add_figure_node(layer_node, figure);
      }
    }
  }
}
void LayerTree::activate_node(const mforms::TreeNodeRef &node, int column) {
  FigureNode *fnode = dynamic_cast<FigureNode *>(node->get_data());
  if (fnode)
    _form->focus_and_make_visible(fnode->object, true);
}