GoTextNode Editor

Is it possible to use a different Text Editor for the GoTextNode Editor? I’ve implemented some kind of auto completition text editor and I’d link to use it in my GoNode, but this editor implements a infragistics text editor. Is it possible to use another editor for my gotextnode or do I have to use the standard one?.

You’ll need to implement a class inheriting from GoText that overrides the GoText.CreateEditor method. This needs to return a GoControl that creates an instance of your custom control that also implement IGoControlObject.

Then you need to make sure that your GoTextNode.Label is an instance of your custom GoText class. If you already have a subclass of GoTextNode, you can just override GoTextNode.CreateLabel.
[code] [Serializable]
public class CustomTextNode : GoTextNode {
public CustomTextNode() { }
protected override GoText CreateLabel() {
GoText l = new CustomText();
l.Selectable = false;
return l;
}
}
[Serializable]
public class CustomText : GoText {
public CustomText() { }
public override GoControl CreateEditor(GoView view) {
GoControl editor = new GoControl();
editor.ControlType = typeof(CustomTextBox);
RectangleF r = this.Bounds;
r.Inflate(2, 2); // a bit bigger than the original GoText object
editor.Bounds = r;
return editor;
}
}
public class CustomTextBox : TextBox, IGoControlObject {
public CustomTextBox() {
this.BackColor = Color.AliceBlue;
}
public GoControl GoControl {
get { return myGoControl; }
set {
GoControl old = myGoControl;
if (old != value) {
myGoControl = value;
if (value != null) {
GoText gotext = value.EditedObject as GoText;
if (gotext != null) {
// initialize the control according to the state of the GoText object
this.Text = gotext.Text;
switch (gotext.Alignment) {
default:
case GoObject.TopLeft:
case GoObject.MiddleLeft:
case GoObject.BottomLeft:
this.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
break;
case GoObject.TopCenter:
case GoObject.MiddleCenter:
case GoObject.BottomCenter:
this.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
break;
case GoObject.TopRight:
case GoObject.MiddleRight:
case GoObject.BottomRight:
this.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
break;
}
this.Multiline = gotext.Multiline || gotext.Wrapping;
this.AcceptsReturn = gotext.Multiline;
this.WordWrap = gotext.Wrapping;
Font objfont = gotext.Font;
float fsize = objfont.Size;
if (this.GoView != null) fsize *= this.GoView.DocScale;
this.Font = new Font(objfont.Name, fsize, objfont.Style, GraphicsUnit.Point);
}
}
}
}
}
public GoView GoView {
get { return myGoView; }
set { myGoView = value; }
}
protected override bool ProcessDialogKey(System.Windows.Forms.Keys key) {
if (HandleKey(key))
return true;
else
return base.ProcessDialogKey(key);
}
protected override void OnLeave(EventArgs evt) {
AcceptText();
base.OnLeave(evt);
}
private bool HandleKey(System.Windows.Forms.Keys key) {
if (key == System.Windows.Forms.Keys.Escape) {
GoControl ctrl = this.GoControl;
if (ctrl != null)
ctrl.DoEndEdit(this.GoView);
this.GoView.RequestFocus();
return true;
} else if (key == System.Windows.Forms.Keys.Enter || key == System.Windows.Forms.Keys.Tab) {
if (key == System.Windows.Forms.Keys.Enter && this.AcceptsReturn) // accept the return to start a new line
return false;
AcceptText();
this.GoView.RequestFocus();
return true;
} else {
return false;
}
}
private void AcceptText() {
GoControl ctrl = this.GoControl;
if (ctrl != null) {
GoText gotext = ctrl.EditedObject as GoText;
if (gotext != null) {
gotext.DoEdit(this.GoView, gotext.Text, this.Text);
}
ctrl.DoEndEdit(this.GoView);
}
}
// CustomTextBox state
private GoControl myGoControl;
private GoView myGoView;
}[/code]
Of course you'll want to replace the definition of CustomTextBox to inherit from that other TextBox control. Some of the code above might not be needed, depending on your control and your application requirements.