///<summary>Saves the the currently edited Wikipage as a draft. This method is copied from Save_Click with a few modifications.</summary> private void SaveDraft_Click(bool showMsgBox = true) { if (showMsgBox && WikiPageCur.IsNew) { MsgBox.Show(this, "You may not save a new Wiki page as a draft. Save the Wiki page, then create a draft."); return; } if (!MarkupL.ValidateMarkup(textContent, true, showMsgBox)) { return; } if (showMsgBox && _isInvalidPreview) { MsgBox.Show(this, "This page is in an invalid state and cannot be saved as a draft."); return; } 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) //If it's already a draft, overwrite the current one. { WikiPageCur.DateTimeSaved = DateTime.Now; try { WikiPages.UpdateDraft(WikiPageCur); } catch (Exception ex) { //should never happen due to the if Draft check above. if (showMsgBox) { MessageBox.Show(ex.Message); } return; } } else //otherwise, set it as a draft, then insert it. { WikiPageCur.IsDraft = true; WikiPages.InsertAsDraft(WikiPageCur); } //HasSaved not set so that the user will stay in FormWikiDrafts when this window closes, causing the grid to update. Close(); }