[geany/geany-plugins] 7de826: geanyprj: Update to the latest Geany tagmanager API

Jiří Techet git-noreply at xxxxx
Sat Nov 8 19:09:09 UTC 2014


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sat, 08 Nov 2014 19:09:09 UTC
Commit:      7de8265bf2eb0c663c0838c77c63242fc02dc1d8
             https://github.com/geany/geany-plugins/commit/7de8265bf2eb0c663c0838c77c63242fc02dc1d8

Log Message:
-----------
geanyprj: Update to the latest Geany tagmanager API


Modified Paths:
--------------
    geanyprj/src/geanyprj.c
    geanyprj/src/project.c
    geanyprj/src/xproject.c

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 at 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))



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list