private void buttonAdd_Click(object sender, EventArgs e) { try { using (new WaitCursor()) { GlossaryLinkItem newEntry = GlossaryManager.Instance.AddFromForm(FindForm()); if (newEntry != null) { listViewGlossary.CheckForDelete(newEntry.Text, null); ListViewItem item = listViewGlossary.AddGlossaryItem(newEntry); // select the item that was added listViewGlossary.SelectedItems.Clear(); item.Selected = true; item.Focused = true; item.EnsureVisible(); // set focus to the list listViewGlossary.Focus(); } return; } } catch (Exception ex) { UnexpectedErrorMessage.Show(ex); } }
public GlossaryLinkItem AddEntry(string text, string url, string title, string rel, bool openInNewWindow) { if (title == null) { title = String.Empty; } if (url == null) { throw new ArgumentException("url cannot be null"); } if (text == null) { throw new ArgumentException("text cannot be null"); } lock (_lock) { RemoveEntry(text); GlossaryLinkItem entry = new GlossaryLinkItem(text, url, title, rel, openInNewWindow); _entries.Add(text, entry); XmlNode newEntry = GlossaryLinkXmlFromItem(entry); mainNode.AppendChild(newEntry); SaveGlossary(); finder.Add(text, entry); return(entry); } }
private void EditSelectedEntry() { if (SelectedEntry == null) { return; } try { using (new WaitCursor()) { GlossaryLinkItem revisedEntry = GlossaryManager.Instance.EditEntry(FindForm(), SelectedEntry.Text); if (revisedEntry != null) { listViewGlossary.CheckForDelete(revisedEntry.Text, listViewGlossary.SelectedItems[0]); // refresh contents of list-view item listViewGlossary.PopulateListItem(listViewGlossary.SelectedItems[0], revisedEntry); } // set focus to the list listViewGlossary.Focus(); } } catch (Exception ex) { UnexpectedErrorMessage.Show(ex); } }
public void PopulateListItem(ListViewItem item, GlossaryLinkItem entry) { // Set tag (back-reference to profile) item.Tag = entry; item.SubItems.Clear(); // set text item.Text = String.Format(CultureInfo.InvariantCulture, "{0}", entry.Text); item.SubItems.Add(String.Format(CultureInfo.InvariantCulture, "{0}", entry.Url)); }
public ListViewItem AddGlossaryItem(GlossaryLinkItem entry) { // create a new list view item ListViewItem listViewItem = new ListViewItem(); PopulateListItem(listViewItem, entry); // add the item to the list and return it Items.Add(listViewItem); return(listViewItem); }
private XmlNode GlossaryLinkXmlFromItem(GlossaryLinkItem item) { XmlElement entryNode = glossaryDocument.CreateElement("entry"); AppendNode(entryNode, TEXT, item.Text); AppendNode(entryNode, URL, item.Url); AppendNode(entryNode, TITLE, item.Title); AppendNode(entryNode, REL, item.Rel); AppendNode(entryNode, NEWWINDOW, item.OpenInNewWindow.ToString()); return(entryNode); }
public bool FindExactEntry(string text, string url, string title) { lock (_lock) { if (_entries.ContainsKey(text)) { GlossaryLinkItem foundItem = (GlossaryLinkItem)_entries[text]; return(foundItem.Url.Equals(url, StringComparison.OrdinalIgnoreCase) && foundItem.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase)); } return(false); } }
public GlossaryLinkItem EditEntry(Form parent, string text) { //shows form to edit existing entry using (AddLinkDialog editForm = new AddLinkDialog(_entries.Keys)) { editForm.Edit = true; GlossaryLinkItem editItem = (GlossaryLinkItem)_entries[text]; editForm.LinkText = editItem.Text; editForm.Url = editItem.Url; editForm.Title = editItem.Title; editForm.OpenInNewWindow = editItem.OpenInNewWindow; editForm.Rel = editItem.Rel; if (DialogResult.OK == editForm.ShowDialog(parent)) { //if the link text was changed, make sure to delete the original entry if (!editItem.Text.Equals(editForm.LinkText, StringComparison.CurrentCultureIgnoreCase)) { if (_entries.ContainsKey(editForm.LinkText)) { if (DisplayMessage.Show(MessageId.ConfirmReplaceEntry) == DialogResult.Yes) { RemoveEntry(text); } else { return(null); } } lock (_lock) { DeleteEntry(editItem.Text); return(AddEntry(editForm.LinkText, editForm.Url, editForm.Title, editForm.Rel, editForm.OpenInNewWindow)); } } else { return(AddEntry(editForm.LinkText, editForm.Url, editForm.Title, editForm.Rel, editForm.OpenInNewWindow)); } } } return(null); }
public ListViewItem AddGlossaryItem(GlossaryLinkItem entry) { // create a new list view item ListViewItem listViewItem = new ListViewItem(); PopulateListItem(listViewItem, entry); // add the item to the list and return it Items.Add(listViewItem); return listViewItem; }
public void Add(string text, GlossaryLinkItem value) { _maxLengthHint = Math.Max(text.Length, _maxLengthHint); _trie.AddReverse(text.ToLower(CultureInfo.CurrentCulture ), value); }
private XmlNode GlossaryLinkXmlFromItem(GlossaryLinkItem item) { XmlElement entryNode = glossaryDocument.CreateElement("entry"); AppendNode(entryNode, TEXT, item.Text); AppendNode(entryNode, URL, item.Url); AppendNode(entryNode, TITLE, item.Title); AppendNode(entryNode, REL, item.Rel); AppendNode(entryNode, NEWWINDOW, item.OpenInNewWindow.ToString()); return entryNode; }
public GlossaryLinkItem AddEntry(string text, string url, string title, string rel, bool openInNewWindow) { if (title == null) title = String.Empty; if (url == null) throw new ArgumentException("url cannot be null"); if (text == null) throw new ArgumentException("text cannot be null"); lock (_lock) { RemoveEntry(text); GlossaryLinkItem entry = new GlossaryLinkItem(text, url, title, rel, openInNewWindow); _entries.Add(text, entry); XmlNode newEntry = GlossaryLinkXmlFromItem(entry); mainNode.AppendChild(newEntry); SaveGlossary(); finder.Add(text, entry); return entry; } }
private void IgnoreSuggestedUrl(string matchText, GlossaryLinkItem linkItem, MarkupRange markupRange) { IHTMLElement parent = markupRange.ParentElement(); while (parent != null && !(parent is IHTMLAnchorElement)) { parent = parent.parentElement; } if (parent != null && matchText.ToLower(CultureInfo.CurrentCulture) == parent.innerText.ToLower(CultureInfo.CurrentCulture)) _linkIgnoreWord = matchText; }
private void InsertSuggestedUrl(string matchText, GlossaryLinkItem linkItem, MarkupRange markupRange) { if (GlossarySettings.AutoLinkTermsOnlyOnce && TermAlreadyLinked(matchText, linkItem.Url)) return; // Make sure we're not in the title and not in a hyperlink already IHTMLElement parentElement = _blogPostHtmlEditorControl.PostTitleElement; IHTMLElement currentElement = markupRange.ParentElement(); while (currentElement != null) { if (parentElement == currentElement) return; // in the title if (currentElement.tagName.ToLower(CultureInfo.InvariantCulture) == "a") return; // in an anchor currentElement = currentElement.parentElement; } if (_linkIgnoreWord != null && matchText.ToLower(CultureInfo.CurrentCulture) == _linkIgnoreWord.ToLower(CultureInfo.CurrentCulture)) return; _blogPostHtmlEditorControl.InsertLink(linkItem.Url, matchText, linkItem.Title, linkItem.Rel, linkItem.OpenInNewWindow, markupRange); _blogPostHtmlEditorControl.SelectedMarkupRange.Collapse(false); }