/// <summary> /// Fills a particular category and all the boxes that belong /// to that category /// </summary> /// <param name="catName">name of the category</param> /// <param name="creators">Creators of the boxes</param> /// <param name="baseNode">The node where a new node should be created /// It is a null, when it should be created to the control itself</param> protected void FillCategory(string catName, IBoxModuleFactoryCreator[] creators, NewBoxNode baseNode) { bool contains; List<IBoxModuleFactoryCreator> newNodes = new List<IBoxModuleFactoryCreator>(); NewBoxNode tn = new NewBoxNode(catName, ENodeType.Category, String.Empty); tn.ImageIndex = iconDictionary["foldericon"]; tn.SelectedImageIndex = iconDictionary["foldericon"]; if (baseNode == null) { Nodes.Add(tn); } else { baseNode.Nodes.Add(tn); } string catFullName = GetFullCategoryName(catName, tn.Parent); //iterating through all the creators we have foreach (IBoxModuleFactoryCreator creator in creators) { contains = false; foreach (string category in creator.BoxCategories) { if (category == catFullName) { contains = true; break; } } if (contains) { newNodes.Add(creator); } } IBoxModuleFactoryCreatorComparer comp = new IBoxModuleFactoryCreatorComparer(); newNodes.Sort(comp); foreach (IBoxModuleFactoryCreator c in newNodes) { NewBoxNode node = new NewBoxNode(c.Label, ENodeType.Box, c.Identifier); if (iconDictionary.ContainsKey(c.Identifier)) { node.ImageIndex = iconDictionary[c.Identifier]; node.SelectedImageIndex = iconDictionary[c.Identifier]; } else { node.ImageIndex = iconDictionary["noicon"]; node.SelectedImageIndex = iconDictionary["noicon"]; } tn.Nodes.Add(node); } }
/// <summary> /// Reaction to a mouse down - the mySelectedNode gets initialized /// </summary> /// <param name="sender">Sender of the event</param> /// <param name="e">Event parameters</param> void NewBoxTreeView_MouseDown(object sender, MouseEventArgs e) { //if it was a left mouse button if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { mySelectedNode = (NewBoxNode)GetNodeAt(e.X, e.Y); } }
/// <summary> /// Creates a tree from a label that contains dots /// </summary> /// <param name="cat">Label of the category</param> /// <param name="creators">Creators of the boxes</param> protected void CreateDottedTree(string cat, IBoxModuleFactoryCreator[] creators) { NewBoxNode tn = null; NewBoxNode nextNode; string beginning; bool contains = false; //the first occurence is dealt separately, because we have to add directly //to the control beginning = cat.Substring(0, cat.IndexOf('.')); cat = cat.Substring(cat.IndexOf('.') + 1); //checking if the treeNode is there already foreach (NewBoxNode n in Nodes) { if (n.Text == beginning) { contains = true; tn = n; break; } } if (!contains) { nextNode = new NewBoxNode(beginning, ENodeType.Category, String.Empty); nextNode.ImageIndex = iconDictionary["foldericon"]; nextNode.SelectedImageIndex = iconDictionary["foldericon"]; Nodes.Add(nextNode); tn = nextNode; } //all other dots while (cat.Contains(".")) { contains = false; beginning = cat.Substring(0, cat.IndexOf('.')); cat = cat.Substring(cat.IndexOf('.') + 1); //checking if the treeNode is there already foreach (NewBoxNode n in tn.Nodes) { if (n.Text == beginning) { contains = true; tn = n; break; } } if (!contains) { nextNode = new NewBoxNode(beginning, ENodeType.Category, String.Empty); nextNode.ImageIndex = iconDictionary["foldericon"]; nextNode.SelectedImageIndex = iconDictionary["foldericon"]; tn.Nodes.Add(nextNode); tn = nextNode; } } //adding the last element that's left (shouldn't be there already, //because FillTreeView chooses only distinct category names //tn.Nodes.Add(cat); FillCategory(cat, creators, tn); }