[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: Project menu actions don't get enabled/disabled when selecting file from editor view
|
Miriam,
You wrote:
> I have a couple of project menu actions that get enabled and disabled
> when the user select a file with a specific extension (*.vxm*) from the
> navigator view.
Actually, the actions are enabled if a .vxm file is selected in ANY view
or part. There is nothing special about the navigator. If you select a
vxm file in the Packages view your action should also be enabled.
> This is all working fine when the user selects a file from the navigator
> view. However, this is not working when the user selects a file from
> different editor views. In this case, the project menu actions don't
> get enabled or disabled depending on the extension of the current file
> being edited (what I have in my plugin.xml file is being ignored). I do
> notice that the focus on the navigator view changes as the user switches
> editors from one file to another, but somehow the focus is not being
> taken as a selection.
> Is there a way to fix this?
The selection service broadcasts the selection for the active part, not
just the navigator. When the editor is selected it becomes the active
part and, if it has a selection, that selection is fired. The selection
service will ignore the selection within the navigator from that point on
until it is activated again.
The editor has an input (typically a file) and a selection (typically a
text item). When the editor is activated this text selection will be
broadcast to all listeners.
In your scenario I think you would like to enable the action if the editor
has input == *.xml. Unfortunately there is no way to define that criteria
in the extension xml. The enablesFor attribute only applies to selection.
This is a known limitation and may be addressed in 2.0.
If your action is instantiated it may define a better algorithm for
enablement in code. If the navigator is open you can get it using
IWorkbenchPage.findView and then hook a listener to selection. However,
"Link Navigator Selection to Active Editor" may be turned off in the
preferences, breaking your algorithm. I would listen for part activation
instead.
For more info on the extension point see the Action Sets extension point
doc in org.eclipse.ui.
Dave