Howto register/unregister words completion provider on buffer change in textview?



All,

  I have an editor that holds the open files on the left in a
treeview/treemodel and displays the buffer containing each file in a textview
(sourceview) window on the right.

  Each treemodel entry has a struct containing a pointer to its
GtkSourceCompletionWords provider. The word-completion works fine for the
first buffer shown in the window, but when I change files and display a
different buffer in the textview window, I am not able to register/unregister
the current buffer from the words provider and use the new buffer as a source?

  Essentially I create the initial completion object as:

    GtkSourceCompletion *completion;
    GtkSourceCompletionWords *prov_words;

    completion = gtk_source_view_get_completion (view);
    prov_words = gtk_source_completion_words_new (NULL, NULL);
    gtk_source_completion_words_register (prov_words,
                    gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
    gtk_source_completion_add_provider (completion,
                    GTK_SOURCE_COMPLETION_PROVIDER (prov_words), NULL);
    /* store a pointer to the completions words provider as part of
     * the editor instance.
     */
    einst->prov_words = prov_words;

  When displaying a new buffer in the textview, I use the treeview "changed"
signal to display the new buffer, update the window title, etc.. and I tried
to unregister the current buffer from the prov_words provider and then
register the new buffer as the word source with:

    GtkSourceCompletionWords *prov_words = einst->prov_words;

    /* unregister current buffer from words completion provider */
    gtk_source_completion_words_unregister (prov_words,
                                        GTK_TEXT_BUFFER(oldbuf));

    /* register new buffer with words completion provider */
    gtk_source_completion_words_register (prov_words,
                                        GTK_TEXT_BUFFER(newbuf));

  However, I am obviously missing something as the new buffer displayed does
not provide any completion functionality at all.

  Since the completion object (GtkSourceCompletion) is part of the sourceview
(GtkSourceView) and the completion provider (GtkSourceCompletionWords) is part
of the completion object, there should be no need to create another object or
provider as the sourceview window is the same. The only thing that I see that
needs doing is to change the buffer registered as the source of words for the
provider on buffer change -- but so far I have not met with any success...

  Is there something I am missing when changing the buffer in the sourceview
that is needed to change the completion so that word completion continues to
function but simply drawing words from the new buffer instead of the old?

  When I switch focus back to the original buffer -- completion works fine
again, it's something in the switch to the new that I must be missing.

  Help?

-- 
David C. Rankin, J.D.,P.E.


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