- Home
- Forum
- ASP.NET Web Forms
- How to avoid the default action taken for Ctrl + V using Command Manager
How to avoid the default action taken for Ctrl + V using Command Manager
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
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
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
Please let us know if you require further assistance on this.
Regards,
Shyam G
- 3 Replies
- 2 Participants
-
JJ Jim Jacobs
- Jul 28, 2015 07:54 PM UTC
- Jul 30, 2015 04:26 AM UTC