using System.Collections.Generic; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using JD.AssetBrowser.Actions; using JD.AssetBrowser.Actions.Asset; using JD.AssetBrowser.Properties; using JD.AssetBrowser.Utilities; using JD.Core.Drawing; using JD.Perforce; using Plume.Interfaces.WPF; using Plume.Interfaces.WPF.Actions; using Plume.Interfaces.WPF.FileEditor; using TeaBox.Actions; using Ubisoft; using Control = System.Windows.Controls.Control; using MenuItem = System.Windows.Controls.MenuItem; namespace JD.AssetBrowser.ViewModel { public class DefaultContextMenuProvider : IContextMenuProvider { public IEnumerable ContextMenuItems(AssetViewModel asset) { var openFileMenu = new MenuItem { Header = "Open", Command = new RelayCommand(() => OpenFile(asset)) }; asset.DefaultMenuAction = openFileMenu; yield return openFileMenu; var fileEditorManager = ((IWpfApplication) Application.Current).FileEditorManager; var editors = fileEditorManager.EditorsFor(asset.AbsolutePath); foreach (var editor in editors) { var menuItem = new MenuItem { Header = "Open with " + editor.Name, Icon = editor.Icon.ToImage(20,20), Tag = editor, Command = new RelayCommand(() => OpenFileWith(asset, editor)) }; menuItem.CommandParameter = menuItem; yield return menuItem; } yield return new Separator(); yield return GetMenuFromAction(asset); yield return GetMenuFromAction(asset); //if (asset.Model.MetadataPath.Exists()) //{ // yield return new Separator(); // var regenerate = new MenuItem { Header = "Regenerate Asset", Command = new RelayCommand(() => RegenerateAsset(asset)) }; // yield return regenerate; //} yield return new Separator(); yield return GetMenuFromAction(asset); yield return GetMenuFromAction(asset); yield return new Separator(); yield return GetMenuFromAction(asset); yield return GetMenuFromAction(asset); yield return GetMenuFromAction(asset); } MenuItem GetMenuFromAction(AssetViewModel asset) where TAction: IAction { var actionManager = ((IWpfApplication)Application.Current).ActionManager; var showDependenciesAction = actionManager.Get().ToMenuItem(); showDependenciesAction.CommandParameter = asset; return showDependenciesAction; } private void OpenFile(AssetViewModel asset) { var processStartInfo = new ProcessStartInfo(asset.AbsolutePath) { WindowStyle = ProcessWindowStyle.Hidden }; Process.Start(processStartInfo); } private void OpenFileWith(AssetViewModel asset, IFileEditor editor) { var processStartInfo = new ProcessStartInfo(editor.ApplicationPath, asset.AbsolutePath) { WindowStyle = ProcessWindowStyle.Hidden }; Process.Start(processStartInfo); } //private void RegenerateAsset(AssetViewModel asset) //{ // var assetCreationDialog = new AssetCreationDialog(); // var creator = AssetCreationManager.Instance.GetCreatorForAsset(asset.Model, true); // if (creator != null) // { // assetCreationDialog.ViewModel.AssetModel = creator; // assetCreationDialog.ShowDialog(); // } // else // { // var notificationManager = ((IWpfApplication)System.Windows.Application.Current).NotificationManager; // notificationManager.ShowError("Unable to regenerate the asset"); // } //} } }