0

Sorry for my english. I am writing in C language simple editor. I can not understand how to implement autocompletion words using GtkSourceCompletion.

static void set_completion(Page *page)
{
    GtkSourceCompletionWords *words = gtk_source_completion_words_new("words_current_page", NULL);
    gtk_source_completion_words_register(words, GTK_TEXT_BUFFER(page->buffer));
    GtkSourceCompletion *comp = gtk_source_view_get_completion(GTK_SOURCE_VIEW(page->text_edit));
    GtkSourceCompletionContext *context = gtk_source_completion_create_context(comp, NULL);
    GtkSourceCompletionProvider *provider;
    gtk_source_completion_add_provider(comp, provider, NULL);
}

I try, but all very confusing. Please tell me how to do it.

kradwhite
  • 11
  • 2

2 Answers2

1

Some explainations:

You need to consider the GtkSourceCompletionWords as a GtkSourceCompletionProvider, with the macro GTK_SOURCE_COMPLETION_PROVIDER(words) and add it as a provider for the completion:

GtkSourceCompletion *comp = gtk_source_view_get_completion(GTK_SOURCE_VIEW(page->text_edit));
gtk_source_completion_add_provider(comp,GTK_SOURCE_COMPLETION_PROVIDER(words),NULL);

Before to add it as provider, the GtkSourceCompletionWords needs to be registered with the buffer of the GtkSourceView:

GtkSourceCompletionWords *words = gtk_source_completion_words_new("wds_current_page", NULL);
gtk_source_completion_words_register(words, GTK_TEXT_BUFFER(page->buffer));

You can get the buffer with:

GtkTextBuffer * buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page->text_edit));

You also can create the buffer independently and pass it as argument for the creation of the GtkSourceView:

GtkSourceBuffer * sBuf = gtk_source_buffer_new(NULL);
GtkWidget * sview = gtk_source_view_new_with_buffer(sBuf);
Bertrand125
  • 904
  • 6
  • 13
0

Try this code:

static void set_completion(Page *page)
{
    GtkSourceCompletionWords *words = gtk_source_completion_words_new("words_current_page", NULL);
    gtk_source_completion_words_register(words, GTK_TEXT_BUFFER(page->buffer));
    GtkSourceCompletion *comp = gtk_source_view_get_completion(GTK_SOURCE_VIEW(page->text_edit));

    gtk_source_completion_add_provider(comp, GTK_SOURCE_COMPLETION_PROVIDER(words), NULL);
}