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



On 09/16/2018 03:53 AM, David C. Rankin wrote:
On 09/16/2018 03:21 AM, David C. Rankin wrote:
  Each treemodel entry has a struct containing a pointer to its
GtkSourceCompletionWords provider.

Uugh...

That should read the editor instance struct associated with the sourceview has
a pointer to its GtkSourceCompletionWords provider. (the tree model just holds
a struct containing a pointer to its GtkSourceBuffer which is what allows
updating the textview/sourceview window on the right with the new buffer).

So when I click a different file in the treeview, I want to associate that
buffer as the word-source for the GtkSourceCompletionWords provider for the
textview by unregistering the existing buffer as the word-source and
registering the new buffer as the source for the provider in the textview.


Let me bump this thread again and update with the next approach I have taken
that also failed. By way of short background, I have an editor where multiple
files are opened and displayed in a Treeview on the left of the main window.
Selecting a file will display its buffer in the textview, e.g.

    +===================================================+
    |menu                                               |
    +------------+--------------------------------------+
    | file_a     |                                      |
    | file_b     |                                      |
    | file_c     |             TextView                 |
    |            |               with                   |
    |            |          WordCompletion              |
    |            |                                      |
    |            |                                      |
    |            |                                      |
    |            |                                      |
    +------------+--------------------------------------+

I enable word completion within the textview on the first file when the window
is created. What I need to do is be able to make the word completion continue
to work with the new word-provider associated with each file when a new file
is displayed in the textview.

As noted in the earlier post, the completion object is associated with the
Textview itself, but the words provider is associated with each file. Earlier
I attempted to use the same provider, by 'registering' and 'unregistering' the
words contained within a single provider.

In this test, I have created a new words completion provider associated with
each file instance and have attempted to remove the current provider and add
the provider associated with the new buffer to be displayed with the following:

    GList *providers = gtk_source_completion_get_providers (completion);

    while (providers) {
        /* TODO add validation and GError */
        gtk_source_completion_remove_provider (completion,
                    GTK_SOURCE_COMPLETION_PROVIDER (providers->data), NULL);
        providers = providers->next;
    }

    /* register the words in the current buffer for provider */
    if (!inst->prov_words) {
        /* create the words provider */
        inst->prov_words = gtk_source_completion_words_new (NULL, NULL);

        gtk_source_completion_words_register (inst->prov_words,
                    gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
    }
    /* add provider to completion - make sure to unref when done */
    gtk_source_completion_add_provider (completion,
                    GTK_SOURCE_COMPLETION_PROVIDER (inst->prov_words), NULL);


However, the results are the same. Word completion works fine for the first
buffer associated with the textview (say 'file_a' above). Switching buffers
(say to 'file_b'), there is no word-completion triggered at all within the
same textview for the new buffer. However, switching back to the first buffer
(file_a) and word completion begins working fine again.

Anybody have any other ideas how to make word completion continue to work
within a textview when the buffer displayed is changed?

Thanks for any thoughts or ideas you may have.

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


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