Example #1
0
        /// <summary>
        /// The dragging tool is applicable when the user can move or copy one or more objects.
        /// </summary>
        /// <returns>
        /// This predicate returns true when:
        /// <list type="bullet">
        /// <item>the user has started moving the mouse with a mouse button down</item>
        /// <item>the view allows objects to be moved or copied or dragged out of the window</item>
        /// <item>the mouse button is not the context menu button</item>
        /// <item>there is a selectable object under the mouse</item>
        /// <item>and that object can be moved or copied</item>
        /// </list>
        /// </returns>
        public override bool CanStart()
        {
            if (!base.View.CanMoveObjects() && !base.View.CanCopyObjects() && !base.View.AllowDragOut)
            {
                return(false);
            }
            if (base.LastInput.IsContextButton)
            {
                return(false);
            }
            if (!IsBeyondDragSize())
            {
                return(false);
            }
            GoObject goObject = base.View.PickObject(doc: true, view: false, base.FirstInput.DocPoint, selectableOnly: true);

            if (goObject == null)
            {
                return(false);
            }
            if (!goObject.CanMove() && !goObject.CanCopy())
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Produce a new <see cref="T:Northwoods.Go.GoSelection" /> that is the real set of objects
        /// to be moved by <see cref="M:Northwoods.Go.GoView.MoveSelection(Northwoods.Go.GoSelection,System.Drawing.SizeF,System.Boolean)" /> or copied by
        /// <see cref="M:Northwoods.Go.GoView.CopySelection(Northwoods.Go.GoSelection,System.Drawing.SizeF,System.Boolean)" />.
        /// </summary>
        /// <param name="coll"></param>
        /// <param name="move">true for moving, false for copying</param>
        /// <returns>a <see cref="T:Northwoods.Go.GoSelection" /> that is cached as <see cref="P:Northwoods.Go.GoToolDragging.EffectiveSelection" /></returns>
        /// <remarks>
        /// This method is used to try to avoid problems with double-moving
        /// due to duplicate entries or both a parent and its child being in
        /// the argument collection.
        /// This also removes objects whose <see cref="P:Northwoods.Go.GoObject.DraggingObject" />
        /// is null or has a false value for <see cref="M:Northwoods.Go.GoObject.CanMove" /> (if
        /// <paramref name="move" /> is true) or a false value for <see cref="M:Northwoods.Go.GoObject.CanCopy" />
        /// (if <paramref name="move" /> is false).
        /// Furthermore this adds to the collection all links that have both
        /// ports in the selection.
        /// </remarks>
        public virtual GoSelection ComputeEffectiveSelection(IGoCollection coll, bool move)
        {
            Dictionary <GoObject, bool> dictionary = new Dictionary <GoObject, bool>();
            GoCollection goCollection = null;
            GoSelection  goSelection  = new GoSelection(null);

            foreach (GoObject item in coll)
            {
                GoObject draggingObject = item.DraggingObject;
                if (draggingObject != null && !(move ? (!draggingObject.CanMove()) : (!draggingObject.CanCopy())) && !alreadyDragged(dictionary, draggingObject))
                {
                    dictionary[draggingObject] = true;
                    if (!draggingObject.IsTopLevel)
                    {
                        if (goCollection == null)
                        {
                            goCollection = new GoCollection();
                        }
                        goCollection.Add(draggingObject);
                    }
                    goSelection.Add(draggingObject);
                }
            }
            if (EffectiveSelectionIncludesLinks)
            {
                GoObject[] array = goSelection.CopyArray();
                for (int i = 0; i < array.Length; i++)
                {
                    IGoNode goNode = array[i] as IGoNode;
                    if (goNode != null)
                    {
                        foreach (IGoLink destinationLink in goNode.DestinationLinks)
                        {
                            if (!alreadyDragged(dictionary, destinationLink.GoObject) && (destinationLink.ToPort == null || alreadyDragged(dictionary, destinationLink.ToPort.GoObject)))
                            {
                                dictionary[destinationLink.GoObject] = true;
                                goSelection.Add(destinationLink.GoObject);
                            }
                        }
                        foreach (IGoLink sourceLink in goNode.SourceLinks)
                        {
                            if (!alreadyDragged(dictionary, sourceLink.GoObject) && (sourceLink.FromPort == null || alreadyDragged(dictionary, sourceLink.FromPort.GoObject)))
                            {
                                dictionary[sourceLink.GoObject] = true;
                                goSelection.Add(sourceLink.GoObject);
                            }
                        }
                    }
                }
            }
            if (goCollection != null)
            {
                GoCollection goCollection2 = null;
                foreach (GoObject item2 in goSelection)
                {
                    GoObject draggingObject2 = item2.DraggingObject;
                    if (draggingObject2 is GoGroup)
                    {
                        foreach (GoObject item3 in goCollection)
                        {
                            if (item3.IsChildOf(draggingObject2))
                            {
                                if (goCollection2 == null)
                                {
                                    goCollection2 = new GoCollection();
                                }
                                goCollection2.Add(item3);
                            }
                        }
                    }
                }
                if (goCollection2 != null)
                {
                    foreach (GoObject item4 in goCollection2)
                    {
                        goSelection.Remove(item4);
                    }
                    return(goSelection);
                }
            }
            return(goSelection);
        }