From 4c906f4040880b3a77686f27289800fb6c0cb55a Mon Sep 17 00:00:00 2001 From: Menotdan Date: Sun, 7 May 2023 13:11:53 -0400 Subject: [PATCH 1/4] Use shorter, relative path for displaying Asset Tooltips. --- Source/Editor/Content/Items/AssetItem.cs | 2 +- Source/Editor/Content/Items/ContentItem.cs | 2 ++ Source/Editor/Utilities/Utils.cs | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Content/Items/AssetItem.cs b/Source/Editor/Content/Items/AssetItem.cs index 6697ed27c..a8303b1d4 100644 --- a/Source/Editor/Content/Items/AssetItem.cs +++ b/Source/Editor/Content/Items/AssetItem.cs @@ -82,7 +82,7 @@ namespace FlaxEditor.Content { sb.Append("Type: ").Append(TypeName).AppendLine(); sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine(); - sb.Append("Path: ").Append(Path).AppendLine(); + sb.Append("Path: ").Append(FlaxEditor.Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine(); } /// diff --git a/Source/Editor/Content/Items/ContentItem.cs b/Source/Editor/Content/Items/ContentItem.cs index 284f3f1b3..1e0a2bad0 100644 --- a/Source/Editor/Content/Items/ContentItem.cs +++ b/Source/Editor/Content/Items/ContentItem.cs @@ -357,6 +357,8 @@ namespace FlaxEditor.Content /// public virtual void UpdateTooltipText() { + Editor.Log(FlaxEditor.Utilities.Utils.GetAssetNamePath(Path)); + TooltipText = "Path: " + Path; } diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index ade084431..21e5fc0da 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1018,15 +1018,28 @@ namespace FlaxEditor.Utilities } /// - /// Gets the asset name relative to the project root folder (without asset file extension) + /// Gets the asset name relative to the project root folder (with asset file extension) /// /// The asset path. /// The processed name path. - public static string GetAssetNamePath(string path) + /// + public static string GetAssetNamePathWithExt(string path) { var projectFolder = Globals.ProjectFolder; if (path.StartsWith(projectFolder)) path = path.Substring(projectFolder.Length + 1); + return path; + } + + /// + /// Gets the asset name relative to the project root folder (without asset file extension) + /// + /// The asset path. + /// The processed name path. + /// + public static string GetAssetNamePath(string path) + { + path = GetAssetNamePathWithExt(path); return StringUtils.GetPathWithoutExtension(path); } From c717a102fcc8ab6385130e128f02d949f4104fc3 Mon Sep 17 00:00:00 2001 From: Menotdan Date: Sun, 7 May 2023 13:12:27 -0400 Subject: [PATCH 2/4] Add an option to toggle translating tooltip type names (not implemented yet) --- Source/Editor/Options/InterfaceOptions.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index acfb7f5e8..d8e30d62b 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -134,6 +134,13 @@ namespace FlaxEditor.Options [EditorDisplay("Interface"), EditorOrder(280), Tooltip("Editor content window orientation.")] public FlaxEngine.GUI.Orientation ContentWindowOrientation { get; set; } = FlaxEngine.GUI.Orientation.Horizontal; + /// + /// Gets or sets the option to use type name translations. + /// + [DefaultValue(true)] + [EditorDisplay("Interface"), EditorOrder(290), Tooltip("Attempt to translate asset type names.")] + public bool TranslateTypeNames { get; set; } = true; + /// /// Gets or sets the timestamps prefix mode for output log messages. /// From cffc3f7f5d9ac0eedb28540e82470563e59d8300 Mon Sep 17 00:00:00 2001 From: Menotdan Date: Sun, 7 May 2023 13:44:15 -0400 Subject: [PATCH 3/4] Better formatting for type names. --- Source/Editor/Content/Items/AssetItem.cs | 4 ++-- Source/Editor/Utilities/Utils.cs | 28 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Content/Items/AssetItem.cs b/Source/Editor/Content/Items/AssetItem.cs index a8303b1d4..120d0e416 100644 --- a/Source/Editor/Content/Items/AssetItem.cs +++ b/Source/Editor/Content/Items/AssetItem.cs @@ -80,9 +80,9 @@ namespace FlaxEditor.Content /// The String Builder. protected virtual void OnBuildTooltipText(StringBuilder sb) { - sb.Append("Type: ").Append(TypeName).AppendLine(); + sb.Append("Type: ").Append(Utilities.Utils.TranslateTypeName(TypeName)).AppendLine(); sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine(); - sb.Append("Path: ").Append(FlaxEditor.Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine(); + sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine(); } /// diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 21e5fc0da..23adc9954 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -20,6 +20,8 @@ using FlaxEditor.SceneGraph; using FlaxEditor.Scripting; using FlaxEngine; using FlaxEngine.GUI; +using FlaxEditor.Options; +using System.Linq; namespace FlaxEngine { @@ -1017,6 +1019,32 @@ namespace FlaxEditor.Utilities node.Visible = isThisVisible | isAnyChildVisible; } + /// + /// Gets the asset type, translating if possible, and if enabled in InterfaceOptions.TranslateTypes. + /// + /// The type name. + /// The translated type name. + public static string TranslateTypeName(string typeName) + { + // TODO: Surely there is a better way to get this value. + if (!Editor.Instance.Options.Options.Interface.TranslateTypeNames) + { + return typeName; + } + + string[] typeNamespaces = typeName.Split('.'); + string lastNamespace = typeNamespaces.Last(); + + // TODO: Add better handling for unconventional type names. + try + { + // Adds spaces between capital letters. + return string.Concat(lastNamespace.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' '); + } catch { + return typeName; + } + } + /// /// Gets the asset name relative to the project root folder (with asset file extension) /// From f3d7ad0aa9b0ccf7725ba93d41de85946c14da35 Mon Sep 17 00:00:00 2001 From: Menotdan Date: Sun, 7 May 2023 14:03:27 -0400 Subject: [PATCH 4/4] Add better tooltips to all files and folders. --- Source/Editor/Content/Items/ContentFolder.cs | 9 ++++- Source/Editor/Content/Items/ContentItem.cs | 14 ++++++-- Source/Editor/Utilities/Utils.cs | 35 ++++++++++++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Content/Items/ContentFolder.cs b/Source/Editor/Content/Items/ContentFolder.cs index cbbc15f24..974b813ee 100644 --- a/Source/Editor/Content/Items/ContentFolder.cs +++ b/Source/Editor/Content/Items/ContentFolder.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text; using FlaxEditor.GUI.Drag; using FlaxEngine; using FlaxEngine.GUI; @@ -137,7 +138,13 @@ namespace FlaxEditor.Content /// public override void UpdateTooltipText() { - TooltipText = Path; + string fileDescription = "Folder"; + StringBuilder sb = new StringBuilder(); + + sb.Append("Type: ").Append(fileDescription).AppendLine(); + sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine(); + + TooltipText = sb.ToString(); } /// diff --git a/Source/Editor/Content/Items/ContentItem.cs b/Source/Editor/Content/Items/ContentItem.cs index 1e0a2bad0..b4a4caa9a 100644 --- a/Source/Editor/Content/Items/ContentItem.cs +++ b/Source/Editor/Content/Items/ContentItem.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Text; using FlaxEditor.Content.GUI; using FlaxEditor.GUI.Drag; using FlaxEngine; @@ -353,13 +355,19 @@ namespace FlaxEditor.Content } /// - /// Updates the tooltip text text. + /// Updates the tooltip text. /// public virtual void UpdateTooltipText() { - Editor.Log(FlaxEditor.Utilities.Utils.GetAssetNamePath(Path)); + string fileExtension = System.IO.Path.GetExtension(Path); + string fileDescription = Utilities.Utils.TranslateFileExtension(fileExtension); + StringBuilder sb = new StringBuilder(); - TooltipText = "Path: " + Path; + sb.Append("Type: ").Append(fileDescription).AppendLine(); + sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine(); + sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine(); + + TooltipText = sb.ToString(); } /// diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 23adc9954..6ef5a8ea0 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1045,12 +1045,42 @@ namespace FlaxEditor.Utilities } } + /// + /// Gets a description of a file from it's extension. + /// + /// The file's extension + /// The processed description. + public static string TranslateFileExtension(string fileExtension) + { + string fileDescription = ""; + switch (fileExtension) + { + case ".cs": + fileDescription = "C# Source Code"; + break; + case ".cpp": + fileDescription = "C++ Source Code"; + break; + case ".h": + fileDescription = "C++ Header File"; + break; + case ".json": + fileDescription = "JSON File"; + break; + default: + fileDescription = fileExtension; + break; + } + + return fileDescription; + } + + /// /// Gets the asset name relative to the project root folder (with asset file extension) /// /// The asset path. - /// The processed name path. - /// + /// The processed name path. public static string GetAssetNamePathWithExt(string path) { var projectFolder = Globals.ProjectFolder; @@ -1064,7 +1094,6 @@ namespace FlaxEditor.Utilities /// /// The asset path. /// The processed name path. - /// public static string GetAssetNamePath(string path) { path = GetAssetNamePathWithExt(path);