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. Image for the cookie policy date

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

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

3 Replies

SG Shyam G Syncfusion Team July 29, 2015 11:32 AM UTC

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



JJ Jim Jacobs July 29, 2015 01:22 PM UTC

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


SG Shyam G Syncfusion Team July 30, 2015 04:26 AM UTC

Hi Jim

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

Regards,
Shyam G

Loader.
Live Chat Icon For mobile
Up arrow icon