Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Sat, 08 Nov 2014 19:21:59 UTC Commit: 28edfa8622a02d5aa06ae9128a9ca9a5614eb659 https://github.com/geany/geany-plugins/commit/28edfa8622a02d5aa06ae9128a9ca9...
Log Message: ----------- Merge pull request #165 from techee/tm
Tm
Modified Paths: -------------- geanygendoc/src/ggd-plugin.c geanygendoc/src/ggd-tag-utils.c geanygendoc/src/ggd.c geanyprj/src/geanyprj.c geanyprj/src/project.c geanyprj/src/xproject.c gproject/src/gproject-main.c gproject/src/gproject-project.c gproject/src/gproject-project.h
Modified: geanygendoc/src/ggd-plugin.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -50,7 +50,7 @@ GeanyData *geany_data; GeanyFunctions *geany_functions;
/* TODO check minimum requierment */ -PLUGIN_VERSION_CHECK (188) +PLUGIN_VERSION_CHECK (221)
PLUGIN_SET_TRANSLATABLE_INFO ( LOCALEDIR, GETTEXT_PACKAGE, @@ -114,7 +114,7 @@ ggd_plugin_get_doctype (filetype_id id) /* FIXME: tm_source_file_buffer_update() is not found in symbols table */ /* (tries to) refresh the tag list to the file's current state */ static void -refresh_tag_list (TMWorkObject *tm_wo, +refresh_tag_list (TMSourceFile *tm_wo, ScintillaObject *sci, GeanyDocument *doc) {
Modified: geanygendoc/src/ggd-tag-utils.c 22 lines changed, 11 insertions(+), 11 deletions(-) =================================================================== @@ -59,9 +59,9 @@ tag_cmp_by_line (gconstpointer a, if (t1->type & tm_tag_file_t || t2->type & tm_tag_file_t) { rv = 0; } else { - if (t1->atts.entry.line > t2->atts.entry.line) { + if (t1->line > t2->line) { rv = +direction; - } else if (t1->atts.entry.line < t2->atts.entry.line) { + } else if (t1->line < t2->line) { rv = -direction; } else { rv = 0; @@ -159,8 +159,8 @@ ggd_tag_find_from_line (const GPtrArray *tags,
GGD_PTR_ARRAY_FOR (tags, i, el) { if (! (el->type & tm_tag_file_t)) { - if (el->atts.entry.line <= line && - (! tag || el->atts.entry.line > tag->atts.entry.line)) { + if (el->line <= line && + (! tag || el->line > tag->line)) { tag = el; } } @@ -211,7 +211,7 @@ ggd_tag_find_parent (const GPtrArray *tags, g_return_val_if_fail (tags != NULL, NULL); g_return_val_if_fail (child != NULL, NULL);
- if (! child->atts.entry.scope) { + if (! child->scope) { /* tag has no parent, we're done */ } else { gchar *parent_scope = NULL; @@ -223,17 +223,17 @@ ggd_tag_find_parent (const GPtrArray *tags, gsize separator_len;
/* scope is of the form a<sep>b<sep>c */ - parent_name = child->atts.entry.scope; + parent_name = child->scope; separator = symbols_get_context_separator (geany_ft); separator_len = strlen (separator); while ((tmp = strstr (parent_name, separator)) != NULL) { parent_name = &tmp[separator_len]; } /* if parent have scope */ - if (parent_name != child->atts.entry.scope) { + if (parent_name != child->scope) { /* the parent scope is the "dirname" of the child's scope */ - parent_scope = g_strndup (child->atts.entry.scope, - parent_name - child->atts.entry.scope - + parent_scope = g_strndup (child->scope, + parent_name - child->scope - separator_len); } /*g_debug ("%s: parent_name = %s", G_STRFUNC, parent_name); @@ -241,8 +241,8 @@ ggd_tag_find_parent (const GPtrArray *tags, GGD_PTR_ARRAY_FOR (tags, i, el) { if (! (el->type & tm_tag_file_t) && (utils_str_equal (el->name, parent_name) && - utils_str_equal (el->atts.entry.scope, parent_scope) && - el->atts.entry.line <= child->atts.entry.line)) { + utils_str_equal (el->scope, parent_scope) && + el->line <= child->line)) { tag = el; } }
Modified: geanygendoc/src/ggd.c 14 lines changed, 7 insertions(+), 7 deletions(-) =================================================================== @@ -162,10 +162,10 @@ get_env_for_tag (GgdFileType *ft, ctpl_environ_push_string (env, "cursor", GGD_CURSOR_IDENTIFIER); ctpl_environ_push_string (env, "symbol", tag->name); /* get argument list it it exists */ - if (tag->atts.entry.arglist) { + if (tag->arglist) { CtplValue *v;
- v = get_arg_list_from_string (ft, tag->atts.entry.arglist); + v = get_arg_list_from_string (ft, tag->arglist); if (v) { ctpl_environ_push (env, "argument_list", v); ctpl_value_free (v); @@ -173,9 +173,9 @@ get_env_for_tag (GgdFileType *ft, } /* get return type -- no matter if the return concept is pointless for that * particular tag, it's up to the rule to use it when it makes sense */ - returns = ! (tag->atts.entry.var_type != NULL && + returns = ! (tag->var_type != NULL && /* C-style none return type hack */ - strcmp ("void", tag->atts.entry.var_type) == 0); + strcmp ("void", tag->var_type) == 0); ctpl_environ_push_int (env, "returns", returns); /* get direct children tags */ children = ggd_tag_find_children (tag_array, tag, @@ -344,13 +344,13 @@ do_insert_comment (GeanyDocument *doc,
switch (setting->position) { case GGD_POS_AFTER: - pos = sci_get_line_end_position (sci, tag->atts.entry.line - 1); + pos = sci_get_line_end_position (sci, tag->line - 1); break;
case GGD_POS_BEFORE: { gint line;
- line = tag->atts.entry.line - 1; + line = tag->line - 1; line = adjust_start_line (sci, tag_array, tag, line); pos = sci_get_position_from_line (sci, line); if (GGD_OPT_indent) { @@ -487,7 +487,7 @@ insert_multiple_comments (GeanyDocument *doc, msgwin_status_add (_("No setting applies to symbol "%s" of type "%s" " "at line %lu."), tag->name, ggd_tag_get_type_name (tag), - tag->atts.entry.line); + tag->line); } } sci_end_undo_action (sci);
Modified: geanyprj/src/geanyprj.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -34,7 +34,7 @@
#include "geanyprj.h"
-PLUGIN_VERSION_CHECK(147) +PLUGIN_VERSION_CHECK(221) PLUGIN_SET_INFO(_("Project"), _("Alternative project support."), VERSION, "Yura Siamashka yurand2@gmail.com")
Modified: geanyprj/src/project.c 68 lines changed, 45 insertions(+), 23 deletions(-) =================================================================== @@ -83,7 +83,11 @@ gboolean (*project_type_filter[NEW_PROJECT_TYPE_SIZE]) (const gchar *) = {
static void free_tag_object(gpointer obj) { - tm_workspace_remove_object((TMWorkObject *) obj, TRUE, FALSE); + if (obj != NULL) + { + tm_workspace_remove_source_file((TMSourceFile *) obj); + tm_source_file_free((TMSourceFile *) obj); + } }
@@ -101,7 +105,7 @@ struct GeanyPrj *geany_project_new(void) struct GeanyPrj *geany_project_load(const gchar *path) { struct GeanyPrj *ret; - TMWorkObject *tm_obj = NULL; + TMSourceFile *tm_obj = NULL; GKeyFile *config; gint i = 0; gchar *file; @@ -153,6 +157,8 @@ struct GeanyPrj *geany_project_load(const gchar *path) } else { + GPtrArray *to_add = g_ptr_array_new(); + /* Create tag files */ key = g_strdup_printf("file%d", i); while ((file = g_key_file_get_string(config, "files", key, NULL))) @@ -160,13 +166,13 @@ struct GeanyPrj *geany_project_load(const gchar *path) filename = get_full_path(path, file);
locale_filename = utils_get_locale_from_utf8(filename); - tm_obj = tm_source_file_new(locale_filename, FALSE, + tm_obj = tm_source_file_new(locale_filename, filetypes_detect_from_file(filename)->name); g_free(locale_filename); if (tm_obj) { g_hash_table_insert(ret->tags, filename, tm_obj); - tm_source_file_update(tm_obj, TRUE, FALSE, TRUE); + g_ptr_array_add(to_add, tm_obj); } else g_free(filename); @@ -175,6 +181,8 @@ struct GeanyPrj *geany_project_load(const gchar *path) g_free(file); key = g_strdup_printf("file%d", i); } + tm_workspace_add_source_files(to_add); + g_ptr_array_free(to_add, TRUE); g_free(key); } g_key_file_free(config); @@ -182,18 +190,28 @@ struct GeanyPrj *geany_project_load(const gchar *path) }
-#if !GLIB_CHECK_VERSION(2, 12, 0) -static gboolean get_true(gpointer key, gpointer value, gpointer user_data) -{ - return TRUE; -} - - -static void g_hash_table_remove_all(GHashTable *hash_table) +static void remove_all_tags(struct GeanyPrj *prj) { - g_hash_table_foreach_remove(hash_table, get_true, NULL); + GPtrArray *to_remove, *keys; + GHashTableIter iter; + gpointer key, value; + + /* instead of relatively slow removal of source files by one from the tag manager, + * use the bulk operations - this requires that the normal destroy function + * of GHashTable is skipped - steal the keys and values and handle them manually */ + to_remove = g_ptr_array_new_with_free_func((GFreeFunc)tm_source_file_free); + keys = g_ptr_array_new_with_free_func(g_free); + g_hash_table_iter_init(&iter, prj->tags); + while (g_hash_table_iter_next(&iter, &key, &value)) + { + g_ptr_array_add(to_remove, value); + g_ptr_array_add(keys, key); + } + tm_workspace_remove_source_files(to_remove); + g_hash_table_steal_all(prj->tags); + g_ptr_array_free(to_remove, TRUE); + g_ptr_array_free(keys, TRUE); } -#endif
void geany_project_regenerate_file_list(struct GeanyPrj *prj) @@ -201,7 +219,7 @@ void geany_project_regenerate_file_list(struct GeanyPrj *prj) GSList *lst;
debug("%s path=%s\n", __FUNCTION__, prj->base_path); - g_hash_table_remove_all(prj->tags); + remove_all_tags(prj);
lst = get_file_list(prj->base_path, NULL, project_type_filter[prj->type], NULL); geany_project_set_tags_from_list(prj, lst); @@ -298,24 +316,25 @@ void geany_project_set_tags_from_list(struct GeanyPrj *prj, GSList *files) { GSList *tmp; gchar *locale_filename; - TMWorkObject *tm_obj = NULL; + TMSourceFile *tm_obj = NULL; + GPtrArray *to_add = g_ptr_array_new();
- if (prj->tags) - g_hash_table_destroy(prj->tags); prj->tags = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_tag_object);
for (tmp = files; tmp != NULL; tmp = g_slist_next(tmp)) { locale_filename = utils_get_locale_from_utf8(tmp->data); - tm_obj = tm_source_file_new(locale_filename, FALSE, + tm_obj = tm_source_file_new(locale_filename, filetypes_detect_from_file(tmp->data)->name); g_free(locale_filename); if (tm_obj) { g_hash_table_insert(prj->tags, g_strdup(tmp->data), tm_obj); - tm_source_file_update(tm_obj, TRUE, FALSE, TRUE); + g_ptr_array_add(to_add, tm_obj); } } + tm_workspace_add_source_files(to_add); + g_ptr_array_free(to_add, TRUE); }
@@ -335,7 +354,10 @@ void geany_project_free(struct GeanyPrj *prj) if (prj->run_cmd) g_free(prj->run_cmd); if (prj->tags) + { + remove_all_tags(prj); g_hash_table_destroy(prj->tags); + }
g_free(prj); } @@ -344,7 +366,7 @@ void geany_project_free(struct GeanyPrj *prj) gboolean geany_project_add_file(struct GeanyPrj *prj, const gchar *path) { gchar *filename; - TMWorkObject *tm_obj = NULL; + TMSourceFile *tm_obj = NULL;
GKeyFile *config;
@@ -363,12 +385,12 @@ gboolean geany_project_add_file(struct GeanyPrj *prj, const gchar *path) g_key_file_free(config);
filename = utils_get_locale_from_utf8(path); - tm_obj = tm_source_file_new(filename, FALSE, filetypes_detect_from_file(path)->name); + tm_obj = tm_source_file_new(filename, filetypes_detect_from_file(path)->name); g_free(filename); if (tm_obj) { g_hash_table_insert(prj->tags, g_strdup(path), tm_obj); - tm_source_file_update(tm_obj, TRUE, FALSE, TRUE); + tm_workspace_add_source_file(tm_obj); } geany_project_save(prj); return TRUE;
Modified: geanyprj/src/xproject.c 49 lines changed, 24 insertions(+), 25 deletions(-) =================================================================== @@ -35,17 +35,15 @@ struct GeanyPrj *g_current_project = NULL; static GPtrArray *g_projects = NULL;
-static void add_tag(G_GNUC_UNUSED gpointer key, gpointer value, G_GNUC_UNUSED gpointer user_data) +static void collect_tags(G_GNUC_UNUSED gpointer key, gpointer value, gpointer user_data) { + GPtrArray *array = user_data; + debug("%s file=%s\n", __FUNCTION__, (const gchar *)key); - tm_workspace_add_object((TMWorkObject *)value); -} - - -static void remove_tag(G_GNUC_UNUSED gpointer key, gpointer value, G_GNUC_UNUSED gpointer user_data) -{ - debug("%s file=%s\n", __FUNCTION__, (const gchar *)key); - tm_workspace_remove_object((TMWorkObject *)value, FALSE, FALSE); + if (value != NULL) + { + g_ptr_array_add(array, value); + } }
@@ -59,7 +57,6 @@ void xproject_close(gboolean cache)
if (cache) { - g_hash_table_foreach(g_current_project->tags, remove_tag, NULL); g_ptr_array_add(g_projects, g_current_project); } else @@ -76,6 +73,7 @@ void xproject_open(const gchar *path) { guint i; struct GeanyPrj *p = NULL; + GPtrArray *to_reload; debug("%s\n", __FUNCTION__);
for (i = 0; i < g_projects->len; i++) @@ -94,7 +92,11 @@ void xproject_open(const gchar *path) return;
ui_set_statusbar(TRUE, _("Project "%s" opened."), p->name); - g_hash_table_foreach(p->tags, add_tag, NULL); + to_reload = g_ptr_array_new(); + g_hash_table_foreach(p->tags, collect_tags, to_reload); + tm_workspace_remove_source_files(to_reload); + tm_workspace_add_source_files(to_reload); + g_ptr_array_free(to_reload, TRUE);
g_current_project = p; sidebar_refresh(); @@ -104,23 +106,27 @@ void xproject_open(const gchar *path) void xproject_update_tag(const gchar *filename) { guint i; - TMWorkObject *tm_obj; + TMSourceFile *tm_obj;
if (g_current_project) { tm_obj = g_hash_table_lookup(g_current_project->tags, filename); if (tm_obj) { - tm_source_file_update(tm_obj, TRUE, FALSE, TRUE); + /* force tag update */ + tm_workspace_remove_source_file(tm_obj); + tm_workspace_add_source_file(tm_obj); } }
for (i = 0; i < g_projects->len; i++) { - tm_obj = (TMWorkObject *)g_hash_table_lookup(((struct GeanyPrj *)(g_projects->pdata[i]))->tags, filename); + tm_obj = (TMSourceFile *)g_hash_table_lookup(((struct GeanyPrj *)(g_projects->pdata[i]))->tags, filename); if (tm_obj) { - tm_source_file_update(tm_obj, TRUE, FALSE, TRUE); + /* force tag update */ + tm_workspace_remove_source_file(tm_obj); + tm_workspace_add_source_file(tm_obj); } } } @@ -128,8 +134,6 @@ void xproject_update_tag(const gchar *filename)
gboolean xproject_add_file(const gchar *path) { - TMWorkObject *tm_obj; - debug("%s path=%s\n", __FUNCTION__, path);
if (!g_current_project) @@ -137,11 +141,6 @@ gboolean xproject_add_file(const gchar *path)
if (geany_project_add_file(g_current_project, path)) { - tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path); - if (tm_obj) - { - tm_workspace_add_object((TMWorkObject *) tm_obj); - } sidebar_refresh(); return TRUE; } @@ -151,17 +150,17 @@ gboolean xproject_add_file(const gchar *path)
gboolean xproject_remove_file(const gchar *path) { - TMWorkObject *tm_obj; + TMSourceFile *tm_obj;
debug("%s path=%s\n", __FUNCTION__, path);
if (!g_current_project) return FALSE;
- tm_obj = (TMWorkObject *) g_hash_table_lookup(g_current_project->tags, path); + tm_obj = (TMSourceFile *) g_hash_table_lookup(g_current_project->tags, path); if (tm_obj) { - tm_workspace_remove_object(tm_obj, FALSE, FALSE); + tm_workspace_remove_source_file(tm_obj); }
if (geany_project_remove_file(g_current_project, path))
Modified: gproject/src/gproject-main.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -32,7 +32,7 @@ #include "gproject-sidebar.h" #include "gproject-menu.h"
-PLUGIN_VERSION_CHECK(214) +PLUGIN_VERSION_CHECK(221) PLUGIN_SET_INFO(_("GProject"), _("Glob-pattern-based project management plugin for Geany."), VERSION,
Modified: gproject/src/gproject-project.c 115 lines changed, 76 insertions(+), 39 deletions(-) =================================================================== @@ -72,48 +72,29 @@ static void deferred_op_queue_clean(void) }
-static void workspace_add_tag(gchar *filename, TagObject *obj, gpointer foo) -{ - TMWorkObject *tm_obj = NULL; - - if (!document_find_by_filename(filename)) - { - gchar *locale_filename; - - locale_filename = utils_get_locale_from_utf8(filename); - tm_obj = tm_source_file_new(locale_filename, FALSE, filetypes_detect_from_file(filename)->name); - g_free(locale_filename); - - if (tm_obj) - { - tm_workspace_add_object(tm_obj); - tm_source_file_update(tm_obj, TRUE, FALSE, TRUE); - } - } - - if (obj->tag) - tm_workspace_remove_object(obj->tag, TRUE, TRUE); - - obj->tag = tm_obj; -} - - static void workspace_add_file_tag(gchar *filename) { TagObject *obj;
obj = g_hash_table_lookup(g_prj->file_tag_table, filename); if (obj) - workspace_add_tag(filename, obj, NULL); -} + { + TMSourceFile *tm_obj = NULL; + + if (!document_find_by_filename(filename)) + { + tm_obj = tm_source_file_new(filename, filetypes_detect_from_file(filename)->name); + if (tm_obj) + tm_workspace_add_source_file(tm_obj); + }
+ if (obj->tag) + { + tm_workspace_remove_source_file(obj->tag); + tm_source_file_free(obj->tag); + }
-static void workspace_remove_tag(gchar *filename, TagObject *obj, gpointer foo) -{ - if (obj->tag) - { - tm_workspace_remove_object(obj->tag, TRUE, TRUE); - obj->tag = NULL; + obj->tag = tm_obj; } }
@@ -123,8 +104,12 @@ static void workspace_remove_file_tag(gchar *filename) TagObject *obj;
obj = g_hash_table_lookup(g_prj->file_tag_table, filename); - if (obj) - workspace_remove_tag(filename, obj, NULL); + if (obj && obj->tag) + { + tm_workspace_remove_source_file(obj->tag); + tm_source_file_free(obj->tag); + obj->tag = NULL; + } }
@@ -217,6 +202,58 @@ static GSList *get_file_list(const gchar * path, GSList *patterns, GSList *ignor }
+static void remove_all_tags() +{ + GPtrArray *to_update; + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, g_prj->file_tag_table); + to_update = g_ptr_array_new(); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + TagObject *obj = value; + + g_ptr_array_add(to_update, obj->tag); + obj->tag = NULL; + } + + tm_workspace_remove_source_files(to_update); + g_ptr_array_foreach(to_update, (GFunc)tm_source_file_free, NULL); + g_ptr_array_free(to_update, TRUE); +} + + +static void add_all_tags() +{ + GPtrArray *to_update; + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, g_prj->file_tag_table); + to_update = g_ptr_array_new(); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + TagObject *obj = value; + gchar *filename = key; + TMSourceFile *tm_obj = NULL; + + if (!document_find_by_filename(filename)) + { + tm_obj = tm_source_file_new(filename, filetypes_detect_from_file(filename)->name); + + if (tm_obj) + g_ptr_array_add(to_update, tm_obj); + } + + obj->tag = tm_obj; + } + + tm_workspace_add_source_files(to_update); + g_ptr_array_free(to_update, TRUE); +} + + void gprj_project_rescan(void) { GSList *pattern_list = NULL; @@ -228,7 +265,7 @@ void gprj_project_rescan(void) return;
if (g_prj->generate_tags) - g_hash_table_foreach(g_prj->file_tag_table, (GHFunc)workspace_remove_tag, NULL); + remove_all_tags(); g_hash_table_destroy(g_prj->file_tag_table); g_prj->file_tag_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
@@ -257,7 +294,7 @@ void gprj_project_rescan(void) }
if (g_prj->generate_tags) - g_hash_table_foreach(g_prj->file_tag_table, (GHFunc)workspace_add_tag, NULL); + add_all_tags();
g_slist_foreach(lst, (GFunc) g_free, NULL); g_slist_free(lst); @@ -470,7 +507,7 @@ void gprj_project_close(void) return; /* can happen on plugin reload */
if (g_prj->generate_tags) - g_hash_table_foreach(g_prj->file_tag_table, (GHFunc)workspace_remove_tag, NULL); + remove_all_tags();
deferred_op_queue_clean();
Modified: gproject/src/gproject-project.h 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -22,7 +22,7 @@
typedef struct { - TMWorkObject *tag; + TMSourceFile *tag; } TagObject;
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).