private void GenerateActionsEnum() { StreamWriter streamWriter = File.CreateText(Path.Combine(this.htmlSavePath, "ActionsEnum.txt")); for (int i = 0; i < Actions.List.get_Count(); i++) { if (!(Actions.CategoryLookup.get_Item(i) == "Tests")) { Type type = Actions.List.get_Item(i); string text = Labels.StripNamespace(type.ToString()); if (Enum.IsDefined(typeof(WikiPages), text)) { WikiPages wikiPages = PlayMakerDocHelpers.StringToEnum <WikiPages>(text); streamWriter.WriteLine(string.Concat(new object[] { "\t\t\t", text, " = ", (int)wikiPages, "," })); } else { streamWriter.WriteLine("\t\t\t" + text + " = TODO,"); } } } streamWriter.Close(); }
/// <summary></summary> private void FillGrid() { gridMain.BeginUpdate(); gridMain.Columns.Clear(); ODGridColumn col = new ODGridColumn(Lan.g(this, "Image Name"), 70); gridMain.Columns.Add(col); gridMain.Rows.Clear(); string[] fileNames = System.IO.Directory.GetFiles(WikiPages.GetWikiPath()); //All files from the wiki file path, including images and other files. ImageNamesList = new List <string>(); for (int i = 0; i < fileNames.Length; i++) { //If the user has entered a search keyword, then only show file names which contain the keyword. if (textSearch.Text != "" && !Path.GetFileName(fileNames[i]).ToLower().Contains(textSearch.Text.ToLower())) { continue; } //Only add image files to the ImageNamesList, not other files such at text files. if (ImageHelper.HasImageExtension(fileNames[i])) { ImageNamesList.Add(fileNames[i]); } } for (int i = 0; i < ImageNamesList.Count; i++) { ODGridRow row = new ODGridRow(); row.Cells.Add(Path.GetFileName(ImageNamesList[i])); gridMain.Rows.Add(row); } gridMain.EndUpdate(); labelImageSize.Text = Lan.g(this, "Image Size") + ":"; picturePreview.Image = null; picturePreview.Invalidate(); }
public void WikiPages_ConvertToPlainText_HTML() { string htmltags = "<h2>Ideas</h2> <h3>Common Passwords file</h3>A file would be &>included that would contain</br> the top 1000 or so"; string htmlResult = "Ideas Common Passwords fileA file would be &>included that would contain the top 1000 or so"; Assert.AreEqual(htmlResult, WikiPages.ConvertToPlainText(htmltags)); }
private bool ValidateTitle() { if (textPageTitle.Text == "") { MsgBox.Show(this, "Page title cannot be empty."); return(false); } if (textPageTitle.Text == PageTitle) { //"rename" to the same thing. DialogResult = DialogResult.Cancel; return(false); } string errorMsg = ""; if (!WikiPages.IsWikiPageTitleValid(textPageTitle.Text, out errorMsg)) { MessageBox.Show(errorMsg); //errorMsg was already translated. return(false); } if (PageTitle != null && textPageTitle.Text.ToLower() == PageTitle.ToLower()) { //the user is just trying to change the capitalization, which is allowed return(true); } WikiPage wp = WikiPages.GetByTitle(textPageTitle.Text); //this is case insensitive, so it won't let you name it the same as another page even if capitalization is different. if (wp != null) { MsgBox.Show(this, "Page title already exists."); return(false); } return(true); }
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(); }
private void butImport_Click(object sender, EventArgs e) { OpenFileDialog openFD = new OpenFileDialog(); openFD.Multiselect = true; if (openFD.ShowDialog() != DialogResult.OK) { return; } Invalidate(); foreach (string fileName in openFD.FileNames) { //check file types? string destinationPath = WikiPages.GetWikiPath() + "\\" + Path.GetFileName(fileName); if (File.Exists(destinationPath)) { switch (MessageBox.Show(Lan.g(this, "Overwrite Existing File") + ": " + destinationPath, "", MessageBoxButtons.YesNoCancel)) { case DialogResult.No: //rename, do not overwrite InputBox ip = new InputBox(Lan.g(this, "New file name.")); ip.textResult.Text = Path.GetFileName(fileName); ip.ShowDialog(); if (ip.DialogResult != DialogResult.OK) { continue; //cancel, next file. } bool cancel = false; while (File.Exists(WikiPages.GetWikiPath() + "\\" + ip.textResult.Text) && !cancel) { MsgBox.Show(this, "File name already exists."); if (ip.ShowDialog() != DialogResult.OK) { cancel = true; } } if (cancel) { continue; //cancel rename, and go to next file. } destinationPath = WikiPages.GetWikiPath() + "\\" + ip.textResult.Text; break; //proceed to save file. case DialogResult.Yes: //overwrite try { File.Delete(destinationPath); } catch (Exception ex) { MessageBox.Show(Lan.g(this, "Cannot copy file") + ":" + fileName + "\r\n" + ex.Message); continue; } break; //file deleted, proceed to save. default: //cancel continue; //skip this file. } } File.Copy(fileName, destinationPath); } FillGrid(); }
/// <summary></summary> private void FillGrid() { gridMain.BeginUpdate(); gridMain.Columns.Clear(); ODGridColumn col = new ODGridColumn(Lan.g(this, "Title"), 70); gridMain.Columns.Add(col); //col=new ODGridColumn(Lan.g(this,"Saved"),42); //gridMain.Columns.Add(col); gridMain.Rows.Clear(); if (checkArchivedOnly.Checked) { //This used to search the wikipagehist table, now archived pages are stored in wikipage. See JobNum 4429. listWikiPageTitles = WikiPages.GetForSearch(textSearch.Text, checkIgnoreContent.Checked, isDeleted: true); } else { listWikiPageTitles = WikiPages.GetForSearch(textSearch.Text, checkIgnoreContent.Checked); } for (int i = 0; i < listWikiPageTitles.Count; i++) { ODGridRow row = new ODGridRow(); row.Cells.Add(listWikiPageTitles[i]); gridMain.Rows.Add(row); } gridMain.EndUpdate(); webBrowserWiki.DocumentText = ""; }
///<summary>Loads page from history based on historyCurIndex.</summary> private void NavToHistory() { if (historyNavBack < 0 || historyNavBack > historyNav.Count - 1) { //This should never happen. MsgBox.Show(this, "Invalid history index."); return; } string pageName = historyNav[historyNav.Count - (1 + historyNavBack)]; //-1 is the last/current page. if (pageName.StartsWith("wiki:")) { pageName = pageName.Substring(5); WikiPage wpage = WikiPages.GetByTitle(pageName); if (wpage == null) { MessageBox.Show("'" + historyNav[historyNav.Count - (1 + historyNavBack)] + "' page does not exist."); //very rare return; } //historyNavBack--;//no need to decrement since this is only called from Back_Click and Forward_Click and the appropriate adjustment to this index happens there LoadWikiPage(pageName); //because it's a duplicate, it won't add it again to the list. } else if (pageName.StartsWith("http://")) //www //no need to set the text because the Navigating event will fire and take care of that. { webBrowserWiki.Navigate(pageName); } else { //? } }
public void WikiPages_IsWikiPageTitleValid_Underline() { string titleUnderline, container; titleUnderline = "_Title that contains an underline"; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleUnderline, out container)); }
public void WikiPages_IsWikiPageTitleValid_Quotes() { string titleQuote, container; titleQuote = "This is really only 1/2 a \"title\"."; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleQuote, out container)); }
public void WikiPages_ConvertToPlainText_PageLinks() { string PageLinks = "This is a title: [[234]] that shouldn't be [There]"; string pageLinkResult = "This is a title: that shouldn't be [There]"; Assert.AreEqual(pageLinkResult, WikiPages.ConvertToPlainText(PageLinks)); }
private void File_Link_Click() { string fileLink; if (CloudStorage.IsCloudStorage) { FormFilePicker FormFP = new FormFilePicker(WikiPages.GetWikiPath()); FormFP.DoHideLocalButton = true; FormFP.ShowDialog(); if (FormFP.DialogResult != DialogResult.OK) { return; } fileLink = FormFP.SelectedFiles[0]; textContent.SelectedText = "[[filecloud:" + fileLink + "]]"; } else //Not cloud { FormWikiFileFolder FormWFF = new FormWikiFileFolder(); FormWFF.ShowDialog(); if (FormWFF.DialogResult != DialogResult.OK) { return; } fileLink = FormWFF.SelectedLink; textContent.SelectedText = "[[file:" + fileLink + "]]"; } textContent.SelectionLength = 0; //RefreshHtml(); }
private void Folder_Link_Click() { if (CloudStorage.IsCloudStorage) { FormFilePicker FormFP = new FormFilePicker(CloudStorage.PathTidy(WikiPages.GetWikiPath())); FormFP.DoHideLocalButton = true; FormFP.ShowDialog(); if (FormFP.DialogResult != DialogResult.OK) { return; } textContent.SelectedText = "[[foldercloud:" + FormFP.SelectedFiles[0] + "]]"; } else { FormWikiFileFolder formWFF = new FormWikiFileFolder(); formWFF.IsFolderMode = true; formWFF.ShowDialog(); if (formWFF.DialogResult != DialogResult.OK) { return; } textContent.SelectedText = "[[folder:" + formWFF.SelectedLink + "]]"; } textContent.SelectionLength = 0; //RefreshHtml(); }
/// <summary></summary> private void FillGrid() { gridMain.BeginUpdate(); gridMain.Columns.Clear(); ODGridColumn col = new ODGridColumn(Lan.g(this, "Title"), 70); gridMain.Columns.Add(col); //col=new ODGridColumn(Lan.g(this,"Saved"),42); //gridMain.Columns.Add(col); gridMain.Rows.Clear(); if (checkDeletedOnly.Checked) { listWikiPageTitles = WikiPageHists.GetDeletedPages(textSearch.Text, checkIgnoreContent.Checked); } else { listWikiPageTitles = WikiPages.GetForSearch(textSearch.Text, checkIgnoreContent.Checked); } for (int i = 0; i < listWikiPageTitles.Count; i++) { ODGridRow row = new ODGridRow(); row.Cells.Add(listWikiPageTitles[i]); gridMain.Rows.Add(row); } gridMain.EndUpdate(); webBrowserWiki.DocumentText = ""; }
///<summary>Adds a new wikipage.</summary> private void butAdd_Click(object sender, EventArgs e) { FormWikiRename FormWR = new FormWikiRename(); FormWR.ShowDialog(); if (FormWR.DialogResult != DialogResult.OK) { return; } Action <string> onWikiSaved = new Action <string>((pageTitleNew) => { //return the new wikipage added to FormWikiEdit WikiPage wp = WikiPages.GetByTitle(pageTitleNew); if (wp != null && OwnerForm != null && !OwnerForm.IsDisposed) { OwnerForm.RefreshPage(wp); } }); FormWikiEdit FormWE = new FormWikiEdit(onWikiSaved); FormWE.WikiPageCur = new WikiPage(); FormWE.WikiPageCur.IsNew = true; FormWE.WikiPageCur.PageTitle = FormWR.PageTitle; FormWE.WikiPageCur.PageContent = "[[" + OwnerForm.WikiPageCur.PageTitle + "]]\r\n" //link back + "<h1>" + FormWR.PageTitle + "</h1>\r\n"; //page title FormWE.Show(); Close(); }
/// <summary></summary> private void FillGrid() { if (textSearch.TextLength < 3) { gridMain.BeginUpdate(); gridMain.ListGridColumns.Clear(); gridMain.ListGridRows.Clear(); gridMain.EndUpdate(); return; } gridMain.BeginUpdate(); gridMain.ListGridColumns.Clear(); GridColumn col = new GridColumn(Lan.g(this, "Title"), 70); gridMain.ListGridColumns.Add(col); //col=new ODGridColumn(Lan.g(this,"Saved"),42); //gridMain.Columns.Add(col); gridMain.ListGridRows.Clear(); listWikiPages = WikiPages.GetByTitleContains(textSearch.Text); for (int i = 0; i < listWikiPages.Count; i++) { GridRow row = new GridRow(); //if(listWikiPages[i].IsDeleted) {//color is not a good way to indicate deleted because it is not self explanatory. Need another column for Deleted X. // row.ColorText=Color.Red; //} row.Cells.Add(listWikiPages[i].PageTitle); gridMain.ListGridRows.Add(row); } gridMain.EndUpdate(); }
public void WikiPages_IsWikiPageTitleValid_HashMark() { string titleHash, container; titleHash = "Title with an # mark"; container = ""; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleHash, out container)); }
public void WikiPages_IsWikiPageTitleValid() { string titleValid, container; titleValid = "This is a valid title"; container = ""; Assert.IsTrue(WikiPages.IsWikiPageTitleValid(titleValid, out container)); }
public void WikiPages_IsWikiPageTitleValid_MultipleLines() { string titleNewLine, container; titleNewLine = "Two line \r\n title"; container = ""; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleNewLine, out container)); }
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?? }
private void butOK_Click(object sender, EventArgs e) { WikiPage masterPage = WikiPages.MasterPage; masterPage.PageContent = textMaster.Text; masterPage.UserNum = Security.CurUser.UserNum; WikiPages.InsertAndArchive(masterPage); DataValid.SetInvalid(InvalidType.Wiki); DialogResult = DialogResult.OK; }
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(WikiPage wikiPage) { try { webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(wikiPage.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); } }
private bool HasExistingWikiPage(WikiPage wikiPage, out WikiPage wpExisting) { wpExisting = null; if (wikiPage == null) { return(false); //This shouldn't happen. } wpExisting = WikiPages.GetByTitle(wikiPage.PageTitle); if (wpExisting == null) { return(false); } return(true); }
private void LoadWikiPage(string WikiPageTitleCur) { webBrowserWiki.AllowNavigation = true; butRestore.Enabled = false; if (checkDeletedOnly.Checked) { webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(WikiPageHists.GetDeletedByTitle(WikiPageTitleCur).PageContent, true); butRestore.Enabled = true; } else { webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(WikiPages.GetByTitle(WikiPageTitleCur).PageContent, true); } }
///<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) { if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "That page does not exist. Would you like to create it?")) { return; } FormWikiEdit FormWE = new FormWikiEdit(); FormWE.WikiPageCur = new WikiPage(); FormWE.WikiPageCur.IsNew = true; FormWE.WikiPageCur.PageTitle = pageTitle; FormWE.WikiPageCur.PageContent = "[[" + WikiPageCur.PageTitle + "]]\r\n" //link back + "<h1>" + pageTitle + "</h1>\r\n"; //page title FormWE.OwnerForm = this; FormWE.Show(); return; } WikiPageCur = wpage; webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(WikiPageCur.PageContent, false); 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 }
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 RefreshHtml() { webBrowserWiki.AllowNavigation = true; try { //remember scroll if (webBrowserWiki.Document != null) { ScrollTop = webBrowserWiki.Document.GetElementsByTagName("HTML")[0].ScrollTop; } webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(textContent.Text, true); } catch (Exception ex) { //don't refresh } //textContent.Focus();//this was causing a bug where it would re-highlight text after a backspace. }
private void Drafts_Click() { if (WikiPageCur == null) { return; } if (WikiPages.GetDraftsByTitle(WikiPageCur.PageTitle).Count == 0) { MsgBox.Show(this, "There are no drafts for this Wiki Page."); return; } FormWikiDrafts FormWD = new FormWikiDrafts(); FormWD.OwnerForm = this; FormWD.ShowDialog(); }
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); } }