private void LoadWikiPage(WikiPage WikiPageCur) { try { textContent.Text=WikiPages.GetWikiPageContentWithWikiPageTitles(WikiPageCur.PageContent); webBrowserWiki.DocumentText=WikiPages.TranslateToXhtml(textContent.Text,false,hasWikiPageTitles: true); } catch(Exception ex) { webBrowserWiki.DocumentText=""; MessageBox.Show(this,Lan.g(this,"This page is broken and cannot be viewed. Error message:")+" "+ex.Message); } }
private void LoadWikiPage(WikiPageHist wikiPageCur) { try { if (string.IsNullOrEmpty(wikiPageCur.PageContent)) { //if this is the first time the user has clicked on this revision, get page content from db (the row's tag will have this as well) wikiPageCur.PageContent = WikiPageHists.GetPageContent(wikiPageCur.WikiPageNum); } textContent.Text = WikiPages.GetWikiPageContentWithWikiPageTitles(wikiPageCur.PageContent); webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(textContent.Text, false, hasWikiPageTitles: true); } catch (Exception ex) { webBrowserWiki.DocumentText = ""; MessageBox.Show(this, Lan.g(this, "This page is broken and cannot be viewed. Error message:") + " " + ex.Message); } }
private void FormWikiEdit_FormClosing(object sender, FormClosingEventArgs e) { //handles both the Cancel button and the user clicking on the x, and also the save button. WikiSaveEvent.Fired -= WikiSaveEvent_Fired; if (HasSaved) { return; } if (!WikiPageCur.IsNew && textContent.Text != WikiPages.GetWikiPageContentWithWikiPageTitles(WikiPageCur.PageContent)) { if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "Unsaved changes will be lost. Would you like to continue?")) { e.Cancel = true; } } }
private void FormWikiEdit_Load(object sender, EventArgs e) { SetFilterControlsAndAction(() => RefreshHtml(), (int)TimeSpan.FromSeconds(0.5).TotalMilliseconds, textContent); ResizeControls(); //LayoutToolBar(); Text = Lan.g(this, "Wiki Edit") + " - " + WikiPageCur.PageTitle; if (WikiPageCur.IsNew) { textContent.Text = WikiPageCur.PageContent; } else { textContent.Text = WikiPages.GetWikiPageContentWithWikiPageTitles(WikiPageCur.PageContent); } string[] strArray = new string[1]; strArray[0] = "\n"; textContent.Focus(); textContent.SelectionStart = 0; textContent.SelectionLength = 0; textContent.ScrollToCaret(); RefreshHtml(); }
///<summary>Before calling this, make sure to increment/decrement the historyNavBack index to keep track of the position in history. If loading a new page, decrement historyNavBack before calling this function. </summary> private void LoadWikiPage(string pageTitle) { //This is called from 11 different places, any time the program needs to refresh a page from the db. //It's also called from the browser_Navigating event when a "wiki:" link is clicked. WikiPage wpage = WikiPages.GetByTitle(pageTitle); if (wpage == null) { string errorMsg = ""; if (!WikiPages.IsWikiPageTitleValid(pageTitle, out errorMsg)) { MsgBox.Show(this, "That page does not exist and cannot be made because the page title contains invalid characters."); return; } if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "That page does not exist. Would you like to create it?")) { return; } Action <string> onWikiSaved = new Action <string>((pageTitleNew) => { //Insert the pageTitleNew where the pageTitle exists in the existing WikiPageCur //(guaranteed to be unique because all INVALID WIKIPAGE LINK's have an ID at the end) string pageContent = WikiPages.GetWikiPageContentWithWikiPageTitles(WikiPageCur.PageContent); WikiPageCur.PageContent = pageContent.Replace(pageTitle, pageTitleNew); WikiPageCur.PageContent = WikiPages.ConvertTitlesToPageNums(WikiPageCur.PageContent); WikiPages.Update(WikiPageCur); }); AddWikiPage(onWikiSaved); return; } WikiPageCur = wpage; try { webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(WikiPageCur.PageContent, false); } catch (Exception ex) { webBrowserWiki.DocumentText = ""; MessageBox.Show(this, Lan.g(this, "This page is broken and cannot be viewed. Error message:") + " " + ex.Message); } Text = "Wiki - " + WikiPageCur.PageTitle; #region historyMaint //This region is duplicated in webBrowserWiki_Navigating() for external links. Modifications here will need to be reflected there. int indexInHistory = historyNav.Count - (1 + historyNavBack); //historyNavBack number of pages before the last page in history. This is the index of the page we are loading. if (historyNav.Count == 0) //empty history { historyNavBack = 0; historyNav.Add("wiki:" + pageTitle); } else if (historyNavBack < 0) //historyNavBack could be negative here. This means before the action that caused this load, we were not navigating through history, simply set back to 0 and add to historyNav[] if necessary. { historyNavBack = 0; if (historyNav[historyNav.Count - 1] != "wiki:" + pageTitle) { historyNav.Add("wiki:" + pageTitle); } } else if (historyNavBack >= 0 && historyNav[indexInHistory] != "wiki:" + pageTitle) //branching from page in history { historyNav.RemoveRange(indexInHistory, historyNavBack + 1); //remove "forward" history. branching off in a new direction historyNavBack = 0; historyNav.Add("wiki:" + pageTitle); } #endregion }