/// <summary> /// Adds a new category to the tree. Tries o find an existing category /// </summary> /// <param name="parent"></param> /// <param name="nodename"></param> /// <param name="iIconIndex"></param> /// <returns></returns> public ShapeCreatorTreeNode AddCategory(ShapeCreatorTreeNode parent, string nodename, int iIconIndex) { TreeNodeCollection nodes = (parent == null) ? treeView_Creators.Nodes : parent.Nodes; if (iIconIndex < 0) // use the folder icon { iIconIndex = GroupShape.GroupIconIndex; } // find existing category string compare = nodename.ToLower(); foreach (ShapeCreatorTreeNode child in nodes) { if (child.Text.ToLower() == compare) { return(child); } } ShapeCreatorTreeNode node = new ShapeCreatorTreeNode(nodename, iIconIndex); nodes.Add(node); return(node); }
private void treeView_Creators_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { _selectedCreatorNode = e.Node as ShapeCreatorTreeNode; if (_selectedCreatorNode == null) { return; } SelectedCreatorObject = _selectedCreatorNode.CreatorObject; }
/// <summary> /// This version adds multiple nodes into the tree id the specified path contains back slashes /// </summary> /// <param name="parent"></param> /// <param name="path"></param> /// <param name="separator"></param> /// <param name="iIconIndex"></param> /// <returns></returns> public ShapeCreatorTreeNode AddCategoryPath(ShapeCreatorTreeNode parent, string path, string separator, int iIconIndex) { string[] folders = path.Split(separator.ToCharArray()); foreach (string folder in folders) { parent = AddCategory(parent, folder, iIconIndex); } return(parent); }
private void treeView_Creators_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { _selectedCreatorNode = e.Node as ShapeCreatorTreeNode; if (_selectedCreatorNode == null) { return; } SelectedCreatorObject = _selectedCreatorNode.CreatorObject; treeView_Creators.SelectedNode = e.Node; }
/// <summary> /// Adds a new creator to the tree. The creator object can be any type that is supported in the View OnDrop function /// </summary> /// <param name="parent"></param> /// <param name="creator"></param> /// <param name="nodename"></param> /// <param name="iIconIndex"></param> /// <returns></returns> public ShapeCreatorTreeNode AddCreator(ShapeCreatorTreeNode parent, object creator, string nodename, int iIconIndex) { TreeNodeCollection nodes = (parent == null) ? treeView_Creators.Nodes : parent.Nodes; ShapeCreatorTreeNode node = new ShapeCreatorTreeNode(nodename, creator, iIconIndex); nodes.Add(node); return(node); }
private void treeView_Creators_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) { ShapeCreatorTreeNode node = (ShapeCreatorTreeNode)e.Item; if (node.CreatorObject == null) { return; } // start dragging the creator object DoDragDrop(node.CreatorObject, DragDropEffects.Copy | DragDropEffects.Scroll); UpdateRecentShapesList(node.CreatorObject); // create item, even if dragdrop was cancelled. }
private void treeView_Creators_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { if (_helpbutton.DynamicHelpKeys == null) { _helpbutton.DynamicHelpKeys = new List <string>(); } else { _helpbutton.DynamicHelpKeys.Clear(); } _selectedCreatorNode = e.Node as ShapeCreatorTreeNode; if (_selectedCreatorNode == null) { return; } _helpbutton.DynamicHelpKeys.Add(_selectedCreatorNode.HelpKey); SelectedCreatorObject = _selectedCreatorNode.CreatorObject; }
void AddPrefabCreators(string dir, ShapeCreatorTreeNode parent) { EditorProject project = EditorApp.Project; int iIcon = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\lock_ok.png"), Color.Magenta); int iCategoryIcon = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\folder_new.png"), Color.Magenta); // Create the prefab category, if still missing ShapeCreatorTreeNode catParent = null; if (parent == null) { catParent = this.AddCategory(null, "Prefabs", iCategoryIcon); } else { catParent = this.AddCategory(parent, dir.Substring(dir.LastIndexOf('\\')), iCategoryIcon); } // Iterate all subdirectories string[] directories = Directory.GetDirectories(dir); foreach (string directory in directories) { AddPrefabCreators(directory, catParent); } // Iterate all files string[] files = Directory.GetFiles(dir, "*.prefab"); Array.Sort(files, new NaturalFileNameComparer()); foreach (string filename in files) { string relname = project.MakeRelative(filename); PrefabDesc desc = PrefabManager.CreatePrefab(relname); if (!desc.Loaded) { continue; } // Get the name of the prefab string _name = desc.Name; if (_name == null || _name == "") { _name = relname; } // Apply the search filter if (!searchPanel.MatchesFilter(_name)) { continue; } // Add the category path to the tree ShapeCreatorTreeNode cat = catParent; string catName = desc.Category; if (catName != null && catName != "") { cat = AddCategoryPath(catParent, catName, "\\", -1); } AddCreator(cat, desc, _name, iIcon); } // Check whether any prefab creators has been added if (catParent.Nodes.Count == 0) { catParent.Remove(); } }
/// <summary> /// Updates all project related creators, this function is called by the project update event /// </summary> protected void ProjectUpdate() { BeginAddCreators(); StoreCollapsedState(); ClearTree(); EditorProject project = EditorApp.Project; if (project == null) { EndAddCreators(); return; } int iCategoryIcon = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\folder_new.png"), Color.Magenta); // add all creator plugins in this project ShapeCreatorTreeNode catCreators = this.AddCategory(null, "Shape Creators", iCategoryIcon); IEditorPluginList list = EditorManager.SortedShapeCreatorPlugins; foreach (IShapeCreatorPlugin plugin in list) { if (!plugin.IsVisible()) { continue; } // Apply the search filter if (!searchPanel.MatchesFilter(plugin.GetPluginName())) { continue; } ShapeCreatorTreeNode catPlugin = catCreators; string catName = plugin.GetPluginCategory(); if (catName != null && catName.Length > 0) { catPlugin = AddCategoryPath(catCreators, catName, "\\", -1); } AddCreator(catPlugin, plugin, plugin.GetPluginName(), plugin.IconIndex); } string prefabDir = project.MakeAbsolute(EditorManager.Settings.PrefabDirectory); if (Directory.Exists(prefabDir)) { // Add prefabs from project directory: try { AddPrefabCreators(prefabDir, null); } catch (Exception ex) { EditorManager.DumpException(ex); } } // Expand all if no collapsed state was restored before, otherwise restore old one. // We can not expand/collapse the TreeNodes at creation time as they have no children // assigned when they are created. if (nodeState == null || nodeState.Length == 0 || searchPanel.IsActive) { treeView_Creators.ExpandAll(); } else { RestoreCollapsedState(treeView_Creators.Nodes); } EndAddCreators(); }
/// <summary> /// Clears all nodes in the tree view /// </summary> public void ClearTree() { this.treeView_Creators.Nodes.Clear(); _selectedCreatorNode = null; SelectedCreatorObject = null; }