Example #1
0
        /// <summary>
        /// </summary>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="collectionToSort"/> is <see langword="null"/>.
        /// <paramref name="comparerToUse"/> is <see langword="null"/>.
        /// </exception>
        public void Sort <T>(NuGenTreeNodeCollection collectionToSort, IComparer <T> comparerToUse) where T : NuGenTreeNode
        {
            if (collectionToSort == null)
            {
                throw new ArgumentNullException("collectionToSort");
            }

            if (comparerToUse == null)
            {
                throw new ArgumentNullException("comparerToUse");
            }

            int nodesCount = collectionToSort.Count;

            if (nodesCount == 0)
            {
                return;
            }

            T[] nodes = new T[nodesCount];

            for (int i = 0; i < nodesCount; i++)
            {
                nodes[i] = (T)collectionToSort[i];
            }

            Array.Sort <T>(nodes, comparerToUse);
            collectionToSort.Clear();
            collectionToSort.AddNodeRange(nodes);

            foreach (T treeNode in nodes)
            {
                this.Sort(treeNode.Nodes, comparerToUse);
            }
        }
		/// <summary>
		/// </summary>
		/// <param name="xmlNodeToLoadFrom"></param>
		/// <param name="parentNodeCollection"></param>
		/// <exception cref="T:System.ArgumentNullException">
		/// <paramref name="xmlNodeToLoadFrom"/> is <see langword="null"/>.
		/// -or-
		/// <paramref name="parentNodeCollection"/> is <see langword="null"/>.
		/// </exception>
		protected void LoadNode(XmlNode xmlNodeToLoadFrom, NuGenTreeNodeCollection parentNodeCollection)
		{
			if (xmlNodeToLoadFrom == null)
			{
				throw new ArgumentNullException("xmlNodeToLoadFrom");
			}

			if (parentNodeCollection == null)
			{
				throw new ArgumentNullException("parentNodeCollection");
			}

			NuGenTaskTreeNodeBase treeNodeToAdd = null;

			if (xmlNodeToLoadFrom.Name == Resources.XmlTag_Folder)
			{
				treeNodeToAdd = new NuGenFolderTreeNode(this.ServiceProvider);
				this.InitializeFolder((NuGenFolderTreeNode)treeNodeToAdd);
			}
			else if (xmlNodeToLoadFrom.Name == Resources.XmlTag_Task)
			{
				treeNodeToAdd = new NuGenTaskTreeNode(this.ServiceProvider);
				this.InitializeTask((NuGenTaskTreeNode)treeNodeToAdd);
			}
			else
			{
				return;
			}

			parentNodeCollection.AddNode(treeNodeToAdd);
			treeNodeToAdd.Load(xmlNodeToLoadFrom);

			foreach (XmlNode childNode in xmlNodeToLoadFrom.ChildNodes)
			{
				this.LoadNode(childNode, treeNodeToAdd.Nodes);
			}
		}
		/*
		 * SelectAllNodes
		 */

		/// <summary>
		/// Selects all the nodes, including sub-nodes, in the specified collection.
		/// </summary>
		/// <param name="nodesToSelect"></param>
		/// <exception cref="T:System.ArgumentNullException"><paramref name="nodesToSelect"/> is <see langword="null"/>.</exception>
		public void SelectAllNodes(NuGenTreeNodeCollection nodesToSelect)
		{
			if (nodesToSelect == null)
			{
				throw new ArgumentNullException("ndoesToSelect");
			}

			if (nodesToSelect.Count == 0)
			{
				return;
			}

			foreach (NuGenTreeNode treeNode in nodesToSelect)
			{
				if (!this.SelectedNodes.Contains(treeNode))
				{
					this.SelectedNodes.Add(treeNode);
				}

				this.SelectAllNodes(treeNode.Nodes);
			}
		}
			public TreeNodeCollectionEventSink(NuGenTreeNodeCollection treeNodeCollection)
			{
				if (treeNodeCollection == null)
				{
					Assert.Fail("treeNodeCollection cannot be null.");
				}

				treeNodeCollection.ContainsNodeRequested += delegate(object sender, NuGenContainsItemRequestedEventArgs e)
				{
					this.containsNodeRequestedCount.Inc();
					this.containsNodeRequested.AddActual(e.NodeToCheck);
				};

				treeNodeCollection.EnumeratorRequested += delegate(object sender, NuGenEnumeratorRequestedEventArgs e)
				{
					this.enumeratorRequestsCount.Inc();
				};

				treeNodeCollection.NodeAdded += delegate(object sender, NuGenAddTreeNodeEventArgs e)
				{
					this.nodeAddedCount.Inc();
					this.nodeAdded.AddActual(e.TreeNodeToAdd);
				};

				treeNodeCollection.NodeRangeAdded += delegate(object sender, NuGenAddTreeNodeRangeEventArgs e)
				{
					this.nodeRangeAddedCount.Inc();
					this.nodeRangeAdded.AddActual(e.TreeNodeRangeToAdd);
				};

				treeNodeCollection.NodeInserted += delegate(object sender, NuGenAddTreeNodeEventArgs e)
				{
					this.nodeInsertedCount.Inc();
					this.nodeAdded.AddActual(e.TreeNodeToAdd);
				};

				treeNodeCollection.NodeRemoved += delegate(object sender, NuGenRemoveTreeNodeEventArgs e)
				{
					this.nodeRemovedCount.Inc();
					this.nodeRemoved.AddActual(e.TreeNodeToRemove);
				};

				treeNodeCollection.NodeByIndexAdjusted += delegate(object sender, NuGenIndexedTreeNodeEventArgs e)
				{
					this.nodeByIndexAdjustedCount.Inc();
				};

				treeNodeCollection.NodeByIndexRequested += delegate(object sender, NuGenIndexedTreeNodeEventArgs e)
				{
					this.nodeByIndexRequestedCount.Inc();
				};

				treeNodeCollection.NodeCountRequested += delegate(object sender, NuGenItemsCountRequestedEventArgs e)
				{
					this.countRequestedCount.Inc();
				};

				treeNodeCollection.ClearNodesRequested += delegate(object sender, NuGenItemsClearRequestedEventArgs e)
				{
					this.clearRequestedCount.Inc();
				};
			}
		public void SetUp()
		{
			this.treeNodeCollection = new NuGenTreeNodeCollection();
		}