示例#1
0
        void ApplyUrlToBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       256 /* max url length */,
                                       Note.TagTable.UrlTag);

            Buffer.RemoveTag(Note.TagTable.UrlTag, start, end);

            Gtk.TextIter searchiter = start;
            for (Match match = regex.Match(start.GetSlice(end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                /*
                 * Logger.Log ("Highlighting url: '{0}' at offset {1}",
                 *   group,
                 *   group.Index);
                 */

                // Use the ForwardSearch instead of group's Index to account for multibyte chars in the text.
                // We'll search using the exact match value within provided boundaries.
                Gtk.TextIter startiter, enditer;
                searchiter.ForwardSearch(group.Value, Gtk.TextSearchFlags.VisibleOnly, out startiter, out enditer, end);
                searchiter = enditer;

                Buffer.ApplyTag(Note.TagTable.UrlTag, startiter, enditer);
            }
        }
示例#2
0
        void ApplyUrlToBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       256 /* max url length */,
                                       Note.TagTable.UrlTag);

            Buffer.RemoveTag(Note.TagTable.UrlTag, start, end);

            for (Match match = regex.Match(start.GetSlice(end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                /*
                 * Logger.Log ("Highlighting url: '{0}' at offset {1}",
                 *   group,
                 *   group.Index);
                 */

                Gtk.TextIter start_cpy = start;
                start_cpy.ForwardChars(group.Index);

                end = start_cpy;
                end.ForwardChars(group.Length);

                Buffer.ApplyTag(Note.TagTable.UrlTag, start_cpy, end);
            }
        }
示例#3
0
        void ApplyWikiwordToBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       80 /* max wiki name */,
                                       broken_link_tag);

            Buffer.RemoveTag(broken_link_tag, start, end);

            for (Match match = regex.Match(start.GetText(end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                Logger.Debug("Highlighting wikiword: '{0}' at offset {1}",
                             group,
                             group.Index);

                Gtk.TextIter start_cpy = start;
                start_cpy.ForwardChars(group.Index);

                end = start_cpy;
                end.ForwardChars(group.Length);

                if (Manager.Find(group.ToString()) == null)
                {
                    Buffer.ApplyTag(broken_link_tag, start_cpy, end);
                }
            }
        }
示例#4
0
        void OnMenuItemActivated(object sender, EventArgs args)
        {
            NoteTag broken_link_tag = Note.TagTable.BrokenLinkTag;

            Gtk.TextIter note_start, note_end;

            // We get the whole note as a range
            // and then just remove the "broken link" tag from it
            Note.Buffer.GetBounds(out note_start, out note_end);

            // Sweep 'em & recreate WikiWord broken links (depending on Preferences),
            Buffer.RemoveTag(broken_link_tag, note_start, note_end);

            // HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
            // It turns WikiWords back into broken links after sweeping all broken links,
            // but only in case WikiWords are enabled.
            // Most probably there's more elegant way of doing this.

            if ((bool)Preferences.Get(Preferences.ENABLE_WIKIWORDS))
            {
                const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";

                Regex regex = new Regex(WIKIWORD_REGEX, RegexOptions.Compiled);

                NoteBuffer.GetBlockExtents(ref note_start,
                                           ref note_end,
                                           80 /* max wiki name */,
                                           broken_link_tag);

                //Buffer.RemoveTag (broken_link_tag, start, end);

                for (Match match = regex.Match(note_start.GetText(note_end));
                     match.Success;
                     match = match.NextMatch())
                {
                    System.Text.RegularExpressions.Group group = match.Groups [1];

                    Logger.Debug("Highlighting back wikiword: '{0}' at offset {1}",
                                 group,
                                 group.Index);

                    Gtk.TextIter start_cpy = note_start;
                    start_cpy.ForwardChars(group.Index);

                    note_end = start_cpy;
                    note_end.ForwardChars(group.Length);

                    if (Manager.Find(group.ToString()) == null)
                    {
                        Buffer.ApplyTag(broken_link_tag, start_cpy, note_end);
                    }
                }
            }
            /// End of hack
        }
示例#5
0
        void OnDeleteRange(object sender, Gtk.DeleteRangeArgs args)
        {
            Gtk.TextIter start = args.Start;
            Gtk.TextIter end   = args.End;

            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       Manager.TitleTrie.MaxLength,
                                       Note.TagTable.LinkTag);

            UnhighlightInBlock(start, end);
            HighlightInBlock(start, end);
        }
示例#6
0
        void OnInsertText(object sender, Gtk.InsertTextArgs args)
        {
            Gtk.TextIter start = args.Pos;
            start.BackwardChars(args.Length);

            Gtk.TextIter end = args.Pos;

            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       Manager.TitleTrie.MaxLength,
                                       Note.TagTable.LinkTag);

            UnhighlightInBlock(start, end);
            HighlightInBlock(start, end);
        }
        public void HighlightWikiWords(Note note)
        {
            NoteTag broken_link_tag = note.TagTable.BrokenLinkTag;

            Gtk.TextIter note_start, note_end;

            note.Buffer.GetBounds(out note_start, out note_end);

            // HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
            // It turns WikiWords back into broken links after sweeping all broken links,
            // but only in case WikiWords are enabled.
            // Most probably there's more elegant way of doing this.

            const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";

            Regex regex = new Regex(WIKIWORD_REGEX, RegexOptions.Compiled);

            NoteBuffer.GetBlockExtents(ref note_start,
                                       ref note_end,
                                       80 /* max wiki name */,
                                       broken_link_tag);

            for (Match match = regex.Match(note_start.GetText(note_end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                Logger.Debug("Highlighting back wikiword: '{0}' at offset {1}",
                             group,
                             group.Index);

                Gtk.TextIter start_cpy = note_start;
                start_cpy.ForwardChars(group.Index);

                note_end = start_cpy;
                note_end.ForwardChars(group.Length);

                if (note.Manager.Find(group.ToString()) == null)
                {
                    note.Buffer.ApplyTag(broken_link_tag, start_cpy, note_end);
                }
            }
            /// End of hack
        }