Exemple #1
0
        /*
         * StableSort
         */

        private static TextChange[] StableSort(IList <TextChange> changes)
        {
            var array = new TextChange[changes.Count];

            changes.CopyTo(array, 0);

            for (var i = 0; i < array.Length - 1; i++)
            {
                Int32 position = array[i].Position;
                var   index    = i;

                for (var j = i + 1; j < array.Length; j++)
                {
                    if (array[j].Position < position)
                    {
                        position = array[j].Position;
                        index    = j;
                    }
                }

                NuGenArgument.Exchange <TextChange>(ref array[i], ref array[index]);
            }

            return(array);
        }
        public void ExchangeTest()
        {
            int aValue = 5;
            int bValue = 6;

            int a = aValue;
            int b = bValue;

            NuGenArgument.Exchange <int>(ref a, ref b);

            Assert.AreEqual(bValue, a);
            Assert.AreEqual(aValue, b);

            Button buttonAValue = new Button();
            Button buttonBValue = new Button();

            Button buttonA = buttonAValue;
            Button buttonB = buttonBValue;

            NuGenArgument.Exchange <Button>(ref buttonA, ref buttonB);

            Assert.AreEqual(buttonBValue, buttonA);
            Assert.AreEqual(buttonAValue, buttonB);
        }
Exemple #3
0
        public void ExchangeTest()
        {
            Int32 aValue = 5;
            Int32 bValue = 6;

            Int32 a = aValue;
            Int32 b = bValue;

            NuGenArgument.Exchange <Int32>(ref a, ref b);

            Assert.AreEqual(bValue, a);
            Assert.AreEqual(aValue, b);

            Button buttonAValue = new Button();
            Button buttonBValue = new Button();

            Button buttonA = buttonAValue;
            Button buttonB = buttonBValue;

            NuGenArgument.Exchange <Button>(ref buttonA, ref buttonB);

            Assert.AreEqual(buttonBValue, buttonA);
            Assert.AreEqual(buttonAValue, buttonB);
        }
        /*
         * AddSelectedNode
         */

        /// <summary>
        /// </summary>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="selectedNodeToAdd"/> is <see langword="null"/>.
        /// </exception>
        public void AddSelectedNode(TreeNode selectedNodeToAdd, Keys pressedKeys, MouseButtons pressedMouseButtons)
        {
            if (selectedNodeToAdd == null)
            {
                throw new ArgumentNullException("selectedNodeToAdd");
            }

            if ((pressedMouseButtons & MouseButtons.Right) == MouseButtons.Right)
            {
                if (!this.SelectedNodes.Contains(selectedNodeToAdd))
                {
                    this.SelectedNodes.Clear();
                    this.SelectedNodes.Add(selectedNodeToAdd);
                }

                return;
            }

            if (pressedKeys == Keys.None)
            {
                this.SelectedNodes.Clear();
                this.SelectedNodes.Add(selectedNodeToAdd);
            }
            else if ((pressedKeys & Keys.Control) != 0)
            {
                if (this.SelectedNodes.Count == 0)
                {
                    this.SelectedNodes.Add(selectedNodeToAdd);
                }
                else
                {
                    if (this.SelectedNodes.Contains(selectedNodeToAdd))
                    {
                        this.SelectedNodes.Remove(selectedNodeToAdd);
                    }
                    else
                    {
                        if (this.SelectedNodes[0].Parent == selectedNodeToAdd.Parent)
                        {
                            this.SelectedNodes.Add(selectedNodeToAdd);
                        }
                    }
                }
            }
            else if ((pressedKeys & Keys.Shift) != 0)
            {
                if (this.SelectedNodes.Count == 0)
                {
                    this.SelectedNodes.Add(selectedNodeToAdd);
                }
                else
                {
                    if (this.SelectedNodes[0].Parent == selectedNodeToAdd.Parent)
                    {
                        int firstSelectedNodeIndex = this.SelectedNodes[0].Index;
                        int lastSelectedNodeIndex  = selectedNodeToAdd.Index;

                        TreeNode currentNode = this.SelectedNodes[0];
                        this.SelectedNodes.Clear();

                        if (lastSelectedNodeIndex > firstSelectedNodeIndex)
                        {
                            lastSelectedNodeIndex++;
                        }
                        else if (lastSelectedNodeIndex < firstSelectedNodeIndex)
                        {
                            this.SelectedNodes.Add(currentNode);
                            currentNode = selectedNodeToAdd;

                            NuGenArgument.Exchange <int>(ref firstSelectedNodeIndex, ref lastSelectedNodeIndex);
                        }

                        for (
                            int nodeIndex = firstSelectedNodeIndex;
                            nodeIndex < lastSelectedNodeIndex;
                            nodeIndex++
                            )
                        {
                            if (currentNode != null)
                            {
                                if (!this.SelectedNodes.Contains(currentNode))
                                {
                                    this.SelectedNodes.Add(currentNode);
                                }

                                currentNode = currentNode.NextVisibleNode;
                            }
                        }
                    }
                }
            }
        }