From 4c906f4040880b3a77686f27289800fb6c0cb55a Mon Sep 17 00:00:00 2001 From: Menotdan Date: Sun, 7 May 2023 13:11:53 -0400 Subject: [PATCH 1/7] 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/7] 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/7] 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/7] 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); From c1fa9e595c4890a027505af1b441239960300f13 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 6 May 2023 14:58:32 +0300 Subject: [PATCH 5/7] Sort profiler window assets when the view is active --- Source/Editor/Windows/Profiler/Assets.cs | 27 +++++++++------------ Source/Editor/Windows/Profiler/MemoryGPU.cs | 23 ++++++++---------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/Source/Editor/Windows/Profiler/Assets.cs b/Source/Editor/Windows/Profiler/Assets.cs index 6987a09e0..1856ff7a1 100644 --- a/Source/Editor/Windows/Profiler/Assets.cs +++ b/Source/Editor/Windows/Profiler/Assets.cs @@ -8,6 +8,7 @@ using FlaxEngine; using FlaxEngine.Json; using FlaxEngine.GUI; using FlaxEditor.GUI.ContextMenu; +using System.Linq; namespace FlaxEditor.Windows.Profiler { @@ -17,7 +18,7 @@ namespace FlaxEditor.Windows.Profiler /// internal sealed class Assets : ProfilerMode { - private struct Resource + private class Resource { public string Name; public string TypeName; @@ -120,19 +121,18 @@ namespace FlaxEditor.Windows.Profiler // Capture current assets usage info var assets = FlaxEngine.Content.Assets; - var sb = _stringBuilder; var resources = new Resource[assets.Length]; - var contentDatabase = Editor.Instance.ContentDatabase; ulong totalMemoryUsage = 0; for (int i = 0; i < resources.Length; i++) { var asset = assets[i]; + ref var resource = ref resources[i]; if (!asset) continue; // Try to reuse cached resource info var assetId = asset.ID; - if (!_resourceCache.TryGetValue(assetId, out var resource)) + if (!_resourceCache.TryGetValue(assetId, out resource)) { resource = new Resource { @@ -154,12 +154,10 @@ namespace FlaxEditor.Windows.Profiler } resource.MemoryUsage = asset.MemoryUsage; - totalMemoryUsage += resource.MemoryUsage; resource.ReferencesCount = asset.ReferencesCount; - resources[i] = resource; + totalMemoryUsage += resource.MemoryUsage; } _memoryUsageChart.AddSample((float)totalMemoryUsage); - Array.Sort(resources, SortResources); if (_resources == null) _resources = new SamplesBuffer(); _resources.Add(resources); @@ -188,11 +186,6 @@ namespace FlaxEditor.Windows.Profiler base.OnDestroy(); } - private static int SortResources(Resource a, Resource b) - { - return (int)(b.MemoryUsage - a.MemoryUsage); - } - private void UpdateTable() { _table.IsLayoutLocked = true; @@ -226,12 +219,13 @@ namespace FlaxEditor.Windows.Profiler if (resources == null || resources.Length == 0) return; + var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage); + // Add rows var rowColor2 = Style.Current.Background * 1.4f; - for (int i = 0; i < resources.Length; i++) + int rowIndex = 0; + foreach (var e in resourcesOrdered) { - ref var e = ref resources[i]; - ClickableRow row; if (_tableRowsCache.Count != 0) { @@ -257,8 +251,9 @@ namespace FlaxEditor.Windows.Profiler // Add row to the table row.Width = _table.Width; - row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent; + row.BackgroundColor = rowIndex % 2 == 0 ? rowColor2 : Color.Transparent; row.Parent = _table; + rowIndex++; } } diff --git a/Source/Editor/Windows/Profiler/MemoryGPU.cs b/Source/Editor/Windows/Profiler/MemoryGPU.cs index f84e4b697..d6c0e1b08 100644 --- a/Source/Editor/Windows/Profiler/MemoryGPU.cs +++ b/Source/Editor/Windows/Profiler/MemoryGPU.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using FlaxEditor.GUI; using FlaxEngine; @@ -15,7 +16,7 @@ namespace FlaxEditor.Windows.Profiler /// internal sealed class MemoryGPU : ProfilerMode { - private struct Resource + private class Resource { public string Name; public string Tooltip; @@ -126,10 +127,11 @@ namespace FlaxEditor.Windows.Profiler for (int i = 0; i < resources.Length; i++) { var gpuResource = gpuResources[i]; + ref var resource = ref resources[i]; // Try to reuse cached resource info var gpuResourceId = gpuResource.ID; - if (!_resourceCache.TryGetValue(gpuResourceId, out var resource)) + if (!_resourceCache.TryGetValue(gpuResourceId, out resource)) { resource = new Resource { @@ -194,9 +196,7 @@ namespace FlaxEditor.Windows.Profiler resource.MemoryUsage = gpuResource.MemoryUsage; if (resource.MemoryUsage == 1) resource.MemoryUsage = 0; // Sometimes GPU backend fakes memory usage as 1 to mark as allocated but not resided in actual GPU memory - resources[i] = resource; } - Array.Sort(resources, SortResources); if (_resources == null) _resources = new SamplesBuffer(); _resources.Add(resources); @@ -240,11 +240,6 @@ namespace FlaxEditor.Windows.Profiler base.OnDestroy(); } - private static int SortResources(Resource a, Resource b) - { - return (int)(b.MemoryUsage - a.MemoryUsage); - } - private void UpdateTable() { _table.IsLayoutLocked = true; @@ -278,12 +273,13 @@ namespace FlaxEditor.Windows.Profiler if (resources == null || resources.Length == 0) return; + var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage); + // Add rows var rowColor2 = Style.Current.Background * 1.4f; - for (int i = 0; i < resources.Length; i++) + int rowIndex = 0; + foreach (var e in resourcesOrdered) { - ref var e = ref resources[i]; - ClickableRow row; if (_tableRowsCache.Count != 0) { @@ -314,8 +310,9 @@ namespace FlaxEditor.Windows.Profiler // Add row to the table row.Width = _table.Width; - row.BackgroundColor = i % 2 == 0 ? rowColor2 : Color.Transparent; + row.BackgroundColor = rowIndex % 2 == 0 ? rowColor2 : Color.Transparent; row.Parent = _table; + rowIndex++; } } From 3bff65d6b6cc521b35bd5af816c352481b09353e Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 10 May 2023 10:03:13 +0200 Subject: [PATCH 6/7] Minor fix --- Source/Editor/Windows/Profiler/Assets.cs | 1 - Source/Editor/Windows/Profiler/MemoryGPU.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Source/Editor/Windows/Profiler/Assets.cs b/Source/Editor/Windows/Profiler/Assets.cs index 1856ff7a1..e2a65d496 100644 --- a/Source/Editor/Windows/Profiler/Assets.cs +++ b/Source/Editor/Windows/Profiler/Assets.cs @@ -218,7 +218,6 @@ namespace FlaxEditor.Windows.Profiler var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex); if (resources == null || resources.Length == 0) return; - var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage); // Add rows diff --git a/Source/Editor/Windows/Profiler/MemoryGPU.cs b/Source/Editor/Windows/Profiler/MemoryGPU.cs index d6c0e1b08..20a7898e0 100644 --- a/Source/Editor/Windows/Profiler/MemoryGPU.cs +++ b/Source/Editor/Windows/Profiler/MemoryGPU.cs @@ -272,7 +272,6 @@ namespace FlaxEditor.Windows.Profiler var resources = _resources.Get(_memoryUsageChart.SelectedSampleIndex); if (resources == null || resources.Length == 0) return; - var resourcesOrdered = resources.OrderByDescending(x => x.MemoryUsage); // Add rows From 0c2c643ea80cd2dfd11b67dd53a78c9620638bd1 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 10 May 2023 10:29:59 +0200 Subject: [PATCH 7/7] Follow up #1085 with expendable type description for content items --- Source/Editor/Content/Items/AssetItem.cs | 37 +++++------ .../Editor/Content/Items/CSharpScriptItem.cs | 3 + Source/Editor/Content/Items/ContentFolder.cs | 12 ++-- Source/Editor/Content/Items/ContentItem.cs | 30 +++++++-- Source/Editor/Content/Items/CppScriptItem.cs | 3 + Source/Editor/Content/Items/FileItem.cs | 3 + Source/Editor/Content/Items/NewItem.cs | 3 + Source/Editor/Content/Items/SceneItem.cs | 3 + .../Editor/Content/Items/ShaderSourceItem.cs | 3 + Source/Editor/Options/InterfaceOptions.cs | 7 --- Source/Editor/Utilities/Utils.cs | 61 +------------------ 11 files changed, 64 insertions(+), 101 deletions(-) diff --git a/Source/Editor/Content/Items/AssetItem.cs b/Source/Editor/Content/Items/AssetItem.cs index 120d0e416..1ce2f6bc4 100644 --- a/Source/Editor/Content/Items/AssetItem.cs +++ b/Source/Editor/Content/Items/AssetItem.cs @@ -1,8 +1,6 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; -using System.IO; -using System.Text; using FlaxEngine; using FlaxEngine.GUI; @@ -38,14 +36,6 @@ namespace FlaxEditor.Content ID = id; } - /// - public override void UpdateTooltipText() - { - var sb = new StringBuilder(); - OnBuildTooltipText(sb); - TooltipText = sb.ToString(); - } - private sealed class TooltipDoubleClickHook : Control { public AssetItem Item; @@ -74,20 +64,25 @@ namespace FlaxEditor.Content hook.Item = this; } - /// - /// Called when building tooltip text. - /// - /// The String Builder. - protected virtual void OnBuildTooltipText(StringBuilder sb) - { - 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(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine(); - } - /// public override ContentItemType ItemType => ContentItemType.Asset; + /// + public override string TypeDescription + { + get + { + // Translate asset type name + var typeName = TypeName; + string[] typeNamespaces = typeName.Split('.'); + if (typeNamespaces.Length != 0 && typeNamespaces.Length != 0) + { + typeName = Utilities.Utils.GetPropertyNameUI(typeNamespaces[typeNamespaces.Length - 1]); + } + return typeName; + } + } + /// /// Determines whether asset is of the specified type (included inheritance checks). /// diff --git a/Source/Editor/Content/Items/CSharpScriptItem.cs b/Source/Editor/Content/Items/CSharpScriptItem.cs index 9a214a0e8..fd6381eea 100644 --- a/Source/Editor/Content/Items/CSharpScriptItem.cs +++ b/Source/Editor/Content/Items/CSharpScriptItem.cs @@ -19,6 +19,9 @@ namespace FlaxEditor.Content { } + /// + public override string TypeDescription => "C# Source Code"; + /// public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CSharpScript128; } diff --git a/Source/Editor/Content/Items/ContentFolder.cs b/Source/Editor/Content/Items/ContentFolder.cs index 974b813ee..86c374fee 100644 --- a/Source/Editor/Content/Items/ContentFolder.cs +++ b/Source/Editor/Content/Items/ContentFolder.cs @@ -121,6 +121,9 @@ namespace FlaxEditor.Content /// public override bool Exists => Directory.Exists(Path); + /// + public override string TypeDescription => "Folder"; + /// public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Folder128; @@ -136,15 +139,10 @@ namespace FlaxEditor.Content } /// - public override void UpdateTooltipText() + protected override void OnBuildTooltipText(StringBuilder sb) { - string fileDescription = "Folder"; - StringBuilder sb = new StringBuilder(); - - sb.Append("Type: ").Append(fileDescription).AppendLine(); + sb.Append("Type: ").Append(TypeDescription).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 b4a4caa9a..4fe75d2c2 100644 --- a/Source/Editor/Content/Items/ContentItem.cs +++ b/Source/Editor/Content/Items/ContentItem.cs @@ -275,6 +275,11 @@ namespace FlaxEditor.Content /// public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path); + /// + /// Gets the content item type description (for UI). + /// + public abstract string TypeDescription { get; } + /// /// Gets the default name of the content item thumbnail. Returns null if not used. /// @@ -359,15 +364,28 @@ namespace FlaxEditor.Content /// public virtual void UpdateTooltipText() { - string fileExtension = System.IO.Path.GetExtension(Path); - string fileDescription = Utilities.Utils.TranslateFileExtension(fileExtension); - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); + OnBuildTooltipText(sb); + if (sb.Length != 0 && sb[sb.Length - 1] == '\n') + { + // Remove new-line from end + int sub = 1; + if (sb.Length != 1 && sb[sb.Length - 2] == '\r') + sub = 2; + sb.Length -= sub; + } + TooltipText = sb.ToString(); + } - sb.Append("Type: ").Append(fileDescription).AppendLine(); + /// + /// Called when building tooltip text. + /// + /// The output string builder. + protected virtual void OnBuildTooltipText(StringBuilder sb) + { + sb.Append("Type: ").Append(TypeDescription).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/Content/Items/CppScriptItem.cs b/Source/Editor/Content/Items/CppScriptItem.cs index c4fbb99e8..aea12ecd3 100644 --- a/Source/Editor/Content/Items/CppScriptItem.cs +++ b/Source/Editor/Content/Items/CppScriptItem.cs @@ -19,6 +19,9 @@ namespace FlaxEditor.Content { } + /// + public override string TypeDescription => Path.EndsWith(".h") ? "C++ Header File" : "C++ Source Code"; + /// public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CPPScript128; } diff --git a/Source/Editor/Content/Items/FileItem.cs b/Source/Editor/Content/Items/FileItem.cs index 5e355087a..1136ee87e 100644 --- a/Source/Editor/Content/Items/FileItem.cs +++ b/Source/Editor/Content/Items/FileItem.cs @@ -25,6 +25,9 @@ namespace FlaxEditor.Content /// public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other; + /// + public override string TypeDescription => "File"; + /// public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128; } diff --git a/Source/Editor/Content/Items/NewItem.cs b/Source/Editor/Content/Items/NewItem.cs index da8b0ca9a..94d95f15b 100644 --- a/Source/Editor/Content/Items/NewItem.cs +++ b/Source/Editor/Content/Items/NewItem.cs @@ -39,6 +39,9 @@ namespace FlaxEditor.Content /// public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other; + /// + public override string TypeDescription => "New"; + /// public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128; diff --git a/Source/Editor/Content/Items/SceneItem.cs b/Source/Editor/Content/Items/SceneItem.cs index cf2ada96b..6a56004f0 100644 --- a/Source/Editor/Content/Items/SceneItem.cs +++ b/Source/Editor/Content/Items/SceneItem.cs @@ -27,6 +27,9 @@ namespace FlaxEditor.Content /// public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Scene; + /// + public override string TypeDescription => "Scene"; + /// public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Scene128; diff --git a/Source/Editor/Content/Items/ShaderSourceItem.cs b/Source/Editor/Content/Items/ShaderSourceItem.cs index b5572787c..1e8f8360f 100644 --- a/Source/Editor/Content/Items/ShaderSourceItem.cs +++ b/Source/Editor/Content/Items/ShaderSourceItem.cs @@ -26,6 +26,9 @@ namespace FlaxEditor.Content /// public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Shader; + /// + public override string TypeDescription => "Shader Source Code"; + /// public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128; } diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index d8e30d62b..acfb7f5e8 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -134,13 +134,6 @@ 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. /// diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 6ef5a8ea0..5f836e069 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -20,8 +20,6 @@ using FlaxEditor.SceneGraph; using FlaxEditor.Scripting; using FlaxEngine; using FlaxEngine.GUI; -using FlaxEditor.Options; -using System.Linq; namespace FlaxEngine { @@ -993,7 +991,7 @@ namespace FlaxEditor.Utilities } /// - /// Updates (recursivly) search popup tree structures based on the filter text. + /// Updates (recursively) search popup tree structures based on the filter text. /// public static void UpdateSearchPopupFilter(TreeNode node, string filterText) { @@ -1019,63 +1017,6 @@ 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 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) ///