public SVNMenuItem(OdinMenuTree tree, string name, object value) : base(tree, name, value) { _popMenu = new GenericMenu(); OnRightClick += OnRightClickEvent; }
public SerializationInfoMenuItem(OdinMenuTree tree, string name, MemberSerializationInfo instance) : base(tree, name, instance) { this.info = instance; this.typeName = instance.MemberInfo.GetReturnType().GetNiceName(); }
protected abstract void BuildSelectionTree(OdinMenuTree tree);
/// <summary> /// Invokes BuildMenuTree. /// </summary> public void ForceRebuildMenuTree() { this.tree = this.BuildMenuTree(); }
/// <summary> /// Adds the menu item at the specified menu item path and populates the result list with all menu items created in order to add the menuItem at the specified path. /// </summary> /// <param name="tree">The tree instance.</param> /// <param name="result">The result list.</param> /// <param name="path">The menu item path.</param> /// <param name="menuItem">The menu item.</param> public static void AddMenuItemAtPath(this OdinMenuTree tree, ICollection <OdinMenuItem> result, string path, OdinMenuItem menuItem) { var curr = tree.Root; if (!string.IsNullOrEmpty(path)) { if (path[0] == '/' || path[path.Length - 1] == '/') { path = path.Trim(); } var iFrom = 0; var iTo = 0; do { iTo = path.IndexOf('/', iFrom); string name; if (iTo < 0) { iTo = path.Length - 1; name = path.Substring(iFrom, iTo - iFrom + 1); } else { name = path.Substring(iFrom, iTo - iFrom); } var childs = curr.ChildMenuItems; // OdinMenuItem child = curr.ChildMenuItems.FirstOrDefault(x => x.Name == name); // If we assume people add menu items in a local order, then starting our search from then end of the list, should be faster. OdinMenuItem child = null; for (int i = childs.Count - 1; i >= 0; i--) { if (childs[i].Name == name) { child = childs[i]; break; } } if (child == null) { child = new OdinMenuItem(tree, name, null); curr.ChildMenuItems.Add(child); } result.Add(child); curr = child; iFrom = iTo + 1; } while (iTo != path.Length - 1); } // var oldItem = curr.ChildMenuItems.FirstOrDefault(x => x.Name == menuItem.Name); // If we assume people add menu items in a local order, then starting our search from then end of the list, should be faster. var currChilds = curr.ChildMenuItems; OdinMenuItem oldItem = null; for (int i = currChilds.Count - 1; i >= 0; i--) { if (currChilds[i].Name == menuItem.Name) { oldItem = currChilds[i]; break; } } if (oldItem != null) { curr.ChildMenuItems.Remove(oldItem); menuItem.ChildMenuItems.AddRange(oldItem.ChildMenuItems); } curr.ChildMenuItems.Add(menuItem); result.Add(menuItem); }
/// <summary> /// Builds the selection tree. /// </summary> protected override void BuildSelectionTree(OdinMenuTree tree) { tree.Config.UseCachedExpandedStates = false; tree.DefaultMenuStyle.NotSelectedIconAlpha = 1f; if (types == null) { List <OdinMenuItem> items; if (cachedAllTypesMenuItems.TryGetValue(this.assemblyTypeFlags, out items)) { AddRecursive(tree, items, tree.MenuItems); } else { var assemblyTypes = OrderTypes(AssemblyUtilities.GetTypes(this.assemblyTypeFlags).Where(x => { if (x.Name == null) { return(false); } var trimmedName = x.Name.TrimStart(); if (trimmedName.Length == 0) { return(false); } return(char.IsLetter(trimmedName[0])); })); foreach (var t in assemblyTypes) { var niceName = t.GetNiceName(); string path = this.GetTypeNamePath(t, niceName); var last = tree.AddObjectAtPath(path, t).AddThumbnailIcons().Last(); last.SearchString = niceName == path ? path : niceName + "|" + path; } cachedAllTypesMenuItems[this.assemblyTypeFlags] = tree.MenuItems; } } else { foreach (var t in this.types) { var niceName = t.GetNiceName(); string path = this.GetTypeNamePath(t, niceName); var last = tree.AddObjectAtPath(path, t).Last(); last.SearchString = niceName == path ? path : niceName + "|" + path; if (this.FlattenTree && t.Namespace != null) { last.OnDrawItem += x => GUI.Label(x.Rect.Padding(10, 0).AlignCenterY(16), t.Namespace, SirenixGUIStyles.RightAlignedGreyMiniLabel); } } tree.EnumerateTree(x => x.Value != null, false).AddThumbnailIcons(); } //tree.EnumerateTree().ForEach(i => //{ // var t = i.Value as Type; // if (t != null) { i.SearchString = t.GetNiceFullName(); } //}); tree.Selection.SupportsMultiSelect = this.supportsMultiSelect; tree.Selection.SelectionChanged += (t) => { lastType = this.SelectionTree.Selection.Select(x => x.Value).OfType <Type>().LastOrDefault() ?? lastType; }; }
/// <summary> /// Adds the asset at the specified menu item path and returns all menu items created in order to end up at the specified menu path. /// </summary> /// <param name="tree">The tree.</param> /// <param name="menuItemPath">The menu item path.</param> /// <param name="assetPath">The asset path.</param> /// <returns>Returns all menu items created in order to add the menu item at the specified menu item path.</returns> public static IEnumerable <OdinMenuItem> AddAssetAtPath(this OdinMenuTree tree, string menuItemPath, string assetPath) { return(AddAssetAtPath(tree, menuItemPath, assetPath, typeof(UnityEngine.Object))); }
/// <summary> /// Adds all assets at the specified path. Each asset found gets its own menu item inside the specified menu item path. /// </summary> /// <param name="tree">The tree.</param> /// <param name="menuPath">The menu item path.</param> /// <param name="assetFolderPath">The asset folder path.</param> /// <param name="includeSubDirectories">Whether to search for assets in subdirectories as well.</param> /// <param name="flattenSubDirectories">If true, sub-directories in the assetFolderPath will no longer get its own sub-menu item at the specified menu item path.</param> /// <returns>Returns all menu items created in order to add the menu item at the specified menu item path.</returns> public static IEnumerable <OdinMenuItem> AddAllAssetsAtPath(this OdinMenuTree tree, string menuPath, string assetFolderPath, bool includeSubDirectories = false, bool flattenSubDirectories = false) { return(AddAllAssetsAtPath(tree, menuPath, assetFolderPath, typeof(UnityEngine.Object), includeSubDirectories, flattenSubDirectories)); }
/// <summary> /// Adds the menu item at specified menu item path, and returns all menu items created in order to add the menuItem at the specified path. /// </summary> /// <param name="tree">The tree.</param> /// <param name="path">The menu item path.</param> /// <param name="menuItem">The menu item.</param> /// <returns>Returns all menu items created in order to add the menu item at the specified menu item path.</returns> public static IEnumerable <OdinMenuItem> AddMenuItemAtPath(this OdinMenuTree tree, string path, OdinMenuItem menuItem) { cache.Clear(); AddMenuItemAtPath(tree, cache, path, menuItem); return(cache); }
/// <summary> /// Builds the selection tree. /// </summary> protected override void BuildSelectionTree(OdinMenuTree tree) { tree.Selection.SupportsMultiSelect = this.supportsMultiSelect; this.getMenuItemName = this.getMenuItemName ?? (x => x == null ? "" : x.ToString()); tree.AddRange(this.collection, this.getMenuItemName); }
/// <summary> /// Initializes a new instance of the <see cref="OdinMenuItem"/> class. /// </summary> /// <param name="tree">The ODIN menu tree instance the menu item belongs to.</param> /// <param name="name">The name of the menu item.</param> /// <param name="instance">The instance the menu item represents.</param> public OdinMenuItem(OdinMenuTree tree, string name, object instance) : this(tree, name, new object[] { instance }) { }