Follow up #1085 with expendable type description for content items
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when building tooltip text.
|
||||
/// </summary>
|
||||
/// <param name="sb">The String Builder.</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ContentItemType ItemType => ContentItemType.Asset;
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether asset is of the specified type (included inheritance checks).
|
||||
/// </summary>
|
||||
|
||||
@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "C# Source Code";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CSharpScript128;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override bool Exists => Directory.Exists(Path);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "Folder";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Folder128;
|
||||
|
||||
@@ -136,15 +139,10 @@ namespace FlaxEditor.Content
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -275,6 +275,11 @@ namespace FlaxEditor.Content
|
||||
/// </summary>
|
||||
public string NamePath => FlaxEditor.Utilities.Utils.GetAssetNamePath(Path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content item type description (for UI).
|
||||
/// </summary>
|
||||
public abstract string TypeDescription { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default name of the content item thumbnail. Returns null if not used.
|
||||
/// </summary>
|
||||
@@ -359,15 +364,28 @@ namespace FlaxEditor.Content
|
||||
/// </summary>
|
||||
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();
|
||||
/// <summary>
|
||||
/// Called when building tooltip text.
|
||||
/// </summary>
|
||||
/// <param name="sb">The output string builder.</param>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,9 @@ namespace FlaxEditor.Content
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => Path.EndsWith(".h") ? "C++ Header File" : "C++ Source Code";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.CPPScript128;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "File";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Other;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "New";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Scene;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "Scene";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Scene128;
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace FlaxEditor.Content
|
||||
/// <inheritdoc />
|
||||
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Shader;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string TypeDescription => "Shader Source Code";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SpriteHandle DefaultThumbnail => Editor.Instance.Icons.Document128;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the option to use type name translations.
|
||||
/// </summary>
|
||||
[DefaultValue(true)]
|
||||
[EditorDisplay("Interface"), EditorOrder(290), Tooltip("Attempt to translate asset type names.")]
|
||||
public bool TranslateTypeNames { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the timestamps prefix mode for output log messages.
|
||||
/// </summary>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates (recursivly) search popup tree structures based on the filter text.
|
||||
/// Updates (recursively) search popup tree structures based on the filter text.
|
||||
/// </summary>
|
||||
public static void UpdateSearchPopupFilter(TreeNode node, string filterText)
|
||||
{
|
||||
@@ -1019,63 +1017,6 @@ namespace FlaxEditor.Utilities
|
||||
node.Visible = isThisVisible | isAnyChildVisible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the asset type, translating if possible, and if enabled in InterfaceOptions.TranslateTypes.
|
||||
/// </summary>
|
||||
/// <param name="typeName">The type name.</param>
|
||||
/// <returns>The translated type name.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a description of a file from it's extension.
|
||||
/// </summary>
|
||||
/// <param name="fileExtension">The file's extension</param>
|
||||
/// <returns>The processed description.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the asset name relative to the project root folder (with asset file extension)
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user