/// <summary> /// Constructs the TreeNodeSample <see cref="Project"/> /// </summary> /// <returns>The project</returns> public static Project CreateTreeNodeTestSampleProject() { Uri projDir = new Uri(ProjectTests.SampleXukFileDirectoryUri, "TreeNodeTestsSample/"); Project proj = new Project(); Presentation pres = proj.AddNewPresentation(); pres.RootUri = projDir; if (Directory.Exists(Path.Combine(projDir.LocalPath, "Data"))) { try { Directory.Delete(Path.Combine(projDir.LocalPath, "Data"), true); } catch (Exception e) { // Added by Julien as the deletion sometimes fails (?) System.Diagnostics.Debug.Print("Oops, could not delete directory {0}: {1}", Path.Combine(projDir.LocalPath, "Data"), e.Message); } } pres.MediaDataManager.DefaultPCMFormat = new PCMFormatInfo(1, 22050, 16); Channel audioChannel = pres.ChannelFactory.CreateAudioChannel(); audioChannel.Name = "channel.audio"; Channel textChannel = pres.ChannelFactory.CreateTextChannel(); textChannel.Name = "channel.text"; TreeNode mRootNode = proj.Presentations.Get(0).RootNode; Assert.IsNotNull(mRootNode, "The mRootNode node of the newly created Presentation is null"); mRootNode.AppendChild(CreateTreeNode(pres, "SamplePDTB2.wav", "Sample PDTB V2")); TreeNode node = pres.TreeNodeFactory.Create(); mRootNode.AppendChild(node); node.AppendChild(CreateTreeNode(pres, "Section1.wav", "Section 1")); TreeNode subNode = pres.TreeNodeFactory.Create(); node.AppendChild(subNode); subNode.AppendChild(CreateTreeNode(pres, "ParagraphWith.wav", "Paragraph with")); subNode.AppendChild(CreateTreeNode(pres, "Emphasis.wav", "emphasis")); subNode.AppendChild(CreateTreeNode(pres, "And.wav", "and")); subNode.AppendChild(CreateTreeNode(pres, "PageBreak.wav", "page break")); return(proj); }
public void InsertBefore_NonChildAnchor() { TreeNode newNode = mPresentation.TreeNodeFactory.Create(); TreeNode rootChild = mPresentation.TreeNodeFactory.Create(); TreeNode anchorNode = mPresentation.TreeNodeFactory.Create(); mRootNode.AppendChild(rootChild); rootChild.AppendChild(anchorNode); mRootNode.InsertBefore(anchorNode, newNode); }
public void InsertAfter_nonChildAnchor() { TreeNode newNode = mPresentation.TreeNodeFactory.Create(); TreeNode mRootNodeChild = mPresentation.TreeNodeFactory.Create(); TreeNode anchorNode = mPresentation.TreeNodeFactory.Create(); mRootNode.AppendChild(mRootNodeChild); mRootNodeChild.AppendChild(anchorNode); mRootNode.InsertAfter(anchorNode, newNode); }
public void RemoveChild_NonChild() { TreeNode rootChild = mPresentation.TreeNodeFactory.Create(); mRootNode.AppendChild(rootChild); TreeNode newNode = mPresentation.TreeNodeFactory.Create(); rootChild.AppendChild(newNode); mRootNode.RemoveChild(newNode); }
public void IndexOf_NonChild() { TreeNode rootChild = mPresentation.TreeNodeFactory.Create(); mRootNode.AppendChild(rootChild); TreeNode newNode = mPresentation.TreeNodeFactory.Create(); rootChild.AppendChild(newNode); int index = mRootNode.Children.IndexOf(newNode); Assert.That(index == -1); }
public void Changed_BubblesFromChildren() { TreeNode child = mRootNode.Children.Get(0); events.DataModelChangedEventArgs childChangedEventArgs = null; object childChangedSender = null; EventHandler <urakawa.events.DataModelChangedEventArgs> handler = new EventHandler <urakawa.events.DataModelChangedEventArgs>( delegate(object sender, events.DataModelChangedEventArgs e) { childChangedEventArgs = e; childChangedSender = sender; }); child.Changed += handler; try { int beforeCount = mChangedEventCount; child.AppendChild(mPresentation.TreeNodeFactory.Create()); Assert.IsNotNull(childChangedEventArgs, "The changed event of the child does not seem to have occured"); Assert.AreSame( child, childChangedSender, "The sender of the changed event on the child must be the child it self"); Assert.AreEqual( beforeCount + 1, mChangedEventCount, "The mChangedEventCount did not increase by one, indicating that the changed event on the parent/mRootNode TreeNode " + "did not occur as a result of the changed event on the child"); Assert.AreSame( childChangedEventArgs, mLatestChangedEventArgs, "The event args of the parent/mRootNode changed event was not the same instance as thoose of the child changed evnet"); Assert.AreSame( mRootNode, mLatestChangedSender, "The sender of the parent/mRootNode changed event must be the parent/mRootNode node itself"); } finally { child.Changed -= handler; } }
private void parseDTBookXmlDocAndPopulateDataModel(XmlNode xmlNode, core.TreeNode parentTreeNode) { XmlNodeType xmlType = xmlNode.NodeType; switch (xmlType) { case XmlNodeType.Attribute: { System.Diagnostics.Debug.Fail("Calling this method with an XmlAttribute should never happen !!"); break; } case XmlNodeType.Document: { parseDTBookXmlDocAndPopulateDataModel(((XmlDocument)xmlNode).DocumentElement, parentTreeNode); break; } case XmlNodeType.Element: { Presentation presentation = m_Project.GetPresentation(0); core.TreeNode treeNode = presentation.TreeNodeFactory.Create(); if (parentTreeNode == null) { presentation.RootNode = treeNode; parentTreeNode = presentation.RootNode; } else { parentTreeNode.AppendChild(treeNode); } XmlProperty xmlProp = presentation.PropertyFactory.CreateXmlProperty(); treeNode.AddProperty(xmlProp); xmlProp.LocalName = xmlNode.Name; if (xmlNode.ParentNode != null && xmlNode.ParentNode.NodeType == XmlNodeType.Document) { presentation.PropertyFactory.DefaultXmlNamespaceUri = xmlNode.NamespaceURI; } if (xmlNode.NamespaceURI != presentation.PropertyFactory.DefaultXmlNamespaceUri) { xmlProp.NamespaceUri = xmlNode.NamespaceURI; } XmlAttributeCollection attributeCol = xmlNode.Attributes; if (attributeCol != null) { for (int i = 0; i < attributeCol.Count; i++) { XmlNode attr = attributeCol.Item(i); if (attr.Name != "smilref") { xmlProp.SetAttribute(attr.Name, "", attr.Value); } } if (xmlNode.Name == "meta") { XmlNode attrName = attributeCol.GetNamedItem("name"); XmlNode attrContent = attributeCol.GetNamedItem("content"); if (attrName != null && attrContent != null && !String.IsNullOrEmpty(attrName.Value) && !String.IsNullOrEmpty(attrContent.Value)) { Metadata md = presentation.MetadataFactory.CreateMetadata(); md.Name = attrName.Value; md.Content = attrContent.Value; presentation.AddMetadata(md); } } } foreach (XmlNode childXmlNode in xmlNode.ChildNodes) { parseDTBookXmlDocAndPopulateDataModel(childXmlNode, treeNode); } break; } case XmlNodeType.Text: { Presentation presentation = m_Project.GetPresentation(0); string text = xmlNode.Value; TextMedia textMedia = presentation.MediaFactory.CreateTextMedia(); textMedia.Text = text; ChannelsProperty cProp = presentation.PropertyFactory.CreateChannelsProperty(); cProp.SetMedia(m_textChannel, textMedia); int counter = 0; foreach (XmlNode childXmlNode in xmlNode.ParentNode.ChildNodes) { XmlNodeType childXmlType = childXmlNode.NodeType; if (childXmlType == XmlNodeType.Text || childXmlType == XmlNodeType.Element) { counter++; } } if (counter == 1) { parentTreeNode.AddProperty(cProp); } else { core.TreeNode txtWrapperNode = presentation.TreeNodeFactory.Create(); txtWrapperNode.AddProperty(cProp); parentTreeNode.AppendChild(txtWrapperNode); } break; } default: { return; } } }