-
Notifications
You must be signed in to change notification settings - Fork 4
/
gtk_completionsv.c
115 lines (88 loc) · 3.32 KB
/
gtk_completionsv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "gtk_completionsv.h"
gchar stub (void) /* NOP to prevent empty compilation unit */
{ return 0; } /* when compiling without GtkSourceView */
#ifdef HAVESOURCEVIEW
/* GtkSourceCompletionProvider class interface implementation, for basic
* word-completion for existing words within the current document.
*/
typedef struct _cmplprovider cmplprovider;
typedef struct _cmplproviderClass cmplproviderClass;
struct _cmplprovider
{
GObject parent;
GList *proposals;
gint priority;
gchar *name;
GdkPixbuf *icon;
};
struct _cmplproviderClass
{
GObjectClass parent_class;
};
/* prototype of '..._iface_init' function to define provider '...' */
static void cmpl_provider_iface_init (GtkSourceCompletionProviderIface *iface);
/* struct type definition */
G_DEFINE_TYPE_WITH_CODE (cmplprovider, cmpl_provider, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GTK_TYPE_SOURCE_COMPLETION_PROVIDER,
cmpl_provider_iface_init))
/* member function - _get_name */
static gchar *cmpl_provider_get_name (GtkSourceCompletionProvider *provider)
{
return g_strdup (((cmplprovider *)provider)->name);
}
/* member funciton - _get_priority */
static gint cmpl_provider_get_priority (GtkSourceCompletionProvider *provider)
{
return ((cmplprovider *)provider)->priority;
}
/* member function - _match */
static gboolean cmpl_provider_match (GtkSourceCompletionProvider *provider,
GtkSourceCompletionContext *context)
{
return TRUE;
if (provider || context) {}
}
/* member function - _populate */
static void cmpl_provider_populate (GtkSourceCompletionProvider *provider,
GtkSourceCompletionContext *context)
{
gtk_source_completion_context_add_proposals (context, provider,
((cmplprovider *)provider)->proposals,
TRUE);
}
/* initialize provider interface with member functions */
static void cmpl_provider_iface_init (GtkSourceCompletionProviderIface *iface)
{
iface->get_name = cmpl_provider_get_name;
iface->populate = cmpl_provider_populate;
iface->match = cmpl_provider_match;
iface->get_priority = cmpl_provider_get_priority;
// iface->get_icon = cmpl_provider_get_icon;
iface->get_icon = NULL;
}
/* struct init */
static void cmpl_provider_class_init (cmplproviderClass *klass)
{
if (klass) {}
}
/* provider member init */
static void cmpl_provider_init (cmplprovider *self)
{
GList *proposals = NULL;
self->proposals = proposals;
}
/* create the word completion object for the source_view */
void create_completion (kwinst *app)
{
GtkSourceCompletionWords *prov_words;
app->completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (app->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 (app->view)));
gtk_source_completion_add_provider (app->completion,
GTK_SOURCE_COMPLETION_PROVIDER (prov_words),
NULL);
g_object_set (prov_words, "minimum-word-size", app->cmplwordsz, NULL);
// g_object_set (prov_words, "priority", 10, NULL);
}
#endif