private void addFabDocxParts()
 {
     PartCreator pc = new PartCreator();
     pc.process(FabDotxAsDocument, true);
     pc.createAnswersPart(FabDotxAsDocument);
 }
        public void enable(bool newDocument)
        {
            string majorVersionString = Globals.ThisAddIn.Application.Version.Split(new char[] { '.' })[0];
            majorVersion = Convert.ToInt32(majorVersionString);

            /* String xml = System.IO.File.ReadAllText(@"C:\Users\jharrop\workspace\docx4j_1\sample-docs\aaa Document.xml");
            object missing = System.Reflection.Missing.Value;
            Globals.ThisAddIn.Application.Selection.InsertXML(xml, ref missing);
             */
            Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;

            Microsoft.Office.Tools.Word.Document extendedDocument
                = Globals.ThisAddIn.Application.ActiveDocument.GetVstoObject(Globals.Factory);

            extendedDocument.ContentControlBeforeDelete += new Word.DocumentEvents2_ContentControlBeforeDeleteEventHandler(extendedDocument_ContentControlBeforeDelete);
            extendedDocument.ContentControlAfterAdd += new Word.DocumentEvents2_ContentControlAfterAddEventHandler(extendedDocument_ContentControlAfterAdd);

            extendedDocument.ContentControlOnEnter +=new Word.DocumentEvents2_ContentControlOnEnterEventHandler(extendedDocument_ContentControlOnEnter);
            extendedDocument.ContentControlOnExit += new Word.DocumentEvents2_ContentControlOnExitEventHandler(extendedDocument_ContentControlOnExit);
            extendedDocument.ContentControlBeforeStoreUpdate += new Word.DocumentEvents2_ContentControlBeforeStoreUpdateEventHandler(extendedDocument_ContentControlBeforeStoreUpdate);

            extendedDocument.BeforeRightClick += new Microsoft.Office.Tools.Word.ClickEventHandler(extendedDocument_BeforeRightClick);

            extendedDocument.BuildingBlockInsert += new Word.DocumentEvents2_BuildingBlockInsertEventHandler(extendedDocument_BuildingBlockInsert);

            extendedDocument.Shutdown += new EventHandler(Globals.ThisAddIn.extendedDocument_Shutdown);

            FabDocxState fabDocxState = new FabDocxState();
            extendedDocument.Tag = fabDocxState;

            PartCreator pc = null;

            if (newDocument)
            {
                log.Info("OpenDoPE parts not detected; adding now.");
                // Questions - I expect most users will want these,
                // since this particular add-in is targeted at the
                // interactive case,
                // but some won't .. some people doing non-interactive
                // processing won't have their own xml formats.
                // Design decision: always have questions part,
                // as a way of documenting what the answers mean.
                // (Better than to put the description in the answer part)
                // TODO: add meta description to questions.xsd
                pc = new PartCreator();
                pc.process(true);
            }
            else
            {
                // Register content controls
                foreach (Word.ContentControl ccx in Globals.ThisAddIn.Application.ActiveDocument.ContentControls)
                {
                    fabDocxState.registerKnownSdt(ccx);
                }
            }

            fabDocxState.model = Model.ModelFactory(document);
            if (fabDocxState.model.answersPart == null)
            {
                Office.CustomXMLPart answerPart = pc.createAnswersPart(document);

                fabDocxState.model = Model.ModelFactory(document);
                //fabDocxState.model.userParts.Add(answerPart);
                fabDocxState.model.answersPart = answerPart;
                //log.Info(answersXml);
            }
            else
            {
                log.Info("Using existing answers: " + fabDocxState.model.answersPart.XML);
                fabDocxState.model.answersPart.NamespaceManager.AddNamespace("oda", "http://opendope.org/answers");
            }

            // Now we have model, we can:
            try
            {
                fabDocxState.initTaskPane(document);
            }
            catch (Exception e)
            {
                log.Error(e);
                /*
                 * The Stack Trace is:
                      at System.Runtime.InteropServices.Marshal.IsComObject(Object o)
                      at System.Runtime.InteropServices.ComAwareEventInfo.AddEventHandler(Object target, Delegate handler)
                      at Microsoft.Office.Tools.CustomTaskPaneImpl..ctor(_CustomTaskPane customTaskPane, UserControl control)
                      at Microsoft.Office.Tools.CustomTaskPaneCollectionImpl.AddHelper(UserControl control, String title, Object window)
                      at Microsoft.Office.Tools.CustomTaskPaneCollectionImpl.Add(UserControl control, String title, Object window
                 */
                // No matter; we do it later
            }
            //MessageBox.Show("task pane inited");

            // Load FabDocx.dotx
            GlobalTemplateManager.GetGlobalTemplateManager();
        }