Home » Eclipse Projects » Eclipse Platform » refreshing commands based on workbench selection
refreshing commands based on workbench selection [message #335368] |
Fri, 03 April 2009 18:32  |
Eclipse User |
|
|
|
Hi,
I'm trying to contribute a command to a toolbar using the command framework. I'm
able to get it there, but I need it to be updated according to the selection in
the workbench. With the old action delegates, this was done with no trouble.
But, commands aren't so nice.
So, basically, what I have done is I've registered my own listeners to track the
active window/selection, and I try to run ICommandService.refreshElements() when
the selection gets changed, but updateElement() never gets called on my command
handler because "no user action has been performed on the command" yet, and my
command handler hasn't been loaded. I don't understand why things are done this
way. I need to be able to update the icon, text, and enablement based on the
selection. Is there any way that I can do this? It seems like it should be
simple. Thanks.
Del
|
|
|
Re: refreshing commands based on workbench selection [message #335377 is a reply to message #335368] |
Sat, 04 April 2009 21:25   |
Eclipse User |
|
|
|
You should be able to do this for your handler in plugin.xml
<enabledWhen>
<with
variable="selection">
<!-- Appropriate equals, instanceof, etc. test here -->
</with>
</enabledWhen>
-Ben
Del Myers wrote:
> Hi,
>
> I'm trying to contribute a command to a toolbar using the command
> framework. I'm able to get it there, but I need it to be updated
> according to the selection in the workbench. With the old action
> delegates, this was done with no trouble. But, commands aren't so nice.
>
> So, basically, what I have done is I've registered my own listeners to
> track the active window/selection, and I try to run
> ICommandService.refreshElements() when the selection gets changed, but
> updateElement() never gets called on my command handler because "no user
> action has been performed on the command" yet, and my command handler
> hasn't been loaded. I don't understand why things are done this way. I
> need to be able to update the icon, text, and enablement based on the
> selection. Is there any way that I can do this? It seems like it should
> be simple. Thanks.
>
> Del
|
|
| |
Re: refreshing commands based on workbench selection [message #335405 is a reply to message #335377] |
Mon, 06 April 2009 12:06   |
Eclipse User |
|
|
|
Almost, but not quite. I need to change more than enablement. It is a "toggle"
command, and it will be either checked or unchecked depending on the current
selection. What I need is for my command to get loaded earlier than it is. There
has got to be a way to do this. I understand the platform's efforts to cut back
on memory used for a command, but, seriously, my command handler is smaller than
the proxy command. Is it really so important? Maybe, I guess, but the action
delegates seemed to work fine without memory overloads, or noticeable slowdown.
Del
Ben Vitale wrote:
> You should be able to do this for your handler in plugin.xml
>
> <enabledWhen>
> <with
> variable="selection">
> <!-- Appropriate equals, instanceof, etc. test here -->
> </with>
> </enabledWhen>
>
> -Ben
>
> Del Myers wrote:
>> Hi,
>>
>> I'm trying to contribute a command to a toolbar using the command
>> framework. I'm able to get it there, but I need it to be updated
>> according to the selection in the workbench. With the old action
>> delegates, this was done with no trouble. But, commands aren't so nice.
>>
>> So, basically, what I have done is I've registered my own listeners to
>> track the active window/selection, and I try to run
>> ICommandService.refreshElements() when the selection gets changed, but
>> updateElement() never gets called on my command handler because "no
>> user action has been performed on the command" yet, and my command
>> handler hasn't been loaded. I don't understand why things are done
>> this way. I need to be able to update the icon, text, and enablement
>> based on the selection. Is there any way that I can do this? It seems
>> like it should be simple. Thanks.
>>
>> Del
|
|
| | |
Goto Forum:
Current Time: Thu May 01 06:23:28 EDT 2025
Powered by FUDForum. Page generated in 0.07387 seconds
|