Add context menu and tooltip to asset items in Content Finder tool
This commit is contained in:
@@ -39,7 +39,7 @@ namespace FlaxEditor.Content
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void UpdateTooltipText()
|
public override void UpdateTooltipText()
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
OnBuildTooltipText(sb);
|
OnBuildTooltipText(sb);
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace FlaxEditor.Content
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void UpdateTooltipText()
|
public override void UpdateTooltipText()
|
||||||
{
|
{
|
||||||
TooltipText = Path;
|
TooltipText = Path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ namespace FlaxEditor.Content
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the tooltip text text.
|
/// Updates the tooltip text text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void UpdateTooltipText()
|
public virtual void UpdateTooltipText()
|
||||||
{
|
{
|
||||||
TooltipText = "Path: " + Path;
|
TooltipText = "Path: " + Path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
using FlaxEditor.Content;
|
using FlaxEditor.Content;
|
||||||
|
using FlaxEditor.GUI.ContextMenu;
|
||||||
|
using FlaxEditor.Windows;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
|
|
||||||
@@ -116,6 +118,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
{
|
{
|
||||||
|
Item = null;
|
||||||
_finder = null;
|
_finder = null;
|
||||||
_icon = null;
|
_icon = null;
|
||||||
|
|
||||||
@@ -131,6 +134,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
|||||||
public class AssetSearchItem : SearchItem, IContentItemOwner
|
public class AssetSearchItem : SearchItem, IContentItemOwner
|
||||||
{
|
{
|
||||||
private AssetItem _asset;
|
private AssetItem _asset;
|
||||||
|
private FlaxEditor.GUI.ContextMenu.ContextMenu _cm;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public AssetSearchItem(string name, string type, AssetItem item, ContentFinder finder, float width, float height)
|
public AssetSearchItem(string name, string type, AssetItem item, ContentFinder finder, float width, float height)
|
||||||
@@ -140,9 +144,70 @@ namespace FlaxEditor.Surface.ContextMenu
|
|||||||
_asset.AddReference(this);
|
_asset.AddReference(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override bool ShowTooltip => true;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool OnShowTooltip(out string text, out Vector2 location, out Rectangle area)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(TooltipText) && Item is AssetItem assetItem)
|
||||||
|
{
|
||||||
|
assetItem.UpdateTooltipText();
|
||||||
|
TooltipText = assetItem.TooltipText;
|
||||||
|
}
|
||||||
|
return base.OnShowTooltip(out text, out location, out area);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool OnMouseUp(Vector2 location, MouseButton button)
|
||||||
|
{
|
||||||
|
if (base.OnMouseUp(location, button))
|
||||||
|
return true;
|
||||||
|
if (button == MouseButton.Right && Item is AssetItem assetItem)
|
||||||
|
{
|
||||||
|
// Show context menu
|
||||||
|
var proxy = Editor.Instance.ContentDatabase.GetProxy(assetItem);
|
||||||
|
ContextMenuButton b;
|
||||||
|
var cm = new FlaxEditor.GUI.ContextMenu.ContextMenu { Tag = assetItem };
|
||||||
|
b = cm.AddButton("Open", () => Editor.Instance.ContentFinding.Open(Item));
|
||||||
|
cm.AddSeparator();
|
||||||
|
cm.AddButton("Show in explorer", () => FileSystem.ShowFileExplorer(System.IO.Path.GetDirectoryName(assetItem.Path)));
|
||||||
|
cm.AddButton("Show in Content window", () => Editor.Instance.Windows.ContentWin.Select(assetItem, true));
|
||||||
|
b.Enabled = proxy != null && proxy.CanReimport(assetItem);
|
||||||
|
if (assetItem is BinaryAssetItem binaryAsset)
|
||||||
|
{
|
||||||
|
if (!binaryAsset.GetImportPath(out string importPath))
|
||||||
|
{
|
||||||
|
string importLocation = System.IO.Path.GetDirectoryName(importPath);
|
||||||
|
if (!string.IsNullOrEmpty(importLocation) && System.IO.Directory.Exists(importLocation))
|
||||||
|
{
|
||||||
|
cm.AddButton("Show import location", () => FileSystem.ShowFileExplorer(importLocation));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cm.AddSeparator();
|
||||||
|
cm.AddButton("Copy asset ID", () => Clipboard.Text = FlaxEngine.Json.JsonSerializer.GetStringID(assetItem.ID));
|
||||||
|
cm.AddButton("Select actors using this asset", () => Editor.Instance.SceneEditing.SelectActorsUsingAsset(assetItem.ID));
|
||||||
|
cm.AddButton("Show asset references graph", () => Editor.Instance.Windows.Open(new AssetReferencesGraphWindow(Editor.Instance, assetItem)));
|
||||||
|
cm.AddSeparator();
|
||||||
|
proxy?.OnContentWindowContextMenu(cm, assetItem);
|
||||||
|
assetItem.OnContextMenu(cm);
|
||||||
|
cm.AddButton("Copy name to Clipboard", () => Clipboard.Text = assetItem.NamePath);
|
||||||
|
cm.AddButton("Copy path to Clipboard", () => Clipboard.Text = assetItem.Path);
|
||||||
|
cm.Show(this, location);
|
||||||
|
_cm = cm;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
// Draw context menu hint
|
||||||
|
if (_cm != null && _cm.Visible)
|
||||||
|
Render2D.FillRectangle(new Rectangle(Vector2.Zero, Size), Color.Gray);
|
||||||
|
|
||||||
base.Draw();
|
base.Draw();
|
||||||
|
|
||||||
// Draw icon
|
// Draw icon
|
||||||
@@ -153,6 +218,7 @@ namespace FlaxEditor.Surface.ContextMenu
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
{
|
{
|
||||||
|
_cm = null;
|
||||||
if (_asset != null)
|
if (_asset != null)
|
||||||
{
|
{
|
||||||
_asset.RemoveReference(this);
|
_asset.RemoveReference(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user