Calling a command guru: editor menu enablement [message #483302] |
Mon, 31 August 2009 21:38 |
Eclipse User |
|
|
|
Originally posted by: marc.esher.comcast.net
Greetings,
I have a simple plugin that takes the currently selected text in the
editor (any editor, as long as it's text), manipulates the text, and copies
it to the clipboard. I started with Eclipse plugin development working on
3.2, and both of the books I used to learn how to do all this were heavy on
Action and light on command. With this plugin, I'm trying to get my act in
gear and learn how to do it all with Commands.
My problem is that I'm having trouble getting the right stuff down for
menu visibility. I want this command to be active/visible when the user
selects text in an editor and then right clicks. In the 3.2 days, I would've
done an editorContribution with a nested <selection
class="org.eclipse.jface.text.ITextSelection"> element. The downside of that
is that I'd have had to redo it (I think) for all editors I wanted to
target. And what I really want is to not target any editors at all... I want
to target the act of selecting text in an editor.
I thought I could use this:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions ">
<command
commandId="blah"
tooltip="Format And Copy to Clipboard"
id="blahCommand">
<visibleWhen>
<with variable="selection">
<equals
value="org.eclipse.jface.text.ISelection">
</equals>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
But that didn't work.
Is it possible to do what I want to do, i.e. register a command that will be
enabled and visible in the editor context menu when and only when the user
highlights some text in the editor?
Thanks!
Marc
|
|
|
|
|
|
|
Re: Calling a command guru: editor menu enablement [message #485241 is a reply to message #483889] |
Thu, 10 September 2009 21:39 |
Eclipse User |
|
|
|
Originally posted by: marc.esher.comcast.net
I will check it out. Thanks Remo!
"Remo Loetscher" <remo.loetscher@postfinance.ch> wrote in message
news:4a9fc9ec$1@news.post.ch...
> Hi Marc,
>
> > Is there an easy way to debug this stuff?
>
> You can download and install the yari eclipse plugin
> (http://sourceforge.net/projects/yari/).
>
> Yari will not allow you to intercept the running system but the
> "expression evaluator" dialog (in the yari main menu) offers you a way for
> the runtime evaluation of eclipse expressions.
> Paste the following snippet in the "Enter an expression and..." text field
> and evaluate the expression:
>
> <with variable="selection">
> <instanceof
> value="org.eclipse.jface.text.ITextSelection">
> </instanceof>
> </with>
>
> This should evaluate to "true" for text selections, otherwise to
> "false"...
>
> In the "Evalute ISource constant" tab you can also inspect the current
> value of the selection: switch to the tab, select
> "ACTIVE_CURRENT_SELECTION_NAME" and open the object pushing the "inspect
> result".
>
> hth,
>
> Remo
>
> Marc Esher wrote:
>> Sweet. Thanks Paul.
>>
>> Is there an easy way to debug this stuff? For example, at runtime, can I
>> intercept at the point where the menu is going to be evaluated and see
>> what the "selection" object actually is?
>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.05458 seconds