using System; using System.Diagnostics; using Umbraco.Core.Services; namespace Umbraco.Web.Trees { [DebuggerDisplay("Tree - {SectionAlias}/{TreeAlias}")] public class Tree : ITree { public Tree(int sortOrder, string applicationAlias, string group, string alias, string title, TreeUse use, Type treeControllerType, bool isSingleNodeTree) { SortOrder = sortOrder; SectionAlias = applicationAlias ?? throw new ArgumentNullException(nameof(applicationAlias)); TreeGroup = group; TreeAlias = alias ?? throw new ArgumentNullException(nameof(alias)); TreeTitle = title; TreeUse = use; TreeControllerType = treeControllerType ?? throw new ArgumentNullException(nameof(treeControllerType)); IsSingleNodeTree = isSingleNodeTree; } /// public int SortOrder { get; set; } /// public string SectionAlias { get; set; } /// public string TreeGroup { get; } /// public string TreeAlias { get; } /// public string TreeTitle { get; set; } /// public TreeUse TreeUse { get; set; } /// public bool IsSingleNodeTree { get; } /// /// Gets the tree controller type. /// public Type TreeControllerType { get; } public static string GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService) { var label = $"[{tree.TreeAlias}]"; // try to look up a the localized tree header matching the tree alias var localizedLabel = textService.Localize("treeHeaders/" + tree.TreeAlias); // if the localizedLabel returns [alias] then return the title if it's defined if (localizedLabel != null && localizedLabel.Equals(label, StringComparison.InvariantCultureIgnoreCase)) { if (string.IsNullOrEmpty(tree.TreeTitle) == false) label = tree.TreeTitle; } else { // the localizedLabel translated into something that's not just [alias], so use the translation label = localizedLabel; } return label; } } }