Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Copy/Paste/Cut Undo-Redo pattern (Read 4821 times)
Marco Pessina
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Jun 4th, 2013
Copy/Paste/Cut Undo-Redo pattern
Dec 3rd, 2015 at 1:13pm
Print Post  
Hi,
i'm quite new to mindfusion diagramming component, and I'm migrating from a Winform solution to a web based application a tool to create and design workflow.

Does anyone has some suggest on how to implement copy/paste/cut and undo-redo pattern in web platform?
In my winform solution was anough handling DV1.KeyDown event  with this code

        If e.KeyCode = Key.C AndAlso
               e.Control = True Then
            ' paste with offset
            m_pasteDX = 10
            m_pasteDY = 10

            ' True specifies that data should stay in the clipboard
            ' after the application exits
            DV1.CopyToClipboard(True)
        ElseIf e.KeyCode = Key.X AndAlso e.Control = True Then
            m_pasteDX = 0
            m_pasteDY = 0

            ' True specifies that data should stay in the clipboard
            ' after the application exits
            DV1.CutToClipboard(True)

        ElseIf e.KeyCode = Key.V AndAlso e.Control = True Then
            ' Code for Paste Action
            ' paste with offset; allow unconnected arrows
            DV1.PasteFromClipboard(m_pasteDX, m_pasteDY, True)

            ' next time paste with bigger offset
            m_pasteDX += 10
            m_pasteDY += 10
        ElseIf e.KeyCode = Key.Z AndAlso e.Control = True Then
            dg.UndoManager.Undo()
        ElseIf e.KeyCode = Key.Y AndAlso e.Control = True Then
            dg.UndoManager.Redo()
        End If

Thans in advance.
Marco Pessina
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy/Paste/Cut Undo-Redo pattern
Reply #1 - Dec 3rd, 2015 at 1:33pm
Print Post  
Hi,

Tutorial 7 shows both clipboard and undo methods. You could also check the Keyboard sample project, which shows how to handle keydown events:

Code
Select All
function onKeyDown(e) {

    var diagram = MindFusion.Diagramming.Diagram.find('diagramView1');

    //copy selected items
    if (e.keyCode == 67 && e.ctrlKey) {
        diagram.copyToClipboard();
    }

    //paste selected items
    if (e.keyCode == 86 && e.ctrlKey) {
        diagram.pasteFromClipboard(5, 5);
    } ...  



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Marco Pessina
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Jun 4th, 2013
Re: Copy/Paste/Cut Undo-Redo pattern
Reply #2 - Jan 13th, 2016 at 7:56am
Print Post  
Hi Stoyan,
I've implemented the pattern you suggest me and everything seems working, except one things.
I've handled diagram.onNodeCreatedScript event to set items.id property (as an identity on database table),
and using pasteFromClipboard it doesn't fire this event so it duplicates ids on items. Is there a sort of itempasted event?
Thanks in advance.
Regards
Marco Pessina
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy/Paste/Cut Undo-Redo pattern
Reply #3 - Jan 13th, 2016 at 11:10am
Print Post  
Hi Marco,

There are NodePasted and LinkPasted events in our desktop components. We'll try to implement them in ASP.NET MVC version in next couple of days. Until they are available, you could loop over selected items and update id values after calling pasteFromClipboard method, as it replaces old selection with the pasted items.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy/Paste/Cut Undo-Redo pattern
Reply #4 - Jan 20th, 2016 at 10:02am
Print Post  
NodePasted and LinkPasted events are now available in this release:
http://mindfusion.eu/Forum/YaBB.pl?num=1453227455

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint