public static void Perform(Node node, bool select = true) { if (node.Parent != Document.Current.Container) { throw new InvalidOperationException(); } if (select) { if (node is Bone && (node as Bone).Index != 0) { var bone = Document.Current.Container.Nodes.GetBone(((Bone)node).BaseIndex); while (bone != null) { SetProperty.Perform(bone.EditorState(), nameof(NodeEditorState.ChildrenExpanded), true); bone = Document.Current.Container.Nodes.GetBone(bone.BaseIndex); } } var rootFolder = Document.Current.Container.EditorState().RootFolder; var folder = rootFolder.Find(node).Folder; while (folder != null) { if (!folder.Expanded) { SetProperty.Perform(folder, nameof(Folder.Expanded), true); } folder = rootFolder.Find(folder).Folder; } } var row = Document.Current.GetRowForObject(node); SelectRow.Perform(row, select); }
public static void Perform() { var rows = Document.Current.Rows.ToList(); // Use temporal row list to avoid 'Collection was modified' exception foreach (var row in rows) { if (row.Selected) { SelectRow.Perform(row, false); } } }
public static void Perform(Row startRow, Row endRow) { if (endRow.Index >= startRow.Index) { for (int i = startRow.Index; i <= endRow.Index; i++) { SelectRow.Perform(Document.Current.Rows[i]); } } else { for (int i = startRow.Index; i >= endRow.Index; i--) { SelectRow.Perform(Document.Current.Rows[i]); } } }
private static void PasteAnimationTracks(string data, RowLocation loc) { try { var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(data)); var animation = TangerinePersistence.Instance.ReadObject <Animation>(string.Empty, stream); ClearRowSelection.Perform(); var tracks = animation.Tracks.ToList(); animation.Tracks.Clear(); int i = Document.Current.Animation.Tracks.Count == 0 ? 0 : loc.Index + 1; foreach (var t in tracks) { InsertIntoList <AnimationTrackList, AnimationTrack> .Perform(Document.Current.Animation.Tracks, i ++, t); SelectRow.Perform(Document.Current.GetRowForObject(t)); } } catch (System.Exception e) { Debug.Write(e); return; } }
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 bool PasteNodes(string data, RowLocation location, Vector2?mousePosition) { bool CanPaste() { // We are support only paste into folders for now. return(location.ParentRow.Components.Contains <FolderRow>() || location.ParentRow.Components.Contains <BoneRow>()); } if (!CanPaste()) { return(false); } Frame frame; try { var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(data)); frame = TangerinePersistence.Instance.ReadObject <Frame>(Document.Current.Path, stream); } catch (System.Exception e) { Debug.Write(e); 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); } var folderLocation = location.ParentRow.Rows.Count > 0 ? Row.GetFolderItemLocation(location.ParentRow.Rows[location.Index]) : new FolderItemLocation { Index = 0, Folder = location.ParentRow.Components.Get <FolderRow>().Folder }; if (!folderLocation.Folder.Expanded) { SetProperty.Perform(folderLocation.Folder, nameof(Folder.Expanded), true); } mousePosition *= Document.Current.Container.AsWidget?.LocalToWorldTransform.CalcInversed(); var shift = mousePosition - items.OfType <Widget>().FirstOrDefault()?.Position; foreach (var n in items.OfType <Node>()) { Document.Current.Decorate(n); } if (shift.HasValue) { 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(); if (item is Bone bone) { 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> { { 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); }