2006-10-02 11:31:54 +00:00
|
|
|
/*
|
|
|
|
* symbols.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2006-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2006-10-02 11:31:54 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2007-02-24 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Tagmanager related convenience functions.
|
|
|
|
* Tagmanager parses tags in the current documents, known as the workspace, plus global tags,
|
|
|
|
* which are lists of tags for each filetype. Global tags are loaded when a document with a
|
|
|
|
* matching filetype is first loaded.
|
|
|
|
*/
|
|
|
|
|
2006-10-02 11:31:54 +00:00
|
|
|
#include "geany.h"
|
2006-11-08 11:42:05 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
2007-01-13 13:25:05 +00:00
|
|
|
#include <string.h>
|
2007-03-21 13:26:16 +00:00
|
|
|
#include <stdlib.h>
|
2006-11-08 11:42:05 +00:00
|
|
|
|
2007-12-12 20:04:45 +00:00
|
|
|
#include "prefix.h"
|
2006-10-02 11:31:54 +00:00
|
|
|
#include "symbols.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "filetypes.h"
|
2006-11-08 11:42:05 +00:00
|
|
|
#include "encodings.h"
|
|
|
|
#include "document.h"
|
2007-01-14 12:12:18 +00:00
|
|
|
#include "support.h"
|
2007-04-18 15:21:33 +00:00
|
|
|
#include "msgwindow.h"
|
2007-07-20 16:33:16 +00:00
|
|
|
#include "treeviews.h"
|
2007-08-23 11:34:06 +00:00
|
|
|
#include "main.h"
|
2007-09-25 12:39:41 +00:00
|
|
|
#include "navqueue.h"
|
|
|
|
#include "ui_utils.h"
|
2008-04-23 16:47:42 +00:00
|
|
|
#include "editor.h"
|
2006-10-02 11:31:54 +00:00
|
|
|
|
2007-07-28 14:10:49 +00:00
|
|
|
|
2006-12-16 17:18:53 +00:00
|
|
|
const guint TM_GLOBAL_TYPE_MASK =
|
|
|
|
tm_tag_class_t | tm_tag_enum_t | tm_tag_interface_t |
|
|
|
|
tm_tag_struct_t | tm_tag_typedef_t | tm_tag_union_t;
|
|
|
|
|
|
|
|
|
2007-02-06 16:13:57 +00:00
|
|
|
static gchar **html_entities = NULL;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gboolean tags_loaded;
|
|
|
|
const gchar *tag_file;
|
|
|
|
} TagFileInfo;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
enum /* Geany tag files */
|
2006-10-02 11:31:54 +00:00
|
|
|
{
|
|
|
|
GTF_C,
|
|
|
|
GTF_PASCAL,
|
|
|
|
GTF_PHP,
|
|
|
|
GTF_HTML_ENTITIES,
|
|
|
|
GTF_LATEX,
|
|
|
|
GTF_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
static TagFileInfo tag_file_info[GTF_MAX] =
|
|
|
|
{
|
|
|
|
{FALSE, "global.tags"},
|
|
|
|
{FALSE, "pascal.tags"},
|
|
|
|
{FALSE, "php.tags"},
|
|
|
|
{FALSE, "html_entities.tags"},
|
|
|
|
{FALSE, "latex.tags"}
|
|
|
|
};
|
|
|
|
|
2007-05-11 11:58:56 +00:00
|
|
|
static gchar *user_tags_dir;
|
|
|
|
|
2006-10-02 11:31:54 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void html_tags_loaded(void);
|
2007-05-11 11:58:56 +00:00
|
|
|
static void load_user_tags(filetype_id ft_id);
|
2006-10-02 11:31:54 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* get the tags_ignore list, exported by tagmanager's options.c */
|
2008-02-24 10:18:36 +00:00
|
|
|
extern gchar **c_tags_ignore;
|
2008-02-18 19:51:34 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void load_c_ignore_tags(void)
|
2008-02-18 19:51:34 +00:00
|
|
|
{
|
|
|
|
gchar *path = g_strconcat(app->configdir, G_DIR_SEPARATOR_S "ignore.tags", NULL);
|
|
|
|
gchar *content;
|
|
|
|
|
|
|
|
if (g_file_get_contents(path, &content, NULL, NULL))
|
|
|
|
{
|
|
|
|
c_tags_ignore = g_strsplit_set(content, " \n\r", -1);
|
|
|
|
g_free(content);
|
|
|
|
}
|
|
|
|
g_free(path);
|
|
|
|
}
|
|
|
|
|
2006-10-02 11:31:54 +00:00
|
|
|
|
2008-02-26 17:11:49 +00:00
|
|
|
/* Ensure that the global tags file(s) for the file_type_idx filetype is loaded.
|
|
|
|
* This provides autocompletion, calltips, etc. */
|
2006-10-02 11:31:54 +00:00
|
|
|
void symbols_global_tags_loaded(gint file_type_idx)
|
|
|
|
{
|
|
|
|
TagFileInfo *tfi;
|
2007-02-06 16:13:57 +00:00
|
|
|
gint tag_type;
|
2006-10-02 11:31:54 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* load ignore list for C/C++ parser */
|
2008-02-18 19:51:34 +00:00
|
|
|
if ((file_type_idx == GEANY_FILETYPES_C || file_type_idx == GEANY_FILETYPES_CPP) &&
|
|
|
|
c_tags_ignore == NULL)
|
|
|
|
{
|
|
|
|
load_c_ignore_tags();
|
|
|
|
}
|
|
|
|
|
2008-02-26 17:11:49 +00:00
|
|
|
if (cl_options.ignore_global_tags || app->tm_workspace == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
load_user_tags(file_type_idx);
|
|
|
|
|
2006-10-02 11:31:54 +00:00
|
|
|
switch (file_type_idx)
|
|
|
|
{
|
2007-03-26 12:18:51 +00:00
|
|
|
case GEANY_FILETYPES_PHP:
|
2006-10-02 11:31:54 +00:00
|
|
|
case GEANY_FILETYPES_HTML:
|
|
|
|
html_tags_loaded();
|
2007-03-26 12:18:51 +00:00
|
|
|
}
|
|
|
|
switch (file_type_idx)
|
|
|
|
{
|
2007-02-06 16:13:57 +00:00
|
|
|
case GEANY_FILETYPES_CPP:
|
2008-02-27 13:17:29 +00:00
|
|
|
symbols_global_tags_loaded(GEANY_FILETYPES_C); /* load C global tags */
|
|
|
|
/* no C++ tagfile yet */
|
2007-03-26 12:18:51 +00:00
|
|
|
return;
|
2007-02-06 16:13:57 +00:00
|
|
|
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;
|
2006-10-02 11:31:54 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2007-02-06 16:13:57 +00:00
|
|
|
tfi = &tag_file_info[tag_type];
|
2006-10-02 11:31:54 +00:00
|
|
|
|
|
|
|
if (! tfi->tags_loaded)
|
|
|
|
{
|
2007-02-06 16:13:57 +00:00
|
|
|
gchar *fname = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, tfi->tag_file, NULL);
|
|
|
|
gint tm_lang;
|
|
|
|
|
|
|
|
tm_lang = filetypes[file_type_idx]->lang;
|
|
|
|
tm_workspace_load_global_tags(fname, tm_lang);
|
2006-10-02 11:31:54 +00:00
|
|
|
tfi->tags_loaded = TRUE;
|
2007-02-06 16:13:57 +00:00
|
|
|
g_free(fname);
|
2006-10-02 11:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* HTML tagfile is just a list of entities for autocompletion (e.g. '&') */
|
2008-02-20 11:24:23 +00:00
|
|
|
static void html_tags_loaded(void)
|
2006-10-02 11:31:54 +00:00
|
|
|
{
|
|
|
|
TagFileInfo *tfi;
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
if (cl_options.ignore_global_tags) return;
|
2006-10-02 11:31:54 +00:00
|
|
|
|
|
|
|
tfi = &tag_file_info[GTF_HTML_ENTITIES];
|
|
|
|
if (! tfi->tags_loaded)
|
|
|
|
{
|
|
|
|
gchar *file = g_strconcat(app->datadir, G_DIR_SEPARATOR_S, tfi->tag_file, NULL);
|
2007-02-06 16:13:57 +00:00
|
|
|
|
2006-10-02 11:31:54 +00:00
|
|
|
html_entities = utils_read_file_in_array(file);
|
|
|
|
tfi->tags_loaded = TRUE;
|
|
|
|
g_free(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-09 12:04:15 +00:00
|
|
|
GString *symbols_find_tags_as_string(GPtrArray *tags_array, guint tag_types, gint lang)
|
2006-10-02 11:31:54 +00:00
|
|
|
{
|
2006-11-08 11:42:05 +00:00
|
|
|
guint j;
|
2007-10-09 12:04:15 +00:00
|
|
|
TMTag *tag;
|
2006-10-02 11:31:54 +00:00
|
|
|
GString *s = NULL;
|
2006-11-08 11:42:05 +00:00
|
|
|
GPtrArray *typedefs;
|
2006-10-02 11:31:54 +00:00
|
|
|
|
2006-11-08 11:42:05 +00:00
|
|
|
g_return_val_if_fail(tags_array != NULL, NULL);
|
2006-10-02 11:31:54 +00:00
|
|
|
|
2006-11-08 11:42:05 +00:00
|
|
|
typedefs = tm_tags_extract(tags_array, tag_types);
|
|
|
|
|
|
|
|
if ((typedefs) && (typedefs->len > 0))
|
|
|
|
{
|
|
|
|
s = g_string_sized_new(typedefs->len * 10);
|
|
|
|
for (j = 0; j < typedefs->len; ++j)
|
2006-10-02 11:31:54 +00:00
|
|
|
{
|
2007-10-09 12:04:15 +00:00
|
|
|
tag = TM_TAG(typedefs->pdata[j]);
|
|
|
|
if (!(tag->atts.entry.scope))
|
2006-10-02 11:31:54 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* tag->atts.file.lang contains (for some reason) the line of the tag if
|
|
|
|
* tag->atts.entry.file is not NULL */
|
2007-10-09 12:04:15 +00:00
|
|
|
gint tag_lang =
|
|
|
|
(tag->atts.entry.file) ? tag->atts.entry.file->lang : tag->atts.file.lang;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* 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 */
|
2007-10-09 12:04:15 +00:00
|
|
|
if (tag->name && (tag_lang == lang || lang == -2))
|
2006-10-02 11:31:54 +00:00
|
|
|
{
|
2006-12-16 17:18:53 +00:00
|
|
|
if (j != 0)
|
|
|
|
g_string_append_c(s, ' ');
|
2007-10-09 12:04:15 +00:00
|
|
|
g_string_append(s, tag->name);
|
2006-10-02 11:31:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-24 17:24:39 +00:00
|
|
|
if (typedefs)
|
|
|
|
g_ptr_array_free(typedefs, TRUE);
|
2006-10-02 11:31:54 +00:00
|
|
|
return s;
|
|
|
|
}
|
2006-11-08 11:42:05 +00:00
|
|
|
|
|
|
|
|
2007-08-15 15:37:21 +00:00
|
|
|
const gchar *symbols_get_context_separator(gint ft_id)
|
2007-01-12 12:33:17 +00:00
|
|
|
{
|
|
|
|
gchar *cosep;
|
|
|
|
|
|
|
|
switch (ft_id)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
case GEANY_FILETYPES_C: /* for C++ .h headers or C structs */
|
2007-01-12 12:33:17 +00:00
|
|
|
case GEANY_FILETYPES_CPP:
|
2008-02-27 13:17:29 +00:00
|
|
|
/*case GEANY_FILETYPES_RUBY:*/ /* not sure what to use atm*/
|
2007-01-12 12:33:17 +00:00
|
|
|
{
|
|
|
|
static gchar cc[] = "::";
|
|
|
|
|
|
|
|
cosep = cc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
static gchar def[] = ".";
|
|
|
|
|
|
|
|
cosep = def;
|
|
|
|
}
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
return cosep; /* return ptr to static string */
|
2007-01-12 12:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
GString *symbols_get_macro_list(void)
|
2006-11-08 11:42:05 +00:00
|
|
|
{
|
|
|
|
guint j, i;
|
|
|
|
GPtrArray *ftags;
|
|
|
|
GString *words;
|
|
|
|
|
2007-03-24 12:10:43 +00:00
|
|
|
if (app->tm_workspace->work_objects == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2006-11-08 11:42:05 +00:00
|
|
|
ftags = g_ptr_array_sized_new(50);
|
|
|
|
words = g_string_sized_new(200);
|
|
|
|
|
|
|
|
for (j = 0; j < app->tm_workspace->work_objects->len; j++)
|
|
|
|
{
|
2008-03-24 17:24:39 +00:00
|
|
|
GPtrArray *tags;
|
|
|
|
|
2006-11-08 11:42:05 +00:00
|
|
|
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]);
|
|
|
|
}
|
2008-03-24 17:24:39 +00:00
|
|
|
g_ptr_array_free(tags, TRUE);
|
2006-11-08 11:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tm_tags_sort(ftags, NULL, FALSE);
|
|
|
|
for (j = 0; j < ftags->len; j++)
|
|
|
|
{
|
2008-03-20 15:48:03 +00:00
|
|
|
if (j > 0) g_string_append_c(words, '\n');
|
2006-11-08 11:42:05 +00:00
|
|
|
g_string_append(words, TM_TAG(ftags->pdata[j])->name);
|
|
|
|
}
|
|
|
|
g_ptr_array_free(ftags, TRUE);
|
|
|
|
return words;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 13:18:15 +00:00
|
|
|
/* Note: if tags is sorted, we can use bsearch or tm_tags_find() to speed this up. */
|
2006-11-08 11:42:05 +00:00
|
|
|
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)
|
|
|
|
{
|
2006-12-07 16:09:45 +00:00
|
|
|
if (utils_str_equal(TM_TAG(tags->pdata[i])->name, tag_name))
|
2006-11-08 11:42:05 +00:00
|
|
|
return TM_TAG(tags->pdata[i]);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-24 16:44:43 +00:00
|
|
|
static TMTag *find_work_object_tag(const TMWorkObject *workobj,
|
|
|
|
const gchar *tag_name, gint type)
|
2006-11-08 11:42:05 +00:00
|
|
|
{
|
2008-03-24 17:24:39 +00:00
|
|
|
GPtrArray *tags;
|
2006-11-08 11:42:05 +00:00
|
|
|
TMTag *tmtag;
|
|
|
|
|
2008-03-24 16:44:43 +00:00
|
|
|
if (workobj != NULL)
|
2006-11-08 11:42:05 +00:00
|
|
|
{
|
2008-03-24 16:44:43 +00:00
|
|
|
tags = tm_tags_extract(workobj->tags_array, type);
|
|
|
|
if (tags != NULL)
|
2006-11-08 11:42:05 +00:00
|
|
|
{
|
2008-03-24 16:44:43 +00:00
|
|
|
tmtag = symbols_find_tm_tag(tags, tag_name);
|
2008-03-24 17:24:39 +00:00
|
|
|
|
|
|
|
g_ptr_array_free(tags, TRUE);
|
|
|
|
|
2008-03-24 16:44:43 +00:00
|
|
|
if (tmtag != NULL)
|
|
|
|
return tmtag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL; /* not found */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static TMTag *find_workspace_tag(const gchar *tag_name, gint type)
|
|
|
|
{
|
|
|
|
guint j;
|
2008-04-08 15:21:54 +00:00
|
|
|
const GPtrArray *work_objects = NULL;
|
2008-03-24 16:44:43 +00:00
|
|
|
|
|
|
|
if (app->tm_workspace != NULL)
|
|
|
|
work_objects = app->tm_workspace->work_objects;
|
|
|
|
|
|
|
|
if (work_objects != NULL)
|
|
|
|
{
|
|
|
|
for (j = 0; j < work_objects->len; j++)
|
|
|
|
{
|
|
|
|
TMWorkObject *workobj = TM_WORK_OBJECT(work_objects->pdata[j]);
|
|
|
|
TMTag *tmtag;
|
|
|
|
|
2008-03-24 17:02:50 +00:00
|
|
|
tmtag = find_work_object_tag(workobj, tag_name, type);
|
2006-11-08 11:42:05 +00:00
|
|
|
if (tmtag != NULL)
|
|
|
|
return tmtag;
|
|
|
|
}
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
return NULL; /* not found */
|
2006-11-08 11:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
const gchar **symbols_get_html_entities(void)
|
2006-12-15 17:09:05 +00:00
|
|
|
{
|
|
|
|
if (html_entities == NULL)
|
2008-02-27 13:17:29 +00:00
|
|
|
html_tags_loaded(); /* if not yet created, force creation of the array but shouldn't occur */
|
2006-12-15 17:09:05 +00:00
|
|
|
|
2007-03-26 12:18:51 +00:00
|
|
|
return (const gchar **) html_entities;
|
2006-12-15 17:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void symbols_finalize(void)
|
2006-12-15 17:09:05 +00:00
|
|
|
{
|
|
|
|
g_strfreev(html_entities);
|
2008-02-18 19:51:34 +00:00
|
|
|
g_strfreev(c_tags_ignore);
|
2006-12-15 17:09:05 +00:00
|
|
|
}
|
2007-01-13 13:25:05 +00:00
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* small struct to track tag name and type together */
|
2007-01-13 13:25:05 +00:00
|
|
|
typedef struct GeanySymbol
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
gint type;
|
|
|
|
gint line;
|
|
|
|
} GeanySymbol;
|
|
|
|
|
|
|
|
|
2007-08-16 17:19:16 +00:00
|
|
|
/* sort by name, line */
|
2007-01-13 13:25:05 +00:00
|
|
|
static gint compare_symbol(const GeanySymbol *a, const GeanySymbol *b)
|
|
|
|
{
|
2007-04-23 15:15:13 +00:00
|
|
|
gint ret;
|
|
|
|
|
2007-01-13 13:25:05 +00:00
|
|
|
if (a == NULL || b == NULL) return 0;
|
|
|
|
|
2007-04-23 15:15:13 +00:00
|
|
|
ret = strcmp(a->str, b->str);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
return a->line - b->line;
|
|
|
|
}
|
|
|
|
return ret;
|
2007-01-13 13:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-16 17:19:16 +00:00
|
|
|
/* sort by line only */
|
|
|
|
static gint compare_symbol_lines(const GeanySymbol *a, const GeanySymbol *b)
|
|
|
|
{
|
|
|
|
if (a == NULL || b == NULL) return 0;
|
|
|
|
|
|
|
|
return a->line - b->line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 16:09:11 +00:00
|
|
|
static const GList *get_tag_list(gint idx, guint tag_types, gint sort_mode)
|
2007-01-13 13:25:05 +00:00
|
|
|
{
|
|
|
|
static GList *tag_names = NULL;
|
|
|
|
|
2008-05-29 17:00:54 +00:00
|
|
|
if (DOC_IDX_VALID(idx) && documents[idx]->tm_file &&
|
|
|
|
documents[idx]->tm_file->tags_array)
|
2007-01-13 13:25:05 +00:00
|
|
|
{
|
|
|
|
TMTag *tag;
|
|
|
|
guint i;
|
|
|
|
GeanySymbol *symbol;
|
|
|
|
gboolean doc_is_utf8 = FALSE;
|
|
|
|
gchar *utf8_name;
|
|
|
|
const gchar *cosep =
|
2008-05-29 17:00:54 +00:00
|
|
|
symbols_get_context_separator(FILETYPE_ID(documents[idx]->file_type));
|
2007-01-13 13:25:05 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* encodings_convert_to_utf8_from_charset() fails with charset "None", so skip conversion
|
|
|
|
* for None at this point completely */
|
2008-05-29 17:00:54 +00:00
|
|
|
if (utils_str_equal(documents[idx]->encoding, "UTF-8") ||
|
|
|
|
utils_str_equal(documents[idx]->encoding, "None"))
|
2007-07-31 17:07:33 +00:00
|
|
|
doc_is_utf8 = TRUE;
|
2007-01-13 13:25:05 +00:00
|
|
|
|
2008-05-29 17:00:54 +00:00
|
|
|
for (i = 0; i < (documents[idx]->tm_file)->tags_array->len; ++i)
|
2007-01-13 13:25:05 +00:00
|
|
|
{
|
2008-05-29 17:00:54 +00:00
|
|
|
tag = TM_TAG((documents[idx]->tm_file)->tags_array->pdata[i]);
|
2007-01-13 13:25:05 +00:00
|
|
|
if (tag == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (tag->type & tag_types)
|
|
|
|
{
|
|
|
|
if (! doc_is_utf8) utf8_name = encodings_convert_to_utf8_from_charset(tag->name,
|
2008-05-29 17:00:54 +00:00
|
|
|
(gsize)-1, documents[idx]->encoding, TRUE);
|
2007-01-13 13:25:05 +00:00
|
|
|
else utf8_name = tag->name;
|
2007-04-23 15:15:13 +00:00
|
|
|
|
2007-07-31 17:07:33 +00:00
|
|
|
if (utf8_name == NULL)
|
|
|
|
continue;
|
|
|
|
|
2007-04-23 15:15:13 +00:00
|
|
|
symbol = g_new0(GeanySymbol, 1);
|
2007-01-13 13:25:05 +00:00
|
|
|
if ((tag->atts.entry.scope != NULL) && isalpha(tag->atts.entry.scope[0]))
|
|
|
|
{
|
2007-04-23 15:15:13 +00:00
|
|
|
symbol->str = g_strconcat(tag->atts.entry.scope, cosep, utf8_name, NULL);
|
2007-01-13 13:25:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-23 15:15:13 +00:00
|
|
|
symbol->str = g_strdup(utf8_name);
|
2007-01-13 13:25:05 +00:00
|
|
|
}
|
2007-04-23 15:15:13 +00:00
|
|
|
symbol->type = tag->type;
|
|
|
|
symbol->line = tag->atts.entry.line;
|
|
|
|
tag_names = g_list_prepend(tag_names, symbol);
|
|
|
|
|
2007-01-13 13:25:05 +00:00
|
|
|
if (! doc_is_utf8) g_free(utf8_name);
|
|
|
|
}
|
|
|
|
}
|
2008-03-18 16:09:11 +00:00
|
|
|
if (sort_mode == SYMBOLS_SORT_BY_NAME)
|
2007-08-15 17:58:58 +00:00
|
|
|
tag_names = g_list_sort(tag_names, (GCompareFunc) compare_symbol);
|
2007-08-16 17:19:16 +00:00
|
|
|
else
|
|
|
|
tag_names = g_list_sort(tag_names, (GCompareFunc) compare_symbol_lines);
|
2007-08-15 17:58:58 +00:00
|
|
|
|
2007-01-13 13:25:05 +00:00
|
|
|
return tag_names;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* amount of types in the symbol list (currently max. 8 are used) */
|
2007-09-17 15:28:27 +00:00
|
|
|
#define MAX_SYMBOL_TYPES (sizeof(tv_iters) / sizeof(GtkTreeIter))
|
|
|
|
|
2007-01-14 12:12:18 +00:00
|
|
|
struct TreeviewSymbols
|
|
|
|
{
|
|
|
|
GtkTreeIter tag_function;
|
|
|
|
GtkTreeIter tag_class;
|
|
|
|
GtkTreeIter tag_macro;
|
|
|
|
GtkTreeIter tag_member;
|
|
|
|
GtkTreeIter tag_variable;
|
|
|
|
GtkTreeIter tag_namespace;
|
|
|
|
GtkTreeIter tag_struct;
|
2007-09-17 15:28:27 +00:00
|
|
|
GtkTreeIter tag_type;
|
2007-01-14 12:12:18 +00:00
|
|
|
GtkTreeIter tag_other;
|
|
|
|
} tv_iters;
|
|
|
|
|
2007-01-15 11:48:14 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void init_tag_iters(void)
|
2007-01-14 12:12:18 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* 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) */
|
2007-01-14 12:12:18 +00:00
|
|
|
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_namespace.stamp = -1;
|
|
|
|
tv_iters.tag_struct.stamp = -1;
|
2007-09-17 15:28:27 +00:00
|
|
|
tv_iters.tag_type.stamp = -1;
|
2007-01-14 12:12:18 +00:00
|
|
|
tv_iters.tag_other.stamp = -1;
|
2007-01-15 11:48:14 +00:00
|
|
|
}
|
2007-01-14 12:12:18 +00:00
|
|
|
|
2007-01-15 11:48:14 +00:00
|
|
|
|
2007-05-23 12:32:06 +00:00
|
|
|
/* Adds symbol list groups in (iter*, title) pairs.
|
|
|
|
* The list must be ended with NULL. */
|
|
|
|
static void G_GNUC_NULL_TERMINATED
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(GtkTreeStore *tree_store, ...)
|
2007-05-23 12:32:06 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
GtkTreeIter *iter;
|
2007-07-22 14:38:47 +00:00
|
|
|
static GtkIconTheme *icon_theme = NULL;
|
|
|
|
static gint x, y;
|
|
|
|
|
|
|
|
if (icon_theme == NULL)
|
|
|
|
{
|
2007-12-12 20:04:45 +00:00
|
|
|
#ifndef G_OS_WIN32
|
2007-12-19 15:37:10 +00:00
|
|
|
gchar *path = g_strconcat(GEANY_DATADIR, "/icons", NULL);
|
2007-12-12 20:04:45 +00:00
|
|
|
#endif
|
2007-07-22 14:38:47 +00:00
|
|
|
gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &x, &y);
|
|
|
|
icon_theme = gtk_icon_theme_get_default();
|
2007-07-23 09:26:05 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
gtk_icon_theme_append_search_path(icon_theme, "share\\icons");
|
|
|
|
#else
|
2007-12-12 20:04:45 +00:00
|
|
|
gtk_icon_theme_append_search_path(icon_theme, path);
|
|
|
|
g_free(path);
|
2007-07-23 09:26:05 +00:00
|
|
|
#endif
|
2007-07-22 14:38:47 +00:00
|
|
|
}
|
2007-05-23 12:32:06 +00:00
|
|
|
|
2007-05-23 17:20:47 +00:00
|
|
|
va_start(args, tree_store);
|
2007-05-23 12:32:06 +00:00
|
|
|
for (; iter = va_arg(args, GtkTreeIter*), iter != NULL;)
|
|
|
|
{
|
|
|
|
gchar *title = va_arg(args, gchar*);
|
2007-07-20 16:33:16 +00:00
|
|
|
gchar *icon_name = va_arg(args, gchar *);
|
|
|
|
GdkPixbuf *icon = NULL;
|
|
|
|
|
2007-07-22 14:38:47 +00:00
|
|
|
if (icon_name)
|
|
|
|
{
|
|
|
|
icon = gtk_icon_theme_load_icon(icon_theme, icon_name, x, 0, NULL);
|
2007-07-20 16:33:16 +00:00
|
|
|
}
|
2007-05-23 12:32:06 +00:00
|
|
|
|
2007-05-23 17:20:47 +00:00
|
|
|
g_assert(title != NULL);
|
|
|
|
gtk_tree_store_append(tree_store, iter, NULL);
|
2007-07-20 16:33:16 +00:00
|
|
|
|
2007-08-24 11:31:27 +00:00
|
|
|
if (G_IS_OBJECT(icon))
|
|
|
|
{
|
2007-07-20 16:33:16 +00:00
|
|
|
gtk_tree_store_set(tree_store, iter, SYMBOLS_COLUMN_ICON, icon,
|
2007-11-21 17:20:26 +00:00
|
|
|
SYMBOLS_COLUMN_NAME, title, -1);
|
2007-07-22 14:38:47 +00:00
|
|
|
g_object_unref(icon);
|
2007-08-24 11:31:27 +00:00
|
|
|
}
|
|
|
|
else
|
2007-11-21 17:20:26 +00:00
|
|
|
gtk_tree_store_set(tree_store, iter, SYMBOLS_COLUMN_NAME, title, -1);
|
2007-05-23 12:32:06 +00:00
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-15 11:48:14 +00:00
|
|
|
static void init_tag_list(gint idx)
|
|
|
|
{
|
2008-05-29 17:00:54 +00:00
|
|
|
filetype_id ft_id = documents[idx]->file_type->id;
|
|
|
|
GtkTreeStore *tag_store = documents[idx]->tag_store;
|
2007-01-15 11:48:14 +00:00
|
|
|
|
|
|
|
init_tag_iters();
|
|
|
|
|
|
|
|
switch (ft_id)
|
2007-01-14 12:12:18 +00:00
|
|
|
{
|
|
|
|
case GEANY_FILETYPES_DIFF:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_function), _("Files"), NULL, NULL);
|
2007-01-14 12:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GEANY_FILETYPES_DOCBOOK:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_function), _("Chapter"), NULL,
|
|
|
|
&(tv_iters.tag_class), _("Section"), NULL,
|
|
|
|
&(tv_iters.tag_member), _("Sect1"), NULL,
|
|
|
|
&(tv_iters.tag_macro), _("Sect2"), NULL,
|
|
|
|
&(tv_iters.tag_variable), _("Sect3"), NULL,
|
|
|
|
&(tv_iters.tag_struct), _("Appendix"), NULL,
|
|
|
|
&(tv_iters.tag_other), _("Other"), NULL,
|
|
|
|
NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* &(tv_iters.tag_namespace), _("Other"), NULL, NULL); */
|
2007-01-14 12:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-05-23 12:32:06 +00:00
|
|
|
case GEANY_FILETYPES_HASKELL:
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&tv_iters.tag_namespace, _("Module"), NULL,
|
|
|
|
&tv_iters.tag_struct, _("Types"), NULL,
|
|
|
|
&tv_iters.tag_macro, _("Type constructors"), NULL,
|
|
|
|
&tv_iters.tag_function, _("Functions"), "classviewer-method",
|
2007-05-23 12:32:06 +00:00
|
|
|
NULL);
|
|
|
|
break;
|
2007-07-02 17:09:48 +00:00
|
|
|
case GEANY_FILETYPES_CONF:
|
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&tv_iters.tag_namespace, _("Sections"), NULL,
|
|
|
|
&tv_iters.tag_macro, _("Keys"), NULL,
|
2007-07-02 17:09:48 +00:00
|
|
|
NULL);
|
|
|
|
break;
|
2007-01-14 12:12:18 +00:00
|
|
|
case GEANY_FILETYPES_LATEX:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_function), _("Command"), NULL,
|
|
|
|
&(tv_iters.tag_class), _("Environment"), NULL,
|
|
|
|
&(tv_iters.tag_member), _("Section"), NULL,
|
|
|
|
&(tv_iters.tag_macro), _("Subsection"), NULL,
|
|
|
|
&(tv_iters.tag_variable), _("Subsubsection"), NULL,
|
|
|
|
&(tv_iters.tag_struct), _("Label"), NULL,
|
|
|
|
&(tv_iters.tag_namespace), _("Chapter"), NULL,
|
|
|
|
&(tv_iters.tag_other), _("Other"), NULL,
|
|
|
|
NULL);
|
2007-01-14 12:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GEANY_FILETYPES_PERL:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_class), _("Package"), NULL,
|
|
|
|
&(tv_iters.tag_function), _("Functions"), "classviewer-method",
|
|
|
|
&(tv_iters.tag_member), _("My"), NULL,
|
|
|
|
&(tv_iters.tag_macro), _("Local"), NULL,
|
|
|
|
&(tv_iters.tag_variable), _("Our"), NULL,
|
|
|
|
NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/*&(tv_iters.tag_struct), _("Label"), NULL,*/
|
|
|
|
/*&(tv_iters.tag_namespace), _("Begin"), NULL,*/
|
|
|
|
/*&(tv_iters.tag_other), _("Other"), NULL, NULL);*/
|
2007-01-14 12:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-07-09 15:11:18 +00:00
|
|
|
case GEANY_FILETYPES_PHP:
|
|
|
|
{
|
|
|
|
tag_list_add_groups(tag_store,
|
2007-11-18 17:17:59 +00:00
|
|
|
&(tv_iters.tag_struct), _("Interfaces"), "classviewer-struct",
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_class), _("Classes"), "classviewer-class",
|
|
|
|
&(tv_iters.tag_function), _("Functions"), "classviewer-method",
|
2007-11-18 17:17:59 +00:00
|
|
|
&(tv_iters.tag_macro), _("Constants"), "classviewer-macro",
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_variable), _("Variables"), "classviewer-var",
|
|
|
|
NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/*&(tv_iters.tag_struct), _("Label"),*/
|
|
|
|
/*&(tv_iters.tag_namespace), _("Begin"),*/
|
|
|
|
/*&(tv_iters.tag_other), _("Other"), NULL);*/
|
2007-07-09 15:11:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-09 18:50:41 +00:00
|
|
|
case GEANY_FILETYPES_HTML:
|
|
|
|
{
|
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&(tv_iters.tag_function), _("JavaScript functions"), NULL,
|
|
|
|
&(tv_iters.tag_member), _("Anchor"), NULL,
|
|
|
|
&(tv_iters.tag_namespace), _("Heading (H1)"), NULL,
|
|
|
|
&(tv_iters.tag_class), _("Heading (H2)"), NULL,
|
|
|
|
&(tv_iters.tag_variable), _("Heading (H3)"), NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
2007-08-14 11:50:03 +00:00
|
|
|
case GEANY_FILETYPES_REST:
|
|
|
|
{
|
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&(tv_iters.tag_namespace), _("Chapter"), NULL,
|
|
|
|
&(tv_iters.tag_member), _("Section"), NULL,
|
|
|
|
&(tv_iters.tag_macro), _("Subsection"), NULL,
|
|
|
|
&(tv_iters.tag_variable), _("Subsubsection"), NULL,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
2007-01-14 12:12:18 +00:00
|
|
|
case GEANY_FILETYPES_RUBY:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-11-29 18:24:06 +00:00
|
|
|
&(tv_iters.tag_namespace), _("Modules"), NULL,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_class), _("Classes"), "classviewer-class",
|
2007-11-29 18:24:06 +00:00
|
|
|
&(tv_iters.tag_member), _("Singletons"), "classviewer-struct",
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_function), _("Methods"), "classviewer-method",
|
|
|
|
NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/*&(tv_iters.tag_namespace), _("Begin"),*/
|
|
|
|
/*&(tv_iters.tag_other), _("Other"), NULL);*/
|
2007-01-14 12:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-21 16:47:17 +00:00
|
|
|
case GEANY_FILETYPES_TCL:
|
2007-01-14 12:12:18 +00:00
|
|
|
case GEANY_FILETYPES_PYTHON:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_class), _("Classes"), "classviewer-class",
|
|
|
|
&(tv_iters.tag_member), _("Methods"), "classviewer-member",
|
|
|
|
&(tv_iters.tag_function), _("Functions"), "classviewer-method",
|
2007-08-07 12:36:03 +00:00
|
|
|
&(tv_iters.tag_variable), _("Variables"), "classviewer-var",
|
2007-07-20 16:33:16 +00:00
|
|
|
NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/*&(tv_iters.tag_macro), _("Mixin"),*/
|
|
|
|
/*&(tv_iters.tag_variable), _("Variables"),*/
|
|
|
|
/*&(tv_iters.tag_struct), _("Members"),*/
|
|
|
|
/*&(tv_iters.tag_namespace), _("Begin"),*/
|
|
|
|
/*&(tv_iters.tag_other), _("Other"), NULL);*/
|
2007-01-14 12:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GEANY_FILETYPES_VHDL:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_function), _("Functions"), "classviewer-method",
|
2008-02-27 13:17:29 +00:00
|
|
|
/*&(tv_iters.tag_class), _("Constants"),*/
|
|
|
|
/*&(tv_iters.tag_member), _("Members"),*/
|
|
|
|
/*&(tv_iters.tag_macro), _("Macros"),*/
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_variable), _("Variables"), "classviewer-var",
|
|
|
|
NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/*&(tv_iters.tag_namespace), _("Namespaces"),*/
|
|
|
|
/*&(tv_iters.tag_struct), _("Signals"),*/
|
|
|
|
/*&(tv_iters.tag_other), _("Other"), NULL);*/
|
2007-01-14 12:12:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-15 11:48:14 +00:00
|
|
|
case GEANY_FILETYPES_JAVA:
|
2007-01-14 12:12:18 +00:00
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_namespace), _("Package"), NULL,
|
2007-11-18 17:17:59 +00:00
|
|
|
&(tv_iters.tag_struct), _("Interfaces"), "classviewer-struct",
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_class), _("Classes"), "classviewer-class",
|
|
|
|
&(tv_iters.tag_function), _("Methods"), "classviewer-method",
|
|
|
|
&(tv_iters.tag_member), _("Members"), "classviewer-member",
|
2008-02-27 13:17:29 +00:00
|
|
|
/*&(tv_iters.tag_macro), _("Macros"),*/
|
|
|
|
/*&(tv_iters.tag_variable), _("Variables"),*/
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_other), _("Other"), "classviewer-other",
|
|
|
|
NULL);
|
2007-01-15 11:48:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-07-26 09:50:12 +00:00
|
|
|
case GEANY_FILETYPES_HAXE:
|
|
|
|
{
|
|
|
|
tag_list_add_groups(tag_store,
|
2007-09-17 15:28:27 +00:00
|
|
|
&(tv_iters.tag_struct), _("Interfaces"), "classviewer-struct",
|
2007-07-26 09:50:12 +00:00
|
|
|
&(tv_iters.tag_class), _("Classes"), "classviewer-class",
|
|
|
|
&(tv_iters.tag_function), _("Methods"), "classviewer-method",
|
2007-11-18 17:17:59 +00:00
|
|
|
&(tv_iters.tag_type), _("Types"), "classviewer-macro",
|
2007-07-26 09:50:12 +00:00
|
|
|
&(tv_iters.tag_variable), _("Variables"), "classviewer-var",
|
2007-09-17 15:28:27 +00:00
|
|
|
&(tv_iters.tag_other), _("Other"), "classviewer-other",
|
2007-07-26 09:50:12 +00:00
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
2007-11-23 16:05:53 +00:00
|
|
|
case GEANY_FILETYPES_BASIC:
|
|
|
|
{
|
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&(tv_iters.tag_function), _("Functions"), "classviewer-method",
|
|
|
|
&(tv_iters.tag_variable), _("Variables"), "classviewer-var",
|
|
|
|
&(tv_iters.tag_macro), _("Constants"), "classviewer-macro",
|
|
|
|
&(tv_iters.tag_struct), _("Types"), "classviewer-namespace",
|
|
|
|
&(tv_iters.tag_namespace), _("Labels"), "classviewer-member",
|
|
|
|
&(tv_iters.tag_other), _("Other"), "classviewer-other",
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
2008-03-03 20:16:52 +00:00
|
|
|
case GEANY_FILETYPES_FORTRAN:
|
|
|
|
{
|
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&(tv_iters.tag_namespace), _("Module"), NULL,
|
|
|
|
&(tv_iters.tag_struct), _("Interfaces"), "classviewer-struct",
|
|
|
|
&(tv_iters.tag_function), _("Functions"), "classviewer-method",
|
|
|
|
&(tv_iters.tag_member), _("Subroutines"), "classviewer-method",
|
|
|
|
&(tv_iters.tag_variable), _("Variables"), "classviewer-var",
|
|
|
|
&(tv_iters.tag_type), _("Types"), "classviewer-namespace",
|
|
|
|
&(tv_iters.tag_macro), _("Blocks"), "classviewer-member",
|
|
|
|
&(tv_iters.tag_other), _("Other"), "classviewer-other",
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
2008-03-05 18:18:19 +00:00
|
|
|
case GEANY_FILETYPES_ASM:
|
|
|
|
{
|
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&(tv_iters.tag_namespace), _("Labels"), "classviewer-namespace",
|
|
|
|
&(tv_iters.tag_function), _("Macros"), "classviewer-method",
|
|
|
|
&(tv_iters.tag_macro), _("Defines"), "classviewer-macro",
|
|
|
|
&(tv_iters.tag_struct), _("Types"), "classviewer-struct",
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
2008-03-23 15:25:42 +00:00
|
|
|
case GEANY_FILETYPES_MAKE:
|
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&tv_iters.tag_function, _("Targets"), "classviewer-method",
|
|
|
|
&tv_iters.tag_macro, _("Macros"), "classviewer-macro",
|
|
|
|
NULL);
|
|
|
|
break;
|
2007-01-15 11:48:14 +00:00
|
|
|
case GEANY_FILETYPES_D:
|
|
|
|
default:
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
if (ft_id == GEANY_FILETYPES_D)
|
2007-07-20 16:33:16 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&(tv_iters.tag_namespace), _("Module"), NULL, NULL);
|
|
|
|
else
|
|
|
|
tag_list_add_groups(tag_store,
|
|
|
|
&(tv_iters.tag_namespace), _("Namespaces"), "classviewer-namespace", NULL);
|
2007-01-15 11:48:14 +00:00
|
|
|
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_class), _("Classes"), "classviewer-class",
|
|
|
|
&(tv_iters.tag_function), _("Functions"), "classviewer-method",
|
|
|
|
&(tv_iters.tag_member), _("Members"), "classviewer-member",
|
|
|
|
&(tv_iters.tag_struct), _("Structs / Typedefs"), "classviewer-struct",
|
|
|
|
NULL);
|
2007-05-23 17:20:47 +00:00
|
|
|
|
2007-01-15 11:48:14 +00:00
|
|
|
if (ft_id != GEANY_FILETYPES_D)
|
|
|
|
{
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_macro), _("Macros"), "classviewer-macro", NULL);
|
2007-01-15 11:48:14 +00:00
|
|
|
}
|
2007-05-23 17:20:47 +00:00
|
|
|
tag_list_add_groups(tag_store,
|
2007-07-20 16:33:16 +00:00
|
|
|
&(tv_iters.tag_variable), _("Variables"), "classviewer-var",
|
|
|
|
&(tv_iters.tag_other), _("Other"), "classviewer-other", NULL);
|
2007-01-14 12:12:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-28 14:10:49 +00:00
|
|
|
/* the following code surely can be improved, at the moment it collects some iters
|
|
|
|
* for removal and after that the actual removal is done. I didn't find a way to find and remove
|
|
|
|
* an empty row in one loop (next iter fails then) */
|
2008-05-12 13:46:19 +00:00
|
|
|
static void hide_empty_rows(GtkTreeStore *store)
|
2007-07-28 14:10:49 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter, *iters[MAX_SYMBOL_TYPES] = { NULL };
|
2007-09-17 15:28:27 +00:00
|
|
|
guint i = 0;
|
2007-07-28 14:10:49 +00:00
|
|
|
|
2008-05-12 13:46:19 +00:00
|
|
|
if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
|
2008-02-27 13:17:29 +00:00
|
|
|
return; /* stop when first iter is invalid, i.e. no elements */
|
2007-07-28 14:10:49 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
do /* first collect the iters we need to delete empty rows */
|
2007-07-28 14:10:49 +00:00
|
|
|
{
|
2008-05-12 13:46:19 +00:00
|
|
|
if (! gtk_tree_model_iter_has_child(GTK_TREE_MODEL(store), &iter))
|
2007-07-28 14:10:49 +00:00
|
|
|
iters[i++] = gtk_tree_iter_copy(&iter);
|
2008-05-12 13:46:19 +00:00
|
|
|
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
|
2007-07-28 14:10:49 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* now actually delete the collected iters */
|
2007-07-28 14:10:49 +00:00
|
|
|
for (i = 0; i < MAX_SYMBOL_TYPES; i++)
|
|
|
|
{
|
|
|
|
if (iters[i] == NULL)
|
|
|
|
break;
|
|
|
|
gtk_tree_store_remove(store, iters[i]);
|
|
|
|
gtk_tree_iter_free(iters[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 16:09:11 +00:00
|
|
|
gboolean symbols_recreate_tag_list(gint idx, gint sort_mode)
|
2007-01-13 13:25:05 +00:00
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
const GList *tags;
|
|
|
|
GtkTreeIter iter;
|
2008-03-18 16:09:11 +00:00
|
|
|
static gint prev_sort_mode = SYMBOLS_SORT_BY_NAME;
|
2008-05-29 17:00:54 +00:00
|
|
|
filetype_id ft_id = FILETYPE_ID(documents[idx]->file_type);
|
2007-01-13 13:25:05 +00:00
|
|
|
|
2007-05-23 12:32:06 +00:00
|
|
|
g_return_val_if_fail(DOC_IDX_VALID(idx), FALSE);
|
|
|
|
|
2008-03-18 16:09:11 +00:00
|
|
|
if (sort_mode == SYMBOLS_SORT_USE_PREVIOUS)
|
|
|
|
sort_mode = prev_sort_mode;
|
|
|
|
else
|
|
|
|
prev_sort_mode = sort_mode;
|
|
|
|
|
|
|
|
tags = get_tag_list(idx, tm_tag_max_t, sort_mode);
|
2008-05-29 17:00:54 +00:00
|
|
|
if (documents[idx]->tm_file == NULL || tags == NULL)
|
2007-08-15 17:58:58 +00:00
|
|
|
return FALSE;
|
2007-01-13 13:25:05 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Make sure the model stays with us after the tree view unrefs it */
|
2008-05-29 17:00:54 +00:00
|
|
|
g_object_ref(GTK_TREE_MODEL(documents[idx]->tag_store));
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Detach model from view */
|
2008-05-29 17:00:54 +00:00
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(documents[idx]->tag_tree), NULL);
|
2008-05-12 13:46:19 +00:00
|
|
|
/* Clear all contents */
|
2008-05-29 17:00:54 +00:00
|
|
|
gtk_tree_store_clear(documents[idx]->tag_store);
|
2007-01-13 13:25:05 +00:00
|
|
|
|
2007-01-14 12:12:18 +00:00
|
|
|
init_tag_list(idx);
|
2007-01-13 13:25:05 +00:00
|
|
|
for (tmp = (GList*)tags; tmp; tmp = g_list_next(tmp))
|
|
|
|
{
|
2007-04-23 15:15:13 +00:00
|
|
|
gchar buf[100];
|
2007-01-14 12:12:18 +00:00
|
|
|
const GeanySymbol *symbol = (GeanySymbol*)tmp->data;
|
2007-07-20 16:33:16 +00:00
|
|
|
GtkTreeIter *parent = NULL;
|
|
|
|
GdkPixbuf *icon = NULL;
|
2007-01-14 12:12:18 +00:00
|
|
|
|
2007-04-23 15:15:13 +00:00
|
|
|
g_snprintf(buf, sizeof(buf), "%s [%d]", symbol->str, symbol->line);
|
|
|
|
|
2007-01-14 12:12:18 +00:00
|
|
|
switch (symbol->type)
|
2007-01-13 13:25:05 +00:00
|
|
|
{
|
|
|
|
case tm_tag_prototype_t:
|
|
|
|
case tm_tag_method_t:
|
|
|
|
case tm_tag_function_t:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_function.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_function);
|
2007-01-13 13:25:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case tm_tag_macro_t:
|
|
|
|
case tm_tag_macro_with_arg_t:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_macro.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_macro);
|
2007-01-13 13:25:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case tm_tag_class_t:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_class.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_class);
|
2007-01-13 13:25:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case tm_tag_member_t:
|
|
|
|
case tm_tag_field_t:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_member.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_member);
|
2007-01-13 13:25:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case tm_tag_typedef_t:
|
|
|
|
case tm_tag_enum_t:
|
2007-09-17 15:28:27 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/** TODO separate C-like types here also */
|
2007-09-17 15:28:27 +00:00
|
|
|
if (ft_id == GEANY_FILETYPES_HAXE)
|
|
|
|
{
|
|
|
|
if (tv_iters.tag_type.stamp == -1) break;
|
|
|
|
parent = &(tv_iters.tag_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-01-13 13:25:05 +00:00
|
|
|
case tm_tag_union_t:
|
|
|
|
case tm_tag_struct_t:
|
|
|
|
case tm_tag_interface_t:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_struct.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_struct);
|
2007-01-13 13:25:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case tm_tag_variable_t:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_variable.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_variable);
|
2007-01-13 13:25:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case tm_tag_namespace_t:
|
|
|
|
case tm_tag_package_t:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_namespace.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_namespace);
|
2007-01-13 13:25:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2007-01-14 12:12:18 +00:00
|
|
|
if (tv_iters.tag_other.stamp == -1) break;
|
2007-07-20 16:33:16 +00:00
|
|
|
parent = &(tv_iters.tag_other);
|
2007-01-13 13:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-20 16:33:16 +00:00
|
|
|
|
2007-07-22 14:38:47 +00:00
|
|
|
if (parent)
|
|
|
|
{
|
2008-05-29 17:00:54 +00:00
|
|
|
gtk_tree_model_get(GTK_TREE_MODEL(documents[idx]->tag_store), parent,
|
2007-07-20 16:33:16 +00:00
|
|
|
SYMBOLS_COLUMN_ICON, &icon, -1);
|
2008-05-29 17:00:54 +00:00
|
|
|
gtk_tree_store_append(documents[idx]->tag_store, &iter, parent);
|
|
|
|
gtk_tree_store_set(documents[idx]->tag_store, &iter,
|
2007-07-20 16:33:16 +00:00
|
|
|
SYMBOLS_COLUMN_ICON, icon,
|
2007-07-22 14:38:47 +00:00
|
|
|
SYMBOLS_COLUMN_NAME, buf,
|
2007-11-21 17:20:26 +00:00
|
|
|
SYMBOLS_COLUMN_LINE, symbol->line, -1);
|
2007-07-20 16:33:16 +00:00
|
|
|
|
|
|
|
if (G_LIKELY(G_IS_OBJECT(icon)))
|
|
|
|
g_object_unref(icon);
|
|
|
|
}
|
2007-01-13 13:25:05 +00:00
|
|
|
}
|
2008-05-29 17:00:54 +00:00
|
|
|
hide_empty_rows(documents[idx]->tag_store);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Re-attach model to view */
|
2008-05-29 17:00:54 +00:00
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(documents[idx]->tag_tree),
|
|
|
|
GTK_TREE_MODEL(documents[idx]->tag_store));
|
|
|
|
g_object_unref(GTK_TREE_MODEL(documents[idx]->tag_store));
|
|
|
|
gtk_tree_view_expand_all(GTK_TREE_VIEW(documents[idx]->tag_tree));
|
2008-05-12 13:46:19 +00:00
|
|
|
|
2007-01-13 13:25:05 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-27 11:00:29 +00:00
|
|
|
/* Detects a global tags filetype from the *.lang.* language extension.
|
|
|
|
* Returns NULL if there was no matching TM language. */
|
2008-05-16 14:17:54 +00:00
|
|
|
static GeanyFiletype *detect_global_tags_filetype(const gchar *utf8_filename)
|
2007-04-27 11:00:29 +00:00
|
|
|
{
|
|
|
|
gchar *tags_ext;
|
|
|
|
gchar *shortname = g_strdup(utf8_filename);
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft = NULL;
|
2007-04-27 11:00:29 +00:00
|
|
|
|
|
|
|
tags_ext = strstr(shortname, ".tags");
|
|
|
|
if (tags_ext)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
*tags_ext = '\0'; /* remove .tags extension */
|
2008-03-05 17:09:57 +00:00
|
|
|
ft = filetypes_detect_from_extension(shortname);
|
2007-04-27 11:00:29 +00:00
|
|
|
}
|
|
|
|
g_free(shortname);
|
|
|
|
|
2007-05-26 15:26:05 +00:00
|
|
|
if (ft == NULL || ! filetype_has_tags(ft))
|
2007-04-27 11:00:29 +00:00
|
|
|
return NULL;
|
|
|
|
return ft;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-21 13:26:16 +00:00
|
|
|
/* Adapted from anjuta-2.0.2/global-tags/tm_global_tags.c, thanks.
|
2007-04-27 11:00:29 +00:00
|
|
|
* Needs full paths for filenames, except for C/C++ tag files, when CFLAGS includes
|
|
|
|
* the relevant path.
|
2007-03-21 13:26:16 +00:00
|
|
|
* Example:
|
2007-04-27 11:00:29 +00:00
|
|
|
* CFLAGS=-I/home/user/libname-1.x geany -g libname.d.tags libname.h */
|
2007-09-28 11:48:55 +00:00
|
|
|
int symbols_generate_global_tags(int argc, char **argv, gboolean want_preprocess)
|
2007-03-21 13:26:16 +00:00
|
|
|
{
|
|
|
|
/* -E pre-process, -dD output user macros, -p prof info (?),
|
|
|
|
* -undef remove builtin macros (seems to be needed with FC5 gcc 4.1.1 */
|
|
|
|
const char pre_process[] = "gcc -E -dD -p -undef";
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
{
|
|
|
|
/* Create global taglist */
|
|
|
|
int status;
|
|
|
|
char *command;
|
2007-04-27 11:00:29 +00:00
|
|
|
const char *tags_file = argv[1];
|
|
|
|
char *utf8_fname;
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft;
|
2007-04-27 11:00:29 +00:00
|
|
|
|
|
|
|
utf8_fname = utils_get_utf8_from_locale(tags_file);
|
|
|
|
ft = detect_global_tags_filetype(utf8_fname);
|
|
|
|
g_free(utf8_fname);
|
|
|
|
|
|
|
|
if (ft == NULL)
|
|
|
|
{
|
2007-04-30 11:56:50 +00:00
|
|
|
g_printerr(_("Unknown filetype extension for \"%s\".\n"), tags_file);
|
2007-04-27 11:00:29 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2007-09-28 11:48:55 +00:00
|
|
|
if (want_preprocess && (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP))
|
2007-04-27 11:00:29 +00:00
|
|
|
command = g_strdup_printf("%s %s", pre_process, NVL(getenv("CFLAGS"), ""));
|
|
|
|
else
|
2008-02-27 13:17:29 +00:00
|
|
|
command = NULL; /* don't preprocess */
|
2007-04-27 11:00:29 +00:00
|
|
|
|
|
|
|
geany_debug("Generating %s tags file.", ft->name);
|
2007-11-30 18:01:43 +00:00
|
|
|
tm_get_workspace();
|
2007-11-01 11:49:29 +00:00
|
|
|
status = tm_workspace_create_global_tags(app->configdir, command,
|
2007-03-21 13:26:16 +00:00
|
|
|
(const char **) (argv + 2),
|
2007-04-27 11:00:29 +00:00
|
|
|
argc - 2, tags_file, ft->lang);
|
2007-03-21 13:26:16 +00:00
|
|
|
g_free(command);
|
2007-04-27 11:00:29 +00:00
|
|
|
if (! status)
|
|
|
|
{
|
2007-11-30 18:01:43 +00:00
|
|
|
g_printerr(_("Failed to create tags file, perhaps because no tags "
|
|
|
|
"were found.\n"));
|
2007-03-21 13:26:16 +00:00
|
|
|
return 1;
|
2007-04-27 11:00:29 +00:00
|
|
|
}
|
2007-03-21 13:26:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-30 11:56:50 +00:00
|
|
|
g_printerr(_("Usage: %s -g <Tag File> <File list>\n\n"), argv[0]);
|
|
|
|
g_printerr(_("Example:\n"
|
2007-03-21 13:26:16 +00:00
|
|
|
"CFLAGS=`pkg-config gtk+-2.0 --cflags` %s -g gtk2.c.tags"
|
2007-04-30 11:56:50 +00:00
|
|
|
" /usr/include/gtk-2.0/gtk/gtk.h\n"), argv[0]);
|
2007-03-21 13:26:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void symbols_show_load_tags_dialog(void)
|
2007-04-18 15:21:33 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkFileFilter *filter;
|
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
dialog = gtk_file_chooser_dialog_new(_("Load Tags"), GTK_WINDOW(main_widgets.window),
|
2007-04-18 15:21:33 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
|
|
|
|
NULL);
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(dialog, "GeanyDialog");
|
2007-04-18 15:21:33 +00:00
|
|
|
filter = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_set_name(filter, _("Geany tag files (*.tags)"));
|
|
|
|
gtk_file_filter_add_pattern(filter, "*.tags");
|
|
|
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
|
|
|
|
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
GSList *flist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
|
|
|
|
GSList *item;
|
|
|
|
|
|
|
|
for (item = flist; item != NULL; item = g_slist_next(item))
|
|
|
|
{
|
|
|
|
gchar *fname = item->data;
|
|
|
|
gchar *utf8_fname;
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft;
|
2007-04-18 15:21:33 +00:00
|
|
|
|
|
|
|
utf8_fname = utils_get_utf8_from_locale(fname);
|
2007-04-27 11:00:29 +00:00
|
|
|
ft = detect_global_tags_filetype(utf8_fname);
|
|
|
|
|
|
|
|
if (ft != NULL && tm_workspace_load_global_tags(fname, ft->lang))
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Loaded %s tags file '%s'."), ft->name, utf8_fname);
|
2007-04-27 11:00:29 +00:00
|
|
|
else
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Could not load tags file '%s'."), utf8_fname);
|
2007-04-27 11:00:29 +00:00
|
|
|
|
2007-04-18 15:21:33 +00:00
|
|
|
g_free(utf8_fname);
|
|
|
|
g_free(fname);
|
|
|
|
}
|
|
|
|
g_slist_free(flist);
|
|
|
|
}
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
2007-05-11 11:58:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Fills a hash table with filetype keys that hold a linked list of filenames. */
|
|
|
|
static GHashTable *get_tagfile_hash(const GSList *file_list)
|
|
|
|
{
|
|
|
|
const GSList *node;
|
|
|
|
GHashTable *hash = g_hash_table_new(NULL, NULL);
|
|
|
|
|
|
|
|
for (node = file_list; node != NULL; node = g_slist_next(node))
|
|
|
|
{
|
|
|
|
GList *fnames;
|
|
|
|
gchar *fname = node->data;
|
|
|
|
gchar *utf8_fname = utils_get_utf8_from_locale(fname);
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft = detect_global_tags_filetype(utf8_fname);
|
2007-05-11 11:58:56 +00:00
|
|
|
|
|
|
|
g_free(utf8_fname);
|
|
|
|
|
2008-05-07 13:54:21 +00:00
|
|
|
if (FILETYPE_ID(ft) < GEANY_FILETYPES_NONE)
|
2007-05-11 11:58:56 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
fnames = g_hash_table_lookup(hash, ft); /* may be NULL */
|
2007-05-11 11:58:56 +00:00
|
|
|
fnames = g_list_append(fnames, fname);
|
|
|
|
g_hash_table_insert(hash, ft, fnames);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
geany_debug("Unknown filetype for file '%s'.", fname);
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static GHashTable *init_user_tags(void)
|
2007-05-11 11:58:56 +00:00
|
|
|
{
|
|
|
|
GSList *file_list;
|
|
|
|
GHashTable *lang_hash;
|
|
|
|
|
|
|
|
user_tags_dir = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "tags", NULL);
|
|
|
|
file_list = utils_get_file_list(user_tags_dir, NULL, NULL);
|
|
|
|
lang_hash = get_tagfile_hash(file_list);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* don't need to delete list contents because they are now used for hash contents */
|
2007-05-11 11:58:56 +00:00
|
|
|
g_slist_free(file_list);
|
2007-07-04 12:07:57 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* create the tags dir for next time if it doesn't exist */
|
2007-07-04 12:07:57 +00:00
|
|
|
if (! g_file_test(user_tags_dir, G_FILE_TEST_IS_DIR))
|
|
|
|
{
|
|
|
|
utils_mkdir(user_tags_dir, FALSE);
|
|
|
|
}
|
2007-05-11 11:58:56 +00:00
|
|
|
return lang_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void load_user_tags(filetype_id ft_id)
|
|
|
|
{
|
2008-05-07 13:54:21 +00:00
|
|
|
static guchar tags_loaded[GEANY_FILETYPES_NONE] = {0};
|
2007-05-11 11:58:56 +00:00
|
|
|
static GHashTable *lang_hash = NULL;
|
|
|
|
GList *fnames;
|
|
|
|
const GList *node;
|
2008-05-16 14:17:54 +00:00
|
|
|
const GeanyFiletype *ft = filetypes[ft_id];
|
2007-05-11 11:58:56 +00:00
|
|
|
|
2008-05-07 13:54:21 +00:00
|
|
|
g_return_if_fail(ft_id < GEANY_FILETYPES_NONE);
|
2007-05-11 11:58:56 +00:00
|
|
|
|
|
|
|
if (tags_loaded[ft_id])
|
|
|
|
return;
|
2008-02-27 13:17:29 +00:00
|
|
|
tags_loaded[ft_id] = TRUE; /* prevent reloading */
|
2007-05-11 11:58:56 +00:00
|
|
|
|
|
|
|
if (lang_hash == NULL)
|
|
|
|
lang_hash = init_user_tags();
|
|
|
|
|
|
|
|
fnames = g_hash_table_lookup(lang_hash, ft);
|
|
|
|
|
|
|
|
for (node = fnames; node != NULL; node = g_list_next(node))
|
|
|
|
{
|
|
|
|
const gint tm_lang = ft->lang;
|
|
|
|
gchar *fname;
|
|
|
|
|
|
|
|
fname = g_strconcat(user_tags_dir, G_DIR_SEPARATOR_S, node->data, NULL);
|
|
|
|
tm_workspace_load_global_tags(fname, tm_lang);
|
|
|
|
geany_debug("Loaded %s (%s).", fname, ft->name);
|
|
|
|
g_free(fname);
|
|
|
|
}
|
|
|
|
g_list_foreach(fnames, (GFunc) g_free, NULL);
|
|
|
|
g_list_free(fnames);
|
|
|
|
g_hash_table_remove(lang_hash, (gpointer) ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-25 12:39:41 +00:00
|
|
|
gboolean symbols_goto_tag(const gchar *name, gboolean definition)
|
|
|
|
{
|
|
|
|
const gint forward_types = tm_tag_prototype_t | tm_tag_externvar_t;
|
|
|
|
gint type;
|
2008-03-24 16:44:43 +00:00
|
|
|
TMTag *tmtag = NULL;
|
2008-02-10 12:34:28 +00:00
|
|
|
gint old_idx = document_get_cur_idx();
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* goto tag definition: all except prototypes / forward declarations / externs */
|
2007-09-25 12:39:41 +00:00
|
|
|
type = (definition) ? tm_tag_max_t - forward_types : forward_types;
|
|
|
|
|
2008-03-24 16:44:43 +00:00
|
|
|
/* first look in the current document */
|
2008-05-29 17:00:54 +00:00
|
|
|
if (documents[old_idx]->tm_file)
|
|
|
|
tmtag = find_work_object_tag(documents[old_idx]->tm_file, name, type);
|
2008-03-24 16:44:43 +00:00
|
|
|
|
|
|
|
/* if not found, look in the workspace */
|
|
|
|
if (tmtag == NULL)
|
|
|
|
tmtag = find_workspace_tag(name, type);
|
|
|
|
|
2007-09-25 12:39:41 +00:00
|
|
|
if (tmtag != NULL)
|
|
|
|
{
|
|
|
|
gint new_idx = document_find_by_filename(
|
|
|
|
tmtag->atts.entry.file->work_object.file_name, TRUE);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* not found in opened document, should open */
|
2008-01-02 21:20:33 +00:00
|
|
|
if (new_idx == -1)
|
|
|
|
{
|
|
|
|
new_idx = document_open_file(tmtag->atts.entry.file->work_object.file_name, FALSE, NULL, NULL);
|
|
|
|
}
|
2007-09-25 12:39:41 +00:00
|
|
|
|
2008-02-10 12:34:28 +00:00
|
|
|
if (navqueue_goto_line(old_idx, new_idx, tmtag->atts.entry.line))
|
2007-09-25 12:39:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* if we are here, there was no match and we are beeping ;-) */
|
2007-09-25 12:39:41 +00:00
|
|
|
utils_beep();
|
|
|
|
if (type == forward_types)
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(FALSE, _("Forward declaration \"%s\" not found."), name);
|
2007-09-25 12:39:41 +00:00
|
|
|
else
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(FALSE, _("Definition of \"%s\" not found."), name);
|
2007-09-25 12:39:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|