117 lines
No EOL
4 KiB
C#
117 lines
No EOL
4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using JD.Application.View.PropertyGrid;
|
|
using JD.Collections.Extensions;
|
|
using JD.Collections.Interfaces;
|
|
using JD.LogService;
|
|
using JD.Maths.Utils;
|
|
using JD.Timeline.View.Actions.Refactor;
|
|
using JD.Timeline.View.PropertyGrid;
|
|
using TeaBox;
|
|
using TeaBox.Macros;
|
|
using JD.Serialization;
|
|
|
|
namespace JD.Timeline.View.Actions.Macros
|
|
{
|
|
[Module]
|
|
public class Selection : TapeActionHandlerBase
|
|
{
|
|
[Macro]
|
|
public void ClearSelection()
|
|
{
|
|
CurrentView.Selection.Clear();
|
|
}
|
|
|
|
private List<Clip> FindClips(IExecutionContext context, string actorNameContains, System.Type clipType)
|
|
{
|
|
var clips = CurrentTape.Clips.Where(clip => (clipType == null || clip.Type == clipType) &&
|
|
clip.ContainsActor(actorNameContains)).ToList();
|
|
|
|
context.Name = $"Found {clips.Count} match";
|
|
|
|
int count = clips.Count();
|
|
if (count == 0)
|
|
{
|
|
context.LogWarning("Could not find any clip matching the criteria.");
|
|
}
|
|
else
|
|
{
|
|
context.LogMessage(MessageImportance.High, "Selected {0} clips", count);
|
|
}
|
|
|
|
return clips;
|
|
}
|
|
|
|
[Macro]
|
|
[Description("Select the single next clip matching the criteria, and focus it")]
|
|
public void SelectNextMatch(IExecutionContext context, string actorNameContains, System.Type clipType)
|
|
{
|
|
var currentView = CurrentView;
|
|
if (currentView != null)
|
|
{
|
|
var clips = FindClips(context, actorNameContains, clipType);
|
|
|
|
using (CurrentView.Selection.BeginScopedUpdate())
|
|
{
|
|
if (clips.Count > 0)
|
|
{
|
|
int index = SelectedClips.CountEquals(1) ? (clips.IndexOf(SelectedClips.First()) + 1) % clips.Count : 0;
|
|
index = index.Clamp(0, clips.Count - 1);
|
|
var toSelect = clips[index];
|
|
CurrentView.Selection.Clear();
|
|
CurrentView.ClipView.AddToSelection(toSelect);
|
|
CurrentView.ClipView.ZoomExtents();
|
|
CurrentView.ClipView.ScrollIntoView(toSelect);
|
|
|
|
foreach (var clip in clips)
|
|
{
|
|
var step = context.AddStep();
|
|
step.Name = clip.Name;
|
|
if (clip == toSelect)
|
|
{
|
|
using (step.Start())
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[Macro]
|
|
public void SelectClipsWhere(IExecutionContext context, string actorNameContains, [PropertyEditor(typeof(ClipTypeEditor))] string clipType)
|
|
{
|
|
var currentView = CurrentView;
|
|
if (currentView != null)
|
|
{
|
|
var type = string.IsNullOrEmpty(clipType) ? null : typeof (Clip).Assembly.GetType(clipType);
|
|
var clips = FindClips(context, actorNameContains, type);
|
|
|
|
using (CurrentView.Selection.BeginScopedUpdate())
|
|
{
|
|
clips.ForEach(CurrentView.ClipView.AddToSelection);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Macro]
|
|
public void InvertSelection()
|
|
{
|
|
var currentView = CurrentView;
|
|
if (currentView != null)
|
|
{
|
|
var selected = SelectedClips.ToList();
|
|
var clips = CurrentTape.Clips.Where(clip => !selected.Contains(clip));
|
|
|
|
using (CurrentView.Selection.BeginScopedUpdate())
|
|
{
|
|
CurrentView.Selection.Clear();
|
|
clips.ForEach(CurrentView.ClipView.AddToSelection);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |