views:

47

answers:

1

Hello :)

I'm making simple code editor in GTK and gtksourceview2.0. I would like to add to my editor a code completion window. There should be 10-15 keywords (always the same).

Can anyone could give me url for some tutorials or describe usage of gtk_source_completion_XXX functions?

+2  A: 

What you need is to parse the user input by the key-press-event signal (or similar signals).

  • Get the GtkTextBuffer by calling gtk_text_view_get_buffer.
  • Get the GtkTextMark by calling gtk_text_buffer_get_insert.
  • Get the GtkTextIter by calling gtk_text_buffer_get_iter_at_mark.
  • Check if the GtkTextIter is at the end of the word by gtk_text_iter_ends_word.
  • If it was
    • then Use gtk_text_iter_backward_word_start to get the GtkTextIter for the start of the word.
    • Call gtk_text_buffer_get_text to get the uncompleted word.
    • Search for related identifiers and display them in a GtkTreeView on a GtkWindow of GTK_WINDOW_POPUP type.

If you want to show the auto-complete list after . or :: or ->, then you should get the previous word by an approach like the above.

PC2st