예제 #1
0
        private void HighlightSearchTerms(string highlight)
        {
            TextBuffer buffer = conversation.Buffer;
            string     text   = buffer.GetText(buffer.StartIter, buffer.EndIter, false).ToLower();

            string [] words    = highlight.Split(' ');
            bool      scrolled = false;

            foreach (string word in words)
            {
                int idx = 0;

                if (word == String.Empty)
                {
                    continue;
                }

                while ((idx = text.IndexOf(word.ToLower(), idx)) != -1)
                {
                    Gtk.TextIter start = buffer.GetIterAtOffset(idx);
                    Gtk.TextIter end   = start;
                    end.ForwardChars(word.Length);
                    if (!scrolled)
                    {
                        scrolled = true;
                        TextMark mark = buffer.CreateMark(null, start, false);
                        conversation.ScrollMarkOnscreen(mark);
                    }
                    buffer.ApplyTag("highlight", start, end);

                    idx += word.Length;
                }
            }
        }
예제 #2
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
        }
예제 #3
0
        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
        }
예제 #4
0
        void HighlightInBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            foreach (TrieHit hit in galago.Trie.FindMatches(start.GetText(end)))
            {
                Gtk.TextIter match_start =
                    Buffer.GetIterAtOffset(start.Offset + hit.Start);

                // Don't create links inside note or URL links
                if (match_start.HasTag(url_tag) ||
                    match_start.HasTag(link_tag))
                {
                    continue;
                }

                Gtk.TextIter match_end = match_start;
                match_end.ForwardChars(hit.End - hit.Start);

                Logger.Log("Matching Person '{0}' at {1}-{2}...",
                           hit.Key,
                           hit.Start,
                           hit.End);
                Buffer.ApplyTag(person_tag, match_start, match_end);
            }
        }
        // get next SQL statement.  Requires GetSqlStatementAtCursor having been called first
        public string GetNextSqlStatement(TextBuffer sqlTextBuffer, ref TextIter iter)
        {
            TextIter start_iter, end_iter;
            TextIter match_start2, match_end2;
            TextIter finish_iter;
            string text = String.Empty;
            int char_count = 0;

            char_count = sqlTextBuffer.CharCount;
            end_iter = sqlTextBuffer.GetIterAtOffset (char_count);
            if (iter.IsEnd == false) {
                iter.ForwardChars (1);
                if (sqlTextBuffer.GetText (iter, end_iter, false).Equals (";"))
                    iter.ForwardChars (1);
            }

            if (iter.IsEnd == true)
                return "";

            start_iter = iter;
            match_start2 = iter;
            match_end2 = sqlTextBuffer.GetIterAtOffset (char_count);
            finish_iter = sqlTextBuffer.GetIterAtOffset (char_count);

            if (start_iter.IsEnd == false) {
                if (iter.ForwardSearch (";", TextSearchFlags.TextOnly,
                        out match_start2, out match_end2, end_iter) == true) 	{
                    finish_iter = match_end2;
                    finish_iter.BackwardChars (1);
                }

                text = sqlTextBuffer.GetText (iter, finish_iter, false);
                iter = finish_iter;

                if(text.Length > 0) {
                    // search does not work if what you are searching for is
                    // at the end of the buffer,
                    // this compensates for this
                    int j = text.Length;
                    int cont = 1;
                    for(int i = text.Length - 1; cont == 1 && i >= 0; i--) {
                        char ch = text[i];
                        switch(ch) {
                        case ' ':
                        case ';':
                            j--;
                            break;
                        default:
                            cont = 0;
                            break;
                        }
                    }

                    if(j != text.Length) {
                        string t = text.Substring(0, j);
                        text = t;
                    }
                }
            }

            return text;
        }