implementing cut/copy/paste [message #159391] |
Fri, 26 November 2004 09:00  |
Eclipse User |
|
|
|
Originally posted by: jojo.virtutech.se
I'm trying to implement cut/copy/paste in my editor using actions created
by
ActionFactory.CUT.create(window)
etc.
I've managed to create the actions and added them to the context menu and
toolbar, but how do I implement the actual code which performs the actions?
Or should I implement my own action classes?
--
/Jesper
|
|
|
|
|
|
Re: implementing cut/copy/paste [message #159564 is a reply to message #159557] |
Mon, 29 November 2004 08:03   |
Eclipse User |
|
|
|
Originally posted by: Lamont_Gilbert.rigidsoftware.com
getSelectedObjects should never return the empty list. If anything it
should return your main editpart (your drawing).
try
ActionRegistry registry = getActionRegistry();
IAction action;
action = new CopyAction(this);
registry.registerAction(action);
getSelectionActions().add(action.getID());
Jesper Eskilson wrote:
> "Pratik Shah" <ppshah@us.ibm.com> writes:
>
>
>>Yes, you'll have to write your own actions (in addition to the retarget
>>actions that you've already created) and add them to your Editor's
>>actionRegistry. Make sure these actions have the same IDs as the retarget
>>actions.
>
>
> The copy-action is now called properly, but I can't get a hold of the
> selection. getSelectedObjects() returns the empty list.
>
> My editor's createActions() looks like this:
>
> protected void createActions()
> {
> super.createActions();
> IActionBars bars = getEditorSite().getActionBars();
> ActionRegistry registry = getActionRegistry();
> IAction action;
>
> action = new CopyAction(this);
> registry.registerAction(action);
> bars.setGlobalActionHandler(CopyAction.ID, action);
>
> [...]
>
> }
>
> I've tried following the logic-example, but to no avail.
>
--
Respectfully,
CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into
the sheepfold{}, but climbeth up some other *way, the same is a thief
and a robber."
GnuPG Key Fingerprint:
82A6 8893 C2A1 F64E A9AD 19AE 55B2 4CD7 80D2 0A2D
For a free Java interface to Freechess.org see
http://www.rigidsoftware.com/Chess/chess.html
|
|
|
|
Re: implementing cut/copy/paste [message #159675 is a reply to message #159658] |
Tue, 30 November 2004 04:26   |
Eclipse User |
|
|
|
Originally posted by: jojo.virtutech.se
Jesper Eskilson wrote:
> "CL [dnoyeb] Gilbert" <Lamont_Gilbert@rigidsoftware.com> writes:
>
>
>>getSelectedObjects should never return the empty list.
>
>
> Well, it does.
>
> After some investigation, it appears that CopyAction's update() method is
> never called, and thus the selection field is never set. I wonder why.
>
> I'll keep investigating.
>
What seems to happen is this: when selectionChanged (in the
GraphicalEditor class) calls updateAction() on all selection-actions,
only the retarget-version of the action gets called -- they have the
same ID, so the action-registry can only hold one of them:
protected void updateActions(List actionIds)
{
ActionRegistry registry = getActionRegistry();
Iterator iter = actionIds.iterator();
while (iter.hasNext()) {
IAction action = registry.getAction(iter.next());
if (action instanceof UpdateAction)
((UpdateAction)action).update();
}
}
The parameter actionIds is here [ 'delete', 'copy' ] when called from
selectionChanged, and registry.getAction() returns a RetargetAction(),
not my CopyAction.
So, something is wrong in my action-registry. Pratik said that I should
create both retarget-actions and "normal" actions with the same ID, but
then they can't reside in the same action-registry. Or did I miss something?
/Jesper
|
|
|
Re: implementing cut/copy/paste [message #159700 is a reply to message #159675] |
Tue, 30 November 2004 11:19   |
Eclipse User |
|
|
|
Originally posted by: Lamont_Gilbert.rigidsoftware.com
Jesper Eskilson wrote:
> Jesper Eskilson wrote:
>
>> "CL [dnoyeb] Gilbert" <Lamont_Gilbert@rigidsoftware.com> writes:
>>
>>
>>> getSelectedObjects should never return the empty list.
>>
>>
>>
>> Well, it does.
>>
>> After some investigation, it appears that CopyAction's update() method is
>> never called, and thus the selection field is never set. I wonder why.
>>
>> I'll keep investigating.
>>
>
> What seems to happen is this: when selectionChanged (in the
> GraphicalEditor class) calls updateAction() on all selection-actions,
> only the retarget-version of the action gets called -- they have the
> same ID, so the action-registry can only hold one of them:
>
> protected void updateActions(List actionIds)
> {
> ActionRegistry registry = getActionRegistry();
> Iterator iter = actionIds.iterator();
> while (iter.hasNext()) {
> IAction action = registry.getAction(iter.next());
> if (action instanceof UpdateAction)
> ((UpdateAction)action).update();
> }
> }
>
> The parameter actionIds is here [ 'delete', 'copy' ] when called from
> selectionChanged, and registry.getAction() returns a RetargetAction(),
> not my CopyAction.
>
> So, something is wrong in my action-registry. Pratik said that I should
> create both retarget-actions and "normal" actions with the same ID, but
> then they can't reside in the same action-registry. Or did I miss
> something?
>
> /Jesper
Relax my friend. Did you try what I indicated in my post?
--
Respectfully,
CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into
the sheepfold{}, but climbeth up some other *way, the same is a thief
and a robber."
GnuPG Key Fingerprint:
82A6 8893 C2A1 F64E A9AD 19AE 55B2 4CD7 80D2 0A2D
For a free Java interface to Freechess.org see
http://www.rigidsoftware.com/Chess/chess.html
|
|
|
Re: implementing cut/copy/paste [message #159866 is a reply to message #159675] |
Tue, 30 November 2004 15:58   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
The registry should hold onto actions maintained by the Editor instance.
RetargetActions should only be created by the ActionBarContributor, not each
editor instance.
The purpose of retarget actions is to map a single ActionBarContributor to
multiple editor instances within a given WorkbenchWindow. I think actionbar
contributors were designed as 1-per-window-per-editor-type to reduce flicker
and repainting when changing between multiple java CU editors. It also
reduces the number of native widgets created.
"Jesper Eskilson" <jojo@virtutech.se> wrote in message
news:cohec2$bf8$1@www.eclipse.org...
> Jesper Eskilson wrote:
> > "CL [dnoyeb] Gilbert" <Lamont_Gilbert@rigidsoftware.com> writes:
> >
> >
> >>getSelectedObjects should never return the empty list.
> >
> >
> > Well, it does.
> >
> > After some investigation, it appears that CopyAction's update() method
is
> > never called, and thus the selection field is never set. I wonder why.
> >
> > I'll keep investigating.
> >
>
> What seems to happen is this: when selectionChanged (in the
> GraphicalEditor class) calls updateAction() on all selection-actions,
> only the retarget-version of the action gets called -- they have the
> same ID, so the action-registry can only hold one of them:
>
> protected void updateActions(List actionIds)
> {
> ActionRegistry registry = getActionRegistry();
> Iterator iter = actionIds.iterator();
> while (iter.hasNext()) {
> IAction action = registry.getAction(iter.next());
> if (action instanceof UpdateAction)
> ((UpdateAction)action).update();
> }
> }
>
> The parameter actionIds is here [ 'delete', 'copy' ] when called from
> selectionChanged, and registry.getAction() returns a RetargetAction(),
> not my CopyAction.
>
> So, something is wrong in my action-registry. Pratik said that I should
> create both retarget-actions and "normal" actions with the same ID, but
> then they can't reside in the same action-registry. Or did I miss
something?
>
> /Jesper
|
|
|
|
|
|
Re: implementing cut/copy/paste [message #160071 is a reply to message #159991] |
Wed, 01 December 2004 21:28   |
Eclipse User |
|
|
|
Originally posted by: Lamont_Gilbert.rigidsoftware.com
Well lets go over all the steps.
1. Create Cut/Copy/Paste commands based on org.eclipse.gef.commands.Command
2. Create Cut/Copy actions based on
org.eclipse.gef.ui.actions.SelectionAction
paste probably wont be a selection action since its not based on selection
be sure to properly override calculateEnabled()
be sure in the init method or some other appropriate place to
setID(ActionFactory.PASTE.getId());
3. Override createActions of GraphicalEditor
NOTE: these are not retarget actions but the ones you created in step 2
super.createActions();
action = new CopyAction((IworkbenchPart)this);
registry.registerAction(action)
getSelectionActions().add(action.getId());
4. in your editorContributor override buildActions and add retarget
actions here
//first create and register the retarget action
IWorkbenchWindow = getPage().getWorkbenchWindow();
addRetargetAction((RetargetAction)ActionFactory.COPY.create( iww));
//then add it to a menu or toolbar
override ContributeToToolBar(IToolBarManager tbm) or wherever you want
to add the actions
tbm.add(getAction(ActionFactory.COPY.getId()));
or contributeToMenu
Only way off hand I know how to use the editor contributor is by telling
the xml file to use it if you extend the point org.eclipse.ui.editors add
contributorClass = "MyContributor"
Wish I could be more help with a more direct route, but I think you got
this part fixed anyway since you are actually seeing the buttons and
menuitems.
Jesper Eskilson wrote:
> Randy Hudson wrote:
>
>> The registry should hold onto actions maintained by the Editor instance.
>> RetargetActions should only be created by the ActionBarContributor,
>> not each
>> editor instance.
>>
>> The purpose of retarget actions is to map a single
>> ActionBarContributor to
>> multiple editor instances within a given WorkbenchWindow. I think
>> actionbar
>> contributors were designed as 1-per-window-per-editor-type to reduce
>> flicker
>> and repainting when changing between multiple java CU editors. It also
>> reduces the number of native widgets created.
>
>
> Ok, thanks. The mist is clearing a little now.
>
> The problem was (I think) that I added the retarget-actions to the
> editors registry instead of using addRetargetAction().
>
> So, now I've changed my actionbar-contributor to do the following:
>
> IWorkbenchWindow window =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
>
> addRetargetAction((RetargetAction) ActionFactory.CUT.create(window));
> addRetargetAction((RetargetAction) ActionFactory.COPY.create(window));
> addRetargetAction((RetargetAction) ActionFactory.PASTE.create(window));
>
> but now I get a ClassCastException() in
>
> org.eclipse.ui.actions.RetargetAction.propagateChange(Retarg etAction.java:195)
>
>
> Apparently this mist didn't clear enough. :-)
>
> /Jesper
--
Respectfully,
CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into
the sheepfold{}, but climbeth up some other *way, the same is a thief
and a robber."
GnuPG Key Fingerprint:
82A6 8893 C2A1 F64E A9AD 19AE 55B2 4CD7 80D2 0A2D
For a free Java interface to Freechess.org see
http://www.rigidsoftware.com/Chess/chess.html
|
|
|
|
|
Re: implementing cut/copy/paste [message #160897 is a reply to message #160880] |
Tue, 07 December 2004 18:20   |
Eclipse User |
|
|
|
Originally posted by: Lamont_Gilbert.rigidsoftware.com
Jesper Eskilson wrote:
> CL [dnoyeb] Gilbert wrote:
>
>> Well lets go over all the steps.
>>
>> 1. Create Cut/Copy/Paste commands based on
>> org.eclipse.gef.commands.Command
>>
>> 2. Create Cut/Copy actions based on
>> org.eclipse.gef.ui.actions.SelectionAction paste probably wont be a
>> selection action since its not based on selection be sure to properly
>> override calculateEnabled() be sure in the init method or some other
>> appropriate place to setID(ActionFactory.PASTE.getId());
>>
>>
>>
>> 3. Override createActions of GraphicalEditor NOTE: these are not
>> retarget actions but the ones you created in step 2
>>
>> super.createActions(); action = new CopyAction((IworkbenchPart)this);
>> registry.registerAction(action)
>> getSelectionActions().add(action.getId());
>>
>>
>> 4. in your editorContributor override buildActions and add retarget
>> actions here
>>
>> //first create and register the retarget action IWorkbenchWindow =
>> getPage().getWorkbenchWindow();
>
>
> Ah. I was looking for the correct way to get a reference to the window.
>
>> addRetargetAction((RetargetAction)ActionFactory.COPY.create( iww));
>>
>> //then add it to a menu or toolbar override
>> ContributeToToolBar(IToolBarManager tbm) or wherever you want to add
>> the actions
>>
>> tbm.add(getAction(ActionFactory.COPY.getId()));
>>
>> or contributeToMenu
>>
>> Only way off hand I know how to use the editor contributor is by
>> telling the xml file to use it if you extend the point
>> org.eclipse.ui.editors add
>>
>> contributorClass = "MyContributor"
>>
>> Wish I could be more help with a more direct route, but I think you
>> got this part fixed anyway since you are actually seeing the buttons
>> and menuitems.
>
>
> Thanks. Now I get stuck on a strange ClassCastException in
> RetargetAction.propagateChange(). The result of getSource() is cast to
> (IActionBars), but according to the debugger, the source-field in the
> event is of type RetargetAction.
>
> setActionHandler(((IActionBars)event.getSource()).getGlobalA ctionHandler(getId()));
>
>
> Hm.
>
> /Jesper (puzzled)
which retarget action is it?, I mean which class exactly. Who fired the
event in question?
--
Respectfully,
CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into
the sheepfold{}, but climbeth up some other *way, the same is a thief
and a robber."
GnuPG Key Fingerprint:
82A6 8893 C2A1 F64E A9AD 19AE 55B2 4CD7 80D2 0A2D
For a free Java interface to Freechess.org see
http://www.rigidsoftware.com/Chess/chess.html
|
|
|
Re: implementing cut/copy/paste [message #161027 is a reply to message #160897] |
Wed, 08 December 2004 15:36  |
Eclipse User |
|
|
|
Originally posted by: jojo.virtutech.se
CL [dnoyeb] Gilbert wrote:
>
> which retarget action is it?, I mean which class exactly. Who fired the
> event in question?
>
I'm not sure, but I traced the problem to my context-menu provider,
which also tried to create retarget-actions. After removing them, things
started working.
Thanks for all help.
/Jesper
|
|
|
Powered by
FUDForum. Page generated in 0.25523 seconds