Updated Spanish translation
[anjuta-git-plugin.git] / plugins / symbol-browser / an_symbol.c
blobae698f89a681e0483e5d947f370674c7ef528693
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * iterable.c
4 * Copyright (C) Naba Kumar <naba@gnome.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <libgnome/gnome-macros.h>
22 #include <libgnomevfs/gnome-vfs-utils.h>
23 #include <libanjuta/anjuta-utils.h>
24 #include <libanjuta/anjuta-debug.h>
25 #include <libanjuta/interfaces/ianjuta-symbol.h>
26 #include "an_symbol_info.h"
27 #include "an_symbol.h"
29 struct _AnjutaSymbolPriv
31 const TMTag *tm_tag;
32 gchar* uri;
35 static gpointer parent_class;
37 /* Anjuta symbol view class */
39 static void
40 anjuta_symbol_finalize (GObject * obj)
42 AnjutaSymbol *s = ANJUTA_SYMBOL (obj);
44 if (s->priv->uri)
45 g_free (s->priv->uri);
46 g_free (s->priv);
47 G_OBJECT_CLASS (parent_class)->finalize (obj);
50 static void
51 anjuta_symbol_instance_init (GObject * obj)
53 AnjutaSymbol *s;
55 s = ANJUTA_SYMBOL (obj);
56 s->priv = g_new0 (AnjutaSymbolPriv, 1);
59 static void
60 anjuta_symbol_class_init (AnjutaSymbolClass * klass)
62 AnjutaSymbolClass *sc;
63 GObjectClass *object_class = G_OBJECT_CLASS (klass);
65 parent_class = g_type_class_peek_parent (klass);
66 sc = ANJUTA_SYMBOL_CLASS (klass);
67 object_class->finalize = anjuta_symbol_finalize;
70 AnjutaSymbol*
71 anjuta_symbol_new (const TMTag *tm_tag)
73 AnjutaSymbol *s;
75 g_return_val_if_fail (tm_tag != NULL, NULL);
76 g_return_val_if_fail (tm_tag->type < tm_tag_max_t, NULL);
77 g_return_val_if_fail (!(tm_tag->type & (tm_tag_file_t|tm_tag_undef_t)),
78 NULL);
80 s = g_object_new (ANJUTA_TYPE_SYMBOL, NULL);
81 s->priv->tm_tag = tm_tag;
82 s->priv->uri = NULL;
83 return s;
87 const gchar*
88 anjuta_symbol_get_name (AnjutaSymbol* symbol)
90 g_return_val_if_fail (symbol != NULL, NULL);
92 return symbol->priv->tm_tag->name;
95 void
96 anjuta_symbol_set_tag (AnjutaSymbol *symbol, const TMTag *tm_tag)
98 g_return_if_fail (ANJUTA_IS_SYMBOL (symbol));
99 symbol->priv->tm_tag = NULL;
100 if (symbol->priv->uri)
102 g_free(symbol->priv->uri);
103 symbol->priv->uri = NULL;
105 if (tm_tag != NULL)
107 g_return_if_fail (tm_tag->type < tm_tag_max_t);
108 g_return_if_fail (!(tm_tag->type & (tm_tag_file_t|tm_tag_undef_t)));
110 symbol->priv->tm_tag = tm_tag;
114 /* IAnjutaSymbol implementation */
115 static const gchar*
116 isymbol_get_name (IAnjutaSymbol *isymbol, GError **err)
118 AnjutaSymbol *s;
120 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), NULL);
121 s = ANJUTA_SYMBOL (isymbol);
122 g_return_val_if_fail (s->priv->tm_tag != NULL, NULL);
123 return s->priv->tm_tag->name;
126 static IAnjutaSymbolType
127 isymbol_get_sym_type (IAnjutaSymbol *isymbol, GError **err)
129 AnjutaSymbol *s;
131 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), IANJUTA_SYMBOL_TYPE_UNDEF);
132 s = ANJUTA_SYMBOL (isymbol);
133 g_return_val_if_fail (s->priv->tm_tag != NULL, IANJUTA_SYMBOL_TYPE_UNDEF);
134 return s->priv->tm_tag->type;
137 static const gchar*
138 isymbol_get_args (IAnjutaSymbol *isymbol, GError **err)
140 AnjutaSymbol *s;
142 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), NULL);
143 s = ANJUTA_SYMBOL (isymbol);
144 g_return_val_if_fail (s->priv->tm_tag != NULL, NULL);
145 return s->priv->tm_tag->atts.entry.arglist;
148 static const gchar*
149 isymbol_get_extra_info_string (IAnjutaSymbol *isymbol, IAnjutaSymbolField sym_info,
150 GError **err)
152 AnjutaSymbol *s;
154 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), NULL);
155 s = ANJUTA_SYMBOL (isymbol);
156 g_return_val_if_fail (s->priv->tm_tag != NULL, NULL);
158 switch (sym_info) {
159 case IANJUTA_SYMBOL_FIELD_FILE_PATH:
160 if (s->priv->tm_tag->atts.entry.file == NULL)
161 return NULL;
162 return s->priv->tm_tag->atts.entry.file->work_object.file_name;
164 case IANJUTA_SYMBOL_FIELD_IMPLEMENTATION:
165 g_message ("TODO IANJUTA_SYMBOL_FIELD_IMPLEMENTATION");
166 return NULL;
167 /*return s->priv->tm_tag->atts.entry.impl;*/
169 case IANJUTA_SYMBOL_FIELD_ACCESS:
170 g_message ("TODO IANJUTA_SYMBOL_FIELD_ACCESS");
171 return NULL;
172 /*return s->priv->tm_tag->atts.entry.access;*/
174 case IANJUTA_SYMBOL_FIELD_KIND:
175 g_message ("No symbol kind to string translation available");
176 return NULL;
178 case IANJUTA_SYMBOL_FIELD_TYPE:
179 g_message ("No symbol type to string translation available");
180 return NULL;
182 case IANJUTA_SYMBOL_FIELD_TYPE_NAME:
183 return s->priv->tm_tag->atts.entry.type_ref[1];
185 case IANJUTA_SYMBOL_FIELD_LANGUAGE:
186 g_message ("No file language available");
187 return NULL;
189 case IANJUTA_SYMBOL_FIELD_FILE_IGNORE:
190 return NULL;
192 case IANJUTA_SYMBOL_FIELD_FILE_INCLUDE:
193 return NULL;
195 case IANJUTA_SYMBOL_FIELD_PROJECT_NAME:
196 return NULL;
198 case IANJUTA_SYMBOL_FIELD_WORKSPACE_NAME:
199 return NULL;
201 default:
202 return NULL;
206 static const gchar*
207 isymbol_uri (IAnjutaSymbol *isymbol, GError **err)
209 AnjutaSymbol *s;
211 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), NULL);
212 s = ANJUTA_SYMBOL (isymbol);
213 g_return_val_if_fail (s->priv->tm_tag != NULL, NULL);
214 if (s->priv->tm_tag->atts.entry.file == NULL)
215 return NULL;
216 if (s->priv->uri == NULL)
218 const gchar *file_path;
219 file_path = s->priv->tm_tag->atts.entry.file->work_object.file_name;
220 s->priv->uri = gnome_vfs_get_uri_from_local_path (file_path);
222 return s->priv->uri;
225 static gulong
226 isymbol_get_line (IAnjutaSymbol *isymbol, GError **err)
228 AnjutaSymbol *s;
230 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), 0);
231 s = ANJUTA_SYMBOL (isymbol);
232 g_return_val_if_fail (s->priv->tm_tag != NULL, 0);
233 return s->priv->tm_tag->atts.entry.line;
236 static gboolean
237 isymbol_is_local (IAnjutaSymbol *isymbol, GError **err)
239 AnjutaSymbol *s;
241 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), FALSE);
242 s = ANJUTA_SYMBOL (isymbol);
243 g_return_val_if_fail (s->priv->tm_tag != NULL, FALSE);
244 return s->priv->tm_tag->atts.entry.local;
247 static const GdkPixbuf*
248 isymbol_get_icon (IAnjutaSymbol *isymbol, GError **err)
250 AnjutaSymbol *s;
251 SVNodeType node_type;
253 g_return_val_if_fail (ANJUTA_IS_SYMBOL (isymbol), FALSE);
254 s = ANJUTA_SYMBOL (isymbol);
255 g_return_val_if_fail (s->priv->tm_tag != NULL, NULL);
256 node_type = anjuta_symbol_info_get_node_type (NULL, s->priv->tm_tag);
257 return anjuta_symbol_info_get_pixbuf (node_type);
260 static void
261 isymbol_iface_init (IAnjutaSymbolIface *iface)
263 iface->get_uri = isymbol_uri;
264 iface->get_name = isymbol_get_name;
265 iface->get_line = isymbol_get_line;
266 iface->is_local = isymbol_is_local;
267 iface->get_sym_type = isymbol_get_sym_type;
268 iface->get_args = isymbol_get_args;
269 iface->get_extra_info_string = isymbol_get_extra_info_string;
270 iface->get_icon = isymbol_get_icon;
274 ANJUTA_TYPE_BEGIN (AnjutaSymbol, anjuta_symbol, G_TYPE_OBJECT);
275 ANJUTA_TYPE_ADD_INTERFACE (isymbol, IANJUTA_TYPE_SYMBOL);
276 ANJUTA_TYPE_END;