/// <summary> /// Adds a category node into the treeview for the specified category /// </summary> /// <param name="tree"></param> /// <param name="nodes"></param> /// <param name="category"></param> /// <returns></returns> private CategoryTreeNode AddNodeForCategory(TreeView tree, TreeNodeCollection nodes, XmlConfigurationCategory category) { if (this.InvokeRequired) { return(this.Invoke(new AddNodeForCategoryInvoker(this.AddNodeForCategory), new object[] { tree, nodes, category }) as CategoryTreeNode); } bool isRootCategory = (nodes == null); if (nodes == null) { if (tree != null) { nodes = tree.Nodes; } } CategoryTreeNode n = new CategoryTreeNode(category.DisplayName); n.BindToCategory(category); nodes.Add(n); if (isRootCategory) { n.ImageIndex = (int)CategoryImageIndexes.UnselectedWithSubCategories; n.SelectedImageIndex = (int)CategoryImageIndexes.SelectedWithSubCategories; } else { /// ok, off the root, now base images on whether the category has sub categories or not, /// and whether the category is selected if (category.Categories.Count > 0) { n.ImageIndex = (int)CategoryImageIndexes.UnselectedWithSubCategories; n.SelectedImageIndex = (int)CategoryImageIndexes.SelectedWithSubCategories; } else { n.ImageIndex = (int)CategoryImageIndexes.NoImage; n.SelectedImageIndex = (int)CategoryImageIndexes.SelectedWithoutSubCategories; } } return(n); }
/// <summary> /// Recursively adds nodes for the specified categories /// </summary> /// <param name="tree"></param> /// <param name="nodes"></param> /// <param name="categories"></param> private void AddNodesForCategories(TreeView tree, TreeNodeCollection nodes, XmlConfigurationCategoryCollection categories) { if (this.InvokeRequired) { this.Invoke(new AddNodesForCategoriesInvoker(this.AddNodesForCategories), new object[] { tree, nodes, categories }); return; } tree.BeginUpdate(); try { foreach (XmlConfigurationCategory category in categories) { if (!category.Hidden) { // try and find an existing node that we can merge with CategoryTreeNode n = this.FindNodeForCategory(nodes, category); if (n == null) { n = this.AddNodeForCategory(tree, nodes, category); } if (n != null) { if (!n.IsBoundToCategory(category)) { n.BindToCategory(category); } this.AddNodesForCategories(tree, n.Nodes, category.Categories); } } } } catch (System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } finally { tree.EndUpdate(); } }
/// <summary> /// Selects the node's type descriptor into the property grid /// </summary> /// <param name="n"></param> private void SelectPropertyDescriptorForNodeIntoPropertyGrid(CategoryTreeNode n) { if (this.InvokeRequired) { this.Invoke(new SelectPropertyDescriptorForNodeIntoPropertyGridInvoker(this.SelectPropertyDescriptorForNodeIntoPropertyGrid), new object[] { n }); return; } try { _propertyGrid.SelectedObject = null; _labelCategory.Text = null; if (n != null) { if (n.Categories.Count > 0) { XmlConfigurationOptionCollectionTypeDescriptor td = new XmlConfigurationOptionCollectionTypeDescriptor(n.Categories); if (td != null) { _propertyGrid.SelectedObject = td; } foreach (DictionaryEntry entry in n.Categories) { XmlConfigurationCategory category = entry.Value as XmlConfigurationCategory; if (category != null) { _labelCategory.Text = category.DisplayName; break; } } } } } catch (System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } }
/// <summary> /// Selects the node's type descriptor into the property grid /// </summary> /// <param name="n"></param> private void SelectPropertyDescriptorForNodeIntoPropertyGrid(CategoryTreeNode n) { if (this.InvokeRequired) { this.Invoke(new SelectPropertyDescriptorForNodeIntoPropertyGridInvoker(this.SelectPropertyDescriptorForNodeIntoPropertyGrid), new object[] {n}); return; } try { _propertyGrid.SelectedObject = null; _labelCategory.Text = null; if (n != null) { if (n.Categories.Count > 0) { XmlConfigurationOptionCollectionTypeDescriptor td = new XmlConfigurationOptionCollectionTypeDescriptor(n.Categories); if (td != null) _propertyGrid.SelectedObject = td; foreach(DictionaryEntry entry in n.Categories) { XmlConfigurationCategory category = entry.Value as XmlConfigurationCategory; if (category != null) { _labelCategory.Text = category.DisplayName; break; } } } } } catch(System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } }
/// <summary> /// Adds a category node into the treeview for the specified category /// </summary> /// <param name="tree"></param> /// <param name="nodes"></param> /// <param name="category"></param> /// <returns></returns> private CategoryTreeNode AddNodeForCategory(TreeView tree, TreeNodeCollection nodes, XmlConfigurationCategory category) { if (this.InvokeRequired) { return this.Invoke(new AddNodeForCategoryInvoker(this.AddNodeForCategory), new object[] {tree, nodes, category}) as CategoryTreeNode; } bool isRootCategory = (nodes == null); if (nodes == null) if (tree != null) nodes = tree.Nodes; CategoryTreeNode n = new CategoryTreeNode(category.DisplayName); n.BindToCategory(category); nodes.Add(n); if (isRootCategory) { n.ImageIndex = (int)CategoryImageIndexes.UnselectedWithSubCategories; n.SelectedImageIndex = (int)CategoryImageIndexes.SelectedWithSubCategories; } else { /// ok, off the root, now base images on whether the category has sub categories or not, /// and whether the category is selected if (category.Categories.Count > 0) { n.ImageIndex = (int)CategoryImageIndexes.UnselectedWithSubCategories; n.SelectedImageIndex = (int)CategoryImageIndexes.SelectedWithSubCategories; } else { n.ImageIndex = (int)CategoryImageIndexes.NoImage; n.SelectedImageIndex = (int)CategoryImageIndexes.SelectedWithoutSubCategories; } } return n; }