Bloom.Edit.EditingModel.GetXmlDocumentForEditScreenWebPage C# (CSharp) Method

GetXmlDocumentForEditScreenWebPage() public method

Return the top-level document that should be displayed in the browser for the current page.
public GetXmlDocumentForEditScreenWebPage ( ) : HtmlDom
return Bloom.Book.HtmlDom
        public HtmlDom GetXmlDocumentForEditScreenWebPage()
        {
            var path = FileLocator.GetFileDistributedWithApplication(Path.Combine(BloomFileLocator.BrowserRoot, "bookEdit", "EditViewFrame.html"));
            // {simulatedPageFileInBookFolder} is placed in the template file where we want the source file for the 'page' iframe.
            // We don't really make a file for the page, the contents are just saved in our local server.
            // But we give it a url that makes it seem to be in the book folder so local urls work.
            // See EnhancedImageServer.MakeSimulatedPageFileInBookFolder() for more details.
            var frameText = RobustFile.ReadAllText(path, Encoding.UTF8).Replace("{simulatedPageFileInBookFolder}", _currentPage.Key);
            var dom = new HtmlDom(XmlHtmlConverter.GetXmlDomFromHtml(frameText));

            if (_currentlyDisplayedBook.BookInfo.ToolboxIsOpen)
            {
                // Make the toolbox initially visible.
                // What we have to do to accomplish this is pretty non-intutive. It's a consequence of the way
                // the pure-drawer CSS achieves the open/close effect. This input is a check-box, so clicking it
                // changes the state of things in a way that all the other CSS can depend on.
                var toolboxCheckBox = dom.SelectSingleNode("//input[@id='pure-toggle-right']");
                if (toolboxCheckBox != null)
                    toolboxCheckBox.SetAttribute("checked", "true");
            }

            return dom;
        }

Usage Example

Example #1
0
        public void UpdateSingleDisplayedPage(IPage page)
        {
            if (!_model.Visible)
            {
                return;
            }

            if (_model.HaveCurrentEditableBook)
            {
                _pageListView.SelectThumbnailWithoutSendingEvent(page);
                _model.SetupServerWithCurrentPageIframeContents();
                HtmlDom domForCurrentPage = _model.GetXmlDocumentForCurrentPage();
                var     dom = _model.GetXmlDocumentForEditScreenWebPage();
                _browser1.Focus();
                _browser1.Navigate(dom.RawDom, domForCurrentPage.RawDom);
                _pageListView.Focus();
                _browser1.Focus();
                // So far, the most reliable way I've found to detect that the page is fully loaded and we can call
                // initialize() is the ReadyStateChanged event (combined with checking that ReadyState is "complete").
                // This works for most pages but not all...some (e.g., the credits page in a basic book) seem to just go on
                // being "interactive". As a desperate step I tried looking for DocumentCompleted (which fires too soon and often),
                // but still, we never get one where the ready state is completed. This page just stays 'interactive'.
                // A desperate expedient would be to try running some Javascript to test whether the 'initialize' function
                // has actually loaded. If you try that, be careful...this function seems to be used in cases where that
                // never happens.
                _browser1.WebBrowser.DocumentCompleted += WebBrowser_ReadyStateChanged;
                _browser1.WebBrowser.ReadyStateChange  += WebBrowser_ReadyStateChanged;
            }
            UpdateDisplay();
        }