JD2022-TU1/main/tools/apps/Orbit.AfterEffects/Actions/ShowInShotgunAction.cs

45 lines
1.4 KiB
C#

using System;
using System.Diagnostics;
using JD.Shotgun.Service;
using Orbit.AfterEffects.Workspaces;
using Plume.Icons;
namespace Orbit.AfterEffects.Actions
{
/// <summary>
/// Open the current asset in Shotgun
/// </summary>
public class ShowInShotgunAction : BaseAction
{
private readonly IShotgunService _shotgunService;
private readonly IExplorerSelection _appContext;
/// <inheritdoc />
public ShowInShotgunAction(IShotgunService shotgunService, IExplorerSelection appContext)
: base("Show in Shotgun", "Open a browser to display the map on Shotgun.", null)
{
_shotgunService = shotgunService ?? throw new ArgumentNullException(nameof(shotgunService));
_appContext = appContext ?? throw new ArgumentNullException(nameof(appContext));
Icon = new Icon(GetType().Assembly, "Resources/sg.png");
}
/// <inheritdoc />
public override void TryExecute()
{
var asset = _appContext.SelectedExplorerAsset;
if (asset == null)
{
throw new Exception("No asset selected.");
}
string assetUrl = _shotgunService.GetAssetUrl(asset.Id);
Process.Start(new ProcessStartInfo(assetUrl));
}
/// <inheritdoc />
public override bool CanExecute()
{
return _appContext.SelectedExplorerAsset != null;
}
}
}