Revision: 1934 http://geany.svn.sourceforge.net/geany/?rev=1934&view=rev Author: eht16 Date: 2007-10-09 05:04:15 -0700 (Tue, 09 Oct 2007)
Log Message: ----------- Fix wrong colouring of type keywords of tags from different filetypes.
Modified Paths: -------------- trunk/ChangeLog trunk/src/document.c trunk/src/highlighting.c trunk/src/symbols.c trunk/src/symbols.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-09 11:49:42 UTC (rev 1933) +++ trunk/ChangeLog 2007-10-09 12:04:15 UTC (rev 1934) @@ -1,3 +1,10 @@ +2007-10-09 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/document.c, src/highlighting.c, src/symbols.c, src/symbols.h: + Fix wrong colouring of type keywords of tags from different + filetypes. + + 2007-10-09 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/keybindings.c:
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2007-10-09 11:49:42 UTC (rev 1933) +++ trunk/src/document.c 2007-10-09 12:04:15 UTC (rev 1934) @@ -85,7 +85,7 @@ static void document_undo_clear(gint idx); static void document_redo_add(gint idx, guint type, gpointer data);
-static gboolean update_type_keywords(ScintillaObject *sci); +static gboolean update_type_keywords(ScintillaObject *sci, gint lang);
// ignore the case of filenames and paths under WIN32, causes errors if not @@ -1271,10 +1271,10 @@ // unfold maybe folded results sci_ensure_line_is_visible(doc_list[idx].sci, sci_get_line_from_position(doc_list[idx].sci, ttf.chrgText.cpMin)); - + sci_set_selection_start(doc_list[idx].sci, ttf.chrgText.cpMin); sci_set_selection_end(doc_list[idx].sci, ttf.chrgText.cpMax); - + // we need to force scrolling in case the cursor is outside of the current visible area // doc_list[].scroll_percent doesn't work because sci isn't always updated while searching editor_scroll_to_line(doc_list[idx].sci, -1, 0.3F); @@ -1710,7 +1710,7 @@ /* Caches the list of project typenames, as a space separated GString. * Returns: TRUE if typenames have changed. * (*types) is set to the list of typenames, or NULL if there are none. */ -static gboolean get_project_typenames(const GString **types) +static gboolean get_project_typenames(const GString **types, gint lang) { static GString *last_typenames = NULL; GString *s = NULL; @@ -1721,7 +1721,7 @@
if (tags_array) { - s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK); + s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK, lang); } }
@@ -1747,7 +1747,7 @@ * If sci is not NULL, then if sci supports typenames, project typenames are updated * if necessary, and typename keywords are set for sci. * Returns: TRUE if any scintilla type keywords were updated. */ -static gboolean update_type_keywords(ScintillaObject *sci) +static gboolean update_type_keywords(ScintillaObject *sci, gint lang) { gboolean ret = FALSE; guint n; @@ -1756,7 +1756,7 @@ if (sci != NULL && editor_lexer_get_type_keyword_idx(sci_get_lexer(sci)) == -1) return FALSE;
- if (! get_project_typenames(&s)) + if (! get_project_typenames(&s, lang)) { // typenames have not changed if (s != NULL && sci != NULL) { @@ -1827,7 +1827,7 @@ { /* Check if project typename keywords have changed. * If they haven't, we may need to colourise the document. */ - if (! update_type_keywords(doc_list[idx].sci) && colourise) + if (! update_type_keywords(doc_list[idx].sci, type->lang) && colourise) sci_colourise(doc_list[idx].sci, 0, -1); } if (ft_changed) @@ -2393,7 +2393,7 @@ memset(doc_set, TRUE, doc_array->len * sizeof(gint8));
// remove existing docs from the set if they don't use typenames or typenames haven't changed - recolour = update_type_keywords(NULL); + recolour = update_type_keywords(NULL, -2); for (i = 0; i < doc_indexes->len; i++) { ScintillaObject *sci;
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2007-10-09 11:49:42 UTC (rev 1933) +++ trunk/src/highlighting.c 2007-10-09 12:04:15 UTC (rev 1934) @@ -344,7 +344,7 @@ }
-static GString *get_global_typenames() +static GString *get_global_typenames(gint lang) { GString *s = NULL;
@@ -354,7 +354,7 @@
if (tags_array) { - s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK); + s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK, lang); } } return s; @@ -592,11 +592,12 @@
/* Assign global typedefs and user secondary keywords */ -static void assign_global_and_user_keywords(ScintillaObject *sci, const gchar *user_words) +static void assign_global_and_user_keywords(ScintillaObject *sci, + const gchar *user_words, gint lang) { GString *s;
- s = get_global_typenames(); + s = get_global_typenames(lang); if (s == NULL) s = g_string_sized_new(200); else @@ -749,7 +750,8 @@ SSM(sci, SCI_SETKEYWORDS, 2, (sptr_t) style_sets[GEANY_FILETYPES_C].keywords[2]);
// assign global types, merge them with user defined keywords and set them - assign_global_and_user_keywords(sci, style_sets[GEANY_FILETYPES_C].keywords[1]); + assign_global_and_user_keywords(sci, style_sets[GEANY_FILETYPES_C].keywords[1], + filetypes[ft_id]->lang);
styleset_c_like(sci, GEANY_FILETYPES_C);
@@ -805,7 +807,8 @@ SSM(sci, SCI_SETKEYWORDS, 2, (sptr_t) style_sets[GEANY_FILETYPES_CPP].keywords[2]);
// assign global types, merge them with user defined keywords and set them - assign_global_and_user_keywords(sci, style_sets[GEANY_FILETYPES_CPP].keywords[1]); + assign_global_and_user_keywords(sci, style_sets[GEANY_FILETYPES_CPP].keywords[1], + filetypes[ft_id]->lang);
styleset_c_like(sci, GEANY_FILETYPES_CPP);
@@ -868,7 +871,7 @@ SSM(sci, SCI_SETKEYWORDS, 2, (sptr_t) style_sets[ft_id].keywords[2]);
// assign global types, merge them with user defined keywords and set them - assign_global_and_user_keywords(sci, style_sets[ft_id].keywords[1]); + assign_global_and_user_keywords(sci, style_sets[ft_id].keywords[1], filetypes[ft_id]->lang);
styleset_c_like(sci, ft_id);
Modified: trunk/src/symbols.c =================================================================== --- trunk/src/symbols.c 2007-10-09 11:49:42 UTC (rev 1933) +++ trunk/src/symbols.c 2007-10-09 12:04:15 UTC (rev 1934) @@ -149,9 +149,10 @@ }
-GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types) +GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types, gint lang) { guint j; + TMTag *tag; GString *s = NULL; GPtrArray *typedefs;
@@ -164,13 +165,22 @@ s = g_string_sized_new(typedefs->len * 10); for (j = 0; j < typedefs->len; ++j) { - if (!(TM_TAG(typedefs->pdata[j])->atts.entry.scope)) + tag = TM_TAG(typedefs->pdata[j]); + if (!(tag->atts.entry.scope)) { - if (TM_TAG(typedefs->pdata[j])->name) + // tag->atts.file.lang contains (for some reason) the line of the tag if + // tag->atts.entry.file is not NULL + gint tag_lang = + (tag->atts.entry.file) ? tag->atts.entry.file->lang : tag->atts.file.lang; + + // the check for tag_lang == lang is necessary to avoid wrong type colouring of + // e.g. PHP classes in C++ files + // lang = -2 disables the check + if (tag->name && (tag_lang == lang || lang == -2)) { if (j != 0) g_string_append_c(s, ' '); - g_string_append(s, TM_TAG(typedefs->pdata[j])->name); + g_string_append(s, tag->name); } } }
Modified: trunk/src/symbols.h =================================================================== --- trunk/src/symbols.h 2007-10-09 11:49:42 UTC (rev 1933) +++ trunk/src/symbols.h 2007-10-09 12:04:15 UTC (rev 1934) @@ -30,7 +30,7 @@
void symbols_global_tags_loaded(gint file_type_idx);
-GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types); +GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types, gint lang);
const gchar *symbols_get_context_separator(gint ft_id);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.