Example #1
0
        void DoHighlight(TrieHit hit, Gtk.TextIter start, Gtk.TextIter end)
        {
            // Some of these checks should be replaced with fixes to
            // TitleTrie.FindMatches, probably.
            if (hit.Value == null)
            {
                Logger.Debug("DoHighlight: null pointer error for '{0}'.", hit.Key);
                return;
            }

            if (Manager.Find(hit.Key) == null)
            {
                Logger.Debug("DoHighlight: '{0}' links to non-existing note.", hit.Key);
                return;
            }

            Note hit_note = (Note)hit.Value;

            if (String.Compare(hit.Key.ToString(), hit_note.Title.ToString(), true) != 0)                 // == 0 if same string
            {
                Logger.Debug("DoHighlight: '{0}' links wrongly to note '{1}'.", hit.Key, hit_note.Title);
                return;
            }

            if (hit_note == this.Note)
            {
                return;
            }

            Gtk.TextIter title_start = start;
            title_start.ForwardChars(hit.Start);

            Gtk.TextIter title_end = start;
            title_end.ForwardChars(hit.End);

            // Only link against whole words/phrases
            if ((!title_start.StartsWord() && !title_start.StartsSentence()) ||
                (!title_end.EndsWord() && !title_end.EndsSentence()))
            {
                return;
            }

            // Don't create links inside URLs
            if (Note.TagTable.HasLinkTag(title_start))
            {
                return;
            }

            Logger.Debug("Matching Note title '{0}' at {1}-{2}...",
                         hit.Key,
                         hit.Start,
                         hit.End);

            Buffer.RemoveTag(Note.TagTable.BrokenLinkTag, title_start, title_end);
            Buffer.ApplyTag(Note.TagTable.LinkTag, title_start, title_end);
        }