private string filename; // original filename public ImportAudio(View.ProjectView view, urakawa.core.TreeNode node, string filename) : base(view) { this.trackNode = node; this.filename = filename; this.audioNode = view.Project.CreateAudioNode(filename); this.selectionAfter = new NodeSelection(view, this.audioNode); }
/// <summary> /// Constructor setting the source <see cref="Presentation"/> of the event /// and the previous+new root node /// </summary> /// <param name="source">The source <see cref="Presentation"/> of the event </param> /// <param name="newRoot">The new root node</param> /// <param name="prevRoot">The root node prior to the change</param> public RootNodeChangedEventArgs(Presentation source, urakawa.core.TreeNode newRoot, urakawa.core.TreeNode prevRoot) : base(source) { NewRootNode = newRoot; PreviousRootNode = prevRoot; }
// Reflect changes in the presentation (added or deleted nodes) private void Presentation_changed(object sender, urakawa.events.DataModelChangedEventArgs e) { urakawa.core.TreeNode changedNode = null; if (e is ObjectAddedEventArgs <urakawa.core.TreeNode> ) { TreeNodeAdded((ObjectAddedEventArgs <urakawa.core.TreeNode>)e); changedNode = ((ObjectAddedEventArgs <urakawa.core.TreeNode>)e).m_AddedObject; } else if (e is ObjectRemovedEventArgs <urakawa.core.TreeNode> ) { TreeNodeRemoved((ObjectRemovedEventArgs <urakawa.core.TreeNode>)e); changedNode = ((ObjectRemovedEventArgs <urakawa.core.TreeNode>)e).m_RemovedObject; } else if (mProjectView.ObiForm.Settings.Project_BackgroundColorForEmptySection && e is urakawa.events.media.data.audio.AudioDataInsertedEventArgs) { TreeNode TreeNode = FindTreeNodeWithoutLabel((SectionNode)m_HighlightedSectionNodeWithoutSelection); if (TreeNode.BackColor == mProjectView.ObiForm.Settings.ColorSettings.EmptySectionBackgroundColor) { TreeNode.BackColor = mProjectView.ColorSettings.HighlightedSectionNodeWithoutSelectionColor; TreeNode.ForeColor = SystemColors.ControlText; } } if (changedNode != null && (changedNode is SectionNode || changedNode is EmptyNode) && ((ObiNode)changedNode).IsRooted) // @emptysectioncolor { PaintColorForEmptySection(changedNode is SectionNode ? (SectionNode)changedNode : ((EmptyNode)changedNode).ParentAs <SectionNode>(), false); } }
private void parseContentDocuments(List <string> spineOfContentDocuments) { if (spineOfContentDocuments == null || spineOfContentDocuments.Count <= 0) { return; } //DirectoryInfo opfParentDir = Directory.GetParent(m_Book_FilePath); //string dirPath = opfParentDir.ToString(); string dirPath = Path.GetDirectoryName(m_Book_FilePath); bool first = true; foreach (string docPath in spineOfContentDocuments) { string fullDocPath = Path.Combine(dirPath, docPath); XmlDocument xmlDoc = readXmlDocument(fullDocPath); parseMetadata(xmlDoc); //XmlNodeList listOfBodies = xmlDoc.GetElementsByTagName("body"); //if (listOfBodies.Count == 0) //{ // listOfBodies = xmlDoc.GetElementsByTagName("book"); //} XmlNode bodyElement = getFirstChildElementsWithName(xmlDoc, true, "body", null); if (bodyElement == null) { bodyElement = getFirstChildElementsWithName(xmlDoc, true, "book", null); } if (bodyElement == null) { continue; } if (first) { Presentation presentation = m_Project.Presentations.Get(0); XmlProperty xmlProp = presentation.PropertyFactory.CreateXmlProperty(); xmlProp.LocalName = "book"; presentation.PropertyFactory.DefaultXmlNamespaceUri = bodyElement.NamespaceURI; xmlProp.NamespaceUri = presentation.PropertyFactory.DefaultXmlNamespaceUri; TreeNode treeNode = presentation.TreeNodeFactory.Create(); treeNode.AddProperty(xmlProp); presentation.RootNode = treeNode; first = false; } foreach (XmlNode childOfBody in bodyElement.ChildNodes) { parseContentDocument(childOfBody, m_Project.Presentations.Get(0).RootNode, fullDocPath); } } }
// Add a new node (track or audio) to the view private void AddNode(urakawa.core.TreeNode node) { if (node is TrackNode) { AddTrack(node); } else if (node is AudioNode) { AddAudioBlock(node); } }
/// <summary> /// Select (or deselect) the control corresponding to the given node. /// </summary> public void SelectControlForNode(urakawa.core.TreeNode node, Selection selection) { Track track = FindTrack(node); if (node is TrackNode) { track.Selection = selection; } else if (node is AudioNode) { track.FindBlock((AudioNode)node).Selection = selection; } }
// Find the track for a given node private Track FindTrack(urakawa.core.TreeNode node) { urakawa.core.TreeNode actual = node is AudioNode?node.getParent() : node; foreach (Control c in Controls) { if (c is Track && ((Track)c).Node == actual) { return((Track)c); } } return(null); }
// Add a new audio block to the project (thread-safe) private void AddAudioBlock(urakawa.core.TreeNode node) { if (InvokeRequired) { Invoke(new AddDelegate(AddAudioBlock), node); } else { SuspendLayout(); Track t = FindTrack(node); t.AddAudioBlock(new AudioBlock((AudioNode)node)); t.Zoom = this.zoom; ResumeLayout(); } }
/// <summary> /// The selection is replaced from the project. The corresponding selectable item is selected. /// </summary> public void SelectNode(urakawa.core.TreeNode node) { if (!nodeMap.ContainsKey(node)) { throw new Exception("No control for node!"); } Selectable s = nodeMap[node] as Selectable; if (s == null) { throw new Exception("Control is not selectable!"); } ReplaceSelection(s); s.Selected = true; }
// Add a new track to the project (thread-safe) private void AddTrack(urakawa.core.TreeNode node) { if (InvokeRequired) { Invoke(new AddDelegate(AddTrack), node); } else { if (node is TrackNode) { SuspendLayout(); Track t = new Track((TrackNode)node); t.Zoom = this.zoom; t.Colors = Colors; Controls.Add(t); SetFlowBreak(t, true); ResumeLayout(); } } }
/// <summary> /// Create a new audio node by importing data from a file. /// </summary> public urakawa.core.TreeNode CreateAudioNode(string filename) { urakawa.Presentation p = getPresentation(0); urakawa.core.TreeNode node = p.getTreeNodeFactory().createNode(typeof(AudioNode).Name, DataModelFactory.NS); // Update the media data manager to accept this type of file if (!p.getMediaDataManager().getEnforceSinglePCMFormat()) { System.IO.FileStream audioStream = System.IO.File.OpenRead(filename); urakawa.media.data.audio.PCMDataInfo info = urakawa.media.data.audio.PCMDataInfo.parseRiffWaveHeader(audioStream); audioStream.Close(); p.getMediaDataManager().setDefaultPCMFormat(info); p.getMediaDataManager().setEnforceSinglePCMFormat(true); } // I'll go ahead and not comment this part urakawa.media.data.audio.AudioMediaData audio = p.getMediaDataFactory().createAudioMediaData(); audio.appendAudioDataFromRiffWave(filename); urakawa.media.data.audio.ManagedAudioMedia media = (urakawa.media.data.audio.ManagedAudioMedia)p.getMediaFactory().createAudioMedia(); media.setMediaData(audio); urakawa.property.channel.ChannelsProperty prop = p.getPropertyFactory().createChannelsProperty(); prop.setMedia(FindChannel("bobi.audio"), media); node.addProperty(prop); return(node); }
private void parseContentDocument(XmlNode xmlNode, TreeNode parentTreeNode, string filePath) { 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: { //XmlNodeList listOfBodies = ((XmlDocument)xmlNode).GetElementsByTagName("body"); //if (listOfBodies.Count == 0) //{ // listOfBodies = ((XmlDocument)xmlNode).GetElementsByTagName("book"); //} XmlNode bodyElement = getFirstChildElementsWithName(xmlNode, true, "body", null); if (bodyElement == null) { bodyElement = getFirstChildElementsWithName(xmlNode, true, "book", null); } if (bodyElement != null) { Presentation presentation = m_Project.Presentations.Get(0); presentation.PropertyFactory.DefaultXmlNamespaceUri = bodyElement.NamespaceURI; // preserve internal DTD if it exists in dtbook string strInternalDTD = ExtractInternalDTD(((XmlDocument)xmlNode).DocumentType); if (strInternalDTD != null) { File.WriteAllText( Path.Combine(presentation.DataProviderManager.DataFileDirectoryFullPath, "DTBookLocalDTD.dtd"), strInternalDTD); } parseContentDocument(bodyElement, parentTreeNode, filePath); } //parseContentDocument(((XmlDocument)xmlNode).DocumentElement, parentTreeNode); break; } case XmlNodeType.Element: { Presentation presentation = m_Project.Presentations.Get(0); 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.LocalName; if (xmlNode.ParentNode != null && xmlNode.ParentNode.NodeType == XmlNodeType.Document) { presentation.PropertyFactory.DefaultXmlNamespaceUri = xmlNode.NamespaceURI; } if (xmlNode.NamespaceURI != presentation.PropertyFactory.DefaultXmlNamespaceUri) { xmlProp.NamespaceUri = xmlNode.NamespaceURI; } string updatedSRC = null; if (xmlNode.LocalName == "img") { XmlNode getSRC = xmlNode.Attributes.GetNamedItem("src"); if (getSRC != null) { string relativePath = xmlNode.Attributes.GetNamedItem("src").Value; if (!relativePath.StartsWith("http://")) { string parentPath = Directory.GetParent(filePath).FullName; string imgSourceFullpath = Path.Combine(parentPath, relativePath); string datafilePath = presentation.DataProviderManager.DataFileDirectoryFullPath; string imgDestFullpath = Path.Combine(datafilePath, Path.GetFileName(imgSourceFullpath)); if (!File.Exists(imgDestFullpath)) { //File.Delete(imgDestFullpath); File.Copy(imgSourceFullpath, imgDestFullpath); } updatedSRC = presentation.RootUri.MakeRelativeUri(new Uri(imgDestFullpath, UriKind.Absolute)) .ToString(); //string dirPath = Path.GetDirectoryName(presentation.RootUri.LocalPath); //updatedSRC = presentation.DataProviderManager.DataFileDirectory + Path.DirectorySeparatorChar + Path.GetFileName(imgDestFullpath); ChannelsProperty chProp = presentation.PropertyFactory.CreateChannelsProperty(); treeNode.AddProperty(chProp); ExternalImageMedia externalImage = presentation.MediaFactory.CreateExternalImageMedia(); externalImage.Src = updatedSRC; chProp.SetMedia(m_ImageChannel, externalImage); } } } XmlAttributeCollection attributeCol = xmlNode.Attributes; if (attributeCol != null) { for (int i = 0; i < attributeCol.Count; i++) { XmlNode attr = attributeCol.Item(i); if (attr.LocalName != "smilref" && attr.Name != "xmlns:xsi" && attr.Name != "xml:space") { if (updatedSRC != null && attr.LocalName == "src") { xmlProp.SetAttribute(attr.LocalName, "", updatedSRC); } else { if (attr.LocalName == "xmlns") { if (attr.Value != presentation.PropertyFactory.DefaultXmlNamespaceUri) { xmlProp.SetAttribute(attr.LocalName, "", attr.Value); } } else if (string.IsNullOrEmpty(attr.NamespaceURI) || attr.NamespaceURI == presentation.PropertyFactory.DefaultXmlNamespaceUri) { xmlProp.SetAttribute(attr.LocalName, "", attr.Value); } else { xmlProp.SetAttribute(attr.Name, attr.NamespaceURI, attr.Value); } } } } } foreach (XmlNode childXmlNode in xmlNode.ChildNodes) { parseContentDocument(childXmlNode, treeNode, filePath); } break; } case XmlNodeType.Text: { Presentation presentation = m_Project.Presentations.Get(0); string text = trimXmlText(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 { TreeNode txtWrapperNode = presentation.TreeNodeFactory.Create(); txtWrapperNode.AddProperty(cProp); parentTreeNode.AppendChild(txtWrapperNode); } break; } default: { return; } } }
private urakawa.core.TreeNode node; // node for the new track public NewTrack(View.ProjectView view) : base(view) { this.node = getPresentation().getTreeNodeFactory().createNode(typeof(TrackNode).Name, DataModelFactory.NS); this.selectionAfter = new NodeSelection(view, this.node); }
public override bool ContainsNode(urakawa.core.TreeNode node) { return(this.node == node); }
public abstract bool ContainsNode(urakawa.core.TreeNode node);
/// <summary> /// Add a node to the selection. /// </summary> public void AddNode(urakawa.core.TreeNode node) { this.nodes.Add(node); }
/// <summary> /// Create a single node selection. /// </summary> public NodeSelection(View.ProjectView view, urakawa.core.TreeNode node) : this(view) { AddNode(node); }
// to do regenerate ids private void CreateDTBookDocument() { // check if there is preserved internal DTD string [] dtbFilesList = Directory.GetFiles(m_Presentation.DataProviderManager.DataFileDirectoryFullPath, "DTBookLocalDTD.dtd", SearchOption.AllDirectories); string strInternalDTD = null; if (dtbFilesList.Length > 0) { strInternalDTD = File.ReadAllText(dtbFilesList[0]); if (strInternalDTD.Trim() == "") { strInternalDTD = null; } } XmlDocument DTBookDocument = CreateStub_DTBDocument(strInternalDTD); m_ListOfLevels = new List <urakawa.core.TreeNode>(); Dictionary <string, string> old_New_IDMap = new Dictionary <string, string> (); List <XmlAttribute> referencingAttributesList = new List <XmlAttribute> (); m_FilesList_Image = new List <string>(); // add metadata XmlNode headNode = getFirstChildElementsWithName(DTBookDocument, true, "head", null); //DTBookDocument.GetElementsByTagName("head")[0] Metadata mdId = AddMetadata_DtbUid(false, DTBookDocument, headNode); AddMetadata_Generator(DTBookDocument, headNode); // todo: filter-out unecessary metadata for DTBOOK (e.g. dtb:multimediatype) foreach (urakawa.metadata.Metadata m in m_Presentation.Metadatas.ContentsAs_YieldEnumerable) { if (mdId == m) { continue; } XmlNode metaNode = DTBookDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(metaNode); string name = m.NameContentAttribute.Name; if (name.Contains(":")) { // split the metadata name and make first alphabet upper, required for daisy 3.0 string splittedName = name.Split(':')[1]; splittedName = splittedName.Substring(0, 1).ToUpper() + splittedName.Remove(0, 1); name = name.Split(':')[0] + ":" + splittedName; } CommonFunctions.CreateAppendXmlAttribute(DTBookDocument, metaNode, "name", name); CommonFunctions.CreateAppendXmlAttribute(DTBookDocument, metaNode, "content", m.NameContentAttribute.Value); // add metadata optional attributes if any foreach (urakawa.metadata.MetadataAttribute ma in m.OtherAttributes.ContentsAs_YieldEnumerable) { if (ma.Name == "id") { continue; } CommonFunctions.CreateAppendXmlAttribute(DTBookDocument, metaNode, ma.Name, ma.Value); } } // add elements to book body m_TreeNode_XmlNodeMap = new Dictionary <urakawa.core.TreeNode, XmlNode>(); urakawa.core.TreeNode rNode = m_Presentation.RootNode; XmlNode bookNode = getFirstChildElementsWithName(DTBookDocument, true, "book", null); //DTBookDocument.GetElementsByTagName("book")[0]; m_ListOfLevels.Add(m_Presentation.RootNode); m_TreeNode_XmlNodeMap.Add(rNode, bookNode); XmlNode currentXmlNode = null; rNode.AcceptDepthFirst( delegate(urakawa.core.TreeNode n) { // add to list of levels if xml property has level string //QualifiedName qName = n.GetXmlElementQName(); //if (qName != null && // (qName.LocalName.StartsWith("level") || qName.LocalName == "doctitle" || qName.LocalName == "docauthor")) //{ // m_ListOfLevels.Add(n); //} if (doesTreeNodeTriggerNewSmil(n)) { m_ListOfLevels.Add(n); } urakawa.property.xml.XmlProperty xmlProp = n.GetProperty <urakawa.property.xml.XmlProperty>(); if (xmlProp != null && xmlProp.LocalName == "book") { return(true); } if (xmlProp == null) { string txtx = n.GetTextMedia() != null ? n.GetTextMedia().Text : null; if (txtx != null) { XmlNode textNode = DTBookDocument.CreateTextNode(txtx); ExternalAudioMedia extAudio = GetExternalAudioMedia(n); if (extAudio == null) { m_TreeNode_XmlNodeMap[n.Parent].AppendChild(textNode); m_TreeNode_XmlNodeMap.Add(n, textNode); } else { Debug.Fail("TreeNode without XmlProperty but with TextMedia cannot have Audio attached to it ! (reason: at authoring time, an XmlProperty should have been added when audio was recorded for the pure-text TreeNode) => " + txtx); //XmlNode textParent = DTBookDocument.CreateElement(null, "sent", bookNode.NamespaceURI); //textParent.AppendChild(textNode); //m_TreeNode_XmlNodeMap[n.Parent].AppendChild(textParent); //m_TreeNode_XmlNodeMap.Add(n, textParent); } } return(true); } // create sml node in dtbook document // code removed because XmlProperty stores proper namespaces, useful for inline MathML, SVG, whatever... //string name = xmlProp.LocalName; //string prefix = name.Contains(":") ? name.Split(':')[0] : null; //string elementName = name.Contains(":") ? name.Split(':')[1] : name; //currentXmlNode = DTBookDocument.CreateElement(prefix, elementName, bookNode.NamespaceURI); currentXmlNode = DTBookDocument.CreateElement(null, xmlProp.LocalName, (string.IsNullOrEmpty(xmlProp.NamespaceUri) ? bookNode.NamespaceURI : xmlProp.NamespaceUri)); // add attributes if (xmlProp.Attributes != null && xmlProp.Attributes.Count > 0) { for (int i = 0; i < xmlProp.Attributes.Count; i++) { //todo: check ID attribute, normalize with fresh new list of IDs // (warning: be careful maintaining ID REFS, such as idref attributes for annotation/annoref and prodnote/noteref // (be careful because idref contain URIs with hash character), // and also the special imgref and headers attributes which contain space-separated list of IDs, not URIs) if (xmlProp.Attributes[i].LocalName == "id") { string id_New = GetNextID(ID_DTBPrefix); CommonFunctions.CreateAppendXmlAttribute(DTBookDocument, currentXmlNode, "id", id_New); if (!old_New_IDMap.ContainsKey(xmlProp.Attributes[i].Value)) { old_New_IDMap.Add(xmlProp.Attributes[i].Value, id_New); } else { System.Diagnostics.Debug.Fail("Duplicate ID found in original DTBook document", "Original DTBook document has duplicate ID: " + xmlProp.Attributes[i].Value); } } else { CommonFunctions.CreateAppendXmlAttribute(DTBookDocument, currentXmlNode, xmlProp.Attributes[i].LocalName, xmlProp.Attributes[i].Value); } } // for loop ends } // attribute nodes created // add id attribute in case it do not exists and it is required if (currentXmlNode.Attributes.GetNamedItem("id") == null && IsIDRequired(currentXmlNode.LocalName)) { CommonFunctions.CreateAppendXmlAttribute(DTBookDocument, currentXmlNode, "id", GetNextID(ID_DTBPrefix)); } // add text from text property string txt = n.GetTextMedia() != null ? n.GetTextMedia().Text : null; if (txt != null) { XmlNode textNode = DTBookDocument.CreateTextNode(txt); currentXmlNode.AppendChild(textNode); Debug.Assert(n.Children.Count == 0); } // add current node to its parent m_TreeNode_XmlNodeMap[n.Parent].AppendChild(currentXmlNode); // add nodes to dictionary m_TreeNode_XmlNodeMap.Add(n, currentXmlNode); // if current xmlnode is referencing node, add its referencing attribute to referencingAttributesList AddReferencingNodeToReferencedAttributesList(currentXmlNode, referencingAttributesList); // if QName is img and img src is on disk, copy it to output dir if (currentXmlNode.LocalName == "img") { XmlAttribute imgSrcAttribute = (XmlAttribute)currentXmlNode.Attributes.GetNamedItem("src"); if (imgSrcAttribute != null && (imgSrcAttribute.Value.StartsWith(m_Presentation.DataProviderManager.DataFileDirectory))) { string imgFileName = Path.GetFileName(imgSrcAttribute.Value); string sourcePath = Path.Combine(m_Presentation.DataProviderManager.DataFileDirectoryFullPath, Uri.UnescapeDataString(imgFileName)); string destPath = Path.Combine(m_OutputDirectory, Uri.UnescapeDataString(imgFileName)); if (File.Exists(sourcePath)) { if (!File.Exists(destPath)) { File.Copy(sourcePath, destPath); } imgSrcAttribute.Value = imgFileName; if (!m_FilesList_Image.Contains(imgFileName)) { m_FilesList_Image.Add(imgFileName); } } else { System.Diagnostics.Debug.Fail("source image not found", sourcePath); } } } return(true); }, delegate(urakawa.core.TreeNode n) { }); // set references to new ids foreach (XmlAttribute attr in referencingAttributesList) { string strIDToFind = attr.Value; if (strIDToFind.Contains("#")) { strIDToFind = strIDToFind.Split('#')[1]; } if (old_New_IDMap.ContainsKey(strIDToFind)) { string id_New = old_New_IDMap[strIDToFind]; attr.Value = "#" + id_New; } } m_DTBDocument = DTBookDocument; //CommonFunctions.WriteXmlDocumentToFile(DTBookDocument, // Path.Combine(m_OutputDirectory, m_Filename_Content)); }
/// <summary> /// Select a single track from below (i.e. a the track.) /// </summary> public void SelectFromBelow(urakawa.core.TreeNode node) { SelectFromBelow(new NodeSelection(this, node)); }