///<summary> ///</summary> ///<param name="document"></param> ///<param name="controls"></param> public static void Store(_Document document, ControlProperties[] controls) { Log.Debug(string.Format(CultureInfo.InvariantCulture, "ControlsStorage - Store : controls count {0}", controls.Length)); string xml = null; using (MemoryStream memStream = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(memStream, controls); XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement(RootNodeName, ControlsStorageNamespace); doc.AppendChild(root); XmlElement controlsDataNode = doc.CreateElement(ControlsNodeName, ControlsStorageNamespace); controlsDataNode.InnerXml = Convert.ToBase64String(memStream.GetBuffer(), 0, (int)memStream.Length); root.AppendChild(controlsDataNode); xml = doc.InnerXml; } CustomXMLParts parts = document.CustomXMLParts.SelectByNamespace(ControlsStorageNamespace); if (parts.Count > 0) { Debug.Assert(parts.Count == 1); parts[1].Delete(); } document.CustomXMLParts.Add(xml, Type.Missing); }
///<summary> ///</summary> ///<param name="document"></param> ///<returns></returns> public static ControlProperties[] Load(_Document document) { Log.Debug(string.Format(CultureInfo.InvariantCulture, "ControlsStorage - Load : document {0}", document)); ControlProperties[] controls = null; CustomXMLParts parts = document.CustomXMLParts.SelectByNamespace(ControlsStorageNamespace); if (parts != null && parts.Count > 0) { Debug.Assert(parts.Count == 1); CustomXMLPart part = parts[1]; XmlDocument doc = new XmlDocument(); doc.LoadXml(part.XML); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("sc", ControlsStorageNamespace); XmlElement controlsElement = doc.SelectSingleNode(String.Format(CultureInfo.CurrentUICulture, "//sc:{0}", ControlsNodeName), nsmgr) as XmlElement; if (controlsElement != null) { byte[] data = Convert.FromBase64String(controlsElement.InnerXml); BinaryFormatter formatter = new BinaryFormatter(); controls = (ControlProperties[])formatter.Deserialize(new MemoryStream(data)); } } return(controls); }
/// <summary> /// Removes all but the last XML part from the workbook. /// </summary> /// <param name="xmlParts"> /// the <see cref="CustomXMLParts"/> in the workbook. /// </param> private static void RemoveSuperfluousXmlParts(CustomXMLParts xmlParts) { while (xmlParts.Count > 1) { // NOTE indices are 1-based here xmlParts[1].Delete(); } }
/// <summary> /// Function which Marks a individual word as Abbreviation or Acronym /// </summary> public void Individual() { CustomXMLParts xmlparts = currentDoc.CustomXMLParts; //If call is from Abbreviation button if (checkAbbrAcr) { object val = System.Reflection.Missing.Value; String nameAbbr = "Abbreviations" + GenerateId().ToString(); currentDoc.Application.Selection.Bookmarks.Add(nameAbbr, ref val); for (int i = 1; i <= xmlparts.Count; i++) { if (xmlparts[i].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[i].XML; customXml.LoadXml(partxml); XmlElement elmtItem = customXml.CreateElement("Item", "http://Daisy-OpenXML/customxml"); elmtItem.SetAttribute("AbbreviationName", nameAbbr); elmtItem.SetAttribute("FullAbbr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); customXml.FirstChild.FirstChild.AppendChild(elmtItem); //Deleting the Current CustomXML xmlparts[i].Delete(); //Adding the updated CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(customXml.InnerXml, System.Reflection.Missing.Value); this.Close(); } } } else { object val = System.Reflection.Missing.Value; String nameAcr = "Acronyms" + pronounceAbbrAcr + GenerateId().ToString(); currentDoc.Application.Selection.Bookmarks.Add(nameAcr, ref val); for (int i = 1; i <= xmlparts.Count; i++) { if (xmlparts[i].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[i].XML; customXml.LoadXml(partxml); XmlElement elmtItem = customXml.CreateElement("Item", "http://Daisy-OpenXML/customxml"); elmtItem.SetAttribute("AcronymName", nameAcr); elmtItem.SetAttribute("FullAcr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); customXml.FirstChild.FirstChild.NextSibling.AppendChild(elmtItem); //Deleting the Current CustomXML xmlparts[i].Delete(); //Adding the updated CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(customXml.InnerXml, System.Reflection.Missing.Value); this.Close(); } } } }
/// <summary> /// Deletes all occurrences of an XML part from the Word document. /// </summary> /// <param name="partNamespace">The namespace of the part to be deleted.</param> public void DeleteXmlPart(string partNamespace) { CustomXMLParts parts = this.document.CustomXMLParts.SelectByNamespace(partNamespace); int count = parts.Count; for (int i = count; i > 0; i--) { parts[i].Delete(); } }
private void btn_Goto_Click(object sender, EventArgs e) { CustomXMLParts xmlparts = pdoc.CustomXMLParts; if (lBx_Abbreviation.SelectedValue.ToString() != "") { String input = lBx_Abbreviation.SelectedValue.ToString(); String[] strKey = input.Split('-'); if (seperate) { for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList listAbr = dc.FirstChild.FirstChild.ChildNodes; for (int j = 0; j < listAbr.Count; j++) { if (listAbr.Item(j).Attributes.Item(2).Value == strKey[0] && listAbr.Item(j).Attributes.Item(1).Value == strKey[1]) { object index = listAbr.Item(j).Attributes.Item(0).Value; pdoc.Bookmarks.get_Item(ref index).Range.HighlightColorIndex = MSword.WdColorIndex.wdTurquoise; } } } } } else { for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList listAcr = dc.FirstChild.FirstChild.NextSibling.ChildNodes; for (int j = 0; j < listAcr.Count; j++) { if (listAcr.Item(j).Attributes.Item(2).Value == strKey[0] && listAcr.Item(j).Attributes.Item(1).Value == strKey[1]) { object index = listAcr.Item(j).Attributes.Item(0).Value; pdoc.Bookmarks.get_Item(ref index).Range.HighlightColorIndex = MSword.WdColorIndex.wdTurquoise; } } } } } } }
public NavigatorViewModel(Document doc) : this() { //get a reference to the document _doc = doc; _parts = _doc.CustomXMLParts.SelectByNamespace(CML.cml.NamespaceName); _parts.PartAfterAdd += OnPartAfterAdd; _parts.PartAfterLoad += OnPartAfterLoad; _parts.PartBeforeDelete += OnPartBeforeDelete; LoadModel(); }
private void PopulateFormWithCustomXMLParts() { CustomXMLParts xmlPartsList = Globals.ThisAddIn.currentDocument.CustomXMLParts; foreach (CustomXMLPart part in xmlPartsList) { ListViewItem listItem = new ListViewItem(Text = part.NamespaceURI); listItem.Tag = part; nameSpaceListView.Items.Add(listItem); } }
/// <summary> /// 根据命名空间删除指定的部件 /// </summary> /// <param name="document"></param> /// <param name="nameSpace"></param> /// <returns></returns> public static bool DeletePartByNamespace(this Document document, string nameSpace) { if (nameSpace == null) { nameSpace = string.Empty; } CustomXMLParts parts = document.CustomXMLParts.SelectByNamespace(nameSpace); foreach (CustomXMLPart part in parts) { part.Delete(); } return(true); }
/// <summary> /// 根据命名空间选择获取用户自定义的XML部件 /// </summary> /// <param name="nameSpace"></param> /// <returns></returns> public static CustomXMLPart SelectPartByNamespace(this Document document, string nameSpace) { if (nameSpace == null) { nameSpace = string.Empty; } CustomXMLParts parts = document.CustomXMLParts.SelectByNamespace(nameSpace); foreach (CustomXMLPart part in parts) { return(part); } return(null); }
/// <summary> /// Removes all but the last XML part from the workbook. /// </summary> /// <param name="xmlParts"> /// the <see cref="CustomXMLParts"/> in the workbook. /// </param> /// <param name="xmlnamespace"> /// The XML namespace of the current <see cref="CustomXMLPart"/> /// </param> private void RemoveSuperfluousXmlParts(CustomXMLParts xmlParts, string xmlnamespace) { var amountOfXmlParts = xmlParts.Count; if (amountOfXmlParts > 1) { logger.Debug("The XML part with namespace {0} is present more than once, all but the last one have been removed to recover from the error", xmlnamespace); for (int i = 1; i < amountOfXmlParts; i++) { var xmlPart = xmlParts[i]; xmlPart.Delete(); } } }
/// <summary> /// 根据命名空间选择用户自定义的XML部件列表 /// </summary> /// <param name="nameSpace"></param> /// <returns></returns> public static IEnumerable <CustomXMLPart> SelectPartsByNamespace(this Document document, string nameSpace) { if (nameSpace == null) { nameSpace = string.Empty; } CustomXMLParts parts = document.CustomXMLParts.SelectByNamespace(nameSpace); var list = new List <CustomXMLPart>(); foreach (CustomXMLPart part in parts) { list.Add(part); } return(list); }
/// <summary> /// Stores the custom XML part. /// </summary> /// <param name="document">The document.</param> /// <param name="customXmlPartDocument">The custom XML part document.</param> /// <returns></returns> public static CustomXMLPart StoreCustomXmlPart(this Word._Document document, XDocument customXmlPartDocument) { if (document != null && customXmlPartDocument != null) { CustomXMLParts parts = document.CustomXMLParts.SelectByNamespace(DocumentGenerationInfo.NamespaceUri); if (parts.Count > 0) { Debug.Assert(parts.Count == 1); parts[1].Delete(); } return(document.CustomXMLParts.Add(customXmlPartDocument.ToString())); } return(null); }
public void SetSearchData(SearchData searchData) { try { XmlSerializer serializer = new XmlSerializer(typeof(SearchData)); var stringwriter = new System.IO.StringWriter(); serializer.Serialize(stringwriter, searchData); string xml = stringwriter.ToString(); Document activeDoc = GetActiveDocument(); CustomXMLParts parts = activeDoc.CustomXMLParts.SelectByNamespace(GlobalVars.MY_NAMESPACE); bool anyDeleted = false; string noSpaceXml = Regex.Replace(xml, @"\s+", ""); if (parts.Count > 0) { foreach (CustomXMLPart p in parts) { string pXml = Regex.Replace(p.XML, @"\s+", ""); if (!pXml.Equals(noSpaceXml)) { p.Delete(); anyDeleted = true; } } if (!anyDeleted) { return; } } try { CustomXMLPart cp = activeDoc.CustomXMLParts.Add(xml); } catch (System.Runtime.InteropServices.COMException ex) { System.Console.Out.Write(ex.Message); } } catch (COMException ex) { System.Console.Out.Write(ex.Message); } }
public SearchData GetSearchData() { Document doc = GetActiveDocument(); if (doc == null) { return(new SearchData()); } CustomXMLParts parts = doc.CustomXMLParts.SelectByNamespace(GlobalVars.MY_NAMESPACE); if (parts.Count > 0) { foreach (CustomXMLPart p in parts) { var stringReader = new System.IO.StringReader(p.XML); var serializer = new XmlSerializer(typeof(SearchData)); return(serializer.Deserialize(stringReader) as SearchData); } } return(new SearchData()); }
/// <summary> /// Function which Marks all occurences of a particular word as Abbreviations or Acronyms /// </summary> public void AllOccurences() { CustomXMLParts xmlparts = currentDoc.CustomXMLParts; //If call is from Abbreviation button if (checkAbbrAcr) { object missing = System.Type.Missing; Object startDoc = 0; Object endDoc = currentDoc.Characters.Count; MSword.Range rngDoc = currentDoc.Range(ref startDoc, ref endDoc); MSword.Find fndDoc = rngDoc.Find; fndDoc.ClearFormatting(); fndDoc.Forward = true; fndDoc.Text = currentDoc.Application.Selection.Text.Trim(); ExecuteFind(fndDoc); //Applying Abbreviation for all the occurrences of the selected Word while (fndDoc.Found) { String nameAbbr = "Abbreviations" + GenerateId().ToString(); if (ValidateBookMark(rngDoc) == "Nobookmarks") { rngDoc.Bookmarks.Add(nameAbbr, ref missing); for (int i = 1; i <= xmlparts.Count; i++) { if (xmlparts[i].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[i].XML; customXml.LoadXml(partxml); XmlElement elmtItem = customXml.CreateElement("Item", "http://Daisy-OpenXML/customxml"); elmtItem.SetAttribute("AbbreviationName", nameAbbr); elmtItem.SetAttribute("FullAbbr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); customXml.FirstChild.FirstChild.AppendChild(elmtItem); //Deleting the Current CustomXML xmlparts[i].Delete(); //Adding the updated CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(customXml.InnerXml, System.Reflection.Missing.Value); } } } ExecuteFind(fndDoc); } this.Close(); } else { object missing = System.Type.Missing; Object start = 0; Object end = currentDoc.Characters.Count; MSword.Range rngDoc = currentDoc.Range(ref start, ref end); MSword.Find fnd = rngDoc.Find; fnd.ClearFormatting(); fnd.Forward = true; fnd.Text = currentDoc.Application.Selection.Text.Trim(); ExecuteFind(fnd); while (fnd.Found) { String nameAcr = "Acronyms" + pronounceAbbrAcr + GenerateId().ToString(); if (ValidateBookMark(rngDoc) == "Nobookmarks") { rngDoc.Bookmarks.Add(nameAcr, ref missing); for (int i = 1; i <= xmlparts.Count; i++) { if (xmlparts[i].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[i].XML; customXml.LoadXml(partxml); XmlElement elmtItem = customXml.CreateElement("Item", "http://Daisy-OpenXML/customxml"); elmtItem.SetAttribute("AcronymName", nameAcr); elmtItem.SetAttribute("FullAcr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); customXml.FirstChild.FirstChild.NextSibling.AppendChild(elmtItem); //Deleting the Current CustomXML xmlparts[i].Delete(); //Adding the updated CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(customXml.InnerXml, System.Reflection.Missing.Value); } } } ExecuteFind(fnd); } this.Close(); } }
/*Function which Unmark all abbreviations/Acronyms*/ private void btn_Unmark_Click(object sender, EventArgs e) { CustomXMLParts xmlparts = pdoc.CustomXMLParts; if (seperate) { DialogResult dr = MessageBox.Show("Do you want to unmark this abbreviation?", "SaveAsDAISY - Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { String input = lBx_Abbreviation.SelectedItem.ToString(); String[] strKey = input.Split('-'); for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList listAbr = dc.FirstChild.FirstChild.ChildNodes; for (int j = 0; j < listAbr.Count; j++) { if (listAbr.Item(j).Attributes.Item(2).Value == strKey[0] && listAbr.Item(j).Attributes.Item(1).Value == strKey[1]) { object index = listAbr.Item(j).Attributes.Item(0).Value; pdoc.Bookmarks.get_Item(ref index).Delete(); } } } } lostElements.Remove(input); lBx_Abbreviation.Items.Remove(input); if (lBx_Abbreviation.Items.Count > 0) { lBx_Abbreviation.SetSelected(0, true); } lBx_Abbreviation.Refresh(); } } else { DialogResult dr = MessageBox.Show("Do you want to unmark this Acronym?", "SaveAsDAISY - Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { String input = lBx_Abbreviation.SelectedItem.ToString(); String[] strKey = input.Split('-'); for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList listAcr = dc.FirstChild.FirstChild.NextSibling.ChildNodes; for (int j = 0; j < listAcr.Count; j++) { if (listAcr.Item(j).Attributes.Item(2).Value == strKey[0] && listAcr.Item(j).Attributes.Item(1).Value == strKey[1]) { object index = listAcr.Item(j).Attributes.Item(0).Value; pdoc.Bookmarks.get_Item(ref index).Delete(); } } } } lostElements.Remove(input); lBx_Abbreviation.Items.Remove(input); if (lBx_Abbreviation.Items.Count > 0) { lBx_Abbreviation.SetSelected(0, true); } lBx_Abbreviation.Refresh(); } } }
/// <summary> /// Function which marks the selected text as an Abbreviation\Acronym /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Mark_Click(object sender, EventArgs e) { try { if (currentDoc.ProtectionType == Microsoft.Office.Interop.Word.WdProtectionType.wdNoProtection) { CustomXMLParts xmlParts = currentDoc.CustomXMLParts; //Checking whether CustomXML is there or not in the Current Document for (int i = 1; i <= xmlParts.Count; i++) { if (xmlParts[i].NamespaceURI == "http://Daisy-OpenXML/customxml") { checkCustomXml = 1; } } //If CustomXML is not there in the Current Document if (checkCustomXml == 0) { //Creating Custom XML document for the Current Document XmlElement elmtManage = manageAbbrAcr.CreateElement("Manage"); manageAbbrAcr.AppendChild(elmtManage); elmtManage.SetAttribute("xmlns", "http://Daisy-OpenXML/customxml"); XmlElement elmtAbbreviations = manageAbbrAcr.CreateElement("Abbreviations"); elmtManage.AppendChild(elmtAbbreviations); XmlElement elmtAcronyms = manageAbbrAcr.CreateElement("Acronyms"); elmtManage.AppendChild(elmtAcronyms); //If user is not selected "allOccurrences" checkbox if (allOccurences == "No") { //If call is from Abbreviation button if (checkAbbrAcr) { object val = System.Reflection.Missing.Value; String nameAbbr = "Abbreviations" + GenerateId().ToString(); //Adding Bookmark for the selected Text currentDoc.Application.Selection.Bookmarks.Add(nameAbbr, ref val); //Updating the CustomXML XmlElement elmtItem = manageAbbrAcr.CreateElement("Item"); elmtItem.SetAttribute("AbbreviationName", nameAbbr); elmtItem.SetAttribute("FullAbbr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); elmtAbbreviations.AppendChild(elmtItem); //Adding the CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(manageAbbrAcr.InnerXml, System.Reflection.Missing.Value); this.Close(); } //If call is from Acronym button else { object val = System.Reflection.Missing.Value; String nameAcr = "Acronyms" + pronounceAbbrAcr + GenerateId().ToString(); //Adding Bookmark for the selected Text currentDoc.Application.Selection.Bookmarks.Add(nameAcr, ref val); //Updating the CustomXML XmlElement elmtItem = manageAbbrAcr.CreateElement("Item"); elmtItem.SetAttribute("AcronymName", nameAcr); elmtItem.SetAttribute("FullAcr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); elmtAcronyms.AppendChild(elmtItem); //Adding the CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(manageAbbrAcr.InnerXml, System.Reflection.Missing.Value); this.Close(); } } //If user is selected "allOccurrences" checkbox else { //If call is from Abbreviation button if (checkAbbrAcr) { object missing = System.Type.Missing; Object startDoc = 0; Object endDoc = currentDoc.Characters.Count; MSword.Range rngDoc = currentDoc.Range(ref startDoc, ref endDoc); MSword.Find fndDoc = rngDoc.Find; fndDoc.ClearFormatting(); fndDoc.Forward = true; fndDoc.Text = currentDoc.Application.Selection.Text.Trim(); ExecuteFind(fndDoc); //Applying Abbreviation for all the occurrences of the selected Word while (fndDoc.Found) { if (ValidateBookMark(rngDoc) == "Nobookmarks") { String nameAbbr = "Abbreviations" + GenerateId().ToString(); rngDoc.Bookmarks.Add(nameAbbr, ref missing); XmlElement elmtItem = manageAbbrAcr.CreateElement("Item"); elmtItem.SetAttribute("AbbreviationName", nameAbbr); elmtItem.SetAttribute("FullAbbr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); elmtAbbreviations.AppendChild(elmtItem); } ExecuteFind(fndDoc); } //Adding the CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(manageAbbrAcr.InnerXml, System.Reflection.Missing.Value); this.Close(); } //If call is from Acronym button else { object missing = System.Type.Missing; Object startDoc = 0; Object endDoc = currentDoc.Characters.Count; MSword.Range rngDoc = currentDoc.Range(ref startDoc, ref endDoc); MSword.Find fndDoc = rngDoc.Find; fndDoc.ClearFormatting(); fndDoc.Forward = true; fndDoc.Text = currentDoc.Application.Selection.Text.Trim(); ExecuteFind(fndDoc); //Applying Abbreviation for all the occurrences of the selected Word while (fndDoc.Found) { if (ValidateBookMark(rngDoc) == "Nobookmarks") { String nameAcr = "Acronyms" + pronounceAbbrAcr + GenerateId().ToString(); rngDoc.Bookmarks.Add(nameAcr, ref missing); XmlElement elmtItem = manageAbbrAcr.CreateElement("Item"); elmtItem.SetAttribute("AcronymName", nameAcr); elmtItem.SetAttribute("FullAcr", tBx_MarkFullForm.Text.TrimEnd()); elmtItem.SetAttribute("OriginalText", currentDoc.Application.Selection.Text.Trim()); elmtAcronyms.AppendChild(elmtItem); } ExecuteFind(fndDoc); } //Adding the CustomXml to the Current Document CustomXMLPart part = currentDoc.CustomXMLParts.Add(manageAbbrAcr.InnerXml, System.Reflection.Missing.Value); this.Close(); } } } //If already CustomXML is there in the Current Document else { //If user is not selected "allOccurrences" checkbox if (allOccurences == "No") { Individual(); } else { AllOccurences(); } } } else { MessageBox.Show("The current document is locked for editing. Please unprotect the document.", "SaveAsDAISY", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "SaveAsDAISY", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/*Constructor which loads differently for Abbreviations/Acronyms*/ public Abbreviation(MSword.Document doc, bool value) { InitializeComponent(); pdoc = doc; seperate = value; CustomXMLParts xmlparts = pdoc.CustomXMLParts; if (seperate) { for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList list = dc.FirstChild.FirstChild.ChildNodes; for (int j = 0; j < list.Count; j++) { if (!pdoc.Bookmarks.Exists(list.Item(j).Attributes.Item(0).Value)) { dc.FirstChild.FirstChild.RemoveChild(dc.FirstChild.FirstChild.ChildNodes[j]); j--; } } xmlparts[p].Delete(); CustomXMLPart part = pdoc.CustomXMLParts.Add(dc.InnerXml, System.Reflection.Missing.Value); } } for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { exists = 1; } } if (exists == 0) { foreach (object item in pdoc.Bookmarks) { if (((MSword.Bookmark)item).Name.StartsWith("Abbreviations", StringComparison.CurrentCulture)) { object val = ((MSword.Bookmark)item).Name; pdoc.Bookmarks.get_Item(ref val).Delete(); } } } else { for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); foreach (object item in pdoc.Bookmarks) { if (((MSword.Bookmark)item).Name.StartsWith("Abbreviations", StringComparison.CurrentCulture)) { String name = ((MSword.Bookmark)item).Name; NameTable nt = new NameTable(); XmlNamespaceManager nsManager = new XmlNamespaceManager(nt); nsManager.AddNamespace("a", "http://Daisy-OpenXML/customxml"); XmlNodeList node = dc.SelectNodes("//a:Item[@AbbreviationName='" + name + "']", nsManager); if (node.Count == 0) { object val = name; pdoc.Bookmarks.get_Item(ref val).Delete(); } if (node.Count != 0) { if (node.Item(0).Attributes[2].Value != ((MSword.Bookmark)item).Range.Text.Trim()) { object val = name; pdoc.Bookmarks.get_Item(ref val).Delete(); } } } } } } } this.Text = "Manage Abbreviation"; this.label1.Text = "&List of Abbreviations:"; for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList listAbr = dc.FirstChild.FirstChild.ChildNodes; int i = 0; for (int j = 0; j < listAbr.Count; j++) { if (pdoc.Bookmarks.Exists(listAbr.Item(j).Attributes.Item(0).Value)) { if (!lostElements.Contains(listAbr.Item(j).Attributes.Item(2).Value + "-" + listAbr.Item(j).Attributes.Item(1).Value)) { lostElements.Add(listAbr.Item(j).Attributes.Item(2).Value + "-" + listAbr.Item(j).Attributes.Item(1).Value); lBx_Abbreviation.Items.Insert(i, listAbr.Item(j).Attributes.Item(2).Value + "-" + listAbr.Item(j).Attributes.Item(1).Value); i++; } } } } } if (lBx_Abbreviation.Items.Count < 1) { btn_Unmark.Enabled = false; } if (lBx_Abbreviation.Items.Count > 0) { lBx_Abbreviation.SetSelected(0, true); } } else { for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList list = dc.FirstChild.FirstChild.NextSibling.ChildNodes; for (int j = 0; j < list.Count; j++) { if (!pdoc.Bookmarks.Exists(list.Item(j).Attributes.Item(0).Value)) { dc.FirstChild.FirstChild.NextSibling.RemoveChild(dc.FirstChild.FirstChild.NextSibling.ChildNodes[j]); j--; } } xmlparts[p].Delete(); CustomXMLPart part = pdoc.CustomXMLParts.Add(dc.InnerXml, System.Reflection.Missing.Value); } } for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { exists = 1; } } if (exists == 0) { foreach (object item in pdoc.Bookmarks) { if (((MSword.Bookmark)item).Name.StartsWith("Acronyms", StringComparison.CurrentCulture)) { object val = ((MSword.Bookmark)item).Name; pdoc.Bookmarks.get_Item(ref val).Delete(); } } } else { for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); foreach (object item in pdoc.Bookmarks) { if (((MSword.Bookmark)item).Name.StartsWith("Acronyms", StringComparison.CurrentCulture)) { String name = ((MSword.Bookmark)item).Name; NameTable nt = new NameTable(); XmlNamespaceManager nsManager = new XmlNamespaceManager(nt); nsManager.AddNamespace("a", "http://Daisy-OpenXML/customxml"); XmlNodeList node = dc.SelectNodes("//a:Item[@AcronymName='" + name + "']", nsManager); if (node.Count == 0) { object val = name; pdoc.Bookmarks.get_Item(ref val).Delete(); } if (node.Count != 0) { if (node.Item(0).Attributes[2].Value != ((MSword.Bookmark)item).Range.Text.Trim()) { object val = name; pdoc.Bookmarks.get_Item(ref val).Delete(); } } } } } } } this.Text = "Manage Acronym"; this.label1.Text = "&List of Acronyms:"; for (int p = 1; p <= xmlparts.Count; p++) { if (xmlparts[p].NamespaceURI == "http://Daisy-OpenXML/customxml") { String partxml = xmlparts[p].XML; dc.LoadXml(partxml); XmlNodeList listAcr = dc.FirstChild.FirstChild.NextSibling.ChildNodes; int i = 0; for (int j = 0; j < listAcr.Count; j++) { if (pdoc.Bookmarks.Exists(listAcr.Item(j).Attributes.Item(0).Value)) { if (!lostElements.Contains(listAcr.Item(j).Attributes.Item(2).Value + "-" + listAcr.Item(j).Attributes.Item(1).Value)) { lostElements.Add(listAcr.Item(j).Attributes.Item(2).Value + "-" + listAcr.Item(j).Attributes.Item(1).Value); lBx_Abbreviation.Items.Insert(i, listAcr.Item(j).Attributes.Item(2).Value + "-" + listAcr.Item(j).Attributes.Item(1).Value); i++; } } } } } if (lBx_Abbreviation.Items.Count < 1) { btn_Unmark.Enabled = false; } if (lBx_Abbreviation.Items.Count > 0) { lBx_Abbreviation.SetSelected(0, true); } } }