Eclipse Community Forums - RDF feed Eclipse Community Forums Cut,Copy commands enabledWhen
I am trying to get my cut, copy main menu commands working in the same way that the default context menu works when focused on a Text widget. i.e. if no text is selected on the focused Text widget, cut and copy should not be enabled.

I am able to enable the handler when the activePartId is my editor, so far so good. However, the commands are always active in the main menu, where in the context menu they are disabled correctly.

I've tried using the selection variable and count with no success so far.

Could someone please point me in the right direction, or let me know if this is a limitation?

Steve ]]>
Stephen Jones 2012-09-16T22:08:05-00:00
Re: Cut,Copy commands enabledWhen In this case, you should have to use legacy way. (IActionBars.setGlobalHandler() and Action, you can get actionbars from viewsite or editorsite)

Command and handler, menu extensions, core expressions are declarative and cost very low to create UI without code running.
But complex and dynamic situation, It's very hard to get you want.

You can also provide another variable which you need through service extensions.
Jeeeyul Lee 2012-09-18T02:49:56-00:00
Re: Cut,Copy commands enabledWhen
I manged to work it out using the variable route, as this seems to be the most logical approach and still uses commands. Basically I create a variable, and used the mouse up and key up events to set the variable based on the getSelectionCount of each Text widget on my form. I also used the focus lost to reset the variable back to false.

Then bolted this variable on the enabledWhen of cut and copy, and woo hoo it works!!!

Stephen Jones 2012-09-19T09:40:27-00:00
Re: Cut,Copy commands enabledWhen
But I want you to consider advantage of command/menuContribution/core-expression and it's cost.

Remarkable Advantages are:
* Lazy: Can creates UI(menu/toolbar) without class loading, so no plugin will be started, no dependencies are resolved till handler will work.
* Extensible: 3rd party can extends menu or can modify behavior of command in specific context.
* Ease to manage: You can list all actions from plugin.xml, it's pretty good entry point to manage or co-operate then hard coded.

If an action which should not have to be initialized lazy(Declarative UI from plugin.xml first and load business logic later, it prevents plugin starting to just create UI)
or it has globally same policy(there is no chance to extended by client or co-worker),
or actions are reasonable in some specific view or editors only (initializing part causes expensive plugin start),

then There is no advantage with command/menuContribution/core-expression.

In your case, ui context is much more complex then business logic.
And your variable provider from service extension should start your plugin. (it's expensive since it has own dependencies)
So, to make advantage real, you should isolate service plugin which provides variables.

And publishing new variables and teach them to your co-worker or client is not so small task.
Jeeeyul Lee 2012-09-20T02:01:36-00:00