Thursday, 10 September 2009 02:43 by
Bill Henning (Actipro)
One highly requested feature for SyntaxEditor for WPF is the ability to be notified when a mouse hover occurs so that IntelliPrompt quick info tips can be displayed in response. Since WPF doesn’t include a mouse hover event, we implemented one ourselves that fires for editor views.
We didn’t stop there though. We wanted to make it simple for a language to provide quick info popups in response to mouse hover events. Thus we came up with the new IQuickInfoProvider service. This service can be registered with a language. It has three methods on it:
1: object GetContext(IHitTestResult hitTestResult);
2: object GetContext(IEditorView view, int offset);
3: void RequestSession(IEditorView view, object context, bool canTrackMouse);
We offer a QuickInfoProviderBase abstract class that should be used as a base class for any implementations of IQuickInfoProvider that you create. QuickInfoProviderBase fully implements mouse tracking such that when a mouse hover occurs over an editor view, it calls the GetContext overload that accepts an IHitTestResult. The IHitTestResult comes from our previously-discussed hit testing feature. The default implementation of this overload is to call the other GetContext overload if the hit is over a character in the text area.
The GetContext methods should return some object that gives detail about what is at the specified hit or offset, or a null reference if it is not important. This could be some object as simple as an IToken or some more complex context object. The important part is that it supports value equality (Equals method implementation) since as the mouse moves, the context returned by GetContext is compared against the context of any already-open quick info session to see if the existing session should be closed or kept open.
By using GetContext, the quick info provider knows when the mouse moves outside of the the region that is appropriate to an already-open quick info session, and when to open a new quick info session. Once a new quick info session is needed, the RequestSession method is called. It is passed the editor view instance, the context object returned by GetContext, and whether the mouse should be tracked (false when quick info is displayed in response to a toolbar button click for example).
Your RequestSession implementations are expected to create a new quick info session, store the passed context in the session, generate content for the quick info popup, and open the session (display the popup).
By using this new provider mechanism, it’s very easy for languages to automatically support quick info display with a minimal amount of work. All the mouse handling is done for you. This feature will be in the next build and we’ve updated our quick info sample to show how easy it is to use.