Fix not setting existing project typenames for C-like files if they

don't contain typenames themselves (bug introduced in r1323).


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1371 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-03-08 13:32:03 +00:00
parent 63639a8feb
commit dfb1bc9fcc
2 changed files with 62 additions and 32 deletions

View File

@ -1,3 +1,10 @@
2007-03-08 Nick Treleaven <nick.treleaven@btinternet.com>
* src/document.c:
Fix not setting existing project typenames for C-like files if they
don't contain typenames themselves (bug introduced in r1323).
2007-03-08 Enrico Tröger <enrico.troeger@uvena.de> 2007-03-08 Enrico Tröger <enrico.troeger@uvena.de>
* geany.glade, src/interface.c: Fixed wrong tooltip. * geany.glade, src/interface.c: Fixed wrong tooltip.

View File

@ -1491,8 +1491,12 @@ void document_update_tag_list(gint idx, gboolean update)
} }
static GString *get_project_typenames() /* 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 GString *last_typenames = NULL;
GString *s = NULL; GString *s = NULL;
if (app->tm_workspace) if (app->tm_workspace)
@ -1504,51 +1508,70 @@ static GString *get_project_typenames()
s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK); s = symbols_find_tags_as_string(tags_array, TM_GLOBAL_TYPE_MASK);
} }
} }
return s;
if (s && last_typenames && g_string_equal(s, last_typenames))
{
g_string_free(s, TRUE);
*types = last_typenames;
return FALSE; // project typenames haven't changed
}
// cache typename list for next time
if (last_typenames)
g_string_free(last_typenames, TRUE);
last_typenames = s;
*types = s;
if (s == NULL) return FALSE;
return TRUE;
} }
/* Returns: TRUE if any scintilla type keywords were updated. /* If sci is NULL, update project typenames for all documents that support typenames,
* sci can be NULL to update if necessary (non-NULL can save time if only one * if typenames have changed.
* document was changed) */ * 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)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
guint n;
const GString *s;
if (sci == NULL || sci_cb_lexer_get_type_keyword_idx(sci_get_lexer(sci)) != -1) if (sci != NULL && sci_cb_lexer_get_type_keyword_idx(sci_get_lexer(sci)) == -1)
{ return FALSE;
guint n;
static GString *last_typenames = NULL;
GString *s = get_project_typenames();
if (s && last_typenames && g_string_equal(s, last_typenames)) if (! get_project_typenames(&s))
{ // typenames have not changed
if (s != NULL && sci != NULL)
{ {
g_string_free(s, TRUE); gint keyword_idx = sci_cb_lexer_get_type_keyword_idx(sci_get_lexer(sci));
return FALSE; // avoid unnecessary recolourising
}
// keep typename list for next time
if (last_typenames)
g_string_free(last_typenames, TRUE);
last_typenames = s;
if (s == NULL) return FALSE;
for (n = 0; n < doc_array->len; n++) sci_set_keywords(sci, keyword_idx, s->str);
{ if (! delay_colourise)
ScintillaObject *wid = doc_list[n].sci;
if (wid)
{ {
gint keyword_idx = sci_cb_lexer_get_type_keyword_idx(sci_get_lexer(wid)); sci_colourise(sci, 0, -1);
}
}
return FALSE;
}
g_return_val_if_fail(s != NULL, FALSE);
if (keyword_idx > 0) for (n = 0; n < doc_array->len; n++)
{
ScintillaObject *wid = doc_list[n].sci;
if (wid)
{
gint keyword_idx = sci_cb_lexer_get_type_keyword_idx(sci_get_lexer(wid));
if (keyword_idx > 0)
{
sci_set_keywords(wid, keyword_idx, s->str);
if (! delay_colourise)
{ {
sci_set_keywords(wid, keyword_idx, s->str); sci_colourise(wid, 0, -1);
if (! delay_colourise)
{
sci_colourise(wid, 0, -1);
}
ret = TRUE;
} }
ret = TRUE;
} }
} }
} }