Updated Spanish translation
[anjuta.git] / plugins / sourceview / sourceview-provider.c
blob84551e661c30203ee395f53622312fe485bc886c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) Johannes Schmid 2009 <jhs@gnome.org>
5 *
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>
26 static void
27 sourceview_provider_iface_init (GtkSourceCompletionProviderIface* provider);
29 G_DEFINE_TYPE_WITH_CODE (SourceviewProvider,
30 sourceview_provider,
31 G_TYPE_OBJECT,
32 G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROVIDER,
33 sourceview_provider_iface_init))
35 static void
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;
46 static void
47 sourceview_provider_populate (GtkSourceCompletionProvider* provider, GtkSourceCompletionContext* context)
49 SourceviewProvider* prov = SOURCEVIEW_PROVIDER(provider);
50 GtkTextIter iter;
51 SourceviewCell* cell;
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);
61 static gchar*
62 sourceview_provider_get_name (GtkSourceCompletionProvider* provider)
64 SourceviewProvider* prov = SOURCEVIEW_PROVIDER(provider);
65 return g_strdup (ianjuta_provider_get_name (prov->iprov, NULL));
69 static gboolean
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);
76 if (iiter)
78 SourceviewCell* cell = SOURCEVIEW_CELL(iiter);
79 GtkTextIter source_iter;
80 sourceview_cell_get_iter(cell, &source_iter);
81 *iter = source_iter;
82 return TRUE;
84 else
85 return FALSE;
88 static gboolean
89 sourceview_provider_activate_proposal (GtkSourceCompletionProvider* provider,
90 GtkSourceCompletionProposal* proposal,
91 GtkTextIter* iter)
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);
100 return TRUE;
103 static gint
104 sourceview_provider_get_priority (GtkSourceCompletionProvider* provider)
106 /* Always the highest priority */
107 return G_MAXINT32;
110 static void
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;
120 static void
121 sourceview_provider_init (SourceviewProvider *object)
123 object->context = NULL;
126 static void
127 sourceview_provider_dispose (GObject* obj)
132 static void
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);
145 prov->sv = sv;
146 prov->iprov = iprov;
147 return GTK_SOURCE_COMPLETION_PROVIDER(obj);