// Convenience method to add a new tree node for a section. Return the added tree node. private TreeNode AddSingleSectionNode(ObiNode node) { if (InvokeRequired) { return((TreeNode)Invoke(new NodeInvokation(AddSingleSectionNode), node)); } else { TreeNode n = null; if (node is SectionNode && node.IsRooted) { if (node.ParentAs <SectionNode>() != null) { TreeNode p = FindTreeNode(node.ParentAs <SectionNode>()); n = p.Nodes.Insert(node.Index, node.GetHashCode().ToString(), ((SectionNode)node).Label); } else { n = Nodes.Insert(node.Index, node.GetHashCode().ToString(), ((SectionNode)node).Label); } n.Tag = node; ChangeColorUsed(n, mProjectView.ColorSettings); } return(n); } }
// Determine what the selection will be after deletion private NodeSelection GetPostDeleteSelection(bool IsAutoPageGenerationInvoked) { ObiNode node = null; if (mNode is SectionNode) { if (View.Selection.Control is ProjectView.ContentView) { // Select the next strip; if there is no next strip, select the previous one. node = ((SectionNode)mNode).FollowingSection; if (node == null) { node = ((SectionNode)mNode).PrecedingSection; } } else { // TODO: review this. ObiNode parent = mNode.ParentAs <ObiNode>(); int index = mNode.Index; node = index < parent.SectionChildCount - 1 ? (ObiNode)parent.SectionChild(index + 1) : index > 0 ? (ObiNode)parent.SectionChild(index - 1) : parent == View.Presentation.RootNode ? null : parent; } } else { SectionNode parent = mNode.ParentAs <SectionNode>(); int index = mNode.Index; // Select the next sibling; // if last child, select the previous sibling; // if first child, select the parent. node = index < parent.PhraseChildCount - 1 ? (ObiNode)parent.PhraseChild(index + 1) : index > 0 ? (ObiNode)parent.PhraseChild(index - 1) : (ObiNode)parent; if (IsAutoPageGenerationInvoked && node != null && node is EmptyNode) { while (node.Parent == parent && (!(node is PhraseNode) || (node is PhraseNode && ((node as PhraseNode).Role_ == PhraseNode.Role.Page)) && node is EmptyNode)) { if (node.PrecedingNode != null) { node = node.PrecedingNode; } else { break; } } } } return(node == null ? null : new NodeSelection(node, View.Selection.Control)); }
private int mIndex; // index of the node that we actually want to delete public DeleteWithOffset(ProjectView.ProjectView view, ObiNode node, int offset) : base(view) { mNode = node; mParent = node.ParentAs <ObiNode>(); mDeleted = null; mIndex = mParent.Children.IndexOf(mNode) + offset; }
// Determine what the selection will be after deletion private NodeSelection GetPostDeleteSelection() { ObiNode node = null; if (mNode is SectionNode) { if (View.Selection.Control is ProjectView.ContentView) { // Select the next strip; if there is no next strip, select the previous one. node = ((SectionNode)mNode).FollowingSection; if (node == null) { node = ((SectionNode)mNode).PrecedingSection; } } else { // TODO: review this. ObiNode parent = mNode.ParentAs <ObiNode>(); int index = mNode.Index; node = index < parent.SectionChildCount - 1 ? (ObiNode)parent.SectionChild(index + 1) : index > 0 ? (ObiNode)parent.SectionChild(index - 1) : parent == View.Presentation.RootNode ? null : parent; } } else { SectionNode parent = mNode.ParentAs <SectionNode>(); int index = mNode.Index; // Select the next sibling; // if last child, select the previous sibling; // if first child, select the parent. node = index < parent.PhraseChildCount - 1 ? (ObiNode)parent.PhraseChild(index + 1) : index > 0 ? (ObiNode)parent.PhraseChild(index - 1) : (ObiNode)parent; } return(node == null ? null : new NodeSelection(node, View.Selection.Control)); }
/// <summary> /// Add an existing node to its parent at its index. /// </summary> public AddNode(ProjectView.ProjectView view, ObiNode node) : this(view, node, node.ParentAs <ObiNode>(), node.Index) { }
/// <summary> /// Create the phrase detection command. /// </summary> public static CompositeCommand GetPhraseDetectionCommand(ProjectView.ProjectView view, ObiNode node, long threshold, double gap, double before, bool mergeFirstTwoPhrases, ObiPresentation presentation = null) { List <PhraseNode> phraseNodesList = new List <PhraseNode> (); if (node is PhraseNode) { phraseNodesList.Add((PhraseNode)node); } else if (node is SectionNode) { SectionNode section = (SectionNode)node; for (int i = 0; i < section.PhraseChildCount; i++) { if (section.PhraseChild(i) is PhraseNode && ((PhraseNode)section.PhraseChild(i)).Role_ != EmptyNode.Role.Silence) { phraseNodesList.Add((PhraseNode)section.PhraseChild(i)); } } } List <List <PhraseNode> > phrasesToMerge = new List <List <PhraseNode> >(); CompositeCommand command = null; if (view.Presentation == null && presentation != null) { command = presentation.CreateCompositeCommand(Localizer.Message("phrase_detection")); } else { command = view.Presentation.CreateCompositeCommand(Localizer.Message("phrase_detection")); } // if phrase is selected but phrase detection node is section,select section if (node is SectionNode && view.GetSelectedPhraseSection != null && view.GetSelectedPhraseSection == node) { command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(node, view.Selection.Control))); } ObiNode parent = node is SectionNode ? node : node.ParentAs <ObiNode> (); int index = 0; if (phraseNodesList.Count > 0) { view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), 0); } for (int j = 0; j < phraseNodesList.Count; j++) { PhraseNode phrase = phraseNodesList[j]; if (j == 0) { index = phrase.Index + 1; } System.Collections.Generic.List <PhraseNode> phrases = null; if (view.Presentation == null && presentation != null) { phrases = presentation.CreatePhraseNodesFromAudioAssetList( Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before)); } else { phrases = view.Presentation.CreatePhraseNodesFromAudioAssetList( Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before)); } for (int i = 0; i < phrases.Count; ++i) { // Copy page/heading role for the first phrase only if (i == 0 || (phrase.Role_ != EmptyNode.Role.Page && phrase.Role_ != EmptyNode.Role.Heading)) { phrases[i].CopyAttributes(phrase); } phrases[i].Used = phrase.Used; phrases[i].TODO = phrase.TODO; if (i == 0 && phrase.TODO && (phrase as EmptyNode).CommentText != null) { (phrases[i] as EmptyNode).CommentText = (phrase as EmptyNode).CommentText; } if (phrases[i].Role_ == EmptyNode.Role.Heading && i > 0) { phrases[i].Role_ = EmptyNode.Role.Plain; } // in following add node constructor, update selection is made false, to improve performance (19 may, 2010) command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, phrases[i], parent, index, false)); index++; } // add first 2 phrases to the list if the merge flag is true if (phrases.Count >= 2 && mergeFirstTwoPhrases && phrases[0] is PhraseNode && phrases [1] is PhraseNode) { List <PhraseNode> mergeList = new List <PhraseNode>(); mergeList.Add(phrases[0]); mergeList.Add(phrases[1]); phrasesToMerge.Add(mergeList); } if (node is PhraseNode && phrases.Count > 0 && view.Selection != null) { //command.append ( new UpdateSelection ( view, new NodeSelection ( node, view.Selection.Control ) ) ); command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(phrases[0], view.Selection.Control))); //uncommenting this because unexecute for update selection can handle null unexecute now } Commands.Node.Delete deleteCmd = new Commands.Node.Delete(view, phrase, false); command.ChildCommands.Insert(command.ChildCommands.Count, deleteCmd);//@singleSection: moved delete command last for improve undo selection if (Obi.Audio.PhraseDetection.CancelOperation) { break; } // skip to next indexes if the two consequtive phrases in phrase list are not consequitive according to phrase index in the parent section if (j < phraseNodesList.Count - 1 && phrase.Index + 1 < phraseNodesList[j + 1].Index) { EmptyNode empty = null; for (int i = phrase.Index + 1; i < phraseNodesList[j + 1].Index; ++i) { empty = phrase.ParentAs <SectionNode>().PhraseChild(i); command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.Delete(view, empty, false)); command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, empty, parent, index, false)); index++; } //index = index + (phraseNodesList[j + 1].Index - (phrase.Index + 1)); } view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), (100 * j) / phraseNodesList.Count); } if (phrasesToMerge.Count > 0) { for (int i = 0; i < phrasesToMerge.Count; i++) { List <PhraseNode> mergeList = phrasesToMerge[i]; Commands.Node.MergeAudio mergeCmd = new MergeAudio(view, mergeList[0], mergeList[1]); mergeCmd.UpdateSelection = false; command.ChildCommands.Insert(command.ChildCommands.Count, mergeCmd); } } return(command); }
private int mIndex; // its original index /// <summary> /// Create a new delete section command from a view. /// </summary> public Delete(ProjectView.ProjectView view, ObiNode node, string label) : this(view, node, node.ParentAs <ObiNode>(), node.Index, true) { SetDescriptions(label); }
private int mIndex; // its original index /// <summary> /// Create a new delete section command from a view. /// </summary> public Delete(ProjectView.ProjectView view, ObiNode node, string label, bool IsAutoPageGenerationInvoked = false) : this(view, node, node.ParentAs <ObiNode>(), node.Index, true, IsAutoPageGenerationInvoked) { SetDescriptions(label); }