Skip to main content

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

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.ShowCheatSheetCommand">

<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



Back to the top