Example #1
0
        private void Save_Click()
        {
            if (!ValidateWikiPage(true))
            {
                return;
            }
            WikiPage wikiPageDB = WikiPages.GetByTitle(WikiPageCur.PageTitle);

            if (wikiPageDB != null && WikiPageCur.DateTimeSaved < wikiPageDB.DateTimeSaved)
            {
                if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This page has been modified and saved since it was opened on this computer.  Save anyway?"))
                {
                    return;
                }
            }
            WikiPageCur.PageContent = textContent.Text;
            //Fix case on all internal links
            MatchCollection matches = Regex.Matches(WikiPageCur.PageContent, @"\[\[.+?\]\]");

            foreach (Match match in matches)
            {
                if (match.Value.StartsWith("[[img:") ||
                    match.Value.StartsWith("[[keywords:") ||
                    match.Value.StartsWith("[[file:") ||
                    match.Value.StartsWith("[[folder:") ||
                    match.Value.StartsWith("[[list:") ||
                    match.Value.StartsWith("[[color:"))
                {
                    continue;                    //we don't care about these.  We are only checking internal links
                }
                //Get the pagename of the link
                string oldTitle = match.Value.Substring(2, match.Value.Length - 4);
                string newTitle = WikiPages.GetTitle(oldTitle);
                if (oldTitle == newTitle)               //casing matches
                {
                    continue;
                }
                if (newTitle == "")               //broken link, leave alone
                {
                    continue;
                }
                WikiPageCur.PageContent = WikiPageCur.PageContent.Replace("[[" + oldTitle + "]]", "[[" + newTitle + "]]");
            }
            WikiPageCur.UserNum = Security.CurUser.UserNum;
            Regex regex = new Regex(@"\[\[(keywords:).+?\]\]");          //only grab first match
            Match m     = regex.Match(textContent.Text);

            WikiPageCur.KeyWords = m.Value.Replace("[[keywords:", "").TrimEnd(']');         //will be empty string if no match
            WikiPages.InsertAndArchive(WikiPageCur);
            FormWiki formWiki = (FormWiki)this.OwnerForm;

            if (formWiki != null && !formWiki.IsDisposed)
            {
                formWiki.RefreshPage(WikiPageCur.PageTitle);
            }
            closingIsSave = true;
            Close();            //should be dialog result??
        }
Example #2
0
		private void menuItemWiki_Click(object sender,EventArgs e) {
			if(Plugins.HookMethod(this,"FormOpenDental.menuItemWiki_Click")) {
				return;
			}
			if(FormMyWiki==null || FormMyWiki.IsDisposed) {
				FormMyWiki=new FormWiki();
			}
			FormMyWiki.Show();
			if(FormMyWiki.WindowState==FormWindowState.Minimized) {
				FormMyWiki.WindowState=FormWindowState.Normal;
			}
			FormMyWiki.BringToFront();
		}
Example #3
0
        private void Save_Click()
        {
            if (!MarkupL.ValidateMarkup(textContent, true))
            {
                return;
            }
            if (_isInvalidPreview)
            {
                MsgBox.Show(this, "This page is in an invalid state and cannot be saved.");
                return;
            }
            WikiPage wikiPageDB = WikiPages.GetByTitle(WikiPageCur.PageTitle);

            if (wikiPageDB != null && WikiPageCur.DateTimeSaved < wikiPageDB.DateTimeSaved)
            {
                if (WikiPageCur.IsDraft)
                {
                    if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "The wiki page has been edited since this draft was last saved.  Overwrite and continue?"))
                    {
                        return;
                    }
                }
                else if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This page has been modified and saved since it was opened on this computer.  Save anyway?"))
                {
                    return;
                }
            }
            List <string> listInvalidWikiPages = WikiPages.GetMissingPageTitles(textContent.Text);
            string        message = Lan.g(this, "This page has the following invalid wiki page link(s):") + "\r\n" + string.Join("\r\n", listInvalidWikiPages.Take(10)) + "\r\n"
                                    + (listInvalidWikiPages.Count > 10 ? "...\r\n\r\n" : "\r\n")
                                    + Lan.g(this, "Create the wikipage(s) automatically?");

            if (listInvalidWikiPages.Count != 0 && MsgBox.Show(this, MsgBoxButtons.YesNo, message))
            {
                foreach (string title in listInvalidWikiPages)
                {
                    WikiPage wp = new WikiPage();
                    wp.PageTitle   = title;
                    wp.UserNum     = Security.CurUser.UserNum;
                    wp.PageContent = "[[" + WikiPageCur.WikiPageNum + "]]\r\n" //link back
                                     + "<h1>" + title + "</h1>\r\n";           //page title
                    WikiPages.InsertAndArchive(wp);
                }
            }
            WikiPageCur.PageContent = WikiPages.ConvertTitlesToPageNums(textContent.Text);
            WikiPageCur.UserNum     = Security.CurUser.UserNum;
            Regex regex = new Regex(@"\[\[(keywords:).+?\]\]");          //only grab first match
            Match m     = regex.Match(textContent.Text);

            WikiPageCur.KeyWords = m.Value.Replace("[[keywords:", "").TrimEnd(']');         //will be empty string if no match
            if (WikiPageCur.IsDraft)
            {
                WikiPages.DeleteDraft(WikiPageCur);   //remove the draft from the database.
                WikiPageCur.IsDraft = false;          //no longer a draft
                if (wikiPageDB != null)               //wikiPageDb should never be null, otherwise there was no way to get to this draft.
                //We need to set the draft copy of the wiki page to the WikiPageNum of the real page.
                //This is because the draft is the most up to date copy of the wiki page, and is about to be saved, however, we want to maintain any
                //links there may be to the real wiki page, since we link by WikiPageNum instead of PageTitle (see JobNum 4429 for more info)
                {
                    WikiPageCur.WikiPageNum = wikiPageDB.WikiPageNum;
                }
            }
            WikiPages.InsertAndArchive(WikiPageCur);
            //If the form was given an action, fire it.
            _onWikiSaved?.Invoke(WikiPageCur.PageTitle);
            FormWiki formWiki = (FormWiki)this.OwnerForm;

            if (formWiki != null && !formWiki.IsDisposed)
            {
                formWiki.RefreshPage(WikiPageCur.PageTitle);
            }
            HasSaved = true;
            Close();            //should be dialog result??
        }
		private void menuItemWiki_Click(object sender,EventArgs e) {
			if(FormMyWiki==null || FormMyWiki.IsDisposed) {
				FormMyWiki=new FormWiki();
			}
			FormMyWiki.Show();
			if(FormMyWiki.WindowState==FormWindowState.Minimized) {
				FormMyWiki.WindowState=FormWindowState.Normal;
			}
			FormMyWiki.BringToFront();
		}