/// <summary> /// Handle Word's AfterAdd event for content controls, to set new controls' placeholder text /// </summary> /// <param name="ccAdded"></param> /// <param name="InUndoRedo"></param> private void doc_ContentControlAfterAdd(Word.ContentControl ccAdded, bool InUndoRedo) { log.Info("doc_ContentControlAfterAdd..."); if (InUndoRedo) { } else if (m_cmTaskPane.RecentDragDrop) { log.Info("recent drag drop..."); ccAdded.Application.ScreenUpdating = false; /* * Don't set placeholder text. We don't want it! * It prevents child content controls from being added. * And it is very difficult to get rid of! * * //set the placeholder text * if (m_cmTaskPane.controlMode1.isModeBind() * && ccAdded.Type != Word.WdContentControlType.wdContentControlRichText * && ccAdded.Type != Word.WdContentControlType.wdContentControlPicture // TODO, what other types don't support placeholder text? * ) * { * log.Debug("Setting placeholder text (fwiw)"); * // set the placeholder text has the side effect of clearing out the control's contents, * // so grab the current text in the node (if any) * string currentText = null; * if (ccAdded.XMLMapping.IsMapped) * { * currentText = ccAdded.XMLMapping.CustomXMLNode.Text; * } * * ccAdded.SetPlaceholderText(null, null, Utilities.GetPlaceholderText(ccAdded.Type)); * * // now bring back the original text * if (currentText != null) * { * ccAdded.Range.Text = currentText; * } * * } * */ string xml = ccAdded.Range.Text; if (ContentDetection.IsBase64Encoded(xml)) { // Don't need to do anything here... } else if (ContentDetection.IsFlatOPCContent(xml)) { xml = xml.Replace(""", "\""); log.Debug(xml); // Need it to be block level Inline2Block i2b = new Inline2Block(); AsyncMethodCallerFlatOPC caller = new AsyncMethodCallerFlatOPC(i2b.blockLevelFlatOPC); caller.BeginInvoke(ccAdded, xml, null, null); } else if (ContentDetection.IsXHTMLContent(ccAdded.Range.Text)) { log.Info("is XHTML .. " + ccAdded.Range.Text); if (Inline2Block.containsBlockLevelContent(ccAdded.Range.Text)) { Inline2Block i2b = new Inline2Block(); AsyncMethodCallerXHTML caller = new AsyncMethodCallerXHTML(i2b.convertToBlockLevel); caller.BeginInvoke(ccAdded, true, true, null, null); } } else { // Have to do CopyAdjacentFormat outside this event. // (It works from OnExit, but not from AfterAdd. Go figure...) ContentControlStyle ccs = new ContentControlStyle(); AsyncMethodCallerPlainText caller2 = new AsyncMethodCallerPlainText(ccs.CopyAdjacentFormat); caller2.BeginInvoke(ccAdded, null, null); } } }
/// <summary> /// Handle Word's AfterAdd event for content controls, to set new controls' placeholder text /// </summary> /// <param name="ccAdded"></param> /// <param name="InUndoRedo"></param> private void doc_ContentControlAfterAdd(Word.ContentControl ccAdded, bool InUndoRedo) { log.Info("doc_ContentControlAfterAdd..."); if (InUndoRedo) { } else if (m_cmTaskPane.RecentDragDrop) { log.Info("recent drag drop..."); ccAdded.Application.ScreenUpdating = false; /* * Don't set placeholder text. We don't want it! * It prevents child content controls from being added. * And it is very difficult to get rid of! * //set the placeholder text if (m_cmTaskPane.controlMode1.isModeBind() && ccAdded.Type != Word.WdContentControlType.wdContentControlRichText && ccAdded.Type != Word.WdContentControlType.wdContentControlPicture // TODO, what other types don't support placeholder text? ) { log.Debug("Setting placeholder text (fwiw)"); // set the placeholder text has the side effect of clearing out the control's contents, // so grab the current text in the node (if any) string currentText = null; if (ccAdded.XMLMapping.IsMapped) { currentText = ccAdded.XMLMapping.CustomXMLNode.Text; } ccAdded.SetPlaceholderText(null, null, Utilities.GetPlaceholderText(ccAdded.Type)); // now bring back the original text if (currentText != null) { ccAdded.Range.Text = currentText; } } * */ string xml = ccAdded.Range.Text; if (ContentDetection.IsBase64Encoded(xml)) { // Don't need to do anything here... } else if (ContentDetection.IsFlatOPCContent(xml)) { xml = xml.Replace(""", "\""); log.Debug(xml); // Need it to be block level Inline2Block i2b = new Inline2Block(); AsyncMethodCallerFlatOPC caller = new AsyncMethodCallerFlatOPC(i2b.blockLevelFlatOPC); caller.BeginInvoke(ccAdded, xml, null, null); } else if (ContentDetection.IsXHTMLContent(ccAdded.Range.Text)) { log.Info("is XHTML .. " + ccAdded.Range.Text); if (Inline2Block.containsBlockLevelContent(ccAdded.Range.Text)) { Inline2Block i2b = new Inline2Block(); AsyncMethodCallerXHTML caller = new AsyncMethodCallerXHTML(i2b.convertToBlockLevel); caller.BeginInvoke(ccAdded, true, true, null, null); } } else { // Have to do CopyAdjacentFormat outside this event. // (It works from OnExit, but not from AfterAdd. Go figure...) ContentControlStyle ccs = new ContentControlStyle(); AsyncMethodCallerPlainText caller2 = new AsyncMethodCallerPlainText(ccs.CopyAdjacentFormat); caller2.BeginInvoke(ccAdded, null, null); } } }