コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
 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);
 }
コード例 #9
0
        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));
        }
コード例 #10
0
        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;
        }
コード例 #11
0
 public void Add(string text, GlossaryLinkItem value)
 {
     _maxLengthHint = Math.Max(text.Length, _maxLengthHint);
     _trie.AddReverse(text.ToLower(CultureInfo.CurrentCulture
         ), value);
 }
コード例 #12
0
        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;
        }
コード例 #13
0
        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;
            }
        }
コード例 #14
0
 public void Add(string text, GlossaryLinkItem value)
 {
     _maxLengthHint = Math.Max(text.Length, _maxLengthHint);
     _trie.AddReverse(text.ToLower(CultureInfo.CurrentCulture
                                   ), value);
 }
コード例 #15
0
 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;
 }
コード例 #16
0
        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);
        }