private MetadataSelection mSelectionAfter; // selection after the deletion public DeleteEntry(ProjectView.ProjectView view) : base(view) { mEntry = ((MetadataSelection)view.Selection).Item.Entry; mSelectionAfter = null; SetDescriptions(Localizer.Message("delete_metadata_entry")); }
//protected override void CreateProjectFileAndDirectory() //{ //if (!Directory.Exists(m_outDirectory)) //{ //Directory.CreateDirectory(m_outDirectory); //} //m_Xuk_FilePath = m_Session.Path; //} protected override void initializeProject(string path) { //m_Project = new Project(); m_Project = m_Session.Presentation.Project; #if false //(DEBUG) m_Project.PrettyFormat = true; #else m_Project.PrettyFormat = false; #endif //Presentation presentation = m_Project.AddNewPresentation(new Uri(m_outDirectory), Path.GetFileName(m_Book_FilePath)); m_Presentation = m_Session.Presentation; PCMFormatInfo pcmFormat = m_Presentation.MediaDataManager.DefaultPCMFormat.Copy(); pcmFormat.Data.SampleRate = (ushort)m_audioProjectSampleRate; m_Presentation.MediaDataManager.DefaultPCMFormat = pcmFormat; m_Presentation.MediaDataManager.EnforceSinglePCMFormat = true; //m_textChannel = m_Presentation.ChannelFactory.CreateTextChannel(); //m_textChannel.Name = "The Text Channel"; m_textChannel = m_Presentation.ChannelsManager.GetOrCreateTextChannel(); //m_audioChannel = m_Presentation.ChannelFactory.CreateAudioChannel(); //m_audioChannel.Name = "The Audio Channel"; m_audioChannel = m_Presentation.ChannelsManager.GetOrCreateAudioChannel(); m_TitleMetadata = m_Presentation.GetFirstMetadataItem(Metadata.DC_TITLE); m_IdentifierMetadata = m_Presentation.GetFirstMetadataItem(Metadata.DC_IDENTIFIER); m_XmlIdToSectionNodeMap = new Dictionary <string, SectionNode>(); m_XmlIdToPageNodeMap = new Dictionary <string, EmptyNode>(); }
public ModifyName(ProjectView.ProjectView view, urakawa.metadata.Metadata entry, string name) : base(view) { mEntry = entry; mPreviousName = mEntry.NameContentAttribute.Name; mNewName = name; SetDescriptions(Localizer.Message("modify_metadata_name")); }
public ModifyContent(ProjectView.ProjectView view, urakawa.metadata.Metadata entry, string content) : base(view) { mEntry = entry; //mPreviousContent = mEntry.getContent(); mPreviousContent = mEntry.NameContentAttribute.Value;//sdk2 mNewContent = content; SetDescriptions(Localizer.Message("modify_metadata_content")); }
private void AdaptMetadataAccordingToDAISYMetadata() { Dictionary <string, string> metadataNamesMap = new Dictionary <string, string> (); foreach (string name in Metadata.DAISY3MetadataNames) { metadataNamesMap.Add(name.ToLower(), name); } for (int i = 0; i < m_Presentation.Metadatas.Count; i++) { urakawa.metadata.Metadata md = m_Presentation.Metadatas.Get(i); if (md != null && md.NameContentAttribute != null && metadataNamesMap.ContainsKey(md.NameContentAttribute.Name)) { md.NameContentAttribute.Name = metadataNamesMap[md.NameContentAttribute.Name]; //Console.WriteLine(md.NameContentAttribute.Name); } } }
private void UpdateMetaDataListForContentChange(MetadataEventArgs e) { if (InvokeRequired) { Invoke(new UpdateMetadataInvokation(UpdateMetaDataListForContentChange), e); } else { if (e.Entry != null) { string entryName = e.Entry.NameContentAttribute.Name; for (int i = 0; i < mMetadataListView.Items.Count; i++) { if (mMetadataListView.Items[i].Tag != null) { urakawa.metadata.Metadata metadataObj = (urakawa.metadata.Metadata)mMetadataListView.Items[i].Tag; if (metadataObj.NameContentAttribute.Name == entryName) { mMetadataListView.Items[i].SubItems[1].Text = metadataObj.NameContentAttribute.Value; if (mSelection != null && mSelection.Item != null && mSelection.Item.Item != null) { mContentTextbox.Text = mSelection.Item.Item.SubItems[1].Text; } // check if custom entry at last of metadataListView is selected. // move selection to one item before so as to prevent user from adding more custom entries by pressing enter multiple times there. if (mMetadataListView.SelectedIndices.Count > 0 && mMetadataListView.SelectedIndices[0] == mMetadataListView.Items.Count - 1 && mMetadataListView.Items.Count > 1) { mMetadataListView.Items[mMetadataListView.Items.Count - 2].Selected = true; } break; } } } } } }
public void CreateFileSet() { List <SectionNode> sectionsList = ((ObiRootNode)m_Presentation.RootNode).GetListOfAllSections(); XmlDocument nccDocument = CreateNCCStubDocument(); // add metadatas XmlNode bodyNode = nccDocument.GetElementsByTagName("body")[0]; XmlNode paraNode = nccDocument.CreateElement("p", bodyNode.NamespaceURI); bodyNode.AppendChild(paraNode); XmlNode boldNode = nccDocument.CreateElement("b", bodyNode.NamespaceURI); paraNode.AppendChild(boldNode); boldNode.AppendChild(nccDocument.CreateTextNode("Book metadata:")); XmlNode ulNodeForMetadata = nccDocument.CreateElement("ul", bodyNode.NamespaceURI); paraNode.AppendChild(ulNodeForMetadata); List <string> metadataStringsList = new List <string>(); m_IdCounter = 0; //m_ExportedSectionCount = 0; XmlNode prevPageXmlNode = null; m_MaxDepth = 0; m_PageNormalCount = 0; for (int i = 0; i < sectionsList.Count; i++) { try { if (m_MaxDepth < sectionsList[i].Level) { m_MaxDepth = sectionsList[i].Level; } //if (Profile_VA) //{ //prevPageXmlNode = CreateElementsForSection(nccDocument, sectionsList[i], i, prevPageXmlNode); //} //else //{ CreateElementsForSection(nccDocument, sectionsList[i], i, null); //} } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } } // add metadata to top of the file urakawa.metadata.Metadata md = m_Presentation.GetFirstMetadataItem(Metadata.DC_TITLE); if (md != null) { metadataStringsList.Add("Title: " + md.NameContentAttribute.Value); } md = null; md = m_Presentation.GetFirstMetadataItem(Metadata.DC_IDENTIFIER); if (md != null) { metadataStringsList.Add("Identifier: " + md.NameContentAttribute.Value); } md = null; metadataStringsList.Add("Max. depth: " + m_MaxDepth.ToString()); metadataStringsList.Add("Normal page count : " + m_PageNormalCount.ToString()); foreach (string s in metadataStringsList) { XmlNode liNode = nccDocument.CreateElement("li", bodyNode.NamespaceURI); ulNodeForMetadata.AppendChild(liNode); liNode.AppendChild(nccDocument.CreateTextNode(s)); } if (Profile_VA) { //XmlNode bodyNode = nccDocument.GetElementsByTagName("body")[0]; int pageCounter = -1; List <XmlNode> nodesToRemove = new List <XmlNode>(); XmlNode lastPageNode = null; XmlNode prevHeading = null; Dictionary <XmlNode, XmlNode> headingToNewPageMap = new Dictionary <XmlNode, XmlNode>(); for (int i = 0; i < bodyNode.ChildNodes.Count; i++) {//1 XmlNode childNode = bodyNode.ChildNodes[i]; if (childNode.Name == "h1" || childNode.Name == "h2" || childNode.Name == "h3" || childNode.Name == "h4" || childNode.Name == "h5" || childNode.Name == "h6") {//2 if (lastPageNode != null) { XmlNode newPage = lastPageNode.Clone(); newPage.Attributes.GetNamedItem("id").Value = newPage.Attributes.GetNamedItem("id").Value + "_1"; headingToNewPageMap.Add(childNode, newPage); } pageCounter = 0; prevHeading = childNode; //Console.WriteLine("Heading has reset page counter: " + pageCounter); }//-2 if (childNode.Name == "span") {//2 lastPageNode = childNode; //if (pageCounter > 0) //{//3 //bodyNode.RemoveChild(childNode); nodesToRemove.Add(childNode); //Console.WriteLine("Removing span: " + childNode.InnerText); //}//-3 pageCounter++; Console.WriteLine("Incrementing page counter: " + pageCounter); }//-2 //if (childNode.Name == "br" && pageCounter > 1) //counter is incremented above if (childNode.Name == "br") //counter is incremented above {//2 //bodyNode.RemoveChild(childNode); nodesToRemove.Add(childNode); } //-2 } //-1 // check if last heading has pages //if (pageCounter == 0 && lastPageNode != null && prevHeading != null) //{ //XmlNode newPage = lastPageNode.Clone(); //newPage.Attributes.GetNamedItem("id").Value = newPage.Attributes.GetNamedItem("id").Value + "_1"; //headingToNewPageMap.Add(prevHeading, newPage); //} // remove all XmlNodes collected for removal if (nodesToRemove.Count > 0) { for (int i = 0; i < nodesToRemove.Count; i++) { bodyNode.RemoveChild(nodesToRemove[i]); } } // add new pages for the headings that do not have pages foreach (XmlNode headingNode in headingToNewPageMap.Keys) { bodyNode.InsertAfter(nccDocument.CreateElement("br"), headingNode); bodyNode.InsertAfter(headingToNewPageMap[headingNode], headingNode); Console.WriteLine("Adding to heading " + headingNode.InnerText); } } // write ncc file WriteXmlDocumentToFile(nccDocument, Path.Combine(m_ExportDirectory, "Exported-Structure.html")); }
private void CommitValues() { if (mSelection != null && !String.IsNullOrEmpty(mNameTextbox.Text)) { if (GetTextFromContentTextbox() != "") { string contentBoxText = GetTextFromContentTextbox(); int itemIndex = 0; if (mMetadataListView.SelectedItems.Count > 0) { itemIndex = mMetadataListView.SelectedItems[0].Index; } urakawa.metadata.Metadata entry = mSelection.Item.Entry; if (entry == null && mNameTextbox.Text != "") { if (mMetadataListView.Items.Count > 0 && mMetadataListView.Items[itemIndex].Tag == null && CanAdd(MetadataEntryDescription.GetDAISYEntry(mNameTextbox.Text))) { entry = mView.AddMetadataEntry(mNameTextbox.Text); } else { return; } } if (mSelection == null) { return; } CompositeCommand command = mView.Presentation.CreateCompositeCommand(Localizer.Message("modify_metadata_entry")); if (entry.NameContentAttribute.Name != mNameTextbox.Text) { if (CanModify(mSelection.Item.Description, mNameTextbox.Text)) { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Metadata.ModifyName(mView, entry, mNameTextbox.Text)); } else { MessageBox.Show(String.Format(Localizer.Message("metadata_name_error_text"), mNameTextbox.Text), Localizer.Message("metadata_name_error_caption"), MessageBoxButtons.OK, MessageBoxIcon.Error); mNameTextbox.Text = entry.NameContentAttribute.Name; } } if (entry.NameContentAttribute.Value != contentBoxText) { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Metadata.ModifyContent(mView, entry, contentBoxText)); } if (command.ChildCommands.Count > 0) { mView.Presentation.UndoRedoManager.Execute(command); } } else { if (!IsDateMetadataSelected || string.IsNullOrEmpty(mContentTextbox.Text)) { MessageBox.Show(Localizer.Message("MetadataView_CannotCommitEmptyContent"), Localizer.Message("Caption_Error")); } mContentTextbox.Focus(); if (mSelection != null && mSelection.Item.Entry == null && mMetadataListView.SelectedItems.Count > 0 && mMetadataListView.SelectedItems[0] != null && mMetadataListView.SelectedItems[0].Checked) { mMetadataListView.SelectedItems[0].Checked = false; } } // contentbox check ends } }
private void UpdateMetaDataListForItemAdd(MetadataEventArgs e) { if (InvokeRequired) { Invoke(new UpdateMetadataInvokation(UpdateMetaDataListForContentChange), e); } else { mMetadataListView.ItemChecked -= new System.Windows.Forms.ItemCheckedEventHandler(mMetadataListView_ItemChecked); this.mMetadataListView.SelectedIndexChanged -= new System.EventHandler(this.mMetadataListView_SelectedIndexChanged); m_IsImportingMetadata = true; string[] nameContent = new string[2]; List <urakawa.metadata.Metadata> items = mView.Presentation.Metadatas.ContentsAs_ListCopy; items.Sort(delegate(urakawa.metadata.Metadata a, urakawa.metadata.Metadata b) { int names = a.NameContentAttribute.Name.CompareTo(b.NameContentAttribute.Name); return(names == 0 && a.NameContentAttribute.Value != null && b.NameContentAttribute.Value != null ? a.NameContentAttribute.Value.CompareTo(b.NameContentAttribute.Value) : names); }); string itemToRemove = ""; List <string> ExistingItemsList = new List <string> (); int i = 0; if (mMetadataListView.Items.Count == 0) { return; } for (i = 0; i < items.Count; i++) { string metaDataListString = mMetadataListView.Items[i].SubItems[0].Text; string itemsListString = items[i].NameContentAttribute.Name; if (string.CompareOrdinal(metaDataListString, itemsListString) != 0) { itemToRemove = itemsListString; urakawa.metadata.Metadata m = items[i]; nameContent[0] = m.NameContentAttribute.Name; nameContent[1] = m.NameContentAttribute.Value; ListViewItem item = new ListViewItem(nameContent); mMetadataListView.Items.Insert(i, item); item.Checked = true; item.Tag = m; MetadataEntryDescription metDes = MetadataEntryDescription.GetDAISYEntry(m.NameContentAttribute.Name); if (metDes != null) { if (metDes.ReadOnly) { item.BackColor = SystemColors.InactiveCaption; } } } ExistingItemsList.Add(itemsListString); } // remove only if metadata is not custom if (itemToRemove != Localizer.Message("metadata_custom")) { // now search items below checked items and remove the item which we have just added above. for (i = i; i < mMetadataListView.Items.Count; i++) { if (string.CompareOrdinal(itemToRemove, mMetadataListView.Items[i].SubItems[0].Text) == 0) { mMetadataListView.Items.RemoveAt(i); break; } } } // check for custom ends m_IsImportingMetadata = false; this.mMetadataListView.SelectedIndexChanged += new System.EventHandler(this.mMetadataListView_SelectedIndexChanged); mMetadataListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(mMetadataListView_ItemChecked); } }