using System;
using System.Diagnostics;
using JD.Shotgun.Service;
using Orbit.AfterEffects.Workspaces;
using Plume.Icons;
namespace Orbit.AfterEffects.Actions
{
///
/// Open the current asset in Shotgun
///
public class ShowInShotgunAction : BaseAction
{
private readonly IShotgunService _shotgunService;
private readonly IExplorerSelection _appContext;
///
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");
}
///
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));
}
///
public override bool CanExecute()
{
return _appContext.SelectedExplorerAsset != null;
}
}
}