Beispiel #1
0
 public static void Rename(ISelectParent parent, int left, int right)
 {
     if (parent.IChildren[left].IInfo is IRenamable renamable)
     {
         renamable.Rename.StartInput(left, right);
     }
 }
        public void SelectAll()
        {
            ISelectParent target = Start.IParent;

            Select(target.IChildren.First());
            Select(target.IChildren.Last(), true);
        }
        static bool DefaultDrop(IControl source, ISelectParent parent, ISelect child, int after, string format, DragEventArgs e)
        {
            List <ISelect> moving        = (List <ISelect>)e.Data.Get(format);
            ISelectParent  source_parent = moving[0].IParent;
            int            before        = moving[0].IParentIndex.Value - 1;

            bool copy = e.KeyModifiers.HasFlag(App.ControlKey);
            bool result;

            if (result = Move(moving, parent, after, copy, out Path <ISelectParent> premove))
            {
                int before_pos = before;
                int after_pos  = moving[0].IParentIndex.Value - 1;
                int count      = moving.Count;

                if (source_parent == parent && after < before)
                {
                    before_pos += count;
                }

                Program.Project.Undo.Add(new DragDropUndoEntry(source_parent, premove, parent, copy, count, before, after, before_pos, after_pos, format));
            }

            return(result);
        }
 public void Action(string action, ISelectParent parent, int left, int right)
 {
     if (action == "Cut")
     {
         parent.IViewer?.Copy(left, right, true);
     }
     else if (action == "Copy")
     {
         parent.IViewer?.Copy(left, right);
     }
     else if (action == "Duplicate")
     {
         parent.IViewer?.Duplicate(left, right);
     }
     else if (action == "Paste")
     {
         parent.IViewer?.Paste(right);
     }
     else if (action == "Replace")
     {
         parent.IViewer?.Replace(left, right);
     }
     else if (action == "Delete")
     {
         parent.IViewer?.Delete(left, right);
     }
     else if (action == "Group")
     {
         parent.IViewer?.Group(left, right);
     }
     else if (action == "Ungroup")
     {
         parent.IViewer?.Ungroup(left);
     }
     else if (action == "Choke")
     {
         parent.IViewer?.Choke(left, right);
     }
     else if (action == "Unchoke")
     {
         parent.IViewer?.Unchoke(left);
     }
     else if (action == "Mute" || action == "Unmute")
     {
         parent.IViewer?.Mute(left, right);
     }
     else if (action == "Rename")
     {
         parent.IViewer?.Rename(left, right);
     }
     else if (action == "Export")
     {
         parent.IViewer?.Export(left, right);
     }
     else if (action == "Import")
     {
         parent.IViewer?.Import(right);
     }
 }
Beispiel #5
0
        public static void Mute(ISelectParent parent, int left, int right)
        {
            if (!(parent.IChildren[left] is IMutable))
            {
                return;
            }

            Program.Project.Undo.AddAndExecute(new MuteUndoEntry(parent, left, right));
        }
Beispiel #6
0
        public static void Choke(ISelectParent parent, int left, int right)
        {
            if (!(parent is Chain chain))
            {
                return;
            }

            Program.Project.Undo.AddAndExecute(new ChokeUndoEntry(chain, left, right));
        }
Beispiel #7
0
        public static void Ungroup(ISelectParent parent, int index)
        {
            if (!(parent is Chain chain) || !(chain[index] is Group group) || group.Count != 1)
            {
                return;
            }

            Program.Project.Undo.AddAndExecute(new UngroupUndoEntry(chain, index));
        }
Beispiel #8
0
        public static void Delete(ISelectParent parent, int left, int right)
        {
            if (parent is Pattern pattern && pattern.Count - (right - left + 1) == 0)
            {
                return;
            }

            Program.Project.Undo.AddAndExecute(new DeleteUndoEntry(parent, left, right));
        }
Beispiel #9
0
        public static async void Paste(ISelectParent parent, int right)
        {
            Copyable paste = await Copyable.DecodeClipboard();

            if (paste != null && InsertCopyable(parent, paste, right, "Pasted", out InsertCopyableUndoEntry entry))
            {
                Program.Project.Undo.AddAndExecute(entry);
            }
        }
Beispiel #10
0
        public static void Copy(ISelectParent parent, int left, int right, bool cut = false)
        {
            CreateCopyable(parent, left, right).StoreToClipboard();

            if (cut)
            {
                Delete(parent, left, right);
            }
        }
Beispiel #11
0
        public static void Unchoke(ISelectParent parent, int index)
        {
            if (!(parent is Chain chain) || !(chain[index] is Choke choke))
            {
                return;
            }

            Program.Project.Undo.AddAndExecute(new UnchokeUndoEntry(chain, index));
        }
Beispiel #12
0
        public static bool DeviceAsChainDrop(IControl source, ISelectParent parent, ISelect child, int after, string format, DragEventArgs e)
        {
            List <Device> moving = ((List <ISelect>)e.Data.Get(format)).Cast <Device>().ToList();

            Chain source_chain = moving[0].Parent;
            Chain target_chain = (Chain)child;

            int  before = moving[0].IParentIndex.Value - 1;
            bool copy   = e.KeyModifiers.HasFlag(App.ControlKey);

            int?remove = null;

            Group parent_group = (Group)parent;

            if (target_chain == null)
            {
                parent_group.Insert((remove = (source.Name != "DropZoneAfter")? 0 : parent_group.Count).Value, target_chain = new Chain());
            }
            else
            {
                if (source.Name != "DropZoneAfter")
                {
                    if (parent_group.Expanded != target_chain.IParentIndex)
                    {
                        parent_group.SpecificViewer.Expand(target_chain.IParentIndex);
                    }
                }
                else
                {
                    parent_group.Insert((remove = target_chain.IParentIndex + 1).Value);
                    target_chain = parent_group[target_chain.IParentIndex.Value + 1];
                }
            }

            bool result;

            if (result = DragDropManager.Move(moving.Cast <ISelect>().ToList(), (ISelectParent)target_chain, after = ((ISelectParent)target_chain).Count - 1, copy, out Path <ISelectParent> premove))
            {
                int before_pos = before;
                int after_pos  = moving[0].IParentIndex.Value - 1;
                int count      = moving.Count;

                if (source_chain == target_chain && after < before)
                {
                    before_pos += count;
                }

                Program.Project.Undo.Add(new DeviceAsChainUndoEntry(source_chain, premove, target_chain, remove, copy, count, before, after, before_pos, after_pos, format));
            }
            else if (remove != null)
            {
                parent_group.Remove(remove.Value);
            }

            return(result);
        }
Beispiel #13
0
            protected override void Action(ISelectParent item, List <string> element)
            {
                for (int i = left; i <= right; i++)
                {
                    ((IName)item.IChildren[i]).Name = element[i - left];
                }

                item.Selection?.Select(item.IChildren[left]);
                item.Selection?.Select(item.IChildren[right], true);
            }
Beispiel #14
0
 static List <FileDialogFilter> CreateFilters(ISelectParent parent) => new List <FileDialogFilter>()
 {
     new FileDialogFilter()
     {
         Extensions = new List <string>()
         {
             parent.ChildFileExtension
         },
         Name = $"Apollo {parent.ChildString} Preset"
     }
 };
Beispiel #15
0
        static Copyable CreateCopyable(ISelectParent parent, int left, int right)
        {
            Copyable copy = new Copyable();

            for (int i = left; i <= right; i++)
            {
                copy.Contents.Add(parent.IChildren[i]);
            }

            return(copy);
        }
Beispiel #16
0
        static bool FileDrop(IControl source, ISelectParent parent, ISelect child, int after, string format, DragEventArgs e)
        {
            string[] paths = e.Data.GetFileNames()?.ToArray();

            if (paths != null)
            {
                Operations.Import(parent, after, paths);
            }

            return(true);
        }
Beispiel #17
0
        public static async void Replace(ISelectParent parent, int left, int right)
        {
            Copyable paste = await Copyable.DecodeClipboard();

            if (paste != null && InsertCopyable(parent, paste, right, "", out InsertCopyableUndoEntry insert))
            {
                Program.Project.Undo.AddAndExecute(new ReplaceUndoEntry(
                                                       parent,
                                                       new DeleteUndoEntry(parent, left, right),
                                                       insert
                                                       ));
            }
        }
Beispiel #18
0
        static bool InsertCopyable(ISelectParent parent, Copyable copyable, int right, string action, out InsertCopyableUndoEntry entry)
        {
            entry = null;

            if (!parent.ChildType.IsAssignableFrom(copyable.Type))
            {
                return(false);
            }

            entry = new InsertCopyableUndoEntry(parent, copyable, right, action);

            return(true);
        }
Beispiel #19
0
        public static bool Move(List <ISelect> source, ISelectParent target, int position, bool copy, out Path <ISelectParent> premove)
        {
            premove = null;

            if (!(source[0] is Track) && !copy && Track.PathContains((ISelect)target, source))
            {
                return(false);
            }

            if (!copy && ((source[0] is Frame && source[0].IParent != target && source[0].IParent.Count == source.Count) ||
                          ((position == -1)
                    ? target.Count > 0 && source[0] == target.IChildren[0]
                    : source.Contains(target.IChildren[position]) || (source[0].IParent == target && source[0].IParentIndex == position + 1)
                          )
                          ))
            {
                return(false);
            }

            premove = new Path <ISelectParent>(target);

            ISelect point = (position == -1)? null : target.IChildren[position];

            for (int i = 0; i < source.Count; i++)
            {
                if (!copy)
                {
                    source[i].IParent.Remove(source[i].IParentIndex.Value, false);
                }

                source[i] = copy? source[i].IClone() : source[i];

                if (source[i] is Pattern pattern)
                {
                    pattern.Window?.Close();
                }

                target.IInsert((point?.IParentIndex.Value ?? -1) + i + 1, source[i]);
            }

            SelectionManager selection = target.Selection;

            selection?.Select(source[0]);
            selection?.Select(source.Last(), true);

            return(true);
        }
Beispiel #20
0
        public static async void Export(ISelectParent parent, int left, int right)
        {
            if (parent.ChildFileExtension == null)
            {
                return;
            }

            Window sender = parent.IWindow;

            string result = await CreateSFD(parent).ShowAsync(sender);

            if (result != null)
            {
                string[] file = result.Split(Path.DirectorySeparatorChar);

                if (Directory.Exists(string.Join("/", file.Take(file.Count() - 1))))
                {
                    await CreateCopyable(parent, left, right).StoreToFile(result, sender);
                }
            }
        }
        public void Action(string action)
        {
            if (Start == null)
            {
                return;
            }

            ISelectParent parent = Start.IParent;

            int left  = Start.IParentIndex.Value;
            int right = (End == null)? left: End.IParentIndex.Value;

            if (left > right)
            {
                int temp = left;
                left  = right;
                right = temp;
            }

            Action(action, parent, left, right);
        }
Beispiel #22
0
        public static async void Import(ISelectParent parent, int right, string[] paths = null)
        {
            if (parent.ChildFileExtension == null)
            {
                return;
            }

            Window sender = parent.IWindow;

            paths = paths ?? await CreateOFD(parent).ShowAsync(sender);

            if (!paths.Any())
            {
                return;
            }

            Copyable loaded = await Copyable.DecodeFile(paths, sender, parent.ChildType);

            if (loaded != null && InsertCopyable(parent, loaded, right, "Imported", out InsertCopyableUndoEntry entry))
            {
                Program.Project.Undo.AddAndExecute(entry);
            }
        }
Beispiel #23
0
 public DeviceAsChainUndoEntry(ISelectParent sourceparent, Path <ISelectParent> premove, ISelectParent targetparent, int?remove, bool copy, int count, int before, int after, int before_pos, int after_pos, string format)
     : base(sourceparent, premove, targetparent, copy, count, before, after, before_pos, after_pos, format) => this.remove = remove;
Beispiel #24
0
 public static void Duplicate(ISelectParent parent, int left, int right)
 => Program.Project.Undo.AddAndExecute(new DuplicateUndoEntry(parent, left, right));
Beispiel #25
0
 static SaveFileDialog CreateSFD(ISelectParent parent) => new SaveFileDialog()
 {
     Filters = CreateFilters(parent),
     Title   = $"Export {parent.ChildString} Preset"
 };
        public void Action(string action, ISelectParent parent, int left, int right)
        {
            if (parent is Pattern pattern && pattern.Window?.Locked == true)
            {
                return;
            }

            if (action == "Cut")
            {
                Operations.Copy(parent, left, right, true);
            }
            else if (action == "Copy")
            {
                Operations.Copy(parent, left, right);
            }
            else if (action == "Duplicate")
            {
                Operations.Duplicate(parent, left, right);
            }
            else if (action == "Paste")
            {
                Operations.Paste(parent, right);
            }
            else if (action == "Replace")
            {
                Operations.Replace(parent, left, right);
            }
            else if (action == "Delete")
            {
                Operations.Delete(parent, left, right);
            }
            else if (action == "Group")
            {
                Operations.Group(parent, left, right);
            }
            else if (action == "Ungroup")
            {
                Operations.Ungroup(parent, left);
            }
            else if (action == "Choke")
            {
                Operations.Choke(parent, left, right);
            }
            else if (action == "Unchoke")
            {
                Operations.Unchoke(parent, left);
            }
            else if (action == "Mute" || action == "Unmute")
            {
                Operations.Mute(parent, left, right);
            }
            else if (action == "Rename")
            {
                Operations.Rename(parent, left, right);
            }
            else if (action == "Export")
            {
                Operations.Export(parent, left, right);
            }
            else if (action == "Import")
            {
                Operations.Import(parent, right);
            }
        }
 public void Action(string action, ISelectParent parent, int index) => Action(action, parent, index, index);
Beispiel #28
0
 static OpenFileDialog CreateOFD(ISelectParent parent) => new OpenFileDialog()
 {
     AllowMultiple = true,
     Filters       = CreateFilters(parent),
     Title         = $"Import {parent.ChildString} Preset"
 };
Beispiel #29
0
 TRet Next <TRet>(ISelectParent current, int index)
 {
     if (current == null)
     {
         return(default);
Beispiel #30
0
 public RenamedUndoEntry(ISelectParent parent, int left, int right, List <string> undo, List <string> redo)
     : base($"{parent.ChildString} Renamed to {redo[0]}", parent, undo.ToList(), redo.ToList())
 {
     this.left  = left;
     this.right = right;
 }