Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to use Ctrl+Drag to copy a node? (Read 4662 times)
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
How to use Ctrl+Drag to copy a node?
Jan 8th, 2013 at 4:01pm
Print Post  
Hi,

Is there any way to enable Ctrl+Drag to copy a node operation in WinForm diagramming? Or anyboday ever made it can give me some hint here?

Thanks. Tongue
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use Ctrl+Drag to copy a node?
Reply #1 - Jan 8th, 2013 at 5:02pm
Print Post  
You could use a behavior class that looks like this:

Code
Select All
public class MyBehavior : LinkShapesBehavior
{
	protected internal MyBehavior(DiagramView diagramView) : base(diagramView)
	{
		diagramView.ModifierKeyActions.Control = ModifierKeyAction.None;
	}

	public override InteractionState StartDraw(PointF point)
	{
		if ((Control.ModifierKeys & Keys.Control) != 0)
		{
			var node = Diagram.GetNodeAt(point);
			if (node != null)
			{
				node = (DiagramNode)node.Clone(false);
				Diagram.Nodes.Add(node);
				return new InteractionState(node, 8, Action.Modify);
			}
		}
		return base.StartDraw(point);
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: How to use Ctrl+Drag to copy a node?
Reply #2 - Jan 8th, 2013 at 6:37pm
Print Post  
This seems simple. Thanks. But how can I register my own behavior class with a diagram/diagramView?

Stoyo wrote on Jan 8th, 2013 at 5:02pm:
You could use a behavior class that looks like this:

Code
Select All
public class MyBehavior : LinkShapesBehavior
...
 



I hope that helps,
Stoyan

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use Ctrl+Drag to copy a node?
Reply #3 - Jan 8th, 2013 at 6:44pm
Print Post  
Set diagramView.CustomBehavior = new MyBehavior(diagramView);
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: How to use Ctrl+Drag to copy a node?
Reply #4 - Jan 8th, 2013 at 7:22pm
Print Post  
Yes. It works fine for single item. I tried to figure out how to deal with multiple selection but failed. Can you help me again? Thank you!

Stoyo wrote on Jan 8th, 2013 at 6:44pm:
Set diagramView.CustomBehavior = new MyBehavior(diagramView);

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use Ctrl+Drag to copy a node?
Reply #5 - Jan 9th, 2013 at 7:55am
Print Post  
Try this version:

Code
Select All
public class MyBehavior : LinkShapesBehavior
{
	protected internal MyBehavior(DiagramView diagramView) : base(diagramView)
	{
		diagramView.ModifierKeyActions.Control = ModifierKeyAction.None;
	}

	public override InteractionState StartDraw(PointF point)
	{
		if ((Control.ModifierKeys & Keys.Control) != 0)
		{
			var node = Diagram.GetNodeAt(point);
			if (node != null)
			{
				var selectionCopy = Diagram.CopySelection(Diagram, false, true);
				Diagram.PasteSelection(Diagram, selectionCopy, null, 0, 0);
				return new InteractionState(Diagram.Selection, 8, Action.Modify);
			}

			return new InteractionState(Diagram.Selection, -1, Action.Create);
		}
		return base.StartDraw(point);
	}

	public override bool ShouldMoveSelection(PointF point)
	{
		return (Control.ModifierKeys & Keys.Control) == 0;
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: How to use Ctrl+Drag to copy a node?
Reply #6 - Jan 9th, 2013 at 11:02pm
Print Post  
Stoyan, thank you very much. I'm sure your solution will work but may not for my situation. Current question is in my application I have to use ModifyBehavior. Is there any way to do multiple nodes selection like this?

Again thank you for your kind reply!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use Ctrl+Drag to copy a node?
Reply #7 - Jan 10th, 2013 at 7:23am
Print Post  
Derive the custom behavior class above from ModifyBehavior instead of LinkShapesBehavior.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kyle Chen
Full Member
***
Offline


I Love MindFusion!

Posts: 104
Joined: Nov 29th, 2012
Re: How to use Ctrl+Drag to copy a node?
Reply #8 - Jan 10th, 2013 at 3:42pm
Print Post  
That's just what I want! Hey Man! You're the best. Thank you!!!
Have a good day! Grin
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint