Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Calling a command guru: editor menu enablement
Calling a command guru: editor menu enablement [message #483302] Mon, 31 August 2009 21:38 Go to next message
Eclipse UserFriend
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 #483415 is a reply to message #483302] Tue, 01 September 2009 14:47 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Eclipse User wrote on Mon, 31 August 2009 17:38
Originally posted by: marc.esher.comcast.net


<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>




selection is a type of (no text package) ISelection (as long as something is selected) ... you're asking if selectionObject.equals("o.e.jface.text.ISelection") which is not true and "....text.ISelection" doesn't exist. You probably mean ITextSelection, right?

Try using <instanceof/> instead of <equals/> and the correct name for ITextSelection.

PW


Re: Calling a command guru: editor menu e nablement [message #483424 is a reply to message #483415] Tue, 01 September 2009 15:01 Go to previous messageGo to next message
Marc Esher is currently offline Marc EsherFriend
Messages: 14
Registered: July 2009
Junior Member
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?
Re: Calling a command guru: editor menu e nablement [message #483470 is a reply to message #483424] Tue, 01 September 2009 17:13 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

No, at least not really. The XML gets converted to Expressions from org.eclipse.core.expressions. But anything that uses "selection" will be re-evaluated every time the selection changes, and it changes all the time Smile

Because a number of variables change when SWT fires events, some of the expressions are hard to track down.

PW


Re: Calling a command guru: editor menu enablement [message #483889 is a reply to message #483424] Thu, 03 September 2009 13:51 Go to previous messageGo to next message
Remo Loetscher is currently offline Remo LoetscherFriend
Messages: 18
Registered: July 2009
Junior Member
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?
>
>
>
Re: Calling a command guru: editor menu enablement [message #485241 is a reply to message #483889] Thu, 10 September 2009 21:39 Go to previous message
Eclipse UserFriend
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?
>>
>>
Previous Topic:Re: signed plug-in
Next Topic:save editor state
Goto Forum:
  


Current Time: Fri Apr 19 21:40:38 GMT 2024

Powered by FUDForum. Page generated in 0.03244 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top