Revision: 976 http://svn.sourceforge.net/geany/?rev=976&view=rev Author: ntrel Date: 2006-11-08 03:42:05 -0800 (Wed, 08 Nov 2006)
Log Message: ----------- Move utils_get_tag_list() to symbols.c, make utils_find_tm_tag() static. Move symbols_get_global_keywords() to get_global_typenames() in highlighting.c. Add symbols_find_tags_as_string(), symbols_get_tag_list(), symbols_get_macro_list(), symbols_find_in_workspace() from various tag-related existing code.
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/document.c trunk/src/highlighting.c trunk/src/sci_cb.c trunk/src/symbols.c trunk/src/symbols.h trunk/src/ui_utils.c trunk/src/utils.c trunk/src/utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/ChangeLog 2006-11-08 11:42:05 UTC (rev 976) @@ -1,3 +1,17 @@ +2006-11-07 Nick Treleaven nick.treleaven@btinternet.com + + * src/utils.c, src/highlighting.c, src/utils.h, src/callbacks.c, + src/sci_cb.c, src/document.c, src/symbols.c, src/ui_utils.c, + src/symbols.h: + Move utils_get_tag_list() to symbols.c, make utils_find_tm_tag() + static. + Move symbols_get_global_keywords() to get_global_typenames() in + highlighting.c. + Add symbols_find_tags_as_string(), symbols_get_tag_list(), + symbols_get_macro_list(), symbols_find_in_workspace() from various + tag-related existing code. + + 2006-11-07 Enrico Tröger enrico.troeger@uvena.de
* src/treeviews.c: Fixed unintentional appearance of sidebar after it
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/callbacks.c 2006-11-08 11:42:05 UTC (rev 976) @@ -50,6 +50,7 @@ #include "encodings.h" #include "search.h" #include "main.h" +#include "symbols.h"
#ifdef G_OS_WIN32 # include "win32.h" @@ -1188,8 +1189,6 @@ gpointer user_data) { gint type; - guint j; - const GPtrArray *tags; TMTag *tmtag;
if (menuitem == GTK_MENU_ITEM(lookup_widget(app->popup_menu, "goto_tag_definition1"))) @@ -1197,24 +1196,13 @@ else type = tm_tag_prototype_t;
- if (app->tm_workspace->work_objects != NULL) + tmtag = symbols_find_in_workspace(editor_info.current_word, type); + if (tmtag != NULL) { - for (j = 0; j < app->tm_workspace->work_objects->len; j++) - { - tags = tm_tags_extract( - TM_WORK_OBJECT(app->tm_workspace->work_objects->pdata[j])->tags_array, - type); - if (tags == NULL) continue; - - tmtag = utils_find_tm_tag(tags, editor_info.current_word); - if (tmtag != NULL) - { - if (! utils_goto_file_line( - tmtag->atts.entry.file->work_object.file_name, - TRUE, tmtag->atts.entry.line)) break; - return; - } - } + if (utils_goto_file_line( + tmtag->atts.entry.file->work_object.file_name, + TRUE, tmtag->atts.entry.line)) + return; } // if we are here, there was no match and we are beeping ;-) utils_beep();
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/document.c 2006-11-08 11:42:05 UTC (rev 976) @@ -58,6 +58,7 @@ #include "main.h" #include "vte.h" #include "build.h" +#include "symbols.h"
/* dynamic array of document elements to hold all information of the notebook tabs */ @@ -1239,6 +1240,24 @@ }
+static GString *get_project_typenames() +{ + GString *s = NULL; + + if (app->tm_workspace) + { + GPtrArray *tags_array = app->tm_workspace->work_object.tags_array; + + if (tags_array) + { + s = symbols_find_tags_as_string(tags_array, + tm_tag_typedef_t | tm_tag_struct_t | tm_tag_class_t); + } + } + return s; +} + + /* sets the filetype of the the document (sets syntax highlighting and tagging) */ void document_set_filetype(gint idx, filetype *type) { @@ -1253,39 +1272,22 @@ // For C/C++/Java files, get list of typedefs for colourising if (sci_get_lexer(doc_list[idx].sci) == SCLEX_CPP) { - guint j, n; + GString *s = get_project_typenames();
- // assign project keywords - if ((app->tm_workspace) && (app->tm_workspace->work_object.tags_array)) + if (s != NULL) { - GPtrArray *typedefs = tm_tags_extract(app->tm_workspace->work_object.tags_array, - tm_tag_typedef_t | tm_tag_struct_t | tm_tag_class_t); - if ((typedefs) && (typedefs->len > 0)) + guint n; + + for (n = 0; n < doc_array->len; n++) { - GString *s = g_string_sized_new(typedefs->len * 10); - for (j = 0; j < typedefs->len; ++j) + if (doc_list[n].sci) { - if (!(TM_TAG(typedefs->pdata[j])->atts.entry.scope)) - { - if (TM_TAG(typedefs->pdata[j])->name) - { - g_string_append(s, TM_TAG(typedefs->pdata[j])->name); - g_string_append_c(s, ' '); - } - } + sci_set_keywords(doc_list[n].sci, 3, s->str); + sci_colourise(doc_list[n].sci, 0, -1); } - for (n = 0; n < doc_array->len; n++) - { - if (doc_list[n].sci) - { - sci_set_keywords(doc_list[n].sci, 3, s->str); - sci_colourise(doc_list[n].sci, 0, -1); - } - } - //SSM(doc_list[idx].sci, SCI_SETKEYWORDS, 3, (sptr_t) s->str); - g_string_free(s, TRUE); } - g_ptr_array_free(typedefs, TRUE); + //SSM(doc_list[idx].sci, SCI_SETKEYWORDS, 3, (sptr_t) s->str); + g_string_free(s, TRUE); } } sci_colourise(doc_list[idx].sci, 0, -1);
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/highlighting.c 2006-11-08 11:42:05 UTC (rev 976) @@ -346,6 +346,24 @@ }
+static GString *get_global_typenames() +{ + GString *s = NULL; + + if (app->tm_workspace) + { + GPtrArray *tags_array = app->tm_workspace->global_tags; + + if (tags_array) + { + s = symbols_find_tags_as_string(tags_array, + tm_tag_typedef_t | tm_tag_struct_t | tm_tag_class_t); + } + } + return s; +} + + static void styleset_common_init(void) { GKeyFile *config = g_key_file_new(); @@ -634,7 +652,7 @@ if (style_sets[GEANY_FILETYPES_C].styling == NULL) styleset_c_init();
/* Assign global keywords */ - s = symbols_get_global_keywords(); + s = get_global_typenames(); if (s != NULL) { SSM(sci, SCI_SETKEYWORDS, 1, (sptr_t) s->str); @@ -722,7 +740,7 @@ if (style_sets[GEANY_FILETYPES_CPP].styling == NULL) styleset_cpp_init();
/* Assign global keywords */ - s = symbols_get_global_keywords(); + s = get_global_typenames(); if (s != NULL) { SSM(sci, SCI_SETKEYWORDS, 1, (sptr_t) s->str); @@ -2572,7 +2590,7 @@ if (style_sets[GEANY_FILETYPES_D].styling == NULL) styleset_d_init();
/* Assign global keywords */ - s = symbols_get_global_keywords(); + s = get_global_typenames(); if (s != NULL) { SSM(sci, SCI_SETKEYWORDS, 1, (sptr_t) s->str);
Modified: trunk/src/sci_cb.c =================================================================== --- trunk/src/sci_cb.c 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/sci_cb.c 2006-11-08 11:42:05 UTC (rev 976) @@ -32,6 +32,7 @@ #include "sciwrappers.h" #include "ui_utils.h" #include "utils.h" +#include "symbols.h"
static gchar current_word[GEANY_MAX_WORD_LENGTH]; // holds word under the mouse or keyboard cursor @@ -1023,36 +1024,12 @@
void sci_cb_show_macro_list(ScintillaObject *sci) { - guint j, i; - const GPtrArray *tags; - GPtrArray *ftags; GString *words;
if (sci == NULL) return;
- ftags = g_ptr_array_sized_new(50); - words = g_string_sized_new(200); - - for (j = 0; j < app->tm_workspace->work_objects->len; j++) - { - tags = tm_tags_extract(TM_WORK_OBJECT(app->tm_workspace->work_objects->pdata[j])->tags_array, - tm_tag_enum_t | tm_tag_variable_t | tm_tag_macro_t | tm_tag_macro_with_arg_t); - if (NULL != tags) - { - for (i = 0; ((i < tags->len) && (i < GEANY_MAX_AUTOCOMPLETE_WORDS)); ++i) - { - g_ptr_array_add(ftags, (gpointer) tags->pdata[i]); - } - } - } - tm_tags_sort(ftags, NULL, FALSE); - for (j = 0; j < ftags->len; j++) - { - if (j > 0) g_string_append_c(words, ' '); - g_string_append(words, TM_TAG(ftags->pdata[j])->name); - } + words = symbols_get_macro_list(); SSM(sci, SCI_USERLISTSHOW, 1, (sptr_t) words->str); - g_ptr_array_free(ftags, TRUE); g_string_free(words, TRUE); }
Modified: trunk/src/symbols.c =================================================================== --- trunk/src/symbols.c 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/symbols.c 2006-11-08 11:42:05 UTC (rev 976) @@ -22,10 +22,15 @@ */
#include "geany.h" + +#include <ctype.h> + #include "symbols.h" #include "utils.h" #include "filetypes.h" #include "sci_cb.h" // html_entities +#include "encodings.h" +#include "document.h"
enum // Geany tag files @@ -53,17 +58,7 @@ {FALSE, "latex.tags"} };
-// langType used in TagManager (see tagmanager/parsers.h) -enum // Geany lang type -{ - GLT_C = 0, - GLT_CPP = 1, - GLT_PASCAL = 4, - GLT_PHP = 6, - GLT_LATEX = 8 -};
- static void html_tags_loaded();
@@ -80,14 +75,15 @@ case GEANY_FILETYPES_HTML: html_tags_loaded(); return; - case GEANY_FILETYPES_C: gtf = GTF_C; lt = GLT_C; break; - case GEANY_FILETYPES_CPP: gtf = GTF_C; lt = GLT_CPP; break; - case GEANY_FILETYPES_PASCAL:gtf = GTF_PASCAL; lt = GLT_PASCAL; break; - case GEANY_FILETYPES_PHP: gtf = GTF_PHP; lt = GLT_PHP; break; - case GEANY_FILETYPES_LATEX: gtf = GTF_LATEX; lt = GLT_LATEX; break; + case GEANY_FILETYPES_C: gtf = GTF_C; break; + case GEANY_FILETYPES_CPP: gtf = GTF_C; break; + case GEANY_FILETYPES_PASCAL:gtf = GTF_PASCAL; break; + case GEANY_FILETYPES_PHP: gtf = GTF_PHP; break; + case GEANY_FILETYPES_LATEX: gtf = GTF_LATEX; break; default: return; } + lt = filetypes[file_type_idx]->lang; tfi = &tag_file_info[gtf];
if (! tfi->tags_loaded) @@ -117,29 +113,175 @@ }
-GString *symbols_get_global_keywords() +GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types) { + guint j; GString *s = NULL; + GPtrArray *typedefs;
- if ((app->tm_workspace) && (app->tm_workspace->global_tags)) + g_return_val_if_fail(tags_array != NULL, NULL); + + typedefs = tm_tags_extract(tags_array, tag_types); + + if ((typedefs) && (typedefs->len > 0)) { - guint j; - GPtrArray *g_typedefs = tm_tags_extract(app->tm_workspace->global_tags, - tm_tag_typedef_t | tm_tag_struct_t | tm_tag_class_t); - - if ((g_typedefs) && (g_typedefs->len > 0)) + s = g_string_sized_new(typedefs->len * 10); + for (j = 0; j < typedefs->len; ++j) { - s = g_string_sized_new(g_typedefs->len * 10); - for (j = 0; j < g_typedefs->len; ++j) + if (!(TM_TAG(typedefs->pdata[j])->atts.entry.scope)) { - if (!(TM_TAG(g_typedefs->pdata[j])->atts.entry.scope)) + if (TM_TAG(typedefs->pdata[j])->name) { - g_string_append(s, TM_TAG(g_typedefs->pdata[j])->name); + g_string_append(s, TM_TAG(typedefs->pdata[j])->name); g_string_append_c(s, ' '); } } } - g_ptr_array_free(g_typedefs, TRUE); } + g_ptr_array_free(typedefs, TRUE); return s; } + + +const GList *symbols_get_tag_list(gint idx, guint tag_types) +{ + static GList *tag_names = NULL; + + if (idx >= 0 && doc_list[idx].is_valid && doc_list[idx].tm_file && + doc_list[idx].tm_file->tags_array) + { + TMTag *tag; + guint i; + GeanySymbol *symbol; + gboolean doc_is_utf8 = FALSE; + gchar *utf8_name; + + if (tag_names) + { + GList *tmp; + for (tmp = tag_names; tmp; tmp = g_list_next(tmp)) + { + g_free(((GeanySymbol*)tmp->data)->str); + g_free(tmp->data); + } + g_list_free(tag_names); + tag_names = NULL; + } + + // do this comparison only once + if (utils_strcmp(doc_list[idx].encoding, "UTF-8")) doc_is_utf8 = TRUE; + + for (i = 0; i < (doc_list[idx].tm_file)->tags_array->len; ++i) + { + tag = TM_TAG((doc_list[idx].tm_file)->tags_array->pdata[i]); + if (tag == NULL) + return NULL; + + if (tag->type & tag_types) + { + if (! doc_is_utf8) utf8_name = encodings_convert_to_utf8_from_charset(tag->name, + -1, doc_list[idx].encoding, TRUE); + else utf8_name = tag->name; + if ((tag->atts.entry.scope != NULL) && isalpha(tag->atts.entry.scope[0])) + { + // context separator + gchar *cosep = (doc_list[idx].file_type->id == GEANY_FILETYPES_CPP) ? "::" : "."; + + symbol = g_new0(GeanySymbol, 1); + symbol->str = g_strdup_printf("%s%s%s [%ld]", tag->atts.entry.scope, cosep, + utf8_name, tag->atts.entry.line); + symbol->type = tag->type; + symbol->line = tag->atts.entry.line; + tag_names = g_list_prepend(tag_names, symbol); + } + else + { + symbol = g_new0(GeanySymbol, 1); + symbol->str = g_strdup_printf("%s [%ld]", utf8_name, tag->atts.entry.line); + symbol->type = tag->type; + symbol->line = tag->atts.entry.line; + tag_names = g_list_prepend(tag_names, symbol); + } + if (! doc_is_utf8) g_free(utf8_name); + } + } + tag_names = g_list_sort(tag_names, (GCompareFunc) utils_compare_symbol); + return tag_names; + } + else + return NULL; +} + + +GString *symbols_get_macro_list() +{ + guint j, i; + const GPtrArray *tags; + GPtrArray *ftags; + GString *words; + + ftags = g_ptr_array_sized_new(50); + words = g_string_sized_new(200); + + for (j = 0; j < app->tm_workspace->work_objects->len; j++) + { + tags = tm_tags_extract(TM_WORK_OBJECT(app->tm_workspace->work_objects->pdata[j])->tags_array, + tm_tag_enum_t | tm_tag_variable_t | tm_tag_macro_t | tm_tag_macro_with_arg_t); + if (NULL != tags) + { + for (i = 0; ((i < tags->len) && (i < GEANY_MAX_AUTOCOMPLETE_WORDS)); ++i) + { + g_ptr_array_add(ftags, (gpointer) tags->pdata[i]); + } + } + } + tm_tags_sort(ftags, NULL, FALSE); + for (j = 0; j < ftags->len; j++) + { + if (j > 0) g_string_append_c(words, ' '); + g_string_append(words, TM_TAG(ftags->pdata[j])->name); + } + g_ptr_array_free(ftags, TRUE); + return words; +} + + +static TMTag * +symbols_find_tm_tag(const GPtrArray *tags, const gchar *tag_name) +{ + guint i; + g_return_val_if_fail(tags != NULL, NULL); + + for (i = 0; i < tags->len; ++i) + { + if (utils_strcmp(TM_TAG(tags->pdata[i])->name, tag_name)) + return TM_TAG(tags->pdata[i]); + } + return NULL; +} + + +TMTag *symbols_find_in_workspace(const gchar *tag_name, gint type) +{ + guint j; + const GPtrArray *tags; + TMTag *tmtag; + + if (app->tm_workspace->work_objects != NULL) + { + for (j = 0; j < app->tm_workspace->work_objects->len; j++) + { + tags = tm_tags_extract( + TM_WORK_OBJECT(app->tm_workspace->work_objects->pdata[j])->tags_array, + type); + if (tags == NULL) continue; + + tmtag = symbols_find_tm_tag(tags, tag_name); + if (tmtag != NULL) + return tmtag; + } + } + return NULL; // not found +} + +
Modified: trunk/src/symbols.h =================================================================== --- trunk/src/symbols.h 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/symbols.h 2006-11-08 11:42:05 UTC (rev 976) @@ -27,6 +27,12 @@
void symbols_global_tags_loaded(gint file_type_idx);
-GString *symbols_get_global_keywords(); +GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types);
+const GList *symbols_get_tag_list(gint idx, guint tag_types); + +GString *symbols_get_macro_list(); + +TMTag *symbols_find_in_workspace(const gchar *tag_name, gint type); + #endif
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/ui_utils.c 2006-11-08 11:42:05 UTC (rev 976) @@ -36,6 +36,7 @@ #include "encodings.h" #include "images.c" #include "treeviews.h" +#include "symbols.h"
static gchar *menu_item_get_text(GtkMenuItem *menu_item); @@ -224,7 +225,7 @@ g_object_ref((gpointer)doc_list[idx].tag_tree); // to hold it after removing }
- tags = utils_get_tag_list(idx, tm_tag_max_t); + tags = symbols_get_tag_list(idx, tm_tag_max_t); if (doc_list[idx].tm_file != NULL && tags != NULL) { GtkTreeIter iter;
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/utils.c 2006-11-08 11:42:05 UTC (rev 976) @@ -43,7 +43,6 @@ #include "sciwrappers.h" #include "dialogs.h" #include "win32.h" -#include "encodings.h"
#include "utils.h"
@@ -190,75 +189,6 @@ }
-const GList *utils_get_tag_list(gint idx, guint tag_types) -{ - static GList *tag_names = NULL; - - if (idx >= 0 && doc_list[idx].is_valid && doc_list[idx].tm_file && - doc_list[idx].tm_file->tags_array) - { - TMTag *tag; - guint i; - GeanySymbol *symbol; - gboolean doc_is_utf8 = FALSE; - gchar *utf8_name; - - if (tag_names) - { - GList *tmp; - for (tmp = tag_names; tmp; tmp = g_list_next(tmp)) - { - g_free(((GeanySymbol*)tmp->data)->str); - g_free(tmp->data); - } - g_list_free(tag_names); - tag_names = NULL; - } - - // do this comparison only once - if (utils_strcmp(doc_list[idx].encoding, "UTF-8")) doc_is_utf8 = TRUE; - - for (i = 0; i < (doc_list[idx].tm_file)->tags_array->len; ++i) - { - tag = TM_TAG((doc_list[idx].tm_file)->tags_array->pdata[i]); - if (tag == NULL) - return NULL; - - if (tag->type & tag_types) - { - if (! doc_is_utf8) utf8_name = encodings_convert_to_utf8_from_charset(tag->name, - -1, doc_list[idx].encoding, TRUE); - else utf8_name = tag->name; - if ((tag->atts.entry.scope != NULL) && isalpha(tag->atts.entry.scope[0])) - { - // context separator - gchar *cosep = (doc_list[idx].file_type->id == GEANY_FILETYPES_CPP) ? "::" : "."; - - symbol = g_new0(GeanySymbol, 1); - symbol->str = g_strdup_printf("%s%s%s [%ld]", tag->atts.entry.scope, cosep, - utf8_name, tag->atts.entry.line); - symbol->type = tag->type; - symbol->line = tag->atts.entry.line; - tag_names = g_list_prepend(tag_names, symbol); - } - else - { - symbol = g_new0(GeanySymbol, 1); - symbol->str = g_strdup_printf("%s [%ld]", utf8_name, tag->atts.entry.line); - symbol->type = tag->type; - symbol->line = tag->atts.entry.line; - tag_names = g_list_prepend(tag_names, symbol); - } - if (! doc_is_utf8) g_free(utf8_name); - } - } - tag_names = g_list_sort(tag_names, (GCompareFunc) utils_compare_symbol); - return tag_names; - } - else - return NULL; -} - /* returns the line of the given tag */ gint utils_get_local_tag(gint idx, const gchar *qual_name) { @@ -1258,20 +1188,6 @@ }
-TMTag *utils_find_tm_tag(const GPtrArray *tags, const gchar *tag_name) -{ - guint i; - g_return_val_if_fail(tags != NULL, NULL); - - for (i = 0; i < tags->len; ++i) - { - if (utils_strcmp(TM_TAG(tags->pdata[i])->name, tag_name)) - return TM_TAG(tags->pdata[i]); - } - return NULL; -} - - GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, GIOFunc func, gpointer data) { GIOChannel *ioc;
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2006-11-07 23:32:30 UTC (rev 975) +++ trunk/src/utils.h 2006-11-08 11:42:05 UTC (rev 976) @@ -34,8 +34,6 @@
gboolean utils_is_opening_brace(gchar c);
-const GList *utils_get_tag_list(gint idx, guint tag_types); - gint utils_get_local_tag(gint idx, const gchar *qual_name);
gboolean utils_goto_file_line(const gchar *file, gboolean is_tm_filename, gint line); @@ -129,8 +127,6 @@ // returned string must be freed. gchar *utils_get_current_time_string();
-TMTag *utils_find_tm_tag(const GPtrArray *tags, const gchar *tag_name); - GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, GIOFunc func, gpointer data);
gchar **utils_read_file_in_array(const gchar *filename);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.