Ejemplo n.º 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 (title_start.HasTag(Note.TagTable.UrlTag))
            {
                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);
        }
Ejemplo n.º 2
0
        void OnPopulatePopup(object sender, Gtk.PopulatePopupArgs args)
        {
            Gtk.TextIter click_iter = Buffer.GetIterAtMark(click_mark);
            NoteTag      url_tag    = Note.TagTable.UrlTag;

            if (click_iter.HasTag(url_tag) || click_iter.EndsTag(url_tag))
            {
                Gtk.MenuItem item;

                item = new Gtk.SeparatorMenuItem();
                item.Show();
                args.Menu.Prepend(item);

                item            = new Gtk.MenuItem(Catalog.GetString("_Copy Link Address"));
                item.Activated += CopyLinkActivate;
                item.Show();
                args.Menu.Prepend(item);

                item            = new Gtk.MenuItem(Catalog.GetString("_Open Link"));
                item.Activated += OpenLinkActivate;
                item.Show();
                args.Menu.Prepend(item);
            }
        }
Ejemplo n.º 3
0
 public bool HasLinkTag(Gtk.TextIter iter)
 {
     return(iter.HasTag(LinkTag) || iter.HasTag(UrlTag) || iter.HasTag(BrokenLinkTag));
 }