Esempio n. 1
0
		private void butDelete_Click(object sender,EventArgs e) {
			if(gridMain.GetSelectedIndex()<0) {
				return;
			}
			int selectedIndex=gridMain.GetSelectedIndex();
			if(!MsgBox.Show(this,MsgBoxButtons.YesNo,"Delete this draft?")) {
				return;
			}
			try {
				WikiPages.DeleteDraft(_listWikiPage[selectedIndex]);
			}
			catch (Exception ex){
				//should never happen because we are only ever editing drafts here.
				MessageBox.Show(ex.Message);
				return;
			}
			//deleting Edge cases.
			FillGrid();
			if(selectedIndex>=_listWikiPage.Count) {
				selectedIndex--;
			}
			if(_listWikiPage.Count<1) {
				//Nothing else a user could possibly do when there are no drafts. Exit.
				Close();
				return;
			}
			gridMain.SetSelected(selectedIndex,true);
			webBrowserWiki.AllowNavigation=true;
			LoadWikiPage(_listWikiPage[selectedIndex]);
			gridMain.Focus();
		}
Esempio n. 2
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??
        }