Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mylyn-dev] Re: command handlers and activeFocusControl

Great that you got it working. You might also want to take a look at 
org.eclipse.ui.handlers.HandlerUtil. The class has a bunch of static methods, 
e.g. getVariable(ExecutionEvent event, String name) that help with some of 
the command handler boiler plate code. 

Steffen


On Monday 09 June 2008, David Green wrote:
> Here's my solution:
>
>
>  public Object execute(ExecutionEvent event) throws ExecutionException {
>
> Object appContext = event.getApplicationContext();
>
> if (appContext instanceof EvaluationContext) {
>
> EvaluationContext context = (EvaluationContext) appContext;
>
> Object activeFocusControl = context.getVariable("activeFocusControl");
>
> if (activeFocusControl instanceof Control) {
>
> Control control = (Control) activeFocusControl;
>
> // ... do something useful here
>
> }
>
> }
>
> return null;
>
> }
>
> On Thu, Jun 5, 2008 at 6:35 AM, David Green <dgreen99@xxxxxxxxx> wrote:
> > As part of the Textile-J contribution for wikitext support in Mylyn I'm
> > converting some actions to commands, and so far so good.  I've got one
> > command that's going to be activated as follows:
> >
> >
> >  <extension point="org.eclipse.ui.handlers">
> >
> > <handler commandId=
> > "org.eclipse.mylyn.wikitext.ui.editor.showCheatSheetCommand"
> >
> > class=
> > "org.eclipse.mylyn.wikitext.ui.editor.internal.commands.ShowCheatSheetCom
> >mand"
> >
> >
> > <activeWhen>
> >
> > <with variable="activeFocusControlId">
> >
> > <equals value="org.eclipse.mylyn.wikitext.ui.editor.sourceViewer">
> >
> > </equals>
> >
> > </with>
> >
> > </activeWhen>
> >
> > </handler>
> >
> > </extension>
> >
> >
> > In my ITaskEditorExtension I can do this:
> >
> >
> >
> >  IFocusService focusService = (IFocusService)
> > PlatformUI.getWorkbench().getService(IFocusService.class);
> >
> >  if (focusService != null) {
> >
> >  focusService.addFocusTracker(viewer.getTextWidget(),
> > "org.eclipse.mylyn.wikitext.ui.editor.sourceViewer");
> >
> >  }
> >
> > viewer.getTextWidget().setData(MarkupLanguage.class.getName(),
> > markupLanguage);
> >
> >  Providing that the editor sets the right context, everything should just
> > work.  Here's the question:
> >
> > I'm wondering how I can access the activeFocusControl in the
> > AbstractHandler.  This will give the handler access to the
> > markupLanguage. Any ideas?
> >
> >
> > Thanks in advance,
> >
> >
> > David



-- 
Steffen Pingel - steffenp@xxxxxx - http://steffenpingel.de


Back to the top