1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Naba Kumar <naba@gnome.org>
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
35 static gpointer parent_class
;
37 /* Anjuta symbol view class */
40 anjuta_symbol_finalize (GObject
* obj
)
42 AnjutaSymbol
*s
= ANJUTA_SYMBOL (obj
);
45 g_free (s
->priv
->uri
);
47 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
51 anjuta_symbol_instance_init (GObject
* obj
)
55 s
= ANJUTA_SYMBOL (obj
);
56 s
->priv
= g_new0 (AnjutaSymbolPriv
, 1);
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
;
71 anjuta_symbol_new (const TMTag
*tm_tag
)
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
)),
80 s
= g_object_new (ANJUTA_TYPE_SYMBOL
, NULL
);
81 s
->priv
->tm_tag
= tm_tag
;
88 anjuta_symbol_get_name (AnjutaSymbol
* symbol
)
90 g_return_val_if_fail (symbol
!= NULL
, NULL
);
92 return symbol
->priv
->tm_tag
->name
;
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
;
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 */
116 isymbol_get_name (IAnjutaSymbol
*isymbol
, GError
**err
)
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
)
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
;
138 isymbol_get_args (IAnjutaSymbol
*isymbol
, GError
**err
)
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
;
149 isymbol_get_extra_info_string (IAnjutaSymbol
*isymbol
, IAnjutaSymbolField sym_info
,
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
);
159 case IANJUTA_SYMBOL_FIELD_FILE_PATH
:
160 if (s
->priv
->tm_tag
->atts
.entry
.file
== 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");
167 /*return s->priv->tm_tag->atts.entry.impl;*/
169 case IANJUTA_SYMBOL_FIELD_ACCESS
:
170 g_message ("TODO IANJUTA_SYMBOL_FIELD_ACCESS");
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");
178 case IANJUTA_SYMBOL_FIELD_TYPE
:
179 g_message ("No symbol type to string translation available");
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");
189 case IANJUTA_SYMBOL_FIELD_FILE_IGNORE
:
192 case IANJUTA_SYMBOL_FIELD_FILE_INCLUDE
:
195 case IANJUTA_SYMBOL_FIELD_PROJECT_NAME
:
198 case IANJUTA_SYMBOL_FIELD_WORKSPACE_NAME
:
207 isymbol_uri (IAnjutaSymbol
*isymbol
, GError
**err
)
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
)
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
);
226 isymbol_get_line (IAnjutaSymbol
*isymbol
, GError
**err
)
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
;
237 isymbol_is_local (IAnjutaSymbol
*isymbol
, GError
**err
)
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
)
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
);
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
);