Right Mouse Drag


#1

My app requires that you can right drag an object and a context menu pops up when you release/drop the object. The same functionality as when you right drag a file (in explorer) and drop it, the context menu pops up and you can now move the object or copy or cancel… I need that event… has anyone out there tried this before… and succeeded?


#2

I suggest you define your own subclass of GoToolDragging to replace the standard one in your views.
GoToolDragging.CanStart explicitly checks for the context button and returns false in that case, so you need to override that method not to return false then. (We wanted to prevent accidental moves when the user tried to context click an object.)
public override bool CanStart() {
if (!this.View.CanMoveObjects() && !this.View.CanCopyObjects() && !this.View.AllowDragOut)
return false;
// comment out this check if (this.LastInput.IsContextButton)
// comment out this check return false;
Size dragSize = SystemInformation.DragSize;
Point a = this.FirstInput.ViewPoint;
Point b = this.LastInput.ViewPoint;
if (Math.Abs(a.X-b.X) <= dragSize.Width/2 && Math.Abs(a.Y-b.Y) <= dragSize.Height/2)
return false;
GoObject obj = this.View.PickObject(true, false, this.FirstInput.DocPoint, true);
if (obj == null)
return false;
// if some selected objects are movable, but some are not,
// don’t move anything if this current object is not draggable
// or if it’s in an unmodifiable layer
if (!obj.CanMove() && !obj.CanCopy())
return false;
return true;
}
And you’ll need to override GoToolDragging.DoMouseUp to bring up a GoContextMenu. The move command can just call base.DoMouseUp on this tool (you’ll need to make that base method callable from your context menu item click handler, and don’t confuse it with your tool’s override of DoMouseUp!). The copy command can do the same, except that you need to make sure GoToolDragging.MustBeCopying() returns true. The easiest way to do that is to just set the GoToolDragging.LastInput.Control property to true. And the cancel command can just call GoToolDragging.DoCancelMouse.