Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » What should a paste action derive from? (triggering calculateEnabled())
What should a paste action derive from? (triggering calculateEnabled()) [message #237609] Mon, 06 August 2007 12:04 Go to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
Platform: eclipse 3.2.2

I've now successfully created a CopyAction that can be used as an
action handler for the retargetable action ActionFactory.COPY. This
action derives from SelectionAction.

I've then created a PasteAction that derives from WorkbenchAction. In
this class the calculateEnabled() method is called when starting up
(then it returns false), but it is not called when the clipboard
contents changes.

So I wonder:
- Should I derive from a different class than WorkbenchAction?
- Is there a way where I can trigger recalculation of enabled state
of all retarget actions?
- Can I notify my current PasteAction somehow when the clipboard
state changes?

Thanx!


- Steinar
Re: What should a paste action derive from? (triggering calculateEnabled()) [message #237629 is a reply to message #237609] Mon, 06 August 2007 13:16 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

[snip!]
> So I wonder:
[snip!]
> - Is there a way where I can trigger recalculation of enabled state
> of all retarget actions?

I've tried two things in this direction:

1. Setting the lazyEnablementCalculation to false in the paste
action, but this just caused the calculateEnabled() method never
to be called:
http://help.eclipse.org/help32/topic/org.eclipse.gef.doc.isv /reference/api/org/eclipse/gef/ui/actions/WorkbenchPartActio n.html#setLazyEnablementCalculation(boolean)
method looked hopeful.

2. doing the following in the CopyAction#run() method, after calling
ClipBoard#setContents() :
((IEditorSite)getWorkbenchPart().getSite()).getActionBars(). updateActionBars();
But it had no effect on the paste action and I didn't hit the
breakpoint I'd set in PasteAction#calculateEnabled()
Re: What should a paste action derive from? (triggering calculateEnabled()) [message #237635 is a reply to message #237629] Mon, 06 August 2007 13:33 Go to previous message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@dod.no>:

>>>>> Steinar Bang <sb@dod.no>:
> [snip!]
>> So I wonder:
> [snip!]
>> - Is there a way where I can trigger recalculation of enabled state
>> of all retarget actions?

> I've tried two things in this direction:

> 1. Setting the lazyEnablementCalculation to false in the paste
> action, but this just caused the calculateEnabled() method never
> to be called:
> http://help.eclipse.org/help32/topic/org.eclipse.gef.doc.isv /reference/api/org/eclipse/gef/ui/actions/WorkbenchPartActio n.html#setLazyEnablementCalculation(boolean)
> method looked hopeful.

> 2. doing the following in the CopyAction#run() method, after calling
> ClipBoard#setContents() :
> ((IEditorSite)getWorkbenchPart().getSite()).getActionBars(). updateActionBars();
> But it had no effect on the paste action and I didn't hit the
> breakpoint I'd set in PasteAction#calculateEnabled()

A variant on version 2, actually works, but feels like a hack: what I
put into the CopyAction#run() method after setting the clipboard
contents was the following:
IAction pasteAction = ((IEditorSite)getWorkbenchPart().getSite()).getActionBars(). getGlobalActionHandler(ActionFactory.PASTE.getId());
pasteAction.isEnabled();

Is this a hack? Is there a better way?

Thanx!
Previous Topic:Get the size of my plugin's view
Next Topic:how to tell an editor to refresh
Goto Forum:
  


Current Time: Fri Apr 19 10:42:26 GMT 2024

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

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

Back to the top