Problem with Word Add-on - TechRepublic
Question
September 19, 2008 at 01:06 AM
h.meyer-heder

Problem with Word Add-on

by h.meyer-heder . Updated 17 years, 10 months ago

1- By deinstallation of add-on the menu tabs remains in symbol bar of word 2003. Looking for the registry entry or INI entry where this information maight be stored.
2. redo/undo issue:
in some cases wehre an action is performed you have too many entries into redo/undo list:
Examples of the methods used:
mark a text containing CML – Nodes then you get 42 user actions in the undo List. How to disbale this behaviour? some methods used in the Add-on:
///

/// Occurs, when the XMLSelection changes. Highlights the new
/// XML-node and de-highlights the old XML-node.
///

/// /// not in use
/// /// /// node to be de-highlighted
/// /// /// node to be highlighted
/// /// /// not ins use
/// private void OnXMLSelectionChange(Word.Selection sel,
Word.XMLNode oldXMLNode,
Word.XMLNode newXMLNode,
ref int reason)
{
Designer.View.SetHighlight(oldXMLNode,
highlightButton.State == MsoButtonState.msoButtonDown);
Designer.View.SetHighlight(newXMLNode, true);
}

//

/// Inserts an XML tag with the given attributes into the current
/// document.
///

/// /// Name of the tag, that is to be created.
/// /// /// A list of attributes for this tag.
/// public static void Insert(String tag, Hashtable attributes)
{
try
{
object objMissing = System.Reflection.Missing.Value;
XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace(Statics.NS_WORDML_PREFIX, Statics.NS_WORDML_URI);
nsm.AddNamespace(Statics.NS_AUX_PREFIX, Statics.NS_AUX_URI);
nsm.AddNamespace(Statics.NS_VML_PREFIX, Statics.NS_VML_URI);

// Get the current selection
Word.Range range = WordPlugin.app.Selection.Range;

// Display the elements name inside a select
if (tag.Equals(Statics.DDL_SELECT) && attributes != null &&
attributes[Statics.DDL_ATTRIBUTE_PATH] != null)
{
String path = attributes[Statics.DDL_ATTRIBUTE_PATH] as String;
range.Text = path.Substring(path.LastIndexOf(“/”) + 1);
}

// Get the selections XML and create the new XML node
XmlDocument rngXml = new XmlDocument();
rngXml.LoadXml(range.get_XML(false));

XmlNode sect = rngXml.SelectSingleNode(“//w:body/wx:sect”, nsm);
XmlElement newNode = rngXml.CreateElement(Statics.NS_DDL_PREFIX,
tag, Statics.NS_DDL_URI);

// Create attributes for the new node.
if (attributes != null)
{
foreach (String key in attributes.Keys)
newNode.SetAttribute(key, attributes[key] as String);
}

// Do the insertion
foreach (XmlNode node in sect.ChildNodes)
{
if (!node.LocalName.Equals(“sectPr”))
newNode.AppendChild(node.CloneNode(true));
}

sect.RemoveAll();
sect.AppendChild(newNode);

// Add the template image for image nodes
if (tag.Equals(Statics.DDL_IMAGE))
{
while (newNode.HasChildNodes)
newNode.RemoveChild(newNode.FirstChild);

AppendDefaultPictNode(newNode, nsm);
}

// Word puts new nodes around paragraphs or table cells if there
// is nothing else inside the structure. For some elements this
// is definitely not wanted (i.e. select) and the node is moved
// here to avoid user confusion.
if (tag.Equals(Statics.DDL_SELECT) ||
tag.Equals(Statics.DDL_FOREACH_START) ||
tag.Equals(Statics.DDL_FOREACH_END) ||
tag.Equals(Statics.DDL_FORMAT_START) ||
tag.Equals(Statics.DDL_FORMAT_END) ||
tag.Equals(Statics.DDL_IMPORT_TEXT))
{
MoveIntoInnerParagraph(newNode, nsm);
}

// Update the document with the new WordML structure
range.InsertXML(rngXml.OuterXml, ref objMissing);
range.End = range.Start++;

Designer.View.UpdatePaths();
}
catch (Exception e)
{
MessageBox.Show(string.Format(Resource.MessageBoxUnknwonFault, e.Message),
Resource.MessageBoxFaultCaption, MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}

This discussion is locked

All Comments