Updated Spanish translation
[anjuta-git-plugin.git] / plugins / symbol-browser / an_symbol_info.c
blobfa2603a20494abb19ece174ec74256751d773b6b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * an_symbol_view.c
4 * Copyright (C) 2004 Naba Kumar
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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
25 #include <gdl/gdl-icons.h>
26 #include <libanjuta/resources.h>
27 #include "an_symbol_info.h"
29 static AnjutaSymbolInfo* symbol_info_dup (const AnjutaSymbolInfo *from);
30 static void symbol_info_free (AnjutaSymbolInfo *sfile);
32 AnjutaSymbolInfo* anjuta_symbol_info_new (TMSymbol *sym, SVNodeType node_type )
34 AnjutaSymbolInfo *sfile = g_new0 (AnjutaSymbolInfo, 1);
35 sfile->sym_name = NULL;
36 sfile->def.name = NULL;
37 sfile->decl.name = NULL;
39 if (sym && sym->tag && sym->tag->atts.entry.file)
41 sfile->sym_name = g_strdup (sym->tag->name);
42 sfile->def.name =
43 g_strdup (sym->tag->atts.entry.file->work_object.file_name);
44 sfile->def.line = sym->tag->atts.entry.line;
45 if ((tm_tag_function_t == sym->tag->type) && sym->info.equiv)
47 sfile->decl.name =
48 g_strdup (sym->info.equiv->atts.entry.file->work_object.file_name);
49 sfile->decl.line = sym->info.equiv->atts.entry.line;
52 /* adding node type */
53 sfile->node_type = node_type;
55 return sfile;
58 void anjuta_symbol_info_free (AnjutaSymbolInfo *sym) {
60 g_return_if_fail( sym != NULL );
62 /* let's free it! */
63 symbol_info_free(sym);
67 static AnjutaSymbolInfo*
68 symbol_info_dup (const AnjutaSymbolInfo *from)
70 if (NULL != from)
72 AnjutaSymbolInfo *to = g_new0 (AnjutaSymbolInfo, 1);
73 to->node_type = from->node_type;
74 if (from->sym_name)
75 to->sym_name = g_strdup (from->sym_name);
76 if (from->def.name)
78 to->def.name = g_strdup (from->def.name);
79 to->def.line = from->def.line;
81 if (from->decl.name)
83 to->decl.name = g_strdup (from->decl.name);
84 to->decl.line = from->decl.line;
86 return to;
88 else
89 return NULL;
92 static void
93 symbol_info_free (AnjutaSymbolInfo *sfile)
96 if (sfile != NULL )
98 if (sfile->sym_name != NULL ) {
99 g_free(sfile->sym_name);
100 sfile->sym_name = NULL;
102 if (sfile->def.name != NULL ) {
103 g_free(sfile->def.name);
104 sfile->def.name = NULL;
106 if (sfile->decl.name != NULL ) {
107 g_free(sfile->decl.name);
108 sfile->decl.name = NULL;
110 g_free(sfile);
114 GType anjuta_symbol_info_get_type (void) {
116 static GType type = 0;
118 if (!type)
120 type = g_boxed_type_register_static ("AnjutaSymbolInfo",
121 (GBoxedCopyFunc) symbol_info_dup,
122 (GBoxedFreeFunc) symbol_info_free);
124 return type;
127 SVNodeType
128 anjuta_symbol_info_get_node_type (const TMSymbol *sym, const TMTag *tag)
130 TMTagType t_type;
131 SVNodeType type;
132 char access;
134 if (sym == NULL && tag == NULL)
135 return sv_none_t;
137 if (sym && sym->tag == NULL)
138 return sv_none_t;
140 if (sym)
141 t_type = sym->tag->type;
142 else
143 t_type = tag->type;
145 if (t_type == tm_tag_file_t)
146 return sv_none_t;
148 if (sym)
149 access = sym->tag->atts.entry.access;
150 else
151 access = tag->atts.entry.access;
153 switch (t_type)
155 case tm_tag_namespace_t:
156 type = sv_namespace_t;
157 break;
158 case tm_tag_class_t:
159 type = sv_class_t;
160 break;
161 case tm_tag_struct_t:
162 type = sv_struct_t;
163 break;
164 case tm_tag_union_t:
165 type = sv_union_t;
166 break;
167 case tm_tag_function_t:
168 case tm_tag_prototype_t:
169 case tm_tag_method_t:
170 if (sym && (sym->info.equiv) && (TAG_ACCESS_UNKNOWN == access))
171 access = sym->info.equiv->atts.entry.access;
172 switch (access)
174 case TAG_ACCESS_PRIVATE:
175 type = sv_private_func_t;
176 break;
177 case TAG_ACCESS_PROTECTED:
178 type = sv_protected_func_t;
179 break;
180 case TAG_ACCESS_PUBLIC:
181 type = sv_public_func_t;
182 break;
183 default:
184 type = sv_function_t;
185 break;
187 break;
188 case tm_tag_member_t:
189 case tm_tag_field_t:
190 switch (access)
192 case TAG_ACCESS_PRIVATE:
193 type = sv_private_var_t;
194 break;
195 case TAG_ACCESS_PROTECTED:
196 type = sv_protected_var_t;
197 break;
198 case TAG_ACCESS_PUBLIC:
199 type = sv_public_var_t;
200 break;
201 default:
202 type = sv_variable_t;
203 break;
205 break;
206 case tm_tag_externvar_t:
207 case tm_tag_variable_t:
208 type = sv_variable_t;
209 break;
210 case tm_tag_macro_t:
211 case tm_tag_macro_with_arg_t:
212 type = sv_macro_t;
213 break;
214 case tm_tag_typedef_t:
215 type = sv_typedef_t;
216 break;
217 case tm_tag_enumerator_t:
218 type = sv_enumerator_t;
219 break;
220 default:
221 type = sv_none_t;
222 break;
224 return type;
227 SVRootType
228 anjuta_symbol_info_get_root_type (SVNodeType type)
230 if (sv_none_t == type)
231 return sv_root_none_t;
232 switch (type)
234 case sv_namespace_t:
235 return sv_root_namespace_t;
236 case sv_class_t:
237 return sv_root_class_t;
238 case sv_struct_t:
239 return sv_root_struct_t;
240 case sv_union_t:
241 return sv_root_union_t;
242 case sv_function_t:
243 return sv_root_function_t;
244 case sv_variable_t:
245 return sv_root_variable_t;
246 case sv_macro_t:
247 return sv_root_macro_t;
248 case sv_typedef_t:
249 return sv_root_typedef_t;
250 default:
251 return sv_root_none_t;
255 static GdlIcons *icon_set = NULL;
256 static GdkPixbuf **sv_symbol_pixbufs = NULL;
258 #define CREATE_SV_ICON(N, F) \
259 pix_file = anjuta_res_get_pixmap_file (F); \
260 sv_symbol_pixbufs[(N)] = gdk_pixbuf_new_from_file (pix_file, NULL); \
261 g_free (pix_file);
263 static void
264 sv_load_symbol_pixbufs (void)
266 gchar *pix_file;
268 if (sv_symbol_pixbufs)
269 return;
271 if (icon_set == NULL)
272 icon_set = gdl_icons_new (16);
274 sv_symbol_pixbufs = g_new (GdkPixbuf *, sv_max_t + 1);
276 CREATE_SV_ICON (sv_none_t, "Icons.16x16.Literal");
277 CREATE_SV_ICON (sv_namespace_t, "Icons.16x16.NameSpace");
278 CREATE_SV_ICON (sv_class_t, "Icons.16x16.Class");
279 CREATE_SV_ICON (sv_struct_t, "Icons.16x16.ProtectedStruct");
280 CREATE_SV_ICON (sv_union_t, "Icons.16x16.PrivateStruct");
281 CREATE_SV_ICON (sv_typedef_t, "Icons.16x16.Reference");
282 CREATE_SV_ICON (sv_function_t, "Icons.16x16.Method");
283 CREATE_SV_ICON (sv_variable_t, "Icons.16x16.Literal");
284 CREATE_SV_ICON (sv_enumerator_t, "Icons.16x16.Enum");
285 CREATE_SV_ICON (sv_macro_t, "Icons.16x16.Field");
286 CREATE_SV_ICON (sv_private_func_t, "Icons.16x16.PrivateMethod");
287 CREATE_SV_ICON (sv_private_var_t, "Icons.16x16.PrivateProperty");
288 CREATE_SV_ICON (sv_protected_func_t, "Icons.16x16.ProtectedMethod");
289 CREATE_SV_ICON (sv_protected_var_t, "Icons.16x16.ProtectedProperty");
290 CREATE_SV_ICON (sv_public_func_t, "Icons.16x16.InternalMethod");
291 CREATE_SV_ICON (sv_public_var_t, "Icons.16x16.InternalProperty");
293 sv_symbol_pixbufs[sv_cfolder_t] = gdl_icons_get_mime_icon (icon_set,
294 "application/directory-normal");
295 sv_symbol_pixbufs[sv_ofolder_t] = gdl_icons_get_mime_icon (icon_set,
296 "application/directory-normal");
297 sv_symbol_pixbufs[sv_max_t] = NULL;
300 /*-----------------------------------------------------------------------------
301 * return the pixbufs. It will initialize pixbufs first if they weren't before
303 GdkPixbuf*
304 anjuta_symbol_info_get_pixbuf (SVNodeType node_type)
306 if (!sv_symbol_pixbufs)
307 sv_load_symbol_pixbufs ();
308 g_return_val_if_fail (node_type >=0 && node_type < sv_max_t, NULL);
310 return sv_symbol_pixbufs[node_type];