2 * symbols.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2006-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * Tag-related functions.
28 * Symbol Tree and TagManager-related convenience functions.
29 * TagManager parses tags for each document, and also adds them to the workspace (session).
30 * Global tags are lists of tags for each filetype, loaded when a document with a
31 * matching filetype is first loaded.
44 #include "filetypes.h"
45 #include "encodings.h"
47 #include "documentprivate.h"
49 #include "msgwindow.h"
55 #include "sciwrappers.h"
56 #include "filetypesprivate.h"
59 const guint TM_GLOBAL_TYPE_MASK
=
60 tm_tag_class_t
| tm_tag_enum_t
| tm_tag_interface_t
|
61 tm_tag_struct_t
| tm_tag_typedef_t
| tm_tag_union_t
| tm_tag_namespace_t
;
64 static gchar
**html_entities
= NULL
;
69 const gchar
*tag_file
;
72 /* Check before adding any more tags files, usually they should be downloaded separately. */
73 enum /* Geany tag files */
84 static TagFileInfo tag_file_info
[GTF_MAX
] =
87 {FALSE
, "pascal.tags"},
89 {FALSE
, "html_entities.tags"},
90 {FALSE
, "latex.tags"},
91 {FALSE
, "python.tags"}
94 static GPtrArray
*top_level_iter_names
= NULL
;
98 GtkWidget
*expand_all
;
99 GtkWidget
*collapse_all
;
100 GtkWidget
*sort_by_name
;
101 GtkWidget
*sort_by_appearance
;
103 symbol_menu
= {NULL
, NULL
, NULL
, NULL
};
106 static void html_tags_loaded(void);
107 static void load_user_tags(filetype_id ft_id
);
109 /* get the tags_ignore list, exported by tagmanager's options.c */
110 extern gchar
**c_tags_ignore
;
112 /* ignore certain tokens when parsing C-like syntax.
113 * Also works for reloading. */
114 static void load_c_ignore_tags(void)
116 gchar
*path
= g_strconcat(app
->configdir
, G_DIR_SEPARATOR_S
"ignore.tags", NULL
);
119 if (g_file_get_contents(path
, &content
, NULL
, NULL
))
121 /* historically we ignore the glib _DECLS for tag generation */
122 SETPTR(content
, g_strconcat("G_BEGIN_DECLS G_END_DECLS\n", content
, NULL
));
124 g_strfreev(c_tags_ignore
);
125 c_tags_ignore
= g_strsplit_set(content
, " \n\r", -1);
132 void symbols_reload_config_files(void)
134 load_c_ignore_tags();
138 static gsize
get_tag_count(void)
140 GPtrArray
*tags
= tm_get_workspace()->global_tags
;
141 gsize count
= tags
? tags
->len
: 0;
147 /* wrapper for tm_workspace_load_global_tags().
148 * note that the tag count only counts new global tags added - if a tag has the same name,
149 * currently it replaces the existing tag, so loading a file twice will say 0 tags the 2nd time. */
150 static gboolean
symbols_load_global_tags(const gchar
*tags_file
, GeanyFiletype
*ft
)
153 gsize old_tag_count
= get_tag_count();
155 result
= tm_workspace_load_global_tags(tags_file
, ft
->lang
);
158 geany_debug("Loaded %s (%s), %u tag(s).", tags_file
, ft
->name
,
159 (guint
) (get_tag_count() - old_tag_count
));
165 /* Ensure that the global tags file(s) for the file_type_idx filetype is loaded.
166 * This provides autocompletion, calltips, etc. */
167 void symbols_global_tags_loaded(guint file_type_idx
)
172 /* load ignore list for C/C++ parser */
173 if ((file_type_idx
== GEANY_FILETYPES_C
|| file_type_idx
== GEANY_FILETYPES_CPP
) &&
174 c_tags_ignore
== NULL
)
176 load_c_ignore_tags();
179 if (cl_options
.ignore_global_tags
|| app
->tm_workspace
== NULL
)
182 /* load config in case of custom filetypes */
183 filetypes_load_config(file_type_idx
, FALSE
);
185 load_user_tags(file_type_idx
);
187 switch (file_type_idx
)
189 case GEANY_FILETYPES_PHP
:
190 case GEANY_FILETYPES_HTML
:
193 switch (file_type_idx
)
195 case GEANY_FILETYPES_CPP
:
196 symbols_global_tags_loaded(GEANY_FILETYPES_C
); /* load C global tags */
197 /* no C++ tagfile yet */
199 case GEANY_FILETYPES_C
: tag_type
= GTF_C
; break;
200 case GEANY_FILETYPES_PASCAL
:tag_type
= GTF_PASCAL
; break;
201 case GEANY_FILETYPES_PHP
: tag_type
= GTF_PHP
; break;
202 case GEANY_FILETYPES_LATEX
: tag_type
= GTF_LATEX
; break;
203 case GEANY_FILETYPES_PYTHON
:tag_type
= GTF_PYTHON
; break;
207 tfi
= &tag_file_info
[tag_type
];
209 if (! tfi
->tags_loaded
)
211 gchar
*fname
= g_strconcat(app
->datadir
, G_DIR_SEPARATOR_S
, tfi
->tag_file
, NULL
);
213 symbols_load_global_tags(fname
, filetypes
[file_type_idx
]);
214 tfi
->tags_loaded
= TRUE
;
220 /* HTML tagfile is just a list of entities for autocompletion (e.g. '&') */
221 static void html_tags_loaded(void)
225 if (cl_options
.ignore_global_tags
)
228 tfi
= &tag_file_info
[GTF_HTML_ENTITIES
];
229 if (! tfi
->tags_loaded
)
231 gchar
*file
= g_strconcat(app
->datadir
, G_DIR_SEPARATOR_S
, tfi
->tag_file
, NULL
);
233 html_entities
= utils_read_file_in_array(file
);
234 tfi
->tags_loaded
= TRUE
;
240 GString
*symbols_find_tags_as_string(GPtrArray
*tags_array
, guint tag_types
, gint lang
)
248 g_return_val_if_fail(tags_array
!= NULL
, NULL
);
250 typedefs
= tm_tags_extract(tags_array
, tag_types
);
252 if ((typedefs
) && (typedefs
->len
> 0))
254 s
= g_string_sized_new(typedefs
->len
* 10);
255 for (j
= 0; j
< typedefs
->len
; ++j
)
257 tag
= TM_TAG(typedefs
->pdata
[j
]);
258 /* tag->atts.file.lang contains (for some reason) the line of the tag if
259 * tag->atts.entry.file is not NULL */
260 tag_lang
= (tag
->atts
.entry
.file
) ? tag
->atts
.entry
.file
->lang
: tag
->atts
.file
.lang
;
262 /* the check for tag_lang == lang is necessary to avoid wrong type colouring of
263 * e.g. PHP classes in C++ files
264 * lang = -2 disables the check */
265 if (tag
->name
&& (tag_lang
== lang
|| lang
== -2))
268 g_string_append_c(s
, ' ');
269 g_string_append(s
, tag
->name
);
274 g_ptr_array_free(typedefs
, TRUE
);
279 /** Gets the context separator used by the tag manager for a particular file
281 * @param ft_id File type identifier.
282 * @return The context separator string.
286 const gchar
*symbols_get_context_separator(gint ft_id
)
290 case GEANY_FILETYPES_C
: /* for C++ .h headers or C structs */
291 case GEANY_FILETYPES_CPP
:
292 case GEANY_FILETYPES_GLSL
: /* for structs */
293 /*case GEANY_FILETYPES_RUBY:*/ /* not sure what to use atm*/
296 /* avoid confusion with other possible separators in group/section name */
297 case GEANY_FILETYPES_CONF
:
298 case GEANY_FILETYPES_REST
:
307 GString
*symbols_get_macro_list(gint lang
)
315 if (app
->tm_workspace
->work_objects
== NULL
)
318 ftags
= g_ptr_array_sized_new(50);
319 words
= g_string_sized_new(200);
321 for (j
= 0; j
< app
->tm_workspace
->work_objects
->len
; j
++)
325 tags
= tm_tags_extract(TM_WORK_OBJECT(app
->tm_workspace
->work_objects
->pdata
[j
])->tags_array
,
326 tm_tag_enum_t
| tm_tag_variable_t
| tm_tag_macro_t
| tm_tag_macro_with_arg_t
);
329 for (i
= 0; ((i
< tags
->len
) && (i
< editor_prefs
.autocompletion_max_entries
)); ++i
)
331 tag
= TM_TAG(tags
->pdata
[i
]);
332 tag_lang
= (tag
->atts
.entry
.file
) ?
333 tag
->atts
.entry
.file
->lang
: tag
->atts
.file
.lang
;
335 if (tag_lang
== lang
)
336 g_ptr_array_add(ftags
, (gpointer
) tags
->pdata
[i
]);
338 g_ptr_array_free(tags
, TRUE
);
344 g_ptr_array_free(ftags
, TRUE
);
345 g_string_free(words
, TRUE
);
349 tm_tags_sort(ftags
, NULL
, FALSE
);
350 for (j
= 0; j
< ftags
->len
; j
++)
353 g_string_append_c(words
, '\n');
354 g_string_append(words
, TM_TAG(ftags
->pdata
[j
])->name
);
356 g_ptr_array_free(ftags
, TRUE
);
361 /* Note: if tags is sorted, we can use bsearch or tm_tags_find() to speed this up. */
363 symbols_find_tm_tag(const GPtrArray
*tags
, const gchar
*tag_name
)
366 g_return_val_if_fail(tags
!= NULL
, NULL
);
368 for (i
= 0; i
< tags
->len
; ++i
)
370 if (utils_str_equal(TM_TAG(tags
->pdata
[i
])->name
, tag_name
))
371 return TM_TAG(tags
->pdata
[i
]);
377 static TMTag
*find_work_object_tag(const TMWorkObject
*workobj
,
378 const gchar
*tag_name
, guint type
)
383 if (G_LIKELY(workobj
!= NULL
))
385 tags
= tm_tags_extract(workobj
->tags_array
, type
);
388 tmtag
= symbols_find_tm_tag(tags
, tag_name
);
390 g_ptr_array_free(tags
, TRUE
);
396 return NULL
; /* not found */
400 static TMTag
*find_workspace_tag(const gchar
*tag_name
, guint type
)
403 const GPtrArray
*work_objects
= NULL
;
405 if (app
->tm_workspace
!= NULL
)
406 work_objects
= app
->tm_workspace
->work_objects
;
408 if (work_objects
!= NULL
)
410 for (j
= 0; j
< work_objects
->len
; j
++)
412 TMWorkObject
*workobj
= TM_WORK_OBJECT(work_objects
->pdata
[j
]);
415 tmtag
= find_work_object_tag(workobj
, tag_name
, type
);
420 return NULL
; /* not found */
424 const gchar
**symbols_get_html_entities(void)
426 if (html_entities
== NULL
)
427 html_tags_loaded(); /* if not yet created, force creation of the array but shouldn't occur */
429 return (const gchar
**) html_entities
;
433 /* sort by name, then line */
434 static gint
compare_symbol(const TMTag
*tag_a
, const TMTag
*tag_b
)
438 if (tag_a
== NULL
|| tag_b
== NULL
)
441 if (tag_a
->name
== NULL
)
442 return -(tag_a
->name
!= tag_b
->name
);
444 if (tag_b
->name
== NULL
)
445 return tag_a
->name
!= tag_b
->name
;
447 ret
= strcmp(tag_a
->name
, tag_b
->name
);
450 return tag_a
->atts
.entry
.line
- tag_b
->atts
.entry
.line
;
456 /* sort by line, then scope */
457 static gint
compare_symbol_lines(gconstpointer a
, gconstpointer b
)
459 const TMTag
*tag_a
= TM_TAG(a
);
460 const TMTag
*tag_b
= TM_TAG(b
);
463 if (a
== NULL
|| b
== NULL
)
466 ret
= tag_a
->atts
.entry
.line
- tag_b
->atts
.entry
.line
;
469 if (tag_a
->atts
.entry
.scope
== NULL
)
470 return -(tag_a
->atts
.entry
.scope
!= tag_b
->atts
.entry
.scope
);
471 if (tag_b
->atts
.entry
.scope
== NULL
)
472 return tag_a
->atts
.entry
.scope
!= tag_b
->atts
.entry
.scope
;
474 return strcmp(tag_a
->atts
.entry
.scope
, tag_b
->atts
.entry
.scope
);
480 static GList
*get_tag_list(GeanyDocument
*doc
, guint tag_types
)
482 GList
*tag_names
= NULL
;
486 g_return_val_if_fail(doc
, NULL
);
488 if (! doc
->tm_file
|| ! doc
->tm_file
->tags_array
)
491 for (i
= 0; i
< doc
->tm_file
->tags_array
->len
; ++i
)
493 tag
= TM_TAG(doc
->tm_file
->tags_array
->pdata
[i
]);
494 if (G_UNLIKELY(tag
== NULL
))
497 if (tag
->type
& tag_types
)
499 tag_names
= g_list_prepend(tag_names
, tag
);
502 tag_names
= g_list_sort(tag_names
, compare_symbol_lines
);
507 /* amount of types in the symbol list (currently max. 8 are used) */
508 #define MAX_SYMBOL_TYPES (sizeof(tv_iters) / sizeof(GtkTreeIter))
510 struct TreeviewSymbols
512 GtkTreeIter tag_function
;
513 GtkTreeIter tag_class
;
514 GtkTreeIter tag_macro
;
515 GtkTreeIter tag_member
;
516 GtkTreeIter tag_variable
;
517 GtkTreeIter tag_namespace
;
518 GtkTreeIter tag_struct
;
519 GtkTreeIter tag_interface
;
520 GtkTreeIter tag_type
;
521 GtkTreeIter tag_other
;
525 static void init_tag_iters(void)
527 /* init all GtkTreeIters with -1 to make them invalid to avoid crashes when switching between
528 * filetypes(e.g. config file to Python crashes Geany without this) */
529 tv_iters
.tag_function
.stamp
= -1;
530 tv_iters
.tag_class
.stamp
= -1;
531 tv_iters
.tag_member
.stamp
= -1;
532 tv_iters
.tag_macro
.stamp
= -1;
533 tv_iters
.tag_variable
.stamp
= -1;
534 tv_iters
.tag_namespace
.stamp
= -1;
535 tv_iters
.tag_struct
.stamp
= -1;
536 tv_iters
.tag_interface
.stamp
= -1;
537 tv_iters
.tag_type
.stamp
= -1;
538 tv_iters
.tag_other
.stamp
= -1;
542 static GdkPixbuf
*get_tag_icon(const gchar
*icon_name
)
544 static GtkIconTheme
*icon_theme
= NULL
;
547 if (G_UNLIKELY(icon_theme
== NULL
))
550 gchar
*path
= g_strconcat(GEANY_DATADIR
, "/icons", NULL
);
552 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU
, &x
, &y
);
553 icon_theme
= gtk_icon_theme_get_default();
555 gtk_icon_theme_append_search_path(icon_theme
, "share\\icons");
557 gtk_icon_theme_append_search_path(icon_theme
, path
);
561 return gtk_icon_theme_load_icon(icon_theme
, icon_name
, x
, 0, NULL
);
565 /* finds the next iter at any level
566 * @param iter in/out, the current iter, will be changed to the next one
567 * @param down whether to try the child iter
568 * @return TRUE if there @p iter was set, or FALSE if there is no next iter */
569 static gboolean
next_iter(GtkTreeModel
*model
, GtkTreeIter
*iter
, gboolean down
)
572 GtkTreeIter copy
= *iter
;
574 /* go down if the item has children */
575 if (down
&& gtk_tree_model_iter_children(model
, &guess
, iter
))
577 /* or to the next item at the same level */
578 else if (gtk_tree_model_iter_next(model
, ©
))
580 /* or to the next item at a parent level */
581 else if (gtk_tree_model_iter_parent(model
, &guess
, iter
))
586 if (gtk_tree_model_iter_next(model
, ©
))
591 else if (gtk_tree_model_iter_parent(model
, ©
, &guess
))
604 static gboolean
find_toplevel_iter(GtkTreeStore
*store
, GtkTreeIter
*iter
, const gchar
*title
)
606 GtkTreeModel
*model
= GTK_TREE_MODEL(store
);
608 if (!gtk_tree_model_get_iter_first(model
, iter
))
614 gtk_tree_model_get(model
, iter
, SYMBOLS_COLUMN_NAME
, &candidate
, -1);
615 /* FIXME: what if 2 different items have the same name?
616 * this should never happen, but might be caused by a typo in a translation */
617 if (utils_str_equal(candidate
, title
))
625 while (gtk_tree_model_iter_next(model
, iter
));
631 /* Adds symbol list groups in (iter*, title) pairs.
632 * The list must be ended with NULL. */
633 static void G_GNUC_NULL_TERMINATED
634 tag_list_add_groups(GtkTreeStore
*tree_store
, ...)
639 g_return_if_fail(top_level_iter_names
);
641 va_start(args
, tree_store
);
642 for (; iter
= va_arg(args
, GtkTreeIter
*), iter
!= NULL
;)
644 gchar
*title
= va_arg(args
, gchar
*);
645 gchar
*icon_name
= va_arg(args
, gchar
*);
646 GdkPixbuf
*icon
= NULL
;
650 icon
= get_tag_icon(icon_name
);
653 g_assert(title
!= NULL
);
654 g_ptr_array_add(top_level_iter_names
, title
);
656 if (!find_toplevel_iter(tree_store
, iter
, title
))
657 gtk_tree_store_append(tree_store
, iter
, NULL
);
659 if (G_IS_OBJECT(icon
))
661 gtk_tree_store_set(tree_store
, iter
, SYMBOLS_COLUMN_ICON
, icon
, -1);
662 g_object_unref(icon
);
664 gtk_tree_store_set(tree_store
, iter
, SYMBOLS_COLUMN_NAME
, title
, -1);
670 static void add_top_level_items(GeanyDocument
*doc
)
672 filetype_id ft_id
= doc
->file_type
->id
;
673 GtkTreeStore
*tag_store
= doc
->priv
->tag_store
;
675 if (top_level_iter_names
== NULL
)
676 top_level_iter_names
= g_ptr_array_new();
678 g_ptr_array_set_size(top_level_iter_names
, 0);
684 case GEANY_FILETYPES_DIFF
:
686 tag_list_add_groups(tag_store
,
687 &(tv_iters
.tag_function
), _("Files"), NULL
, NULL
);
690 case GEANY_FILETYPES_DOCBOOK
:
692 tag_list_add_groups(tag_store
,
693 &(tv_iters
.tag_function
), _("Chapter"), NULL
,
694 &(tv_iters
.tag_class
), _("Section"), NULL
,
695 &(tv_iters
.tag_member
), _("Sect1"), NULL
,
696 &(tv_iters
.tag_macro
), _("Sect2"), NULL
,
697 &(tv_iters
.tag_variable
), _("Sect3"), NULL
,
698 &(tv_iters
.tag_struct
), _("Appendix"), NULL
,
699 &(tv_iters
.tag_other
), _("Other"), NULL
,
703 case GEANY_FILETYPES_HASKELL
:
704 tag_list_add_groups(tag_store
,
705 &tv_iters
.tag_namespace
, _("Module"), NULL
,
706 &tv_iters
.tag_type
, _("Types"), NULL
,
707 &tv_iters
.tag_macro
, _("Type constructors"), NULL
,
708 &tv_iters
.tag_function
, _("Functions"), "classviewer-method",
711 case GEANY_FILETYPES_COBOL
:
712 tag_list_add_groups(tag_store
,
713 &tv_iters
.tag_class
, _("Program"), "classviewer-class",
714 &tv_iters
.tag_function
, _("File"), "classviewer-method",
715 &tv_iters
.tag_namespace
, _("Sections"), "classviewer-namespace",
716 &tv_iters
.tag_macro
, _("Paragraph"), "classviewer-other",
717 &tv_iters
.tag_struct
, _("Group"), "classviewer-struct",
718 &tv_iters
.tag_variable
, _("Data"), "classviewer-var",
721 case GEANY_FILETYPES_CONF
:
722 tag_list_add_groups(tag_store
,
723 &tv_iters
.tag_namespace
, _("Sections"), "classviewer-other",
724 &tv_iters
.tag_macro
, _("Keys"), "classviewer-var",
727 case GEANY_FILETYPES_NSIS
:
728 tag_list_add_groups(tag_store
,
729 &tv_iters
.tag_namespace
, _("Sections"), "classviewer-other",
730 &tv_iters
.tag_function
, _("Functions"), "classviewer-method",
731 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
734 case GEANY_FILETYPES_LATEX
:
736 tag_list_add_groups(tag_store
,
737 &(tv_iters
.tag_function
), _("Command"), NULL
,
738 &(tv_iters
.tag_class
), _("Environment"), NULL
,
739 &(tv_iters
.tag_member
), _("Section"), NULL
,
740 &(tv_iters
.tag_macro
), _("Subsection"), NULL
,
741 &(tv_iters
.tag_variable
), _("Subsubsection"), NULL
,
742 &(tv_iters
.tag_struct
), _("Label"), NULL
,
743 &(tv_iters
.tag_namespace
), _("Chapter"), NULL
,
744 &(tv_iters
.tag_other
), _("Other"), NULL
,
748 case GEANY_FILETYPES_MATLAB
:
750 tag_list_add_groups(tag_store
,
751 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
752 &(tv_iters
.tag_struct
), _("Structures"), "classviewer-struct",
756 case GEANY_FILETYPES_R
:
758 tag_list_add_groups(tag_store
,
759 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
760 &(tv_iters
.tag_struct
), _("Other"), NULL
,
764 case GEANY_FILETYPES_PERL
:
766 tag_list_add_groups(tag_store
,
767 &(tv_iters
.tag_namespace
), _("Package"), "classviewer-namespace",
768 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
769 &(tv_iters
.tag_macro
), _("Labels"), NULL
,
770 &(tv_iters
.tag_type
), _("Constants"), NULL
,
771 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
775 case GEANY_FILETYPES_PHP
:
777 tag_list_add_groups(tag_store
,
778 &(tv_iters
.tag_interface
), _("Interfaces"), "classviewer-struct",
779 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
780 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
781 &(tv_iters
.tag_macro
), _("Constants"), "classviewer-macro",
782 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
786 case GEANY_FILETYPES_HTML
:
788 tag_list_add_groups(tag_store
,
789 &(tv_iters
.tag_function
), _("Functions"), NULL
,
790 &(tv_iters
.tag_member
), _("Anchors"), NULL
,
791 &(tv_iters
.tag_namespace
), _("H1 Headings"), NULL
,
792 &(tv_iters
.tag_class
), _("H2 Headings"), NULL
,
793 &(tv_iters
.tag_variable
), _("H3 Headings"), NULL
,
797 case GEANY_FILETYPES_CSS
:
799 tag_list_add_groups(tag_store
,
800 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
801 &(tv_iters
.tag_variable
), _("ID Selectors"), "classviewer-var",
802 &(tv_iters
.tag_struct
), _("Type Selectors"), "classviewer-struct", NULL
);
805 case GEANY_FILETYPES_REST
:
806 case GEANY_FILETYPES_TXT2TAGS
:
807 case GEANY_FILETYPES_ABC
:
809 tag_list_add_groups(tag_store
,
810 &(tv_iters
.tag_namespace
), _("Chapter"), NULL
,
811 &(tv_iters
.tag_member
), _("Section"), NULL
,
812 &(tv_iters
.tag_macro
), _("Subsection"), NULL
,
813 &(tv_iters
.tag_variable
), _("Subsubsection"), NULL
,
817 case GEANY_FILETYPES_RUBY
:
819 tag_list_add_groups(tag_store
,
820 &(tv_iters
.tag_namespace
), _("Modules"), NULL
,
821 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
822 &(tv_iters
.tag_member
), _("Singletons"), "classviewer-struct",
823 &(tv_iters
.tag_function
), _("Methods"), "classviewer-method",
827 case GEANY_FILETYPES_TCL
:
829 tag_list_add_groups(tag_store
,
830 &(tv_iters
.tag_namespace
), _("Namespaces"), "classviewer-namespace",
831 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
832 &(tv_iters
.tag_member
), _("Methods"), "classviewer-method",
833 &(tv_iters
.tag_function
), _("Procedures"), "classviewer-other",
837 case GEANY_FILETYPES_PYTHON
:
839 tag_list_add_groups(tag_store
,
840 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
841 &(tv_iters
.tag_member
), _("Methods"), "classviewer-macro",
842 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
843 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
844 &(tv_iters
.tag_namespace
), _("Imports"), "classviewer-namespace",
848 case GEANY_FILETYPES_VHDL
:
850 tag_list_add_groups(tag_store
,
851 &(tv_iters
.tag_namespace
), _("Package"), "classviewer-namespace",
852 &(tv_iters
.tag_class
), _("Entities"), "classviewer-class",
853 &(tv_iters
.tag_struct
), _("Architectures"), "classviewer-struct",
854 &(tv_iters
.tag_type
), _("Types"), "classviewer-other",
855 &(tv_iters
.tag_function
), _("Functions / Procedures"), "classviewer-method",
856 &(tv_iters
.tag_variable
), _("Variables / Signals"), "classviewer-var",
857 &(tv_iters
.tag_member
), _("Processes / Components"), "classviewer-member",
858 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
862 case GEANY_FILETYPES_VERILOG
:
864 tag_list_add_groups(tag_store
,
865 &(tv_iters
.tag_type
), _("Events"), "classviewer-macro",
866 &(tv_iters
.tag_class
), _("Modules"), "classviewer-class",
867 &(tv_iters
.tag_function
), _("Functions / Tasks"), "classviewer-method",
868 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
869 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
873 case GEANY_FILETYPES_JAVA
:
875 tag_list_add_groups(tag_store
,
876 &(tv_iters
.tag_namespace
), _("Package"), "classviewer-namespace",
877 &(tv_iters
.tag_interface
), _("Interfaces"), "classviewer-struct",
878 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
879 &(tv_iters
.tag_function
), _("Methods"), "classviewer-method",
880 &(tv_iters
.tag_member
), _("Members"), "classviewer-member",
881 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
885 case GEANY_FILETYPES_AS
:
887 tag_list_add_groups(tag_store
,
888 &(tv_iters
.tag_namespace
), _("Package"), "classviewer-namespace",
889 &(tv_iters
.tag_interface
), _("Interfaces"), "classviewer-struct",
890 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
891 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
892 &(tv_iters
.tag_member
), _("Properties"), "classviewer-member",
893 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
894 &(tv_iters
.tag_macro
), _("Constants"), "classviewer-macro",
895 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
899 case GEANY_FILETYPES_HAXE
:
901 tag_list_add_groups(tag_store
,
902 &(tv_iters
.tag_interface
), _("Interfaces"), "classviewer-struct",
903 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
904 &(tv_iters
.tag_function
), _("Methods"), "classviewer-method",
905 &(tv_iters
.tag_type
), _("Types"), "classviewer-macro",
906 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
907 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
911 case GEANY_FILETYPES_BASIC
:
913 tag_list_add_groups(tag_store
,
914 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
915 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
916 &(tv_iters
.tag_macro
), _("Constants"), "classviewer-macro",
917 &(tv_iters
.tag_struct
), _("Types"), "classviewer-namespace",
918 &(tv_iters
.tag_namespace
), _("Labels"), "classviewer-member",
919 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
923 case GEANY_FILETYPES_F77
:
924 case GEANY_FILETYPES_FORTRAN
:
926 tag_list_add_groups(tag_store
,
927 &(tv_iters
.tag_namespace
), _("Module"), "classviewer-class",
928 &(tv_iters
.tag_interface
), _("Interfaces"), "classviewer-struct",
929 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
930 &(tv_iters
.tag_member
), _("Subroutines"), "classviewer-method",
931 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
932 &(tv_iters
.tag_type
), _("Types"), "classviewer-namespace",
933 &(tv_iters
.tag_macro
), _("Blocks"), "classviewer-member",
934 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
938 case GEANY_FILETYPES_ASM
:
940 tag_list_add_groups(tag_store
,
941 &(tv_iters
.tag_namespace
), _("Labels"), "classviewer-namespace",
942 &(tv_iters
.tag_function
), _("Macros"), "classviewer-method",
943 &(tv_iters
.tag_macro
), _("Defines"), "classviewer-macro",
944 &(tv_iters
.tag_struct
), _("Types"), "classviewer-struct",
948 case GEANY_FILETYPES_MAKE
:
949 tag_list_add_groups(tag_store
,
950 &tv_iters
.tag_function
, _("Targets"), "classviewer-method",
951 &tv_iters
.tag_macro
, _("Macros"), "classviewer-macro",
954 case GEANY_FILETYPES_SQL
:
956 tag_list_add_groups(tag_store
,
957 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
958 &(tv_iters
.tag_namespace
), _("Procedures"), "classviewer-namespace",
959 &(tv_iters
.tag_struct
), _("Indexes"), "classviewer-struct",
960 &(tv_iters
.tag_class
), _("Tables"), "classviewer-class",
961 &(tv_iters
.tag_macro
), _("Triggers"), "classviewer-macro",
962 &(tv_iters
.tag_member
), _("Views"), "classviewer-var",
963 &(tv_iters
.tag_other
), _("Other"), "classviewer-other",
967 case GEANY_FILETYPES_D
:
970 if (ft_id
== GEANY_FILETYPES_D
)
971 tag_list_add_groups(tag_store
,
972 &(tv_iters
.tag_namespace
), _("Module"), NULL
, NULL
);
974 tag_list_add_groups(tag_store
,
975 &(tv_iters
.tag_namespace
), _("Namespaces"), "classviewer-namespace", NULL
);
977 tag_list_add_groups(tag_store
,
978 &(tv_iters
.tag_class
), _("Classes"), "classviewer-class",
979 &(tv_iters
.tag_interface
), _("Interfaces"), "classviewer-struct",
980 &(tv_iters
.tag_function
), _("Functions"), "classviewer-method",
981 &(tv_iters
.tag_member
), _("Members"), "classviewer-member",
982 &(tv_iters
.tag_struct
), _("Structs"), "classviewer-struct",
983 &(tv_iters
.tag_type
), _("Typedefs / Enums"), "classviewer-struct",
986 if (ft_id
!= GEANY_FILETYPES_D
)
988 tag_list_add_groups(tag_store
,
989 &(tv_iters
.tag_macro
), _("Macros"), "classviewer-macro", NULL
);
991 tag_list_add_groups(tag_store
,
992 &(tv_iters
.tag_variable
), _("Variables"), "classviewer-var",
993 &(tv_iters
.tag_other
), _("Other"), "classviewer-other", NULL
);
999 /* removes toplevel items that have no children */
1000 static void hide_empty_rows(GtkTreeStore
*store
)
1003 gboolean cont
= TRUE
;
1005 if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store
), &iter
))
1006 return; /* stop when first iter is invalid, i.e. no elements */
1010 if (! gtk_tree_model_iter_has_child(GTK_TREE_MODEL(store
), &iter
))
1011 cont
= gtk_tree_store_remove(store
, &iter
);
1013 cont
= gtk_tree_model_iter_next(GTK_TREE_MODEL(store
), &iter
);
1018 static const gchar
*get_symbol_name(GeanyDocument
*doc
, const TMTag
*tag
, gboolean found_parent
)
1021 const gchar
*scope
= tag
->atts
.entry
.scope
;
1022 static GString
*buffer
= NULL
; /* buffer will be small so we can keep it for reuse */
1023 gboolean doc_is_utf8
= FALSE
;
1025 /* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion
1026 * for None at this point completely */
1027 if (utils_str_equal(doc
->encoding
, "UTF-8") ||
1028 utils_str_equal(doc
->encoding
, "None"))
1032 utf8_name
= encodings_convert_to_utf8_from_charset(tag
->name
,
1033 -1, doc
->encoding
, TRUE
);
1035 utf8_name
= tag
->name
;
1037 if (utf8_name
== NULL
)
1041 buffer
= g_string_new(NULL
);
1043 g_string_truncate(buffer
, 0);
1045 /* check first char of scope is a wordchar */
1046 if (!found_parent
&& scope
&&
1047 strpbrk(scope
, GEANY_WORDCHARS
) == scope
)
1049 const gchar
*sep
= symbols_get_context_separator(doc
->file_type
->id
);
1051 g_string_append(buffer
, scope
);
1052 g_string_append(buffer
, sep
);
1054 g_string_append(buffer
, utf8_name
);
1059 g_string_append_printf(buffer
, " [%lu]", tag
->atts
.entry
.line
);
1065 static gchar
*get_symbol_tooltip(GeanyDocument
*doc
, const TMTag
*tag
)
1067 gchar
*utf8_name
= editor_get_calltip_text(doc
->editor
, tag
);
1069 /* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion
1070 * for None at this point completely */
1071 if (utf8_name
!= NULL
&&
1072 ! utils_str_equal(doc
->encoding
, "UTF-8") &&
1073 ! utils_str_equal(doc
->encoding
, "None"))
1076 encodings_convert_to_utf8_from_charset(utf8_name
, -1, doc
->encoding
, TRUE
));
1079 if (utf8_name
!= NULL
)
1080 SETPTR(utf8_name
, g_markup_escape_text(utf8_name
, -1));
1086 /* find the last word in "foo::bar::blah", e.g. "blah" */
1087 static const gchar
*get_parent_name(const TMTag
*tag
, filetype_id ft_id
)
1089 const gchar
*scope
= tag
->atts
.entry
.scope
;
1090 const gchar
*separator
= symbols_get_context_separator(ft_id
);
1091 const gchar
*str
, *ptr
;
1100 ptr
= strstr(str
, separator
);
1103 str
= ptr
+ strlen(separator
);
1109 return NZV(str
) ? str
: NULL
;
1113 static GtkTreeIter
*get_tag_type_iter(TMTagType tag_type
, filetype_id ft_id
)
1115 GtkTreeIter
*iter
= NULL
;
1119 case tm_tag_prototype_t
:
1120 case tm_tag_method_t
:
1121 case tm_tag_function_t
:
1123 iter
= &tv_iters
.tag_function
;
1126 case tm_tag_macro_t
:
1127 case tm_tag_macro_with_arg_t
:
1129 iter
= &tv_iters
.tag_macro
;
1132 case tm_tag_class_t
:
1134 iter
= &tv_iters
.tag_class
;
1137 case tm_tag_member_t
:
1138 case tm_tag_field_t
:
1140 iter
= &tv_iters
.tag_member
;
1143 case tm_tag_typedef_t
:
1146 iter
= &tv_iters
.tag_type
;
1149 case tm_tag_union_t
:
1150 case tm_tag_struct_t
:
1152 iter
= &tv_iters
.tag_struct
;
1155 case tm_tag_interface_t
:
1156 iter
= &tv_iters
.tag_interface
;
1158 case tm_tag_variable_t
:
1160 iter
= &tv_iters
.tag_variable
;
1163 case tm_tag_namespace_t
:
1164 case tm_tag_package_t
:
1166 iter
= &tv_iters
.tag_namespace
;
1171 iter
= &tv_iters
.tag_other
;
1174 if (G_LIKELY(iter
->stamp
!= -1))
1181 static GdkPixbuf
*get_child_icon(GtkTreeStore
*tree_store
, GtkTreeIter
*parent
)
1183 GdkPixbuf
*icon
= NULL
;
1185 if (parent
== &tv_iters
.tag_other
)
1187 return get_tag_icon("classviewer-var");
1189 /* copy parent icon */
1190 gtk_tree_model_get(GTK_TREE_MODEL(tree_store
), parent
,
1191 SYMBOLS_COLUMN_ICON
, &icon
, -1);
1196 static gboolean
tag_equal(gconstpointer v1
, gconstpointer v2
)
1198 const TMTag
*t1
= v1
;
1199 const TMTag
*t2
= v2
;
1201 return (t1
->type
== t2
->type
&& strcmp(t1
->name
, t2
->name
) == 0 &&
1202 utils_str_equal(t1
->atts
.entry
.scope
, t2
->atts
.entry
.scope
) &&
1203 /* include arglist in match to support e.g. C++ overloading */
1204 utils_str_equal(t1
->atts
.entry
.arglist
, t2
->atts
.entry
.arglist
));
1208 /* inspired from g_str_hash() */
1209 static guint
tag_hash(gconstpointer v
)
1211 const TMTag
*tag
= v
;
1215 h
= (h
<< 5) + h
+ tag
->type
;
1216 for (p
= tag
->name
; *p
!= '\0'; p
++)
1217 h
= (h
<< 5) + h
+ *p
;
1218 if (tag
->atts
.entry
.scope
)
1220 for (p
= tag
->atts
.entry
.scope
; *p
!= '\0'; p
++)
1221 h
= (h
<< 5) + h
+ *p
;
1223 /* for e.g. C++ overloading */
1224 if (tag
->atts
.entry
.arglist
)
1226 for (p
= tag
->atts
.entry
.arglist
; *p
!= '\0'; p
++)
1227 h
= (h
<< 5) + h
+ *p
;
1234 /* like gtk_tree_view_expand_to_path() but with an iter */
1235 static void tree_view_expand_to_iter(GtkTreeView
*view
, GtkTreeIter
*iter
)
1237 GtkTreeModel
*model
= gtk_tree_view_get_model(view
);
1238 GtkTreePath
*path
= gtk_tree_model_get_path(model
, iter
);
1240 gtk_tree_view_expand_to_path(view
, path
);
1241 gtk_tree_path_free(path
);
1245 /* like gtk_tree_store_remove() but finds the next iter at any level */
1246 static gboolean
tree_store_remove_row(GtkTreeStore
*store
, GtkTreeIter
*iter
)
1249 gboolean has_parent
;
1252 has_parent
= gtk_tree_model_iter_parent(GTK_TREE_MODEL(store
), &parent
, iter
);
1253 cont
= gtk_tree_store_remove(store
, iter
);
1254 /* if there is no next at this level but there is a parent iter, continue from it */
1255 if (! cont
&& has_parent
)
1258 cont
= next_iter(GTK_TREE_MODEL(store
), iter
, FALSE
);
1265 /* adds a new element in the parent table if it's key is known.
1266 * duplicates are kept */
1267 static void update_parents_table(GHashTable
*table
, const TMTag
*tag
, const gchar
*parent_name
,
1268 const GtkTreeIter
*iter
)
1271 if (g_hash_table_lookup_extended(table
, tag
->name
, NULL
, (gpointer
*) &list
) &&
1272 ! utils_str_equal(parent_name
, tag
->name
) /* prevent Foo::Foo from making parent = child */)
1276 list
= g_slice_alloc(sizeof *list
);
1278 g_hash_table_insert(table
, tag
->name
, list
);
1280 *list
= g_list_prepend(*list
, g_slice_dup(GtkTreeIter
, iter
));
1285 static void free_iter_slice_list(gpointer data
)
1287 GList
**list
= data
;
1292 foreach_list(node
, *list
)
1293 g_slice_free(GtkTreeIter
, node
->data
);
1295 g_slice_free1(sizeof *list
, list
);
1300 /* inserts a @data in @table on key @tag.
1301 * previous data is not overwritten if the key is duplicated, but rather the
1302 * two values are kept in a list
1304 * table is: GHashTable<TMTag, GList<GList<TMTag>>> */
1305 static void tags_table_insert(GHashTable
*table
, TMTag
*tag
, GList
*data
)
1307 GList
*list
= g_hash_table_lookup(table
, tag
);
1308 list
= g_list_prepend(list
, data
);
1309 g_hash_table_insert(table
, tag
, list
);
1313 /* looks up the entry in @table that better matches @tag.
1314 * if there are more than one candidate, the one that has closest line position to @tag is chosen */
1315 static GList
*tags_table_lookup(GHashTable
*table
, TMTag
*tag
)
1318 GList
*node
= g_hash_table_lookup(table
, tag
);
1324 #define TAG_DELTA(a, b) ABS((glong) TM_TAG(a)->atts.entry.line - (glong) TM_TAG(b)->atts.entry.line)
1326 delta
= TAG_DELTA(((GList
*) node
->data
)->data
, tag
);
1327 for (node
= node
->next
; node
; node
= node
->next
)
1329 glong d
= TAG_DELTA(((GList
*) node
->data
)->data
, tag
);
1345 /* removes the element at @tag from @table.
1346 * @tag must be the exact pointer used at insertion time */
1347 static void tags_table_remove(GHashTable
*table
, TMTag
*tag
)
1349 GList
*list
= g_hash_table_lookup(table
, tag
);
1353 foreach_list(node
, list
)
1355 if (((GList
*) node
->data
)->data
== tag
)
1358 list
= g_list_delete_link(list
, node
);
1360 g_hash_table_insert(table
, tag
, list
);
1362 g_hash_table_remove(table
, tag
);
1368 * Updates the tag tree for a document with the tags in *list.
1369 * @param doc a document
1370 * @param tags a pointer to a GList* holding the tags to add/update. This
1371 * list may be updated, removing updated elements.
1373 * The update is done in two passes:
1374 * 1) walking the current tree, update tags that still exist and remove the
1376 * 2) walking the remaining (non updated) tags, adds them in the list.
1378 * For better performances, we use 2 hash tables:
1379 * - one containing all the tags for lookup in the first pass (actually stores a
1380 * reference in the tags list for removing it efficiently), avoiding list search
1382 * - the other holding "tag-name":row references for tags having children, used to
1383 * lookup for a parent in both passes, avoiding tree traversal.
1385 static void update_tree_tags(GeanyDocument
*doc
, GList
**tags
)
1387 GtkTreeStore
*store
= doc
->priv
->tag_store
;
1388 GtkTreeModel
*model
= GTK_TREE_MODEL(store
);
1389 GHashTable
*parents_table
;
1390 GHashTable
*tags_table
;
1395 /* Build hash tables holding tags and parents */
1396 /* parent table holds "tag-name":GtkTreeIter */
1397 parents_table
= g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
, free_iter_slice_list
);
1398 /* tags table is another representation of the @tags list, TMTag:GList<TMTag> */
1399 tags_table
= g_hash_table_new_full(tag_hash
, tag_equal
, NULL
, NULL
);
1400 foreach_list(item
, *tags
)
1402 TMTag
*tag
= item
->data
;
1405 tags_table_insert(tags_table
, tag
, item
);
1407 name
= get_parent_name(tag
, doc
->file_type
->id
);
1409 g_hash_table_insert(parents_table
, (gpointer
) name
, NULL
);
1412 /* First pass, update existing rows or delete them.
1413 * It is OK to delete them since we walk top down so we would remove
1414 * parents before checking for their children, thus never implicitly
1415 * deleting an updated child */
1416 cont
= gtk_tree_model_get_iter_first(model
, &iter
);
1421 gtk_tree_model_get(model
, &iter
, SYMBOLS_COLUMN_TAG
, &tag
, -1);
1422 if (! tag
) /* most probably a toplevel, skip it */
1423 cont
= next_iter(model
, &iter
, TRUE
);
1428 found_item
= tags_table_lookup(tags_table
, tag
);
1429 if (! found_item
) /* tag doesn't exist, remove it */
1430 cont
= tree_store_remove_row(store
, &iter
);
1431 else /* tag still exist, update it */
1434 const gchar
*parent_name
;
1435 TMTag
*found
= found_item
->data
;
1437 parent_name
= get_parent_name(found
, doc
->file_type
->id
);
1438 /* if parent is unknown, ignore it */
1439 if (parent_name
&& ! g_hash_table_lookup(parents_table
, parent_name
))
1442 /* only update fields that (can) have changed (name that holds line
1443 * number, and the tag itself) */
1444 name
= get_symbol_name(doc
, found
, parent_name
!= NULL
);
1445 gtk_tree_store_set(store
, &iter
,
1446 SYMBOLS_COLUMN_NAME
, name
,
1447 SYMBOLS_COLUMN_TAG
, found
,
1450 update_parents_table(parents_table
, found
, parent_name
, &iter
);
1452 /* remove the updated tag from the table and list */
1453 tags_table_remove(tags_table
, found
);
1454 *tags
= g_list_delete_link(*tags
, found_item
);
1456 cont
= next_iter(model
, &iter
, TRUE
);
1463 /* Second pass, now we have a tree cleaned up from invalid rows,
1464 * we simply add new ones */
1465 foreach_list (item
, *tags
)
1467 TMTag
*tag
= item
->data
;
1468 GtkTreeIter
*parent
;
1470 parent
= get_tag_type_iter(tag
->type
, doc
->file_type
->id
);
1471 if (G_UNLIKELY(! parent
))
1472 geany_debug("Missing symbol-tree parent iter for type %d!", tag
->type
);
1477 const gchar
*parent_name
;
1479 GdkPixbuf
*icon
= get_child_icon(store
, parent
);
1481 parent_name
= get_parent_name(tag
, doc
->file_type
->id
);
1485 GtkTreeIter
*parent_search
= NULL
;
1487 /* walk parent candidates to find the better one.
1488 * if there are more than one, take the one that has the closest line number
1489 * after the tag we're searching the parent for */
1490 candidates
= g_hash_table_lookup(parents_table
, parent_name
);
1494 glong delta
= G_MAXLONG
;
1495 foreach_list(node
, *candidates
)
1500 gtk_tree_model_get(GTK_TREE_MODEL(store
), node
->data
,
1501 SYMBOLS_COLUMN_TAG
, &parent_tag
, -1);
1503 d
= tag
->atts
.entry
.line
- parent_tag
->atts
.entry
.line
;
1504 if (! parent_search
|| (d
>= 0 && d
< delta
))
1507 parent_search
= node
->data
;
1513 parent
= parent_search
;
1518 /* only expand to the iter if the parent was empty, otherwise we let the
1519 * folding as it was before (already expanded, or closed by the user) */
1520 expand
= ! gtk_tree_model_iter_has_child(model
, parent
);
1522 /* insert the new element */
1523 gtk_tree_store_append(store
, &iter
, parent
);
1524 name
= get_symbol_name(doc
, tag
, parent_name
!= NULL
);
1525 tooltip
= get_symbol_tooltip(doc
, tag
);
1526 gtk_tree_store_set(store
, &iter
,
1527 SYMBOLS_COLUMN_NAME
, name
,
1528 SYMBOLS_COLUMN_TOOLTIP
, tooltip
,
1529 SYMBOLS_COLUMN_ICON
, icon
,
1530 SYMBOLS_COLUMN_TAG
, tag
,
1534 g_object_unref(icon
);
1536 update_parents_table(parents_table
, tag
, parent_name
, &iter
);
1539 tree_view_expand_to_iter(GTK_TREE_VIEW(doc
->priv
->tag_tree
), &iter
);
1543 g_hash_table_destroy(parents_table
);
1544 g_hash_table_destroy(tags_table
);
1548 /* we don't want to sort 1st-level nodes, but we can't return 0 because the tree sort
1549 * is not stable, so the order is already lost. */
1550 static gint
compare_top_level_names(const gchar
*a
, const gchar
*b
)
1555 /* This should never happen as it would mean that two or more top
1556 * level items have the same name but it can happen by typos in the translations. */
1557 if (utils_str_equal(a
, b
))
1560 foreach_ptr_array(name
, i
, top_level_iter_names
)
1562 if (utils_str_equal(name
, a
))
1564 if (utils_str_equal(name
, b
))
1567 g_warning("Couldn't find top level node '%s' or '%s'!", a
, b
);
1572 static gboolean
tag_has_missing_parent(const TMTag
*tag
, GtkTreeStore
*store
,
1575 /* if the tag has a parent tag, it should be at depth >= 2 */
1576 return NZV(tag
->atts
.entry
.scope
) &&
1577 gtk_tree_store_iter_depth(store
, iter
) == 1;
1581 static gint
tree_sort_func(GtkTreeModel
*model
, GtkTreeIter
*a
, GtkTreeIter
*b
,
1584 gboolean sort_by_name
= GPOINTER_TO_INT(user_data
);
1585 TMTag
*tag_a
, *tag_b
;
1588 gtk_tree_model_get(model
, a
, SYMBOLS_COLUMN_TAG
, &tag_a
, -1);
1589 gtk_tree_model_get(model
, b
, SYMBOLS_COLUMN_TAG
, &tag_b
, -1);
1591 /* Check if the iters can be sorted based on tag name and line, not tree item name.
1592 * Sort by tree name if the scope was prepended, e.g. 'ScopeNameWithNoTag::TagName'. */
1593 if (tag_a
&& !tag_has_missing_parent(tag_a
, GTK_TREE_STORE(model
), a
) &&
1594 tag_b
&& !tag_has_missing_parent(tag_b
, GTK_TREE_STORE(model
), b
))
1596 cmp
= sort_by_name
? compare_symbol(tag_a
, tag_b
) :
1597 compare_symbol_lines(tag_a
, tag_b
);
1603 gtk_tree_model_get(model
, a
, SYMBOLS_COLUMN_NAME
, &astr
, -1);
1604 gtk_tree_model_get(model
, b
, SYMBOLS_COLUMN_NAME
, &bstr
, -1);
1606 /* if a is toplevel, b must be also */
1607 if (gtk_tree_store_iter_depth(GTK_TREE_STORE(model
), a
) == 0)
1609 cmp
= compare_top_level_names(astr
, bstr
);
1613 /* this is what g_strcmp0() does */
1615 cmp
= -(astr
!= bstr
);
1620 cmp
= strcmp(astr
, bstr
);
1622 /* sort duplicate 'ScopeName::OverloadedTagName' items by line as well */
1624 if (!sort_by_name
||
1625 (utils_str_equal(tag_a
->name
, tag_b
->name
) &&
1626 utils_str_equal(tag_a
->atts
.entry
.scope
, tag_b
->atts
.entry
.scope
)))
1627 cmp
= compare_symbol_lines(tag_a
, tag_b
);
1633 tm_tag_unref(tag_a
);
1634 tm_tag_unref(tag_b
);
1640 static void sort_tree(GtkTreeStore
*store
, gboolean sort_by_name
)
1642 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store
), SYMBOLS_COLUMN_NAME
, tree_sort_func
,
1643 GINT_TO_POINTER(sort_by_name
), NULL
);
1645 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store
), SYMBOLS_COLUMN_NAME
, GTK_SORT_ASCENDING
);
1649 gboolean
symbols_recreate_tag_list(GeanyDocument
*doc
, gint sort_mode
)
1653 g_return_val_if_fail(doc
!= NULL
, FALSE
);
1655 tags
= get_tag_list(doc
, tm_tag_max_t
);
1659 /* FIXME: Not sure why we detached the model here? */
1661 /* disable sorting during update because the code doesn't support correctly
1662 * models that are currently being built */
1663 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(doc
->priv
->tag_store
), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID
, 0);
1665 /* add grandparent type iters */
1666 add_top_level_items(doc
);
1668 update_tree_tags(doc
, &tags
);
1671 hide_empty_rows(doc
->priv
->tag_store
);
1673 if (sort_mode
== SYMBOLS_SORT_USE_PREVIOUS
)
1674 sort_mode
= doc
->priv
->symbol_list_sort_mode
;
1676 sort_tree(doc
->priv
->tag_store
, sort_mode
== SYMBOLS_SORT_BY_NAME
);
1677 doc
->priv
->symbol_list_sort_mode
= sort_mode
;
1683 /* Detects a global tags filetype from the *.lang.* language extension.
1684 * Returns NULL if there was no matching TM language. */
1685 static GeanyFiletype
*detect_global_tags_filetype(const gchar
*utf8_filename
)
1688 gchar
*shortname
= utils_strdupa(utf8_filename
);
1689 GeanyFiletype
*ft
= NULL
;
1691 tags_ext
= g_strrstr(shortname
, ".tags");
1694 *tags_ext
= '\0'; /* remove .tags extension */
1695 ft
= filetypes_detect_from_extension(shortname
);
1696 if (ft
->id
!= GEANY_FILETYPES_NONE
)
1703 /* Adapted from anjuta-2.0.2/global-tags/tm_global_tags.c, thanks.
1704 * Needs full paths for filenames, except for C/C++ tag files, when CFLAGS includes
1705 * the relevant path.
1707 * CFLAGS=-I/home/user/libname-1.x geany -g libname.d.tags libname.h */
1708 int symbols_generate_global_tags(int argc
, char **argv
, gboolean want_preprocess
)
1710 /* -E pre-process, -dD output user macros, -p prof info (?) */
1711 const char pre_process
[] = "gcc -E -dD -p -I.";
1715 /* Create global taglist */
1718 const char *tags_file
= argv
[1];
1722 utf8_fname
= utils_get_utf8_from_locale(tags_file
);
1723 ft
= detect_global_tags_filetype(utf8_fname
);
1728 g_printerr(_("Unknown filetype extension for \"%s\".\n"), tags_file
);
1731 /* load config in case of custom filetypes */
1732 filetypes_load_config(ft
->id
, FALSE
);
1734 /* load ignore list for C/C++ parser */
1735 if (ft
->id
== GEANY_FILETYPES_C
|| ft
->id
== GEANY_FILETYPES_CPP
)
1736 load_c_ignore_tags();
1738 if (want_preprocess
&& (ft
->id
== GEANY_FILETYPES_C
|| ft
->id
== GEANY_FILETYPES_CPP
))
1739 command
= g_strdup_printf("%s %s", pre_process
, NVL(getenv("CFLAGS"), ""));
1741 command
= NULL
; /* don't preprocess */
1743 geany_debug("Generating %s tags file.", ft
->name
);
1745 status
= tm_workspace_create_global_tags(command
, (const char **) (argv
+ 2),
1746 argc
- 2, tags_file
, ft
->lang
);
1748 symbols_finalize(); /* free c_tags_ignore data */
1751 g_printerr(_("Failed to create tags file, perhaps because no tags "
1758 g_printerr(_("Usage: %s -g <Tag File> <File list>\n\n"), argv
[0]);
1759 g_printerr(_("Example:\n"
1760 "CFLAGS=`pkg-config gtk+-2.0 --cflags` %s -g gtk2.c.tags"
1761 " /usr/include/gtk-2.0/gtk/gtk.h\n"), argv
[0]);
1768 void symbols_show_load_tags_dialog(void)
1771 GtkFileFilter
*filter
;
1773 dialog
= gtk_file_chooser_dialog_new(_("Load Tags"), GTK_WINDOW(main_widgets
.window
),
1774 GTK_FILE_CHOOSER_ACTION_OPEN
,
1775 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
1776 GTK_STOCK_OPEN
, GTK_RESPONSE_OK
,
1778 gtk_widget_set_name(dialog
, "GeanyDialog");
1779 filter
= gtk_file_filter_new();
1780 gtk_file_filter_set_name(filter
, _("Geany tag files (*.*.tags)"));
1781 gtk_file_filter_add_pattern(filter
, "*.*.tags");
1782 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog
), filter
);
1784 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_OK
)
1786 GSList
*flist
= gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog
));
1789 for (item
= flist
; item
!= NULL
; item
= g_slist_next(item
))
1791 gchar
*fname
= item
->data
;
1795 utf8_fname
= utils_get_utf8_from_locale(fname
);
1796 ft
= detect_global_tags_filetype(utf8_fname
);
1798 if (ft
!= NULL
&& symbols_load_global_tags(fname
, ft
))
1799 /* For translators: the first wildcard is the filetype, the second the filename */
1800 ui_set_statusbar(TRUE
, _("Loaded %s tags file '%s'."),
1801 filetypes_get_display_name(ft
), utf8_fname
);
1803 ui_set_statusbar(TRUE
, _("Could not load tags file '%s'."), utf8_fname
);
1808 g_slist_free(flist
);
1810 gtk_widget_destroy(dialog
);
1814 static void detect_tag_files(const GSList
*file_list
)
1818 for (node
= file_list
; node
!= NULL
; node
= g_slist_next(node
))
1820 gchar
*fname
= node
->data
;
1821 gchar
*utf8_fname
= utils_get_utf8_from_locale(fname
);
1822 GeanyFiletype
*ft
= detect_global_tags_filetype(utf8_fname
);
1826 if (FILETYPE_ID(ft
) != GEANY_FILETYPES_NONE
)
1827 ft
->priv
->tag_files
= g_slist_prepend(ft
->priv
->tag_files
, fname
);
1829 geany_debug("Unknown filetype for file '%s'.", fname
);
1834 static void init_user_tags(void)
1836 GSList
*file_list
= NULL
, *list
= NULL
;
1839 dir
= g_build_filename(app
->configdir
, "tags", NULL
);
1840 /* create the user tags dir for next time if it doesn't exist */
1841 if (! g_file_test(dir
, G_FILE_TEST_IS_DIR
))
1843 utils_mkdir(dir
, FALSE
);
1845 file_list
= utils_get_file_list_full(dir
, TRUE
, FALSE
, NULL
);
1847 SETPTR(dir
, g_build_filename(app
->datadir
, "tags", NULL
));
1848 list
= utils_get_file_list_full(dir
, TRUE
, FALSE
, NULL
);
1851 file_list
= g_slist_concat(file_list
, list
);
1852 detect_tag_files(file_list
);
1853 /* don't need to delete list contents because they are stored in ft->priv->tag_files */
1854 g_slist_free(file_list
);
1858 static void load_user_tags(filetype_id ft_id
)
1860 static guchar
*tags_loaded
= NULL
;
1861 static gboolean init_tags
= FALSE
;
1863 GeanyFiletype
*ft
= filetypes
[ft_id
];
1865 g_return_if_fail(ft_id
> 0);
1868 tags_loaded
= g_new0(guchar
, filetypes_array
->len
);
1869 if (tags_loaded
[ft_id
])
1871 tags_loaded
[ft_id
] = TRUE
; /* prevent reloading */
1879 for (node
= ft
->priv
->tag_files
; node
!= NULL
; node
= g_slist_next(node
))
1881 const gchar
*fname
= node
->data
;
1883 symbols_load_global_tags(fname
, ft
);
1888 static gboolean
goto_tag(const gchar
*name
, gboolean definition
)
1890 const gint forward_types
= tm_tag_prototype_t
| tm_tag_externvar_t
;
1892 TMTag
*tmtag
= NULL
;
1893 GeanyDocument
*old_doc
= document_get_current();
1895 /* goto tag definition: all except prototypes / forward declarations / externs */
1896 type
= (definition
) ? tm_tag_max_t
- forward_types
: forward_types
;
1898 /* first look in the current document */
1899 if (old_doc
!= NULL
&& old_doc
->tm_file
)
1900 tmtag
= find_work_object_tag(old_doc
->tm_file
, name
, type
);
1902 /* if not found, look in the workspace */
1904 tmtag
= find_workspace_tag(name
, type
);
1908 GeanyDocument
*new_doc
= document_find_by_real_path(
1909 tmtag
->atts
.entry
.file
->work_object
.file_name
);
1913 /* If we are already on the tag line, swap definition/declaration */
1914 if (new_doc
== old_doc
&&
1915 tmtag
->atts
.entry
.line
== (guint
)sci_get_current_line(old_doc
->editor
->sci
) + 1)
1917 if (goto_tag(name
, !definition
))
1923 /* not found in opened document, should open */
1924 new_doc
= document_open_file(tmtag
->atts
.entry
.file
->work_object
.file_name
, FALSE
, NULL
, NULL
);
1927 if (navqueue_goto_line(old_doc
, new_doc
, tmtag
->atts
.entry
.line
))
1934 gboolean
symbols_goto_tag(const gchar
*name
, gboolean definition
)
1936 if (goto_tag(name
, definition
))
1939 /* if we are here, there was no match and we are beeping ;-) */
1943 ui_set_statusbar(FALSE
, _("Forward declaration \"%s\" not found."), name
);
1945 ui_set_statusbar(FALSE
, _("Definition of \"%s\" not found."), name
);
1950 /* This could perhaps be improved to check for #if, class etc. */
1951 static gint
get_function_fold_number(GeanyDocument
*doc
)
1953 /* for Java the functions are always one fold level above the class scope */
1954 if (doc
->file_type
->id
== GEANY_FILETYPES_JAVA
)
1955 return SC_FOLDLEVELBASE
+ 1;
1957 return SC_FOLDLEVELBASE
;
1961 /* Should be used only with symbols_get_current_function. */
1962 static gboolean
current_function_changed(GeanyDocument
*doc
, gint cur_line
, gint fold_level
)
1964 static gint old_line
= -2;
1965 static GeanyDocument
*old_doc
= NULL
;
1966 static gint old_fold_num
= -1;
1967 const gint fold_num
= fold_level
& SC_FOLDLEVELNUMBERMASK
;
1970 /* check if the cached line and file index have changed since last time: */
1971 if (doc
== NULL
|| doc
!= old_doc
)
1974 if (cur_line
== old_line
)
1978 /* if the line has only changed by 1 */
1979 if (abs(cur_line
- old_line
) == 1)
1981 const gint fn_fold
=
1982 get_function_fold_number(doc
);
1983 /* It's the same function if the fold number hasn't changed, or both the new
1984 * and old fold numbers are above the function fold number. */
1986 fold_num
== old_fold_num
||
1987 (old_fold_num
> fn_fold
&& fold_num
> fn_fold
);
1994 /* record current line and file index for next time */
1995 old_line
= cur_line
;
1997 old_fold_num
= fold_num
;
2002 /* Parse the function name up to 2 lines before tag_line.
2003 * C++ like syntax should be parsed by parse_cpp_function_at_line, otherwise the return
2004 * type or argument names can be confused with the function name. */
2005 static gchar
*parse_function_at_line(ScintillaObject
*sci
, gint tag_line
)
2007 gint start
, end
, max_pos
;
2011 switch (sci_get_lexer(sci
))
2013 case SCLEX_RUBY
: fn_style
= SCE_RB_DEFNAME
; break;
2014 case SCLEX_PYTHON
: fn_style
= SCE_P_DEFNAME
; break;
2015 default: fn_style
= SCE_C_IDENTIFIER
; /* several lexers use SCE_C_IDENTIFIER */
2017 start
= sci_get_position_from_line(sci
, tag_line
- 2);
2018 max_pos
= sci_get_position_from_line(sci
, tag_line
+ 1);
2019 while (sci_get_style_at(sci
, start
) != fn_style
2020 && start
< max_pos
) start
++;
2023 while (sci_get_style_at(sci
, end
) == fn_style
2024 && end
< max_pos
) end
++;
2028 cur_tag
= g_malloc(end
- start
+ 1);
2029 sci_get_text_range(sci
, start
, end
, cur_tag
);
2034 /* Parse the function name */
2035 static gchar
*parse_cpp_function_at_line(ScintillaObject
*sci
, gint tag_line
)
2037 gint start
, end
, first_pos
, max_pos
;
2042 first_pos
= end
= sci_get_position_from_line(sci
, tag_line
);
2043 max_pos
= sci_get_position_from_line(sci
, tag_line
+ 1);
2045 /* goto the begin of function body */
2046 while (end
< max_pos
&&
2047 (tmp
= sci_get_char_at(sci
, end
)) != '{' &&
2049 if (tmp
== 0) end
--;
2051 /* go back to the end of function identifier */
2052 while (end
> 0 && end
> first_pos
- 500 &&
2053 (tmp
= sci_get_char_at(sci
, end
)) != '(' &&
2056 if (end
< 0) end
= 0;
2058 /* skip whitespaces between identifier and ( */
2059 while (end
> 0 && isspace(sci_get_char_at(sci
, end
))) end
--;
2063 /* Use tmp to find SCE_C_IDENTIFIER or SCE_C_GLOBALCLASS chars */
2064 while (start
>= 0 && ((tmp
= sci_get_style_at(sci
, start
)) == SCE_C_IDENTIFIER
2065 || tmp
== SCE_C_GLOBALCLASS
2066 || (c
= sci_get_char_at(sci
, start
)) == '~'
2069 if (start
!= 0 && start
< end
) start
++; /* correct for last non-matching char */
2071 if (start
== end
) return NULL
;
2072 cur_tag
= g_malloc(end
- start
+ 2);
2073 sci_get_text_range(sci
, start
, end
+ 1, cur_tag
);
2078 /* Sets *tagname to point at the current function or tag name.
2079 * If doc is NULL, reset the cached current tag data to ensure it will be reparsed on the next
2080 * call to this function.
2081 * Returns: line number of the current tag, or -1 if unknown. */
2082 gint
symbols_get_current_function(GeanyDocument
*doc
, const gchar
**tagname
)
2084 static gint tag_line
= -1;
2085 static gchar
*cur_tag
= NULL
;
2088 TMWorkObject
*tm_file
;
2090 if (doc
== NULL
) /* reset current function */
2092 current_function_changed(NULL
, -1, -1);
2094 cur_tag
= g_strdup(_("unknown"));
2095 if (tagname
!= NULL
)
2101 line
= sci_get_current_line(doc
->editor
->sci
);
2102 fold_level
= sci_get_fold_level(doc
->editor
->sci
, line
);
2103 /* check if the cached line and file index have changed since last time: */
2104 if (! current_function_changed(doc
, line
, fold_level
))
2106 /* we can assume same current function as before */
2110 g_free(cur_tag
); /* free the old tag, it will be replaced. */
2112 /* if line is at base fold level, we're not in a function */
2113 if ((fold_level
& SC_FOLDLEVELNUMBERMASK
) == SC_FOLDLEVELBASE
)
2115 cur_tag
= g_strdup(_("unknown"));
2120 tm_file
= doc
->tm_file
;
2122 /* if the document has no changes, get the previous function name from TM */
2123 if (! doc
->changed
&& tm_file
!= NULL
&& tm_file
->tags_array
!= NULL
)
2125 const TMTag
*tag
= (const TMTag
*) tm_get_current_function(tm_file
->tags_array
, line
);
2130 tmp
= tag
->atts
.entry
.scope
;
2131 cur_tag
= tmp
? g_strconcat(tmp
, "::", tag
->name
, NULL
) : g_strdup(tag
->name
);
2133 tag_line
= tag
->atts
.entry
.line
;
2138 /* parse the current function name here because TM line numbers may have changed,
2139 * and it would take too long to reparse the whole file. */
2140 if (doc
->file_type
!= NULL
&& doc
->file_type
->id
!= GEANY_FILETYPES_NONE
)
2142 const gint fn_fold
= get_function_fold_number(doc
);
2145 do /* find the top level fold point */
2147 tag_line
= sci_get_fold_parent(doc
->editor
->sci
, tag_line
);
2148 fold_level
= sci_get_fold_level(doc
->editor
->sci
, tag_line
);
2149 } while (tag_line
>= 0 &&
2150 (fold_level
& SC_FOLDLEVELNUMBERMASK
) != fn_fold
);
2154 if (sci_get_lexer(doc
->editor
->sci
) == SCLEX_CPP
)
2155 cur_tag
= parse_cpp_function_at_line(doc
->editor
->sci
, tag_line
);
2157 cur_tag
= parse_function_at_line(doc
->editor
->sci
, tag_line
);
2159 if (cur_tag
!= NULL
)
2167 cur_tag
= g_strdup(_("unknown"));
2174 static void on_symbol_tree_sort_clicked(GtkMenuItem
*menuitem
, gpointer user_data
)
2176 gint sort_mode
= GPOINTER_TO_INT(user_data
);
2177 GeanyDocument
*doc
= document_get_current();
2179 if (ignore_callback
)
2183 doc
->has_tags
= symbols_recreate_tag_list(doc
, sort_mode
);
2187 static void on_symbol_tree_menu_show(GtkWidget
*widget
,
2190 GeanyDocument
*doc
= document_get_current();
2193 enable
= doc
&& doc
->has_tags
;
2194 gtk_widget_set_sensitive(symbol_menu
.sort_by_name
, enable
);
2195 gtk_widget_set_sensitive(symbol_menu
.sort_by_appearance
, enable
);
2196 gtk_widget_set_sensitive(symbol_menu
.expand_all
, enable
);
2197 gtk_widget_set_sensitive(symbol_menu
.collapse_all
, enable
);
2202 ignore_callback
= TRUE
;
2204 if (doc
->priv
->symbol_list_sort_mode
== SYMBOLS_SORT_BY_NAME
)
2205 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(symbol_menu
.sort_by_name
), TRUE
);
2207 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(symbol_menu
.sort_by_appearance
), TRUE
);
2209 ignore_callback
= FALSE
;
2213 static void on_expand_collapse(GtkWidget
*widget
, gpointer user_data
)
2215 gboolean expand
= GPOINTER_TO_INT(user_data
);
2216 GeanyDocument
*doc
= document_get_current();
2221 g_return_if_fail(doc
->priv
->tag_tree
);
2224 gtk_tree_view_expand_all(GTK_TREE_VIEW(doc
->priv
->tag_tree
));
2226 gtk_tree_view_collapse_all(GTK_TREE_VIEW(doc
->priv
->tag_tree
));
2230 static void create_taglist_popup_menu(void)
2232 GtkWidget
*item
, *menu
;
2234 tv
.popup_taglist
= menu
= gtk_menu_new();
2236 symbol_menu
.expand_all
= item
= ui_image_menu_item_new(GTK_STOCK_ADD
, _("_Expand All"));
2237 gtk_widget_show(item
);
2238 gtk_container_add(GTK_CONTAINER(menu
), item
);
2239 g_signal_connect(item
, "activate", G_CALLBACK(on_expand_collapse
), GINT_TO_POINTER(TRUE
));
2241 symbol_menu
.collapse_all
= item
= ui_image_menu_item_new(GTK_STOCK_REMOVE
, _("_Collapse All"));
2242 gtk_widget_show(item
);
2243 gtk_container_add(GTK_CONTAINER(menu
), item
);
2244 g_signal_connect(item
, "activate", G_CALLBACK(on_expand_collapse
), GINT_TO_POINTER(FALSE
));
2246 item
= gtk_separator_menu_item_new();
2247 gtk_widget_show(item
);
2248 gtk_container_add(GTK_CONTAINER(menu
), item
);
2250 symbol_menu
.sort_by_name
= item
= gtk_radio_menu_item_new_with_mnemonic(NULL
,
2251 _("Sort by _Name"));
2252 gtk_widget_show(item
);
2253 gtk_container_add(GTK_CONTAINER(menu
), item
);
2254 g_signal_connect(item
, "activate", G_CALLBACK(on_symbol_tree_sort_clicked
),
2255 GINT_TO_POINTER(SYMBOLS_SORT_BY_NAME
));
2257 symbol_menu
.sort_by_appearance
= item
= gtk_radio_menu_item_new_with_mnemonic_from_widget(
2258 GTK_RADIO_MENU_ITEM(item
), _("Sort by _Appearance"));
2259 gtk_widget_show(item
);
2260 gtk_container_add(GTK_CONTAINER(menu
), item
);
2261 g_signal_connect(item
, "activate", G_CALLBACK(on_symbol_tree_sort_clicked
),
2262 GINT_TO_POINTER(SYMBOLS_SORT_BY_APPEARANCE
));
2264 g_signal_connect(menu
, "show", G_CALLBACK(on_symbol_tree_menu_show
), NULL
);
2266 sidebar_add_common_menu_items(GTK_MENU(menu
));
2270 static void on_document_save(G_GNUC_UNUSED GObject
*object
, GeanyDocument
*doc
)
2272 gchar
*f
= g_build_filename(app
->configdir
, "ignore.tags", NULL
);
2274 g_return_if_fail(NZV(doc
->real_path
));
2276 if (utils_str_equal(doc
->real_path
, f
))
2277 load_c_ignore_tags();
2283 void symbols_init(void)
2287 create_taglist_popup_menu();
2289 f
= g_build_filename(app
->configdir
, "ignore.tags", NULL
);
2290 ui_add_config_file_menu_item(f
, NULL
, NULL
);
2293 g_signal_connect(geany_object
, "document-save", G_CALLBACK(on_document_save
), NULL
);
2297 void symbols_finalize(void)
2299 g_strfreev(html_entities
);
2300 g_strfreev(c_tags_ignore
);