Exemple #1
0
        /// <summary>
        /// Invoked when a method on the invoker has been raised.
        /// </summary>
        /// <param name="sender">Object whose event was raised</param>
        /// <param name="e">Event arguments for the raised event.</param>
#endif
        internal override void OnEventInvoked(object sender, EventArgs e)
        {
            bool          isSameItem = false;
            UltraTreeNode item       = this.Invoker;

            UltraTreeNode eventItem = this.GetItem(e);

            if (eventItem != null)
            {
                isSameItem = eventItem != null && eventItem == item;
            }
            else
            {
                SelectedNodesCollection nodes = this.GetSelectedNodes(e);

                if (nodes != null)
                {
                    isSameItem = nodes.Contains(item);
                }
                else
                {
                    UltraTreeNode[] nodeArray = this.GetNodeArray(e);

                    if (nodeArray != null)
                    {
                        isSameItem = Array.IndexOf <UltraTreeNode>(nodeArray, item) >= 0;
                    }
                }
            }

            if (isSameItem)
            {
                this.FireCommand();
            }
        }
Exemple #2
0
        private void UpdateMultiselection(TreeNode node)
        {
            bool bControl = (ModifierKeys == Keys.Control);
            bool bShift   = (ModifierKeys == Keys.Shift);

            if (bControl)
            {
                if (mySelectedNodes.Contains(node))
                {
                    mySelectedNodes.Remove(node);
                }
                else
                {
                    mySelectedNodes.Add(node);
                }
            }
            else if (bShift)
            {
                Queue myQueue = new Queue();

                TreeNode uppernode  = myFirstMultiSelectNode;
                TreeNode bottomnode = node;
                // case 1 : begin and end nodes are parent
                bool bParent = IsParent(myFirstMultiSelectNode, node); // is m_firstNode parent (direct or not) of e.Node
                if (!bParent)
                {
                    bParent = IsParent(bottomnode, uppernode);
                    if (bParent) // swap nodes
                    {
                        TreeNode t = uppernode;
                        uppernode  = bottomnode;
                        bottomnode = t;
                    }
                }
                if (bParent)
                {
                    if (uppernode != null)
                    {
                        TreeNode n = bottomnode;
                        while (n != uppernode.Parent)
                        {
                            if (!mySelectedNodes.Contains(n)) // new node ?
                            {
                                myQueue.Enqueue(n);
                            }

                            n = n.Parent;
                        }
                    }
                }
                // case 2 : nor the begin nor the end node are descendant one another
                else
                {
                    if ((uppernode.Parent == null && bottomnode.Parent == null) || (uppernode.Parent != null && uppernode.Parent.Nodes.Contains(bottomnode))) // are they siblings ?
                    {
                        int nIndexUpper  = uppernode.Index;
                        int nIndexBottom = bottomnode.Index;
                        if (nIndexBottom < nIndexUpper) // reversed?
                        {
                            TreeNode t = uppernode;
                            uppernode    = bottomnode;
                            bottomnode   = t;
                            nIndexUpper  = uppernode.Index;
                            nIndexBottom = bottomnode.Index;
                        }

                        TreeNode n = uppernode;
                        while (nIndexUpper <= nIndexBottom)
                        {
                            if (!mySelectedNodes.Contains(n)) // new node ?
                            {
                                myQueue.Enqueue(n);
                            }

                            n = n.NextNode;

                            nIndexUpper++;
                        } // end while
                    }
                    else
                    {
                        if (!mySelectedNodes.Contains(uppernode))
                        {
                            myQueue.Enqueue(uppernode);
                        }
                        if (!mySelectedNodes.Contains(bottomnode))
                        {
                            myQueue.Enqueue(bottomnode);
                        }
                    }
                }

                mySelectedNodes.AddRange(myQueue);
                myFirstMultiSelectNode = node;                // let us chain several SHIFTs if we like it
            }
            else if (myLastMouseButton != MouseButtons.Right) // don't clear selection when popup menu is invoked
            {
                // in the case of a simple click, just add this item
                if (mySelectedNodes != null && mySelectedNodes.Count > 0)
                {
                    mySelectedNodes.Clear();
                }
                mySelectedNodes.Add(node);
            }
        }