-
Notifications
You must be signed in to change notification settings - Fork 586
/
symbols.c
2622 lines (2214 loc) · 71.1 KB
/
symbols.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* symbols.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2006-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* Copyright 2011-2012 Colomban Wendling <ban(at)herbesfolles(dot)org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* @file symbols.h
* Tag-related functions.
**/
/*
* Symbol Tree and TagManager-related convenience functions.
* TagManager parses tags for each document, and also adds them to the workspace (session).
* Global tags are lists of tags for each filetype, loaded when a document with a
* matching filetype is first loaded.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "symbols.h"
#include "app.h"
#include "callbacks.h" /* FIXME: for ignore_callback */
#include "documentprivate.h"
#include "editor.h"
#include "encodings.h"
#include "filetypesprivate.h"
#include "geanyobject.h"
#include "main.h"
#include "navqueue.h"
#include "sciwrappers.h"
#include "sidebar.h"
#include "support.h"
#include "tm_parser.h"
#include "tm_tag.h"
#include "ui_utils.h"
#include "utils.h"
#include "SciLexer.h"
#include "gtkcompat.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
static gchar **html_entities = NULL;
typedef struct
{
gboolean tags_loaded;
const gchar *tag_file;
} TagFileInfo;
/* Check before adding any more tags files, usually they should be downloaded separately. */
enum /* Geany tag files */
{
GTF_C,
GTF_PASCAL,
GTF_PHP,
GTF_HTML_ENTITIES,
GTF_LATEX,
GTF_PYTHON,
GTF_MAX
};
static TagFileInfo tag_file_info[GTF_MAX] =
{
{FALSE, "c99.tags"},
{FALSE, "pascal.tags"},
{FALSE, "php.tags"},
{FALSE, "html_entities.tags"},
{FALSE, "latex.tags"},
{FALSE, "python.tags"}
};
static GPtrArray *top_level_iter_names = NULL;
enum
{
ICON_CLASS,
ICON_MACRO,
ICON_MEMBER,
ICON_METHOD,
ICON_NAMESPACE,
ICON_OTHER,
ICON_STRUCT,
ICON_VAR,
ICON_NONE,
N_ICONS = ICON_NONE
};
static struct
{
const gchar *icon_name;
GdkPixbuf *pixbuf;
}
symbols_icons[N_ICONS] = {
[ICON_CLASS] = { "classviewer-class", NULL },
[ICON_MACRO] = { "classviewer-macro", NULL },
[ICON_MEMBER] = { "classviewer-member", NULL },
[ICON_METHOD] = { "classviewer-method", NULL },
[ICON_NAMESPACE] = { "classviewer-namespace", NULL },
[ICON_OTHER] = { "classviewer-other", NULL },
[ICON_STRUCT] = { "classviewer-struct", NULL },
[ICON_VAR] = { "classviewer-var", NULL },
};
static struct
{
GtkWidget *expand_all;
GtkWidget *collapse_all;
GtkWidget *sort_by_name;
GtkWidget *sort_by_appearance;
GtkWidget *find_usage;
GtkWidget *find_doc_usage;
GtkWidget *find_in_files;
}
symbol_menu;
static void html_tags_loaded(void);
static void load_user_tags(GeanyFiletypeID ft_id);
/* get the tags_ignore list, exported by tagmanager's options.c */
extern gchar **c_tags_ignore;
/* ignore certain tokens when parsing C-like syntax.
* Also works for reloading. */
static void load_c_ignore_tags(void)
{
gchar *path = g_build_filename(app->configdir, "ignore.tags", NULL);
gchar *content;
if (g_file_get_contents(path, &content, NULL, NULL))
{
/* historically we ignore the glib _DECLS for tag generation */
SETPTR(content, g_strconcat("G_BEGIN_DECLS G_END_DECLS\n", content, NULL));
g_strfreev(c_tags_ignore);
c_tags_ignore = g_strsplit_set(content, " \n\r", -1);
g_free(content);
}
g_free(path);
}
void symbols_reload_config_files(void)
{
load_c_ignore_tags();
}
static gsize get_tag_count(void)
{
GPtrArray *tags = tm_get_workspace()->global_tags;
gsize count = tags ? tags->len : 0;
return count;
}
/* wrapper for tm_workspace_load_global_tags().
* note that the tag count only counts new global tags added - if a tag has the same name,
* currently it replaces the existing tag, so loading a file twice will say 0 tags the 2nd time. */
static gboolean symbols_load_global_tags(const gchar *tags_file, GeanyFiletype *ft)
{
gboolean result;
gsize old_tag_count = get_tag_count();
result = tm_workspace_load_global_tags(tags_file, ft->lang);
if (result)
{
geany_debug("Loaded %s (%s), %u symbol(s).", tags_file, ft->name,
(guint) (get_tag_count() - old_tag_count));
}
return result;
}
/* Ensure that the global tags file(s) for the file_type_idx filetype is loaded.
* This provides autocompletion, calltips, etc. */
void symbols_global_tags_loaded(guint file_type_idx)
{
TagFileInfo *tfi;
gint tag_type;
/* load ignore list for C/C++ parser */
if ((file_type_idx == GEANY_FILETYPES_C || file_type_idx == GEANY_FILETYPES_CPP) &&
c_tags_ignore == NULL)
{
load_c_ignore_tags();
}
if (cl_options.ignore_global_tags || app->tm_workspace == NULL)
return;
/* load config in case of custom filetypes */
filetypes_load_config(file_type_idx, FALSE);
load_user_tags(file_type_idx);
switch (file_type_idx)
{
case GEANY_FILETYPES_PHP:
case GEANY_FILETYPES_HTML:
html_tags_loaded();
}
switch (file_type_idx)
{
case GEANY_FILETYPES_CPP:
symbols_global_tags_loaded(GEANY_FILETYPES_C); /* load C global tags */
/* no C++ tagfile yet */
return;
case GEANY_FILETYPES_C: tag_type = GTF_C; break;
case GEANY_FILETYPES_PASCAL:tag_type = GTF_PASCAL; break;
case GEANY_FILETYPES_PHP: tag_type = GTF_PHP; break;
case GEANY_FILETYPES_LATEX: tag_type = GTF_LATEX; break;
case GEANY_FILETYPES_PYTHON:tag_type = GTF_PYTHON; break;
default:
return;
}
tfi = &tag_file_info[tag_type];
if (! tfi->tags_loaded)
{
gchar *fname = g_build_filename(app->datadir, tfi->tag_file, NULL);
symbols_load_global_tags(fname, filetypes[file_type_idx]);
tfi->tags_loaded = TRUE;
g_free(fname);
}
}
/* HTML tagfile is just a list of entities for autocompletion (e.g. '&') */
static void html_tags_loaded(void)
{
TagFileInfo *tfi;
if (cl_options.ignore_global_tags)
return;
tfi = &tag_file_info[GTF_HTML_ENTITIES];
if (! tfi->tags_loaded)
{
gchar *file = g_build_filename(app->datadir, tfi->tag_file, NULL);
html_entities = utils_read_file_in_array(file);
tfi->tags_loaded = TRUE;
g_free(file);
}
}
GString *symbols_find_typenames_as_string(TMParserType lang, gboolean global)
{
guint j;
TMTag *tag;
GString *s = NULL;
GPtrArray *typedefs;
TMParserType tag_lang;
if (global)
typedefs = app->tm_workspace->global_typename_array;
else
typedefs = app->tm_workspace->typename_array;
if ((typedefs) && (typedefs->len > 0))
{
const gchar *last_name = "";
s = g_string_sized_new(typedefs->len * 10);
for (j = 0; j < typedefs->len; ++j)
{
tag = TM_TAG(typedefs->pdata[j]);
tag_lang = tag->lang;
if (tag->name && tm_tag_langs_compatible(lang, tag_lang) &&
strcmp(tag->name, last_name) != 0)
{
if (j != 0)
g_string_append_c(s, ' ');
g_string_append(s, tag->name);
last_name = tag->name;
}
}
}
return s;
}
/** Gets the context separator used by the tag manager for a particular file
* type.
* @param ft_id File type identifier.
* @return The context separator string.
*
* Returns non-printing sequence "\x03" ie ETX (end of text) for filetypes
* without a context separator.
*
* @since 0.19
*/
GEANY_API_SYMBOL
const gchar *symbols_get_context_separator(gint ft_id)
{
return tm_tag_context_separator(filetypes[ft_id]->lang);
}
const gchar **symbols_get_html_entities(void)
{
if (html_entities == NULL)
html_tags_loaded(); /* if not yet created, force creation of the array but shouldn't occur */
return (const gchar **) html_entities;
}
/* sort by name, then line */
static gint compare_symbol(const TMTag *tag_a, const TMTag *tag_b)
{
gint ret;
if (tag_a == NULL || tag_b == NULL)
return 0;
if (tag_a->name == NULL)
return -(tag_a->name != tag_b->name);
if (tag_b->name == NULL)
return tag_a->name != tag_b->name;
ret = strcmp(tag_a->name, tag_b->name);
if (ret == 0)
{
return tag_a->line - tag_b->line;
}
return ret;
}
/* sort by line, then scope */
static gint compare_symbol_lines(gconstpointer a, gconstpointer b)
{
const TMTag *tag_a = TM_TAG(a);
const TMTag *tag_b = TM_TAG(b);
gint ret;
if (a == NULL || b == NULL)
return 0;
ret = tag_a->line - tag_b->line;
if (ret == 0)
{
if (tag_a->scope == NULL)
return -(tag_a->scope != tag_b->scope);
if (tag_b->scope == NULL)
return tag_a->scope != tag_b->scope;
else
return strcmp(tag_a->scope, tag_b->scope);
}
return ret;
}
static GList *get_tag_list(GeanyDocument *doc, TMTagType tag_types)
{
GList *tag_names = NULL;
TMTag *tag;
guint i;
g_return_val_if_fail(doc, NULL);
if (! doc->tm_file || ! doc->tm_file->tags_array)
return NULL;
for (i = 0; i < doc->tm_file->tags_array->len; ++i)
{
tag = TM_TAG(doc->tm_file->tags_array->pdata[i]);
if (G_UNLIKELY(tag == NULL))
return NULL;
if (tag->type & tag_types)
{
tag_names = g_list_prepend(tag_names, tag);
}
}
tag_names = g_list_sort(tag_names, compare_symbol_lines);
return tag_names;
}
/* amount of types in the symbol list (currently max. 8 are used) */
#define MAX_SYMBOL_TYPES (sizeof(tv_iters) / sizeof(GtkTreeIter))
struct TreeviewSymbols
{
GtkTreeIter tag_function;
GtkTreeIter tag_class;
GtkTreeIter tag_macro;
GtkTreeIter tag_member;
GtkTreeIter tag_variable;
GtkTreeIter tag_externvar;
GtkTreeIter tag_namespace;
GtkTreeIter tag_struct;
GtkTreeIter tag_interface;
GtkTreeIter tag_type;
GtkTreeIter tag_other;
} tv_iters;
static void init_tag_iters(void)
{
/* init all GtkTreeIters with -1 to make them invalid to avoid crashes when switching between
* filetypes(e.g. config file to Python crashes Geany without this) */
tv_iters.tag_function.stamp = -1;
tv_iters.tag_class.stamp = -1;
tv_iters.tag_member.stamp = -1;
tv_iters.tag_macro.stamp = -1;
tv_iters.tag_variable.stamp = -1;
tv_iters.tag_externvar.stamp = -1;
tv_iters.tag_namespace.stamp = -1;
tv_iters.tag_struct.stamp = -1;
tv_iters.tag_interface.stamp = -1;
tv_iters.tag_type.stamp = -1;
tv_iters.tag_other.stamp = -1;
}
static GdkPixbuf *get_tag_icon(const gchar *icon_name)
{
static GtkIconTheme *icon_theme = NULL;
static gint x = -1;
if (G_UNLIKELY(x < 0))
{
gint dummy;
icon_theme = gtk_icon_theme_get_default();
gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &x, &dummy);
}
return gtk_icon_theme_load_icon(icon_theme, icon_name, x, 0, NULL);
}
static gboolean find_toplevel_iter(GtkTreeStore *store, GtkTreeIter *iter, const gchar *title)
{
GtkTreeModel *model = GTK_TREE_MODEL(store);
if (!gtk_tree_model_get_iter_first(model, iter))
return FALSE;
do
{
gchar *candidate;
gtk_tree_model_get(model, iter, SYMBOLS_COLUMN_NAME, &candidate, -1);
/* FIXME: what if 2 different items have the same name?
* this should never happen, but might be caused by a typo in a translation */
if (utils_str_equal(candidate, title))
{
g_free(candidate);
return TRUE;
}
else
g_free(candidate);
}
while (gtk_tree_model_iter_next(model, iter));
return FALSE;
}
/* Adds symbol list groups in (iter*, title) pairs.
* The list must be ended with NULL. */
static void G_GNUC_NULL_TERMINATED
tag_list_add_groups(GtkTreeStore *tree_store, ...)
{
va_list args;
GtkTreeIter *iter;
g_return_if_fail(top_level_iter_names);
va_start(args, tree_store);
for (; iter = va_arg(args, GtkTreeIter*), iter != NULL;)
{
gchar *title = va_arg(args, gchar*);
guint icon_id = va_arg(args, guint);
GdkPixbuf *icon = NULL;
if (icon_id < N_ICONS)
icon = symbols_icons[icon_id].pixbuf;
g_assert(title != NULL);
g_ptr_array_add(top_level_iter_names, title);
if (!find_toplevel_iter(tree_store, iter, title))
gtk_tree_store_append(tree_store, iter, NULL);
if (icon)
gtk_tree_store_set(tree_store, iter, SYMBOLS_COLUMN_ICON, icon, -1);
gtk_tree_store_set(tree_store, iter, SYMBOLS_COLUMN_NAME, title, -1);
}
va_end(args);
}
static void add_top_level_items(GeanyDocument *doc)
{
GeanyFiletypeID ft_id = doc->file_type->id;
GtkTreeStore *tag_store = doc->priv->tag_store;
if (top_level_iter_names == NULL)
top_level_iter_names = g_ptr_array_new();
else
g_ptr_array_set_size(top_level_iter_names, 0);
init_tag_iters();
switch (ft_id)
{
case GEANY_FILETYPES_DIFF:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Files"), ICON_NONE, NULL);
break;
}
case GEANY_FILETYPES_DOCBOOK:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Chapter"), ICON_NONE,
&(tv_iters.tag_class), _("Section"), ICON_NONE,
&(tv_iters.tag_member), _("Sect1"), ICON_NONE,
&(tv_iters.tag_macro), _("Sect2"), ICON_NONE,
&(tv_iters.tag_variable), _("Sect3"), ICON_NONE,
&(tv_iters.tag_struct), _("Appendix"), ICON_NONE,
&(tv_iters.tag_other), _("Other"), ICON_NONE,
NULL);
break;
}
case GEANY_FILETYPES_HASKELL:
tag_list_add_groups(tag_store,
&tv_iters.tag_namespace, _("Module"), ICON_NONE,
&tv_iters.tag_type, _("Types"), ICON_NONE,
&tv_iters.tag_macro, _("Type constructors"), ICON_NONE,
&tv_iters.tag_function, _("Functions"), ICON_METHOD,
NULL);
break;
case GEANY_FILETYPES_COBOL:
tag_list_add_groups(tag_store,
&tv_iters.tag_class, _("Program"), ICON_CLASS,
&tv_iters.tag_function, _("File"), ICON_METHOD,
&tv_iters.tag_namespace, _("Sections"), ICON_NAMESPACE,
&tv_iters.tag_macro, _("Paragraph"), ICON_OTHER,
&tv_iters.tag_struct, _("Group"), ICON_STRUCT,
&tv_iters.tag_variable, _("Data"), ICON_VAR,
NULL);
break;
case GEANY_FILETYPES_CONF:
tag_list_add_groups(tag_store,
&tv_iters.tag_namespace, _("Sections"), ICON_OTHER,
&tv_iters.tag_macro, _("Keys"), ICON_VAR,
NULL);
break;
case GEANY_FILETYPES_NSIS:
tag_list_add_groups(tag_store,
&tv_iters.tag_namespace, _("Sections"), ICON_OTHER,
&tv_iters.tag_function, _("Functions"), ICON_METHOD,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
NULL);
break;
case GEANY_FILETYPES_LATEX:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Command"), ICON_NONE,
&(tv_iters.tag_class), _("Environment"), ICON_NONE,
&(tv_iters.tag_member), _("Section"), ICON_NONE,
&(tv_iters.tag_macro), _("Subsection"), ICON_NONE,
&(tv_iters.tag_variable), _("Subsubsection"), ICON_NONE,
&(tv_iters.tag_struct), _("Label"), ICON_NONE,
&(tv_iters.tag_namespace), _("Chapter"), ICON_NONE,
&(tv_iters.tag_other), _("Other"), ICON_NONE,
NULL);
break;
}
case GEANY_FILETYPES_MATLAB:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_struct), _("Structures"), ICON_STRUCT,
NULL);
break;
}
case GEANY_FILETYPES_ABAQUS:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_class), _("Parts"), ICON_NONE,
&(tv_iters.tag_member), _("Assembly"), ICON_NONE,
&(tv_iters.tag_namespace), _("Steps"), ICON_NONE,
NULL);
break;
}
case GEANY_FILETYPES_R:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_other), _("Other"), ICON_NONE,
NULL);
break;
}
case GEANY_FILETYPES_RUST:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Modules"), ICON_NAMESPACE,
&(tv_iters.tag_struct), _("Structures"), ICON_STRUCT,
&(tv_iters.tag_interface), _("Traits"), ICON_CLASS,
&(tv_iters.tag_class), _("Implementations"), ICON_CLASS,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_type), _("Typedefs / Enums"), ICON_STRUCT,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_macro), _("Macros"), ICON_MACRO,
&(tv_iters.tag_member), _("Methods"), ICON_MEMBER,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_GO:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Package"), ICON_NAMESPACE,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_struct), _("Structs"), ICON_STRUCT,
&(tv_iters.tag_type), _("Types"), ICON_STRUCT,
&(tv_iters.tag_macro), _("Constants"), ICON_MACRO,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_member), _("Members"), ICON_MEMBER,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_PERL:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Package"), ICON_NAMESPACE,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_macro), _("Labels"), ICON_NONE,
&(tv_iters.tag_type), _("Constants"), ICON_NONE,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_PHP:
case GEANY_FILETYPES_ZEPHIR:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Namespaces"), ICON_NAMESPACE,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_macro), _("Constants"), ICON_MACRO,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_struct), _("Traits"), ICON_STRUCT,
NULL);
break;
}
case GEANY_FILETYPES_HTML:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Functions"), ICON_NONE,
&(tv_iters.tag_member), _("Anchors"), ICON_NONE,
&(tv_iters.tag_namespace), _("H1 Headings"), ICON_NONE,
&(tv_iters.tag_class), _("H2 Headings"), ICON_NONE,
&(tv_iters.tag_variable), _("H3 Headings"), ICON_NONE,
NULL);
break;
}
case GEANY_FILETYPES_CSS:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_variable), _("ID Selectors"), ICON_VAR,
&(tv_iters.tag_struct), _("Type Selectors"), ICON_STRUCT, NULL);
break;
}
case GEANY_FILETYPES_REST:
case GEANY_FILETYPES_TXT2TAGS:
case GEANY_FILETYPES_ABC:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Chapter"), ICON_NONE,
&(tv_iters.tag_member), _("Section"), ICON_NONE,
&(tv_iters.tag_macro), _("Subsection"), ICON_NONE,
&(tv_iters.tag_variable), _("Subsubsection"), ICON_NONE,
NULL);
break;
}
case GEANY_FILETYPES_ASCIIDOC:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Document"), ICON_NONE,
&(tv_iters.tag_member), _("Section Level 1"), ICON_NONE,
&(tv_iters.tag_macro), _("Section Level 2"), ICON_NONE,
&(tv_iters.tag_variable), _("Section Level 3"), ICON_NONE,
&(tv_iters.tag_struct), _("Section Level 4"), ICON_NONE,
NULL);
break;
}
case GEANY_FILETYPES_RUBY:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Modules"), ICON_NAMESPACE,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_member), _("Singletons"), ICON_STRUCT,
&(tv_iters.tag_function), _("Methods"), ICON_METHOD,
NULL);
break;
}
case GEANY_FILETYPES_TCL:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Namespaces"), ICON_NAMESPACE,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_member), _("Methods"), ICON_METHOD,
&(tv_iters.tag_function), _("Procedures"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_PYTHON:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_member), _("Methods"), ICON_MACRO,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_externvar), _("Imports"), ICON_NAMESPACE,
NULL);
break;
}
case GEANY_FILETYPES_VHDL:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Package"), ICON_NAMESPACE,
&(tv_iters.tag_class), _("Entities"), ICON_CLASS,
&(tv_iters.tag_struct), _("Architectures"), ICON_STRUCT,
&(tv_iters.tag_type), _("Types"), ICON_OTHER,
&(tv_iters.tag_function), _("Functions / Procedures"), ICON_METHOD,
&(tv_iters.tag_variable), _("Variables / Signals"), ICON_VAR,
&(tv_iters.tag_member), _("Processes / Blocks / Components"), ICON_MEMBER,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_VERILOG:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_type), _("Events"), ICON_MACRO,
&(tv_iters.tag_class), _("Modules"), ICON_CLASS,
&(tv_iters.tag_function), _("Functions / Tasks"), ICON_METHOD,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_JAVA:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Package"), ICON_NAMESPACE,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_function), _("Methods"), ICON_METHOD,
&(tv_iters.tag_member), _("Members"), ICON_MEMBER,
&(tv_iters.tag_type), _("Enums"), ICON_STRUCT,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_AS:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Package"), ICON_NAMESPACE,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_member), _("Properties"), ICON_MEMBER,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_macro), _("Constants"), ICON_MACRO,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_HAXE:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_function), _("Methods"), ICON_METHOD,
&(tv_iters.tag_type), _("Types"), ICON_MACRO,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_BASIC:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_macro), _("Constants"), ICON_MACRO,
&(tv_iters.tag_struct), _("Types"), ICON_NAMESPACE,
&(tv_iters.tag_namespace), _("Labels"), ICON_MEMBER,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_F77:
case GEANY_FILETYPES_FORTRAN:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Module"), ICON_CLASS,
&(tv_iters.tag_struct), _("Programs"), ICON_CLASS,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_function), _("Functions / Subroutines"), ICON_METHOD,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_class), _("Types"), ICON_CLASS,
&(tv_iters.tag_member), _("Components"), ICON_MEMBER,
&(tv_iters.tag_macro), _("Blocks"), ICON_MEMBER,
&(tv_iters.tag_type), _("Enums"), ICON_STRUCT,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
NULL);
break;
}
case GEANY_FILETYPES_ASM:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Labels"), ICON_NAMESPACE,
&(tv_iters.tag_function), _("Macros"), ICON_METHOD,
&(tv_iters.tag_macro), _("Defines"), ICON_MACRO,
&(tv_iters.tag_struct), _("Types"), ICON_STRUCT,
NULL);
break;
}
case GEANY_FILETYPES_MAKE:
tag_list_add_groups(tag_store,
&tv_iters.tag_function, _("Targets"), ICON_METHOD,
&tv_iters.tag_macro, _("Macros"), ICON_MACRO,
NULL);
break;
case GEANY_FILETYPES_SQL:
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_namespace), _("Procedures"), ICON_NAMESPACE,
&(tv_iters.tag_struct), _("Indexes"), ICON_STRUCT,
&(tv_iters.tag_class), _("Tables"), ICON_CLASS,
&(tv_iters.tag_macro), _("Triggers"), ICON_MACRO,
&(tv_iters.tag_member), _("Views"), ICON_VAR,
&(tv_iters.tag_other), _("Other"), ICON_OTHER,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
NULL);
break;
}
case GEANY_FILETYPES_D:
default:
{
if (ft_id == GEANY_FILETYPES_D)
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Module"), ICON_NONE, NULL);
else
tag_list_add_groups(tag_store,
&(tv_iters.tag_namespace), _("Namespaces"), ICON_NAMESPACE, NULL);
tag_list_add_groups(tag_store,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_function), _("Functions"), ICON_METHOD,
&(tv_iters.tag_member), _("Members"), ICON_MEMBER,
&(tv_iters.tag_struct), _("Structs"), ICON_STRUCT,
&(tv_iters.tag_type), _("Typedefs / Enums"), ICON_STRUCT,
NULL);
if (ft_id != GEANY_FILETYPES_D)
{
tag_list_add_groups(tag_store,
&(tv_iters.tag_macro), _("Macros"), ICON_MACRO, NULL);
}
tag_list_add_groups(tag_store,
&(tv_iters.tag_variable), _("Variables"), ICON_VAR,
&(tv_iters.tag_externvar), _("Extern Variables"), ICON_VAR,
&(tv_iters.tag_other), _("Other"), ICON_OTHER, NULL);
}
}
}
/* removes toplevel items that have no children */
static void hide_empty_rows(GtkTreeStore *store)
{
GtkTreeIter iter;
gboolean cont = TRUE;
if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
return; /* stop when first iter is invalid, i.e. no elements */
while (cont)
{
if (! gtk_tree_model_iter_has_child(GTK_TREE_MODEL(store), &iter))
cont = gtk_tree_store_remove(store, &iter);
else
cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
}
}
static const gchar *get_symbol_name(GeanyDocument *doc, const TMTag *tag, gboolean found_parent)
{
gchar *utf8_name;
const gchar *scope = tag->scope;
static GString *buffer = NULL; /* buffer will be small so we can keep it for reuse */
gboolean doc_is_utf8 = FALSE;
/* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion
* for None at this point completely */
if (utils_str_equal(doc->encoding, "UTF-8") ||
utils_str_equal(doc->encoding, "None"))
doc_is_utf8 = TRUE;
else /* normally the tags will always be in UTF-8 since we parse from our buffer, but a
* plugin might have called tm_source_file_update(), so check to be sure */
doc_is_utf8 = g_utf8_validate(tag->name, -1, NULL);
if (! doc_is_utf8)
utf8_name = encodings_convert_to_utf8_from_charset(tag->name,
-1, doc->encoding, TRUE);
else
utf8_name = tag->name;
if (utf8_name == NULL)
return NULL;
if (! buffer)
buffer = g_string_new(NULL);
else
g_string_truncate(buffer, 0);
/* check first char of scope is a wordchar */
if (!found_parent && scope &&
strpbrk(scope, GEANY_WORDCHARS) == scope)
{
const gchar *sep = symbols_get_context_separator(doc->file_type->id);
g_string_append(buffer, scope);
g_string_append(buffer, sep);
}
g_string_append(buffer, utf8_name);
if (! doc_is_utf8)
g_free(utf8_name);
g_string_append_printf(buffer, " [%lu]", tag->line);
return buffer->str;
}
static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag)
{
gchar *utf8_name = editor_get_calltip_text(doc->editor, tag);
/* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion
* for None at this point completely */
if (utf8_name != NULL &&
! utils_str_equal(doc->encoding, "UTF-8") &&
! utils_str_equal(doc->encoding, "None"))
{
SETPTR(utf8_name,
encodings_convert_to_utf8_from_charset(utf8_name, -1, doc->encoding, TRUE));
}
return utf8_name;
}
/* find the last word in "foo::bar::blah", e.g. "blah" */