I have a command that I have added to the context menu of a view (which has a treeviewer) and the context menu of my custom editor.
In my handler is there any way for me to differentiate which context menu the command has been called from? This is because in the case of the view, I use something like this to get the data I need,
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
.getActivePage().getSelection();
if (selection != null & selection instanceof IStructuredSelection)
{
IStructuredSelection strucSelection = (IStructuredSelection) selection;
.....
In the case of the editor, the selection is null, of course. So I added the following to handle the editor part,
IEditorPart editor = HandlerUtil.getActiveEditor(event);
IEditorInput input = editor.getEditorInput();
IPath path = ((FileEditorInput)input).getPath();
But what happens is that even if I execute this command from my view, it always returns an active editor. Does this mean I have to write to separate handlers that will be active based on whether the view or the editor is in focus?
Thank you!
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection()toHandlerUtil.getCurrentSelectionChecked(event)... :-) - Tonny Madsen