private void toggleButtonMapping_Click(object sender, RibbonControlEventArgs e)
        {
            Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;

            //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 a control?");

                //it's being unclicked
                if (ctpPaneForThisWindow != null)
                    ctpPaneForThisWindow.Visible = false;

            }
            else if (ctpPaneForThisWindow == null)
            {
                if (CustomXmlUtilities.areOpenDoPEPartsPresent(Globals.ThisAddIn.Application.ActiveDocument))
                {
                    log.Debug("OpenDoPE parts detected as present");
                }
                else
                {
                    log.Info("OpenDoPE parts not detected; adding now.");

                    Model model = Model.ModelFactory(document);
                    string requiredRoot = System.Configuration.ConfigurationManager.AppSettings["RootElement"];
                    Office.CustomXMLPart userPart = model.getUserPart(requiredRoot);

                    bool cancelled = false;
                    while (userPart == null && !cancelled)
                    {
                        using (Forms.FormAddPart fap = new Forms.FormAddPart())
                        {
                            //add a new stream from the XML retrieved from the Add New dialog
                            //otherwise, select the last selected item and populate with its xml
                            if (fap.ShowDialog() == DialogResult.OK)
                            {
                                object missing = System.Reflection.Missing.Value;
                                Office.CustomXMLPart newCxp = document.CustomXMLParts.Add(fap.XmlString, missing);

                                model = Model.ModelFactory(document);
                                userPart = model.getUserPart(requiredRoot);
                                if (userPart == null)
                                {
                                    newCxp.Delete();
                                    MessageBox.Show("You need to use root element: " + requiredRoot);
                                }
                            }
                            else
                            {
                                cancelled = true;
                            }
                        }
                    }
                    if (cancelled)
                    {
                        MessageBox.Show("For template authoring, you need to add your XML.");
                        toggleButtonMapping.Checked = false;
                        return;
                    }

                    InitialSetup init = new InitialSetup();
                    init.process();
                }
                launchTaskPane();
            }
            else
            {
                //it's built and being clicked, show it
                ctpPaneForThisWindow.Visible = true;
            }
        }
        public void toggleButtonMapping_Click(Office.IRibbonControl control, bool pressed)//, ref bool cancelDefault)
        {
            Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;

            //get the ctp for this window (or null if there's not one)
            CustomTaskPane ctpPaneForThisWindow = Utilities.FindTaskPaneForCurrentWindow();

            if (pressed)
            {
                toggleButtonMappingChecked = true;
            }


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

                //it's being unclicked
                if (ctpPaneForThisWindow != null)
                {
                    ctpPaneForThisWindow.Visible = false;
                }
            }
            else if (ctpPaneForThisWindow == null)
            {
                if (CustomXmlUtilities.areOpenDoPEPartsPresent(Globals.ThisAddIn.Application.ActiveDocument))
                {
                    log.Debug("OpenDoPE parts detected as present");
                }
                else
                {
                    log.Info("OpenDoPE parts not detected; adding now.");

                    Model  model                  = Model.ModelFactory(document);
                    string requiredRoot           = System.Configuration.ConfigurationManager.AppSettings["RootElement"];
                    Office.CustomXMLPart userPart = model.getUserPart(requiredRoot);

                    bool cancelled = false;
                    while (userPart == null && !cancelled)
                    {
                        using (Forms.FormAddPart fap = new Forms.FormAddPart())
                        {
                            //add a new stream from the XML retrieved from the Add New dialog
                            //otherwise, select the last selected item and populate with its xml
                            if (fap.ShowDialog() == DialogResult.OK)
                            {
                                object missing = System.Reflection.Missing.Value;
                                Office.CustomXMLPart newCxp = document.CustomXMLParts.Add(fap.XmlString, missing);

                                model    = Model.ModelFactory(document);
                                userPart = model.getUserPart(requiredRoot);
                                if (userPart == null)
                                {
                                    newCxp.Delete();
                                    MessageBox.Show("You need to use root element: " + requiredRoot);
                                }
                            }
                            else
                            {
                                cancelled = true;
                            }
                        }
                    }
                    if (cancelled)
                    {
                        MessageBox.Show("For template authoring, you need to add your XML.");
                        toggleButtonMappingChecked = false;
                        return;
                    }

                    InitialSetup init = new InitialSetup();
                    init.process();
                }
                launchTaskPane();
            }
            else
            {
                //it's built and being clicked, show it
                ctpPaneForThisWindow.Visible = true;
            }
        }