I set the property Editable to True,
Now I have a new requirement:
When using the Text tool, I apply the box and it is selected, but I cannot type. I have to click the box a second time to get a cursor and type. Make text entry active when box is placed.
OK, so you have set the node’s TextBlock.editable to true. Also give it a GraphObject.name:
nodeTemplate:
$(go.Node, "Auto",
. . .,
$(go.TextBlock,
{ margin: 2, editable: true, name: "TB" },
new go.Binding("text", "color"))),
Then in DragCreatingTool.insertPart override, also call CommandHandler.editTextBlock:
insertPart: function(bounds) { // override DragCreatingTool.insertPart
// use a different color each time
this.archetypeNodeData.color = go.Brush.randomColor();
// call the base method to do normal behavior and return its result
var newpart = DragCreatingTool.prototype.insertPart.call(this, bounds);
// also start editing the text
this.diagram.commandHandler.editTextBlock(newpart.findObject("TB"));
return newpart;
}
Oh Thank you so much!
For anyone finding this topic but interested in automatically starting editing after a drag-and-drop from a Palette, see the sample Graphical Macros via Auto Ungrouping, which does something similar in an “ExternalObjectsDropped” DiagramEvent listener.