We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to avoid the default action taken for Ctrl + V using Command Manager

Thread ID:

Created:

Updated:

Platform:

Replies:

119758 Jul 28,2015 03:54 PM Jul 30,2015 12:26 AM ASP.NET Web Forms 3
loading
Tags: Diagram
Jim Jacobs
Asked On July 28, 2015 03:54 PM

Hi,

Here's what I want to do.
If a paste operation is attempted using Ctrl + V I do NOT want the default action to take place.
Since I need to create a new database record for certain nodes, I need to update the pasted node and change various addInfo properties.

In order to achieve this I have created the following commands:

{"copyObject", new Command() { Execute = "copyObject", Gesture = new Gesture() { Key = Keys.C, KeyModifiers = KeyModifiers.Control}}},
{"pasteObject", new Command() { Execute = "pasteObject", Gesture = new Gesture() { Key = Keys.V, KeyModifiers = KeyModifiers.Control}}}, ...

And the functions called look like this:

        function copyObject(args) {
            g_selectedBoundObjectCount = getselectedBoundObjectCount(); // This variable will be used in the NodeCollectionChange handler
            diagram.copy();
        }

        function pasteObject(args) {
            console.log('In pasteObject');
            $find('<%=chkPasteInProgress.ClientID%>').set_checked(true);
            diagram.paste();
        }

The problem is that when I select Ctrl + V the node is pasted BEFORE the pasteObject function fires and then my pasteObject method fires.
So I end up with 2 copies of the original node - one exactly the same as the original, and the second with my database updates applied - see the attached video for a demonstration.

I realize I can disable Ctrl + V by using a CanExecute function, but then my pasteObject method will not fire.

How do I accomplish what I'm trying to do?

Thanks

Jim

Attachment: Syncfusion__Paste_Firing_Twice__28jul2015_a6a01c6f.zip

Shyam G [Syncfusion]
Replied On July 29, 2015 07:32 AM

Hi Jim

Thanks for using Syncfusion products.

Please note that you have set an incorrect command name in your code snippet. we suggest you to change the command name as copy and paste instead of copyObject and pasteObject. We have modified your code snippet and provided below.

Code snippet:

Dictionary<string, object> Commands = new Dictionary<string, object>()

             {

            //clone command

            {

               //command name

               "copy",

               //command definition

               new Command()

               {

                   //Name of the method/command handler that is defined in scripts

                   Execute = "copyObject",

                   //Gesture to define when the command is to be executed

                   Gesture = new Gesture()

                   {

                       //Combination of keys and modifier keys

                       Key = Keys.C, KeyModifiers = KeyModifiers.Control

                    }

                }

            },

            {

               //command name

               "paste",

               //command definition

               new Command()

               {

                   //Name of the method/command handler that is defined in scripts

                   Execute = "pasteObject",

                   //Gesture to define when the command is to be executed

                   Gesture = new Gesture()

                   {

                       //Combination of keys and modifier keys

                       Key = Keys.V, KeyModifiers = KeyModifiers.Control

                    }

                }

            },

        };
            DiagramContent.CommandManager.Commands = Commands;


Please let me know if any concerns.

Regards,
Shyam G


Jim Jacobs
Replied On July 29, 2015 09:22 AM

Hi Shyam,

This works just the way I wanted :)
Kamesh made me aware of this on our call this morning.
So thanks to both of you for getting me the solution.

Jim

Shyam G [Syncfusion]
Replied On July 30, 2015 12:26 AM

Hi Jim

Please let us know if you require further assistance on this.

Regards,
Shyam G

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;