public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            var currentDoc = CurrentDoc;

            if (CookieDocumentMap.ContainsKey(docCookie))
            {
                CurrentDoc = CookieDocumentMap[docCookie];
                MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1);
                CommandsEnabled = true;
            }
            else
            {
                string fullname = GetDocFullname(docCookie);
                if (IsUDNDocument(fullname))
                {
                    object codeWindow;
                    pFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out codeWindow);

                    IVsTextView view;
                    (codeWindow as IVsCodeWindow).GetPrimaryView(out view);

                    var wpfView = EditorAdaptersFactoryService.GetWpfTextView(view);

                    var docView = new UDNDocView(fullname, wpfView, pFrame, package, UIShell);
                    CookieDocumentMap[docCookie] = docView;
                    docView.ParsingResultsCache.AfterParsingEvent += PassResultsToChangedEvent;

                    CurrentDoc = CookieDocumentMap[docCookie];

                    MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1);
                    CommandsEnabled = true;
                }
                else
                {
                    MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 0);
                    CommandsEnabled = false;
                }
            }

            if (currentDoc != CurrentDoc)
            {
                CurrentUDNDocView.ParsingResultsCache.AsyncReparseIfDirty();
            }

            return(VSConstants.S_OK);
        }
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            var currentDoc = CurrentDoc;

            if (CookieDocumentMap.ContainsKey(docCookie))
            {
                CurrentDoc = CookieDocumentMap[docCookie];
                MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1);
                CommandsEnabled = true;
            }
            else
            {
                string fullname = GetDocFullname(docCookie);
                if (IsUDNDocument(fullname))
                {
                    object codeWindow;
                    pFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out codeWindow);

                    IVsTextView view;
                    (codeWindow as IVsCodeWindow).GetPrimaryView(out view);

                    var wpfView = EditorAdaptersFactoryService.GetWpfTextView(view);

                    var docView = new UDNDocView(fullname, wpfView, pFrame, package, UIShell);
                    CookieDocumentMap[docCookie] = docView;
                    docView.ParsingResultsCache.AfterParsingEvent += PassResultsToChangedEvent;

                    CurrentDoc = CookieDocumentMap[docCookie];

                    MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 1);
                    CommandsEnabled = true;
                }
                else
                {
                    MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 0);
                    CommandsEnabled = false;
                }
            }

            if (currentDoc != CurrentDoc)
            {
                CurrentUDNDocView.ParsingResultsCache.AsyncReparseIfDirty();
            }

            return VSConstants.S_OK;
        }