Using the Tab key to navigate text in a GoGroup

Hi!

I’ve been thinking about implementing a method, using the Tab key on the keyboard, to navigate through text items (GoText) held in a GoGroup. My custom object is a GoBoxNode with a GoNode body. The GoNode body maintains the GoGroup containing the GoText objects. The desired functionality for the Tab key in my circumstances would be that once one of the GoText items are selected (using the mouse to select), pressing the Tab key would move the selection to the next GoText and begin an edit on that GoText. Wraparound to the first GoText would occur when pressing the Tab key on the last GoText. I’d like Tab to reverse the selection order. Unfortunately, Ch 5 of the users manual doesn’t mention Tab key functionality (events/overrides/etc…). I’ve experimented with OnKeyDown and other OnKey… events for my GoView but they are not firing for the tab key. I’m not sure this is what I want anyway. I did find one mention of what seemed like similar behavior using the arrow keys in these forums but that thread was from 3 or 4 years ago and I wasn’t sure if the approach discussed in that thread was OBE (overtaken by events).

Your thoughts or suggestions on this issue would be very much appreciated.

Thanks.

R. Houston

Like most things in GoDiagram there is more than one way to do things. You can either create a new GoToolManager that has a DoKeyDown override, or you can override GoView.DoKeyDown.
Which is best?
The tradeoff is how global you want it to be. A GoView DoKeyDown trumps the currently active Tool... whereas doing it in the tool will deliver the key to a tool only when it is active.
So the tool override is the right way for most of uses for most keys. The reason is that you probably don't want to change the behavior of other tools (such as linking or resizing) if the user hits that special key.
There is also the rare circumstance you'll need to override a method (or just an event handler) on the view. This is one of them, just because the key is TAB, a key used for navigating between controls. If you wanted to handle Ctrl-A, for example, you wouldn't need to override Control.IsInputKey:
public class TabGoView : GoView {
public TabGoView() {}
protected override bool IsInputKey(Keys k) {
if (k == Keys.Tab) return true;
return base.IsInputKey(k);
}
}
In any case, here's the custom tool:
[Serializable]
public class TabManager : GoToolManager {
public TabManager(GoView v) : base(v) { }
public override void DoKeyDown() {
if (this.LastInput.Key == Keys.Tab) {
this.View.MoveSelection(null, new SizeF(10, 10), true);
} else {
base.DoKeyDown();
}
}
}
(note the red code here doesn't move the focus to the next editable text...)
Install the tool by:
goView1.DefaultTool = new TabManager(goView1);
goView1.Tool = goView1.DefaultTool;