using System.IO; using System.Linq; using JD.Reflection.Attributes; using JD.TeaBoxAddinSystem.Bootstrap; using JD.Timeline.Document; using JD.Timeline.Model; using JD.Timeline.Plugin; using JD.Timeline.View.Actions.Refactor; using TeaBox; using TeaBox.Actions; using TeaBox.Bootstrap; namespace JD.Timeline.View.Actions { [Export(typeof(IBootstrapCommand))] public class NewTapeHandler : IBootstrapCommand { public void Execute() { ((SimpleAction)TeaBox.ObjectModel.Application.Main.Actions[TeaBox.ApplicationActions.NewFile]).DefaultHandler = new Handler(); ((SimpleAction)TeaBox.ObjectModel.Application.Main.Actions[TeaBox.ApplicationActions.NewFile]).Text = "New tape"; ((SimpleAction)TeaBox.ObjectModel.Application.Main.Actions[TeaBox.ApplicationActions.NewFile]).Description = "Adds a tape to the current Tape Case"; } private class Handler : ActionHandler { public override bool Update(ActionContext context, ActionInfo info) { return TimelinePlugin.Instance != null; } public override void Execute(ActionExecutionContext context) { TimelinePlugin.TapeLabelResponse response; if (TimelinePlugin.Instance.GetTapeCaseLabels().Join(out response)) { if (response.InvalidQuery) { MessageService.MessageService.ShowError("You can only add a tape to an existing TapeCaseComponent. Open a tape case in the engine (Right click->Edit Tapes) on an actor with a tape case component.", "Invalid Operation"); return; } } else { return; } string relativePath; if (TapeCreator.CreateTapeFile(out relativePath) != null) { string labelName = Path.GetFileNameWithoutExtension(relativePath); labelName = MessageService.MessageService.ShowInputBox("Enter label name", "Enter label name", labelName); if (!string.IsNullOrEmpty(labelName)) { // Add the new tape in a new group uint group = response.Labels.Select(label => label.Group + 1).DefaultIfEmpty().Max(); TimelinePlugin.Instance.SendAddTapeLabel(new TapeLabel { Label = labelName, Path = relativePath, Group = group }); // Save the current tape case. TimelinePlugin.Instance.SendSaveTape(string.Empty); TimelinePlugin.Instance.SendGetTape(relativePath); TimelinePlugin.Instance.Tapes.GetOrCreate(relativePath).OpenDocument(); } } } } } }