Limiting GoText length


#1
Greetings: Might there be a simple and elegant means to limit the length of user entered text on a GoIconicNode? Perusing the documentation, I find instructions to add a GoView.ObjectEdited event handler, yet this event tells you past tense an object (in my case, a GoText object) has been edited, whereas I would greatly prefer preventing the user from entering to many characters in the first place. Thanks for any recommendations. Doug

#2

Take a look at the documentation for GoText.DoBeginEdit.


#3
GoText.DoBeginEdit() looks like a promising hook into the editing process, but I'm having trouble understanding the overrides in this case. To test, I created a class clsGoText that inherits from GoText: Public Class clsGoText Inherits Northwoods.Go.GoText Public Overrides Sub DoBeginEdit(ByVal view As Northwoods.Go.GoView) MyBase.DoBeginEdit(view) End Sub Public Overrides Property Text() As String Get Return MyBase.Text End Get Set(ByVal Value As String) MyBase.Text = Value End Set End Property ... End Class In other code I did this: Dim cGoIconIonicNode As New Northwoods.Go.GoIconicNode ... cGoIconIonicNode.Label = New.clsGoText ... When I run the full code, a breakpoint on clsGoText.Text() is constantly getting hit, but a breakpoint on clsGoText.DoBeginEdit() never is. Obviously, there is something fundamentally wrong in my approach. Can you see anything obvious? Thanks, Doug

#4
Public Overrides Sub DoBeginEdit(ByVal view As GoView) If Not (Me.Editor Is Nothing) Then Return ' already editing MyBase.DoBeginEdit(view) Dim ctrl As TextBox = CType(Me.Editor.GetControl(view), TextBox) ' create Control in view if needed If Not (ctrl Is Nothing) Then ctrl.MaxLength = ... End If End Sub

#5
Good Morning Walter: Thanks for the code snippet. What to do in DoBeginEdit() seems fairly strait forward, but I still do not understand what triggers the call to DoBeginEdit() in the first place. In the Demo1.sln which accompanied my Northwoods installation, DoBeginEdit() is explicitly called from OnSingleClick(). Do I need to explicitly call my DoBeginEdit() also? As the GoText object allows user entry by default, I would assume a DoBeginEdit() call is already executed from somewhere. I would expect my DoBeginEdit() override should intercept that call, but a breakpoint on my overridden DoBeginEdit() never breaks. Am I missing something here, or is a manual call the way to go? Sorry to be so dense about this, but limiting text length seems like such a simple thing to do, but I’m a bit frustrated by being so confused about it. Doug

#6

Here’s the definition of GoText.OnSingleClick, invoked by a click on an editable GoText:
public override bool OnSingleClick(GoInputEventArgs evt, GoView view) {
if (!CanEdit()) return false;
if (!view.CanEditObjects()) return false;
if (evt.Shift || evt.Control) return false;
DoBeginEdit(view);
return true;
}
And here’s the definition of GoView.EditObject, invoked by F2 and GoView.EditEdit():
public virtual void EditObject(GoObject obj) {
if (obj == null) return;
if (!CanEditObjects()) return;
if (obj.CanEdit()) {
obj.DoBeginEdit(this);
}
}


#7
Hello Again Walter: Thanks ever so much for your help. With your code, and referencing the ProtoApp.sln demo, I have succeeded in limited GoIconicNode input text length. The key to my problem was that I was not overriding the GoIconicNode.CreateLabel(). Once I recognized that was the proper place to hook in my GoText derived class, things pretty much fell into place. On to my next problem! But at least my attitude is much improved. Thanks again, Doug