예제 #1
0
        private void toggleButtonMapping_Click(object sender, RibbonControlEventArgs e)
        {
            //get the ctp for this window (or null if there's not one)
            CustomTaskPane ctpPaneForThisWindow = Utilities.FindTaskPaneForCurrentWindow();

            if (toggleButtonMapping.Checked == false)
            {
                Debug.Assert(ctpPaneForThisWindow != null, "how was the ribbon button pressed if there was no control?");

                //it's being unclicked
                if (ctpPaneForThisWindow != null)
                {
                    ctpPaneForThisWindow.Visible = false;
                }
            }
            else
            {
                if (ctpPaneForThisWindow == null)
                {
                    //set the cursor to wait
                    Globals.ThisAddIn.Application.System.Cursor = Word.WdCursorType.wdCursorWait;

                    //set up the task pane
                    ctpPaneForThisWindow = Globals.ThisAddIn.CustomTaskPanes.Add(new Controls.ControlMain(), Properties.Resources.TaskPaneName);
                    ctpPaneForThisWindow.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;

                    //store it for later
                    if (Globals.ThisAddIn.Application.ShowWindowsInTaskbar)
                    {
                        Globals.ThisAddIn.TaskPaneList.Add(Globals.ThisAddIn.Application.ActiveWindow, ctpPaneForThisWindow);
                    }

                    //connect task pane events
                    Globals.ThisAddIn.ConnectTaskPaneEvents(ctpPaneForThisWindow);

                    //get the control we hosted
                    Controls.ControlMain ccm = (Controls.ControlMain)ctpPaneForThisWindow.Control;

                    //hand the eventing class to the control
                    DocumentEvents de = new DocumentEvents(ccm);
                    ccm.EventHandlerAndOnChildren = de;
                    ccm.RefreshControls(Controls.ControlMain.ChangeReason.DocumentChanged, null, null, null, null, null);

                    //show it
                    ctpPaneForThisWindow.Visible = true;

                    //reset the cursor
                    Globals.ThisAddIn.Application.System.Cursor = Word.WdCursorType.wdCursorNormal;
                }
                else
                {
                    //it's built and being clicked, show it
                    ctpPaneForThisWindow.Visible = true;
                }
            }
        }
 /// <summary>
 /// Handle Word's OnEnter event for content controls, to set the selection in the pane (if the option is set).
 /// </summary>
 /// <param name="ccEntered">A ContentControl object specifying the control that was entered.</param>
 private void doc_ContentControlOnEnter(Word.ContentControl ccEntered)
 {
     Debug.WriteLine("Document.ContentControlOnEnter fired.");
     if (ccEntered.XMLMapping.IsMapped && ccEntered.XMLMapping.CustomXMLNode != null)
     {
         m_cmTaskPane.RefreshControls(Controls.ControlMain.ChangeReason.OnEnter, null, null, null, ccEntered.XMLMapping.CustomXMLNode, null);
     }
 }
        /// <summary>
        /// Handle Word's OnEnter event for content controls, to set the selection in the pane (if the option is set).
        /// </summary>
        /// <param name="ccEntered">A ContentControl object specifying the control that was entered.</param>
        private void doc_ContentControlOnEnter(Word.ContentControl ccEntered)
        {
            log.Debug("Document.ContentControlOnEnter fired.");
            if (ccEntered.XMLMapping.IsMapped)
            {
                log.Debug("control mapped to " + ccEntered.XMLMapping.XPath);
                if (ccEntered.XMLMapping.CustomXMLNode != null)
                {
                    m_cmTaskPane.RefreshControls(Controls.ControlMain.ChangeReason.OnEnter, null, null, null, ccEntered.XMLMapping.CustomXMLNode, null);
                }
                else
                {
                    // Not mapped to anything; probably because the part was replaced?
                    log.Debug(".. but XMLMapping.CustomXMLNode is null");
                    m_cmTaskPane.controlTreeView.DeselectNode();
                    m_cmTaskPane.WarnViaProperties(ccEntered.XMLMapping.XPath);
                }
            }
            else if (ccEntered.Tag != null)
            {
                TagData td      = new TagData(ccEntered.Tag);
                string  xpathid = td.getXPathID();
                if (xpathid == null)
                {
                    xpathid = td.getRepeatID();
                }

                if (xpathid == null)
                {
                    // Visually indicate in the task pane that we're no longer in a mapped control
                    m_cmTaskPane.controlTreeView.DeselectNode();
                    m_cmTaskPane.PropertiesClear();
                }
                else
                {
                    log.Debug("control mapped via tag to " + xpathid);

                    // Repeats, escaped XHTML; we don't show anything for conditions
                    XPathsPartEntry      xppe          = new XPathsPartEntry(m_cmTaskPane.model);
                    xpathsXpath          xx            = xppe.getXPathByID(xpathid);
                    Office.CustomXMLNode customXMLNode = null;
                    if (xx != null)
                    {
                        log.Debug(xx.dataBinding.xpath);
                        customXMLNode = m_currentPart.SelectSingleNode(xx.dataBinding.xpath);
                    }
                    if (customXMLNode == null)
                    {
                        // Not mapped to anything; probably because the part was replaced?
                        m_cmTaskPane.controlTreeView.DeselectNode();
                        if (xx == null)
                        {
                            log.Error("Couldn't find xpath for " + xpathid);
                            m_cmTaskPane.WarnViaProperties("Missing");
                        }
                        else
                        {
                            log.Warn("Couldn't find target node for " + xx.dataBinding.xpath);
                            m_cmTaskPane.WarnViaProperties(xx.dataBinding.xpath);
                        }
                    }
                    else
                    {
                        m_cmTaskPane.RefreshControls(Controls.ControlMain.ChangeReason.OnEnter, null, null, null, customXMLNode, null);
                    }
                }
            }
            Ribbon.buttonEditEnabled   = true;
            Ribbon.buttonDeleteEnabled = true;

            Ribbon.myInvalidate();
        }