Hello,
I spent quite a time on finding out how to create a custom tool and about the concepts of the standard tools for diagrams.
What I want to have is one custom tool that does the following:
- in default mode (i.e. when it's just activated) it should do nothing else then show the normal mouse cursor and perform a click and selection on diagram nodes. It must not offer selecting a range, panning, zooming or whatever, just a simple click
- if I hold ctrl pressed I want to change to the MoveTool as long as the ctrl key is pressed. As soon as the ctrl key is not pressed it should return back to the default mode
- if I hold down the alt key I want the zoom tool for as long as the alt key is pressed
- if I hold the shift key I want the tool to pan the diagram
My approach is this one below. But this does not do what I want. Pan and Zoom works fine, but when I leave the ctrl or alt key, the tool remains active and I do not get back to this tool at all.
Even worse when I do this with MoveTool it first moves the node and when I release the mouse button a copy of the dragged node is created.
How can I get this working?
Regards,
Christian
public class DiagramStandardTool : UITool
{
public DiagramStandardTool(DiagramController controller)
: base(controller, "InteractiveNodeTool")
{
this.SingleActionTool = false;
}
public override Tool ProcessMouseMove(MouseEventArgs e)
{
return this;
}
public override Tool ProcessMouseUp(MouseEventArgs e)
{
return this;
}
public override Tool ProcessMouseDown(MouseEventArgs e)
{
if (!InAction)
{
if (Control.ModifierKeys == Keys.Alt)
{
return PerformZoom(e);
}
if (Control.ModifierKeys == Keys.Control)
{
return PerformPan(e);
}
}
return this;
}
///
/// Activate Zoomtool and process its MouseDown.
/// ///
The event args.
///
The tool to resize. protected virtual Tool PerformZoom(MouseEventArgs evtArgs)
{
ZoomTool tool = new ZoomTool(this.Controller);
tool.ProcessMouseDown(evtArgs);
return tool;
}
///
/// Activate Zoomtool and process its MouseDown.
/// ///
The event args.
///
The tool to resize. protected virtual Tool PerformPan(MouseEventArgs evtArgs)
{
PanTool tool = new PanTool(this.Controller);
tool.ProcessMouseDown(evtArgs);
tool.SingleActionTool = true;
return tool;
}
}