예제 #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);

            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);
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
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);
        }
예제 #4
0
파일: Applet.cs 프로젝트: shubhtr/tomboy-1
        void PrependTimestampedText(Note note, DateTime timestamp, string text)
        {
            NoteBuffer    buffer      = note.Buffer;
            StringBuilder insert_text = new StringBuilder();

            insert_text.Append("\n");              // initial newline
            string date_format = Catalog.GetString("dddd, MMMM d, h:mm tt");

            insert_text.Append(timestamp.ToString(date_format));
            insert_text.Append("\n");              // begin content
            insert_text.Append(text);
            insert_text.Append("\n");              // trailing newline

            buffer.Undoer.FreezeUndo();

            // Insert the date and list of links...
            Gtk.TextIter cursor = buffer.StartIter;
            cursor.ForwardLines(1);              // skip title

            buffer.Insert(ref cursor, insert_text.ToString());

            // Make the date string a small font...
            cursor = buffer.StartIter;
            cursor.ForwardLines(2);              // skip title & leading newline

            Gtk.TextIter end = cursor;
            end.ForwardToLineEnd();              // end of date

            buffer.ApplyTag("datetime", cursor, end);

            // Select the text we've inserted (avoid trailing newline)...
            end = cursor;
            end.ForwardChars(insert_text.Length - 1);

            buffer.MoveMark(buffer.SelectionBound, cursor);
            buffer.MoveMark(buffer.InsertMark, end);

            buffer.Undoer.ThawUndo();
        }