private int GetSectionDepth(SectionNode section) { int depth = 1; ObiNode parent = section.ParentAs <ObiNode> (); while (parent != mView.Presentation.RootNode) { section = (SectionNode)parent; parent = section.ParentAs <ObiNode>(); depth++; } //Console.WriteLine("section depth: " + depth); return(depth); }
// Fill in the fields of the view when the form is loaded. private void SectionProperties_Load(object sender, EventArgs e) { m_txtName.Text = mNode.Label; m_txtName.ReadOnly = mView.ObiForm.Settings.Project_ReadOnlyMode; int maxLevel = mNode.PrecedingSection == null ? 1 : mNode.PrecedingSection.Level + 1; for (int i = 1; i <= maxLevel; ++i) { m_comboLevel.Items.Add(i); } m_comboLevel.SelectedIndex = mNode.Level - 1; if (mNode.Level == 1) { m_lbParentsList.Items.Insert(0, Localizer.Message("top_level_section")); } else { for (SectionNode parent = mNode.ParentAs <SectionNode>(); parent != null; parent = parent.ParentAs <SectionNode>()) { m_lbParentsList.Items.Insert(0, string.Format(Localizer.Message("section_level"), parent.Label, parent.Level)); } } m_comboLevel.Enabled = !mView.ObiForm.Settings.Project_ReadOnlyMode; m_txtTimeLength.Text = Program.FormatDuration_Long(mNode.Duration); m_txtPhraseCount.Text = mNode.PhraseChildCount.ToString(); m_chkUsed.Checked = mNode.Used; for (ObiNode n = mNode.FirstLeaf; n != null && n.FollowingNode != null; n = n.FollowingNode) { if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Page) { if (m_txtPagesInSection.Text.Trim() == string.Empty) { m_txtPagesInSection.Text += "#" + ((EmptyNode)n).PageNumber.ToString(); } else { m_txtPagesInSection.Text += ", #" + ((EmptyNode)n).PageNumber.ToString(); } } if (n.Parent != n.FollowingNode.Parent) { break; } } if (mView != null && mView.Selection != null && mView.Selection.Node is SectionNode) { SectionNode secNode = (SectionNode)mView.Selection.Node; if (secNode != null && secNode.PrecedingNode != null && secNode.PrecedingSection is SectionNode) { CalculateSectionTime((SectionNode)secNode.PrecedingSection); } } m_txtSectionTimePosition.Text = Program.FormatDuration_Long(m_TotalSectionTime); }
/// <summary> /// Increase the level of the section. /// </summary> public static void Move(SectionNode section) { int index = section.Index + 1; SectionNode sibling = section.ParentAs <SectionNode>(); int children = sibling.SectionChildCount; for (int i = index; i < children; ++i) { SectionNode child = sibling.SectionChild(index); child.Detach(); section.AppendChild(child); } section.Detach(); sibling.ParentAs <ObiNode>().InsertAfter(section, sibling); }
// Fill in the fields of the view when the form is loaded. private void SectionProperties_Load(object sender, EventArgs e) { m_txtName.Text = mNode.Label; int maxLevel = mNode.PrecedingSection == null ? 1 : mNode.PrecedingSection.Level + 1; for (int i = 1; i <= maxLevel; ++i) { m_comboLevel.Items.Add(i); } m_comboLevel.SelectedIndex = mNode.Level - 1; if (mNode.Level == 1) { m_lbParentsList.Items.Insert(0, Localizer.Message("top_level_section")); } else { for (SectionNode parent = mNode.ParentAs <SectionNode>(); parent != null; parent = parent.ParentAs <SectionNode>()) { m_lbParentsList.Items.Insert(0, string.Format(Localizer.Message("section_level"), parent.Label, parent.Level)); } } m_txtTimeLength.Text = Program.FormatDuration_Long(mNode.Duration); m_txtPhraseCount.Text = mNode.PhraseChildCount.ToString(); m_chkUsed.Checked = mNode.Used; if (mView != null && mView.Selection != null && mView.Selection.Node is SectionNode) { SectionNode secNode = (SectionNode)mView.Selection.Node; if (secNode != null && secNode.PrecedingNode != null && secNode.PrecedingSection is SectionNode) { CalculateSectionTime((SectionNode)secNode.PrecedingSection); } } m_txtSectionTimePosition.Text = Program.FormatDuration_Long(m_TotalSectionTime); }
// Fill out the fields when the form loads. private void PhraseProperties_Load(object sender, EventArgs e) { m_txtParentSection.Text = mNode.AncestorAs <SectionNode>().Label; m_txtLocationInsideSection.Text = string.Format(Localizer.Message("node_position"), mNode.Index + 1, mNode.ParentAs <ObiNode>().PhraseChildCount); for (SectionNode parent = mNode.AncestorAs <SectionNode>(); parent != null; parent = parent.ParentAs <SectionNode>()) { m_lbParentsList.Items.Insert(0, string.Format(Localizer.Message("section_level"), parent.Label, parent.Level)); } m_txtTimeLength.Text = Program.FormatDuration_Long(mNode.Duration); // SectionNode section = mView.Selection.Node.ParentAs<SectionNode>(); if (mView != null && mView.Selection != null && mView.Selection.Node is PhraseNode) { PhraseNode phraseNode = (PhraseNode)mView.Selection.Node; if (mView.Selection is AudioSelection) { if (((AudioSelection)mView.Selection).AudioRange != null && ((AudioSelection)mView.Selection).AudioRange.HasCursor) { if (!m_IsPause) { m_TotalCursorTime += ((AudioSelection)mView.Selection).AudioRange.CursorTime; } } } if (m_IsPause) { m_TotalCursorTime += mView.TransportBar.CurrentPlaylist.CurrentTimeInAsset; m_IsPause = false; } if (phraseNode.PrecedingNode != null && phraseNode.PrecedingNode is PhraseNode && phraseNode.Parent == phraseNode.PrecedingNode.Parent) { CalculateCursorTime((PhraseNode)phraseNode.PrecedingNode); } if (phraseNode.Parent is SectionNode) { if (((SectionNode)phraseNode.Parent).PrecedingSection != null) { CalculateSectionTime(((SectionNode)phraseNode.Parent).PrecedingSection); } } //SectionNode secNode = (SectionNode)mView.Selection.Node; //if (secNode != null) //{ // CalculateCursorTime((SectionNode)secNode.PrecedingNode); //} } // m_txtCurrentCursorPosition.Text = mView.TransportBar.CalculateTimeElapsedInSectionForProperties().ToString(); m_txtCurrentCursorPosition.Text = Program.FormatDuration_Long(m_TotalCursorTime); if (mView.CanAssignHeadingRole || mNode.Role_ == EmptyNode.Role.Heading) { m_comboPhraseRole.Items.Add(EmptyNode.LOCALIZED_HEADING); } if (mView.CanAssignARole || mNode.Role_ == EmptyNode.Role.Page) { m_comboPhraseRole.Items.Add(EmptyNode.LOCALIZED_PAGE); } if (mView.CanAssignPlainRole || mNode.Role_ == EmptyNode.Role.Plain) { m_comboPhraseRole.Items.Add(EmptyNode.LOCALIZED_PLAIN); } if (mView.CanAssignSilenceRole || mNode.Role_ == EmptyNode.Role.Silence) { m_comboPhraseRole.Items.Add(EmptyNode.LOCALIZED_SILENCE); } if (mView.CanAssignAnchorRole || mNode.Role_ == EmptyNode.Role.Anchor) { m_comboPhraseRole.Items.Add(EmptyNode.LOCALIZED_ANCHOR); } if (mView.CanAssignARole) { m_comboPhraseRole.Items.Add(EmptyNode.LOCALIZED_CUSTOM); } m_comboPhraseRole.SelectedItem = EmptyNode.LocalizedRoleFor(mNode.Role_); // load custom class combobox foreach (string customType in mView.Presentation.CustomClasses) { m_comboCustomClassName.Items.Add(customType); } m_comboCustomClassName.Text = mNode.Role_ == EmptyNode.Role.Custom ? mNode.CustomRole : ""; m_chkUsed.Checked = mNode.Used; m_chkToDo.Checked = mNode.TODO; if (mNode.Role_ == EmptyNode.Role.Page) { m_lblPageNumberDetails.Visible = true; m_txtPageNumberDetails.AccessibleName = m_lblPageNumberDetails.Text.Replace("&", ""); m_txtPageNumberDetails.Visible = true; m_txtPageNumberDetails.Text = mNode.PageNumber.Kind.ToString() + ", #" + mNode.PageNumber.ToString(); m_chkChangePageNumber.Visible = true; } else if (mNode.Role_ == EmptyNode.Role.Anchor) { m_lbl_ReferredNote.Visible = true; m_txtPageNumberDetails.AccessibleName = m_lbl_ReferredNote.Text.Replace("&", ""); m_txtPageNumberDetails.Visible = true; m_txtPageNumberDetails.Text = mNode.AssociatedNode != null?mNode.AssociatedNode.ParentAs <SectionNode>().Label + ", " + mNode.AssociatedNode.ToString() : "?"; } EnableCustomClassField(); if (m_IsSetCustomClass) { SetCustomClassOnLoad(); } }
/// <summary> /// Check whether a (possibly null) section can be moved out. /// </summary> public static bool CanMoveNode(SectionNode section) { return(section != null && section.ParentAs <SectionNode>() != null && section.SectionChildCount == 0); }