65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using JD.Asset;
|
|
using JD.Asset.Database;
|
|
using JD.AssetBrowser.ViewModel;
|
|
using Plume.Icons;
|
|
using Plume.Interfaces.WPF.Actions;
|
|
using Plume.Interfaces.WPF.Dialogs;
|
|
using Trinity;
|
|
|
|
namespace JD.AssetBrowser.Actions.Asset
|
|
{
|
|
public class RenameOrMoveAssetAction : Plume.Interfaces.WPF.Actions.Action<AssetViewModel>
|
|
{
|
|
/// <inheritdoc />
|
|
public RenameOrMoveAssetAction() :
|
|
base("Rename/Move", "Rename or move an asset", null, null, null)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Execute(IActionContext context, AssetViewModel asset)
|
|
{
|
|
var task = RenameOrMoveAssetAsync(context, asset);
|
|
}
|
|
|
|
private async Task RenameOrMoveAssetAsync(IActionContext context, AssetViewModel asset)
|
|
{
|
|
var dialogManager = context.DialogManager;
|
|
if (!AssetDatabase.Instance.DependenciesParsed)
|
|
{
|
|
var result = dialogManager.ShowMessageBox("", "Dependencies will be analyzed first.", StandardIcon.Info, StandardButton.Ok, StandardButton.Cancel);
|
|
if (result.StandardButton == StandardButton.Ok)
|
|
{
|
|
await AssetDatabase.Instance.RefreshDependenciesAsync();
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (asset.IsFolder && asset.Model.Dependencies.Count == 0 && asset.Model.ReferencedBy.Count == 0)
|
|
{
|
|
asset.Model.FindDependencies(true);
|
|
}
|
|
|
|
var viewModel = new MoveDialogViewModel { SelectedFile = asset };
|
|
var dialog = new MoveDialog { ViewModel = viewModel };
|
|
dialogManager.ShowDialog(dialog, settings =>
|
|
{
|
|
settings.Title = $"Rename/Move asset {asset}";
|
|
settings.Buttons.Add(viewModel.MoveButton);
|
|
settings.Buttons.Add(StandardButton.Cancel);
|
|
});
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool CanExecute(IActionContext context, AssetViewModel asset)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|