1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2004 Naba Kumar
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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
);
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
)
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
;
58 void anjuta_symbol_info_free (AnjutaSymbolInfo
*sym
) {
60 g_return_if_fail( sym
!= NULL
);
63 symbol_info_free(sym
);
67 static AnjutaSymbolInfo
*
68 symbol_info_dup (const AnjutaSymbolInfo
*from
)
72 AnjutaSymbolInfo
*to
= g_new0 (AnjutaSymbolInfo
, 1);
73 to
->node_type
= from
->node_type
;
75 to
->sym_name
= g_strdup (from
->sym_name
);
78 to
->def
.name
= g_strdup (from
->def
.name
);
79 to
->def
.line
= from
->def
.line
;
83 to
->decl
.name
= g_strdup (from
->decl
.name
);
84 to
->decl
.line
= from
->decl
.line
;
93 symbol_info_free (AnjutaSymbolInfo
*sfile
)
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
;
114 GType
anjuta_symbol_info_get_type (void) {
116 static GType type
= 0;
120 type
= g_boxed_type_register_static ("AnjutaSymbolInfo",
121 (GBoxedCopyFunc
) symbol_info_dup
,
122 (GBoxedFreeFunc
) symbol_info_free
);
128 anjuta_symbol_info_get_node_type (const TMSymbol
*sym
, const TMTag
*tag
)
134 if (sym
== NULL
&& tag
== NULL
)
137 if (sym
&& sym
->tag
== NULL
)
141 t_type
= sym
->tag
->type
;
145 if (t_type
== tm_tag_file_t
)
149 access
= sym
->tag
->atts
.entry
.access
;
151 access
= tag
->atts
.entry
.access
;
155 case tm_tag_namespace_t
:
156 type
= sv_namespace_t
;
161 case tm_tag_struct_t
:
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
;
174 case TAG_ACCESS_PRIVATE
:
175 type
= sv_private_func_t
;
177 case TAG_ACCESS_PROTECTED
:
178 type
= sv_protected_func_t
;
180 case TAG_ACCESS_PUBLIC
:
181 type
= sv_public_func_t
;
184 type
= sv_function_t
;
188 case tm_tag_member_t
:
192 case TAG_ACCESS_PRIVATE
:
193 type
= sv_private_var_t
;
195 case TAG_ACCESS_PROTECTED
:
196 type
= sv_protected_var_t
;
198 case TAG_ACCESS_PUBLIC
:
199 type
= sv_public_var_t
;
202 type
= sv_variable_t
;
206 case tm_tag_externvar_t
:
207 case tm_tag_variable_t
:
208 type
= sv_variable_t
;
211 case tm_tag_macro_with_arg_t
:
214 case tm_tag_typedef_t
:
217 case tm_tag_enumerator_t
:
218 type
= sv_enumerator_t
;
228 anjuta_symbol_info_get_root_type (SVNodeType type
)
230 if (sv_none_t
== type
)
231 return sv_root_none_t
;
235 return sv_root_namespace_t
;
237 return sv_root_class_t
;
239 return sv_root_struct_t
;
241 return sv_root_union_t
;
243 return sv_root_function_t
;
245 return sv_root_variable_t
;
247 return sv_root_macro_t
;
249 return sv_root_typedef_t
;
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); \
264 sv_load_symbol_pixbufs (void)
268 if (sv_symbol_pixbufs
)
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
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
];