public static void Perform(IEnumerable <IFolderItem> items, FolderItemLocation targetFolder) { foreach (var item in items) { Perform(item, targetFolder); } }
public static void Perform() { Document.Current.History.DoTransaction(() => { var rows = Document.Current.TopLevelSelectedRows().ToList(); int prevIndex = -1; for (int i = rows.Count - 1; i >= 0; --i) { var row = rows[i]; IFolderItem item = null; var nr = row.Components.Get <NodeRow>(); if (nr != null) { item = nr.Node; } var fr = row.Components.Get <FolderRow>(); if (fr != null) { item = fr.Folder; } var oldLoc = Row.GetFolderItemLocation(row); var newLoc = new FolderItemLocation(oldLoc.Folder, oldLoc.Index + 2); if (newLoc.Index > newLoc.Folder.Items.Count || prevIndex == newLoc.Index - 1) { prevIndex = oldLoc.Index; continue; } prevIndex = newLoc.Index; Core.Operations.MoveNodes.Perform(item, newLoc); } }); }
private MoveNodes(Node container, FolderItemLocation location, FolderItemLocation prevLocation, IFolderItem item) { Container = container; Location = location; Item = item; PrevLocation = prevLocation; }
public static void Perform(Node container, FolderItemLocation location, IFolderItem item) { if (item is Node && !NodeCompositionValidator.Validate(container.GetType(), item.GetType())) { throw new InvalidOperationException($"Can't put {item.GetType()} into {container.GetType()}"); } DocumentHistory.Current.Perform(new InsertFolderItem(container, location, item)); }
public static void Perform(IFolderItem item, FolderItemLocation targetFolder) { DocumentHistory.Current.Perform( new MoveNodes( Document.Current.Container, targetFolder, GetParentFolder(item), item)); }
protected static void MoveFolderItemTo(IFolderItem item, RowLocation newLocation) { FolderItemLocation targetLoc; var folder = newLocation.ParentRow.Components.Get <FolderRow>().Folder; if (newLocation.ParentRow.Rows.Count <= newLocation.Index) { targetLoc = new FolderItemLocation(folder, folder.Items.Count); } else { targetLoc = Row.GetFolderItemLocation(newLocation.ParentRow.Rows[newLocation.Index]); } MoveNodes.Perform(item, targetLoc); }
public static Node Perform(Node container, FolderItemLocation location, Type nodeType) { if (!nodeType.IsSubclassOf(typeof(Node))) { throw new InvalidOperationException(); } var ctr = nodeType.GetConstructor(Type.EmptyTypes); var node = (Node)ctr.Invoke(new object[] { }); var attrs = ClassAttributes <TangerineNodeBuilderAttribute> .Get(nodeType); if (attrs?.MethodName != null) { var builder = nodeType.GetMethod(attrs.MethodName, BindingFlags.NonPublic | BindingFlags.Instance); builder.Invoke(node, new object[] { }); } node.Id = GenerateNodeId(container, nodeType); InsertFolderItem.Perform(container, location, node); ClearRowSelection.Perform(); SelectNode.Perform(node); Document.Current.Decorate(node); return(node); }
public static bool Perform(string data, RowLocation location) { if (!CanPaste(data, location)) { return(false); } Frame frame; try { var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(data)); frame = Serialization.ReadObject <Frame>(Document.Current.Path, stream); } catch (System.Exception e) { Debug.Write(e); return(false); } FolderItemLocation folderLocation; if (location.ParentRow.Rows.Count > 0) { folderLocation = Row.GetFolderItemLocation(location.ParentRow.Rows[location.Index]); folderLocation.Index++; } else { folderLocation = new FolderItemLocation { Index = 0, Folder = location.ParentRow.Components.Get <FolderRow>().Folder }; } if (!folderLocation.Folder.Expanded) { SetProperty.Perform(folderLocation.Folder, nameof(Folder.Expanded), true); } var items = frame.RootFolder().Items.ToList(); foreach (var n in items.OfType <Node>()) { Document.Current.Decorate(n); } frame.RootFolder().Items.Clear(); frame.RootFolder().SyncDescriptorsAndNodes(frame); ClearRowSelection.Perform(); while (items.Count > 0) { var item = items.First(); var bone = item as Bone; if (bone != null) { if (bone.BaseIndex != 0) { continue; } var newIndex = Document.Current.Container.Nodes.OfType <Bone>().Max(b => b.Index) + 1; var children = BoneUtils.FindBoneDescendats(bone, items.OfType <Bone>()).ToList(); var map = new Dictionary <int, int>(); map.Add(bone.Index, newIndex); bone.BaseIndex = location.ParentRow.Components.Get <BoneRow>()?.Bone.Index ?? 0; bone.Index = newIndex; InsertFolderItem.Perform( Document.Current.Container, folderLocation, bone); folderLocation.Index++; foreach (var b in children) { b.BaseIndex = map[b.BaseIndex]; map.Add(b.Index, b.Index = ++newIndex); InsertFolderItem.Perform( Document.Current.Container, folderLocation, b); folderLocation.Index++; items.Remove(b); } Document.Current.Container.RootFolder().SyncDescriptorsAndNodes(Document.Current.Container); SortBonesInChain.Perform(bone); SelectRow.Perform(Document.Current.GetRowForObject(item)); } else { if (!location.ParentRow.Components.Contains <BoneRow>()) { InsertFolderItem.Perform( Document.Current.Container, folderLocation, item); folderLocation.Index++; SelectRow.Perform(Document.Current.GetRowForObject(item)); } } items.Remove(item); } return(true); }
public static Node Perform(Type nodeType, FolderItemLocation location) { return(Perform(Document.Current.Container, location, nodeType)); }
private InsertFolderItem(Node container, FolderItemLocation location, IFolderItem item) { Container = container; Location = location; Item = item; }
public static bool Perform(string data, RowLocation location, bool pasteAtMouse = false) { if (!CanPaste(data, location)) { return(false); } Frame frame; try { var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(data)); frame = TangerineYuzu.Instance.Value.ReadObject <Frame>(Document.Current.Path, stream); } catch (System.Exception e) { Debug.Write(e); try { var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(data)); frame = (Frame) new HotSceneImporter(isTangerine: true).Import(stream, new Frame(), null); } catch (System.Exception e2) { Debug.Write(e2); return(false); } } var animators = frame.Animators; var items = frame.RootFolder().Items.Where(item => NodeCompositionValidator.IsCopyPasteAllowed(item.GetType())).ToList(); if (items.Count == 0) { if (animators.Count != 0) { foreach (var row in Document.Current.TopLevelSelectedRows().ToList()) { if (!(row.Components.Get <NodeRow>()?.Node is IAnimationHost animable)) { continue; } Document.Current.History.DoTransaction(() => { foreach (var animator in animators) { if (animable.GetType().GetProperty(animator.TargetPropertyPath) == null) { continue; } foreach (var keyframe in animator.Keys) { SetKeyframe.Perform(animable, animator.TargetPropertyPath, animator.AnimationId, keyframe); } } }); } } return(true); } FolderItemLocation folderLocation; if (location.ParentRow.Rows.Count > 0) { folderLocation = Row.GetFolderItemLocation(location.ParentRow.Rows[location.Index]); folderLocation.Index++; } else { folderLocation = new FolderItemLocation { Index = 0, Folder = location.ParentRow.Components.Get <FolderRow>().Folder }; } if (!folderLocation.Folder.Expanded) { SetProperty.Perform(folderLocation.Folder, nameof(Folder.Expanded), true); } var mousePosition = Document.Current.Container.AsWidget?.LocalMousePosition(); var shift = mousePosition - items.OfType <Widget>().FirstOrDefault()?.Position; foreach (var n in items.OfType <Node>()) { Document.Current.Decorate(n); } if (shift.HasValue && pasteAtMouse) { foreach (var w in items.OfType <Widget>()) { w.Position += shift.Value; } } frame.RootFolder().Items.Clear(); frame.RootFolder().SyncDescriptorsAndNodes(frame); ClearRowSelection.Perform(); while (items.Count > 0) { var item = items.First(); var bone = item as Bone; if (bone != null) { if (bone.BaseIndex != 0) { continue; } var newIndex = 1; var bones = Document.Current.Container.Nodes.OfType <Bone>(); if (bones.Any()) { newIndex = bones.Max(b => b.Index) + 1; } var children = BoneUtils.FindBoneDescendats(bone, items.OfType <Bone>()).ToList(); var map = new Dictionary <int, int>(); map.Add(bone.Index, newIndex); bone.BaseIndex = location.ParentRow.Components.Get <BoneRow>()?.Bone.Index ?? 0; bone.Index = newIndex; InsertFolderItem.Perform( Document.Current.Container, folderLocation, bone); folderLocation.Index++; foreach (var b in children) { b.BaseIndex = map[b.BaseIndex]; map.Add(b.Index, b.Index = ++newIndex); InsertFolderItem.Perform( Document.Current.Container, folderLocation, b); folderLocation.Index++; items.Remove(b); } Document.Current.Container.RootFolder().SyncDescriptorsAndNodes(Document.Current.Container); SortBonesInChain.Perform(bone); SelectRow.Perform(Document.Current.GetRowForObject(item)); } else { if (!location.ParentRow.Components.Contains <BoneRow>()) { InsertFolderItem.Perform( Document.Current.Container, folderLocation, item); folderLocation.Index++; SelectRow.Perform(Document.Current.GetRowForObject(item)); } } items.Remove(item); } return(true); }