Cut Copy and paste Implementation [message #223880] |
Fri, 06 October 2006 05:49 |
Eclipse User |
|
|
|
Originally posted by: siddharth.star.gmail.com
Hi,
I have been grappling with the Cut Copy and Paste implementaion in GEF for
the past few days and was just hoping if someone could help me find a
better solution.
As of now when performing Cut (say in Cut Action) I create a list of model
elements corresponding to the selected elements and place it in the
Clipboard [in say CutCommand so that I can undo and redo Cut operation].
Similarly in the Copy Action I place in the Clipboard a copy of all the
selected model elements. Now in the Paste Action say I execute a paste
Command which takes whatever is in the Clipboard and pastes it. So far so
good, everything works fine including undo and redo.
The problem is that say the user presses simultaneous Paste how do i cope
with that. Right now what I am doing is after every paste i create a copy
of the pasted elements and store it in the clipboard so that on doing a
successive paste without either of cut or copy the correct behavior is
observed. However, the obvious drawback woth this approach is that the
Clipboard contains an unnecessary copy. So if someone can please
give/suggest me a better idea.
Basically, I believe all my problems would be solved if in the paste
Action I have the handle as to which of them[Cut Copy] was the action last
invoked in a series of actions [example actions A, B, Copy, C, D, Cut, F,
G ], so in my paste if I would know that Cut was last invoked [as per
example] I'll simply paste the elements of the Clipboard or else if its
Copy I'll create a copy and paste it in the clipboard. So the logic of
Copy would be with paste action and it would suit my needs. At least i
hope so:-)
Thanks for your help in advance,
Siddharth
|
|
|
Re: Cut Copy and paste Implementation [message #223887 is a reply to message #223880] |
Fri, 06 October 2006 09:03 |
Hallvard Traetteberg Messages: 673 Registered: July 2009 Location: Trondheim, Norway |
Senior Member |
|
|
I've implemented cut, copy and paste and have struggled with the same
problems. My strategy was as follows:
- I used the XMI serialisation as the clipboard content, to make sure
it is independent of the actual objects in the editor. This makes it
possible to paste it somewhere else, too, e.g. in notepad, fix the
objects and paste it back. I essentially implemented a new transfer
type (I think that's what it is called). Note that not all object
structures may be handled this way, it works best with hierarchies and
well-defined cross-references.
- Copy generated the serialisation
- Paste re-created the objects by reading it in. Note that this
strategy looses the identity of objects, which must instead be handled
by using id-fields. My reasoning is that the identity cannot be the
same when pasting, since we must support several pastes of the same
objects. I guess this is the problem you're struggling with.
- Cut is copy followed by delete.
Hallvard
On Fri, 6 Oct 2006 05:49:37 +0000 (UTC), siddharth.star@gmail.com
(Siddharth) wrote:
>Hi,
>
>I have been grappling with the Cut Copy and Paste implementaion in GEF for
>the past few days and was just hoping if someone could help me find a
>better solution.
>
>As of now when performing Cut (say in Cut Action) I create a list of model
>elements corresponding to the selected elements and place it in the
>Clipboard [in say CutCommand so that I can undo and redo Cut operation].
>Similarly in the Copy Action I place in the Clipboard a copy of all the
>selected model elements. Now in the Paste Action say I execute a paste
>Command which takes whatever is in the Clipboard and pastes it. So far so
>good, everything works fine including undo and redo.
>The problem is that say the user presses simultaneous Paste how do i cope
>with that. Right now what I am doing is after every paste i create a copy
>of the pasted elements and store it in the clipboard so that on doing a
>successive paste without either of cut or copy the correct behavior is
>observed. However, the obvious drawback woth this approach is that the
>Clipboard contains an unnecessary copy. So if someone can please
>give/suggest me a better idea.
>
>Basically, I believe all my problems would be solved if in the paste
>Action I have the handle as to which of them[Cut Copy] was the action last
>invoked in a series of actions [example actions A, B, Copy, C, D, Cut, F,
>G ], so in my paste if I would know that Cut was last invoked [as per
>example] I'll simply paste the elements of the Clipboard or else if its
>Copy I'll create a copy and paste it in the clipboard. So the logic of
>Copy would be with paste action and it would suit my needs. At least i
>hope so:-)
>
>Thanks for your help in advance,
>Siddharth
|
|
|
Powered by
FUDForum. Page generated in 0.03347 seconds