1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Johannes Schmid 2009 <jhs@gnome.org>
6 * anjuta is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * anjuta is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "sourceview-provider.h"
21 #include "sourceview-cell.h"
22 #include "sourceview-private.h"
23 #include <libanjuta/anjuta-debug.h>
27 sourceview_provider_iface_init (GtkSourceCompletionProviderIface
* provider
);
29 G_DEFINE_TYPE_WITH_CODE (SourceviewProvider
,
32 G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROVIDER
,
33 sourceview_provider_iface_init
))
36 on_context_cancelled (GtkSourceCompletionContext
* context
, SourceviewProvider
* provider
)
38 g_signal_handlers_disconnect_by_func (context
, on_context_cancelled
, provider
);
40 g_signal_emit_by_name (provider
->sv
, "cancelled");
42 provider
->cancelled
= TRUE
;
43 provider
->context
= NULL
;
47 sourceview_provider_populate (GtkSourceCompletionProvider
* provider
, GtkSourceCompletionContext
* context
)
49 SourceviewProvider
* prov
= SOURCEVIEW_PROVIDER(provider
);
52 gtk_source_completion_context_get_iter(context
, &iter
);
53 cell
= sourceview_cell_new (&iter
, GTK_TEXT_VIEW(prov
->sv
->priv
->view
));
54 prov
->context
= context
;
55 prov
->cancelled
= FALSE
;
56 g_signal_connect (context
, "cancelled", G_CALLBACK(on_context_cancelled
), prov
);
57 ianjuta_provider_populate(prov
->iprov
, IANJUTA_ITERABLE(cell
), NULL
);
58 g_object_unref (cell
);
62 sourceview_provider_get_name (GtkSourceCompletionProvider
* provider
)
64 SourceviewProvider
* prov
= SOURCEVIEW_PROVIDER(provider
);
65 return g_strdup (ianjuta_provider_get_name (prov
->iprov
, NULL
));
70 sourceview_provider_get_start_iter (GtkSourceCompletionProvider
* provider
,
71 GtkSourceCompletionContext
* context
,
72 GtkSourceCompletionProposal
* proposal
, GtkTextIter
* iter
)
74 SourceviewProvider
* prov
= SOURCEVIEW_PROVIDER(provider
);
75 IAnjutaIterable
* iiter
= ianjuta_provider_get_start_iter (prov
->iprov
, NULL
);
78 SourceviewCell
* cell
= SOURCEVIEW_CELL(iiter
);
79 GtkTextIter source_iter
;
80 sourceview_cell_get_iter(cell
, &source_iter
);
89 sourceview_provider_activate_proposal (GtkSourceCompletionProvider
* provider
,
90 GtkSourceCompletionProposal
* proposal
,
93 SourceviewProvider
* prov
= SOURCEVIEW_PROVIDER (provider
);
94 SourceviewCell
* cell
= sourceview_cell_new (iter
, GTK_TEXT_VIEW(prov
->sv
->priv
->view
));
95 gpointer data
= g_object_get_data (G_OBJECT(proposal
), "__data");
97 ianjuta_provider_activate(prov
->iprov
, IANJUTA_ITERABLE(cell
), data
, NULL
);
99 g_object_unref (cell
);
104 sourceview_provider_get_priority (GtkSourceCompletionProvider
* provider
)
106 /* Always the highest priority */
111 sourceview_provider_iface_init (GtkSourceCompletionProviderIface
* provider
)
113 provider
->get_name
= sourceview_provider_get_name
;
114 provider
->populate
= sourceview_provider_populate
;
115 provider
->get_start_iter
= sourceview_provider_get_start_iter
;
116 provider
->activate_proposal
= sourceview_provider_activate_proposal
;
117 provider
->get_priority
= sourceview_provider_get_priority
;
121 sourceview_provider_init (SourceviewProvider
*object
)
123 object
->context
= NULL
;
127 sourceview_provider_dispose (GObject
* obj
)
133 sourceview_provider_class_init (SourceviewProviderClass
*klass
)
135 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
137 object_class
->dispose
= sourceview_provider_dispose
;
140 GtkSourceCompletionProvider
* sourceview_provider_new (Sourceview
* sv
,
141 IAnjutaProvider
* iprov
)
143 GObject
* obj
= g_object_new (SOURCEVIEW_TYPE_PROVIDER
, NULL
);
144 SourceviewProvider
* prov
= SOURCEVIEW_PROVIDER(obj
);
147 return GTK_SOURCE_COMPLETION_PROVIDER(obj
);