Kaydet (Commit) 7419f18f authored tarafından Enrico Tröger's avatar Enrico Tröger

Fix wrong colouring of type keywords of tags from different filetypes.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1934 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst d3489262
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> 2007-10-09 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/keybindings.c: * src/keybindings.c:
......
...@@ -85,7 +85,7 @@ void msgwin_status_add_new(const gchar *format, ...) G_GNUC_PRINTF(1, 2); // tem ...@@ -85,7 +85,7 @@ void msgwin_status_add_new(const gchar *format, ...) G_GNUC_PRINTF(1, 2); // tem
static void document_undo_clear(gint idx); static void document_undo_clear(gint idx);
static void document_redo_add(gint idx, guint type, gpointer data); 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 // ignore the case of filenames and paths under WIN32, causes errors if not
...@@ -1271,10 +1271,10 @@ gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gbool ...@@ -1271,10 +1271,10 @@ gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gbool
// unfold maybe folded results // unfold maybe folded results
sci_ensure_line_is_visible(doc_list[idx].sci, sci_ensure_line_is_visible(doc_list[idx].sci,
sci_get_line_from_position(doc_list[idx].sci, ttf.chrgText.cpMin)); 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_start(doc_list[idx].sci, ttf.chrgText.cpMin);
sci_set_selection_end(doc_list[idx].sci, ttf.chrgText.cpMax); 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 // 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 // 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); editor_scroll_to_line(doc_list[idx].sci, -1, 0.3F);
...@@ -1710,7 +1710,7 @@ void document_update_tag_list(gint idx, gboolean update) ...@@ -1710,7 +1710,7 @@ void document_update_tag_list(gint idx, gboolean update)
/* Caches the list of project typenames, as a space separated GString. /* Caches the list of project typenames, as a space separated GString.
* Returns: TRUE if typenames have changed. * Returns: TRUE if typenames have changed.
* (*types) is set to the list of typenames, or NULL if there are none. */ * (*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; static GString *last_typenames = NULL;
GString *s = NULL; GString *s = NULL;
...@@ -1721,7 +1721,7 @@ static gboolean get_project_typenames(const GString **types) ...@@ -1721,7 +1721,7 @@ static gboolean get_project_typenames(const GString **types)
if (tags_array) 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 @@ static gboolean get_project_typenames(const GString **types) ...@@ -1747,7 +1747,7 @@ static gboolean get_project_typenames(const GString **types)
* If sci is not NULL, then if sci supports typenames, project typenames are updated * If sci is not NULL, then if sci supports typenames, project typenames are updated
* if necessary, and typename keywords are set for sci. * if necessary, and typename keywords are set for sci.
* Returns: TRUE if any scintilla type keywords were updated. */ * 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; gboolean ret = FALSE;
guint n; guint n;
...@@ -1756,7 +1756,7 @@ static gboolean update_type_keywords(ScintillaObject *sci) ...@@ -1756,7 +1756,7 @@ static gboolean update_type_keywords(ScintillaObject *sci)
if (sci != NULL && editor_lexer_get_type_keyword_idx(sci_get_lexer(sci)) == -1) if (sci != NULL && editor_lexer_get_type_keyword_idx(sci_get_lexer(sci)) == -1)
return FALSE; return FALSE;
if (! get_project_typenames(&s)) if (! get_project_typenames(&s, lang))
{ // typenames have not changed { // typenames have not changed
if (s != NULL && sci != NULL) if (s != NULL && sci != NULL)
{ {
...@@ -1827,7 +1827,7 @@ void document_set_filetype(gint idx, filetype *type) ...@@ -1827,7 +1827,7 @@ void document_set_filetype(gint idx, filetype *type)
{ {
/* Check if project typename keywords have changed. /* Check if project typename keywords have changed.
* If they haven't, we may need to colourise the document. */ * 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); sci_colourise(doc_list[idx].sci, 0, -1);
} }
if (ft_changed) if (ft_changed)
...@@ -2393,7 +2393,7 @@ void document_colourise_new() ...@@ -2393,7 +2393,7 @@ void document_colourise_new()
memset(doc_set, TRUE, doc_array->len * sizeof(gint8)); 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 // 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++) for (i = 0; i < doc_indexes->len; i++)
{ {
ScintillaObject *sci; ScintillaObject *sci;
......
...@@ -344,7 +344,7 @@ void styleset_free_styles() ...@@ -344,7 +344,7 @@ void styleset_free_styles()
} }
static GString *get_global_typenames() static GString *get_global_typenames(gint lang)
{ {
GString *s = NULL; GString *s = NULL;
...@@ -354,7 +354,7 @@ static GString *get_global_typenames() ...@@ -354,7 +354,7 @@ static GString *get_global_typenames()
if (tags_array) 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; return s;
...@@ -592,11 +592,12 @@ static void styleset_common(ScintillaObject *sci, gint style_bits, filetype_id f ...@@ -592,11 +592,12 @@ static void styleset_common(ScintillaObject *sci, gint style_bits, filetype_id f
/* Assign global typedefs and user secondary keywords */ /* 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; GString *s;
s = get_global_typenames(); s = get_global_typenames(lang);
if (s == NULL) if (s == NULL)
s = g_string_sized_new(200); s = g_string_sized_new(200);
else else
...@@ -749,7 +750,8 @@ void styleset_c(ScintillaObject *sci) ...@@ -749,7 +750,8 @@ void styleset_c(ScintillaObject *sci)
SSM(sci, SCI_SETKEYWORDS, 2, (sptr_t) style_sets[GEANY_FILETYPES_C].keywords[2]); 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 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); styleset_c_like(sci, GEANY_FILETYPES_C);
...@@ -805,7 +807,8 @@ void styleset_cpp(ScintillaObject *sci) ...@@ -805,7 +807,8 @@ void styleset_cpp(ScintillaObject *sci)
SSM(sci, SCI_SETKEYWORDS, 2, (sptr_t) style_sets[GEANY_FILETYPES_CPP].keywords[2]); 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 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); styleset_c_like(sci, GEANY_FILETYPES_CPP);
...@@ -868,7 +871,7 @@ void styleset_cs(ScintillaObject *sci) ...@@ -868,7 +871,7 @@ void styleset_cs(ScintillaObject *sci)
SSM(sci, SCI_SETKEYWORDS, 2, (sptr_t) style_sets[ft_id].keywords[2]); 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 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); styleset_c_like(sci, ft_id);
......
...@@ -149,9 +149,10 @@ static void html_tags_loaded() ...@@ -149,9 +149,10 @@ static void html_tags_loaded()
} }
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; guint j;
TMTag *tag;
GString *s = NULL; GString *s = NULL;
GPtrArray *typedefs; GPtrArray *typedefs;
...@@ -164,13 +165,22 @@ GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types) ...@@ -164,13 +165,22 @@ GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types)
s = g_string_sized_new(typedefs->len * 10); s = g_string_sized_new(typedefs->len * 10);
for (j = 0; j < typedefs->len; ++j) 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) if (j != 0)
g_string_append_c(s, ' '); g_string_append_c(s, ' ');
g_string_append(s, TM_TAG(typedefs->pdata[j])->name); g_string_append(s, tag->name);
} }
} }
} }
......
...@@ -30,7 +30,7 @@ extern const guint TM_GLOBAL_TYPE_MASK; ...@@ -30,7 +30,7 @@ extern const guint TM_GLOBAL_TYPE_MASK;
void symbols_global_tags_loaded(gint file_type_idx); 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); const gchar *symbols_get_context_separator(gint ft_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment