Re: searching text




On Jan 5, 2010, at 20:50, Chris Bare <chris bareflix com> wrote:

I'm working on porting a simple text note taking application from motif to gtk. The basics were very easy to get working, but I'm a little stuck on how
to implement search.
In the old implementation, I got the text data, got the curser offset and did
the search with regex.

Looking through the gtk docs, I see there are GtkTextView and GtkSourceView widgets with corresponding Buffer objects. TextBuffer lists insensitive search as a "possible future" feature, while SourceBuffer implements insensitive search,
but still lists regex as "possible future".

I don't need most of what SourceView does, I'm only dealing with plain text.

2 questions.

#1 if I have:
   GtkTextMark *mark;
   GtkTextBuffer *bf;

   data = gtk_text_buffer_get_text (bf, &start, &end, FALSE);
   mark = gtk_text_buffer_get_insert (bf);

is there a simple way to convert mark into an offset into data?
I realize that won't work right with non-ascii characters.

#2 is there yet another set of gtk objects that will give me regex and case
insensitive searches using an official api?
Glib has regular expressions and you can always transform an iter/mark to a string position.

Take a look at this demo:
http://github.com/potyl/gtk2-sourceview2/blob/master/examples/perl-editor.pl#L261
It was my attempt to mimic nedit (a great motif editor) in gtk2. I have there support for detach with regexpes event if gtkdourceview doest provide it.

--
Chris Bare
chris bareflix com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]