Revision: 1069 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1069&view=re... Author: eht16 Date: 2009-11-29 21:35:35 +0000 (Sun, 29 Nov 2009)
Log Message: ----------- Update the task list only for changed documents and on document closing, simply delete matching TODO tasks instead of updating all. This is major speed up of the whole tasks processing.
Modified Paths: -------------- trunk/geany-plugins/addons/ChangeLog trunk/geany-plugins/addons/src/addons.c trunk/geany-plugins/addons/src/ao_tasks.c trunk/geany-plugins/addons/src/ao_tasks.h
Modified: trunk/geany-plugins/addons/ChangeLog =================================================================== --- trunk/geany-plugins/addons/ChangeLog 2009-11-29 13:40:56 UTC (rev 1068) +++ trunk/geany-plugins/addons/ChangeLog 2009-11-29 21:35:35 UTC (rev 1069) @@ -6,6 +6,10 @@ * src/addons.c, src/ao_tasks.c: Update the tasks list on startup only first the main window has been realized, i.e. Geany has finished the startup process. + * src/addons.c, src/ao_tasks.c, src/ao_tasks.h: + Update the task list only for changed documents and on document + closing, simply delete matching TODO tasks instead of updating all. + This is major speed up of the whole tasks processing.
2009-11-28 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/geany-plugins/addons/src/addons.c =================================================================== --- trunk/geany-plugins/addons/src/addons.c 2009-11-29 13:40:56 UTC (rev 1068) +++ trunk/geany-plugins/addons/src/addons.c 2009-11-29 21:35:35 UTC (rev 1069) @@ -158,7 +158,7 @@ { g_return_if_fail(doc != NULL && doc->is_valid);
- ao_tasks_update(ao_info->tasks, doc); + ao_tasks_remove(ao_info->tasks, doc); }
Modified: trunk/geany-plugins/addons/src/ao_tasks.c =================================================================== --- trunk/geany-plugins/addons/src/ao_tasks.c 2009-11-29 13:40:56 UTC (rev 1068) +++ trunk/geany-plugins/addons/src/ao_tasks.c 2009-11-29 21:35:35 UTC (rev 1069) @@ -264,6 +264,8 @@
static gboolean update_list_delay(gpointer t) { + /* TODO add a signal in Geany when the main window is realised or the startup process + * has been in general */ if (main_is_realized()) { AoTasksPrivate *priv = AO_TASKS_GET_PRIVATE(t); @@ -373,61 +375,111 @@ }
-void ao_tasks_update(AoTasks *t, G_GNUC_UNUSED GeanyDocument *cur_doc) +void ao_tasks_remove(AoTasks *t, GeanyDocument *cur_doc) { - guint i, lines, line; - gchar *line_buf, *context, *display_name, *tooltip; - const gchar **token; - GeanyDocument *doc; AoTasksPrivate *priv = AO_TASKS_GET_PRIVATE(t); + GtkTreeModel *model = GTK_TREE_MODEL(priv->store); + GtkTreeIter iter; + gchar *filename;
if (! priv->active) return;
- /* TODO this could be improved to only update the currently loaded/saved document instead of - * iterating over all documents. */ - gtk_list_store_clear(priv->store); + if (gtk_tree_model_get_iter_first(model, &iter)) + { + while (TRUE) + { + gtk_tree_model_get(model, &iter, TLIST_COL_FILENAME, &filename, -1);
- for (i = 0; i < geany->documents_array->len; i++) + if (utils_str_equal(filename, cur_doc->file_name)) + { /* gtk_list_store_remove() manages the iter and set it to the next row */ + if (! gtk_list_store_remove(priv->store, &iter)) + break; + } + else + { /* if we didn't delete the row, we need to manage the iter manually */ + if (! gtk_tree_model_iter_next(model, &iter)) + break; + } + g_free(filename); + } + } +} + + +static void update_tasks_for_doc(AoTasks *t, G_GNUC_UNUSED GeanyDocument *doc) +{ + guint lines, line; + gchar *line_buf, *context, *display_name, *tooltip; + const gchar **token; + AoTasksPrivate *priv = AO_TASKS_GET_PRIVATE(t); + + if (doc->is_valid) { - doc = document_index(i); - if (doc->is_valid) + display_name = document_get_basename_for_display(doc, -1); + lines = sci_get_line_count(doc->editor->sci); + for (line = 0; line < lines; line++) { - display_name = document_get_basename_for_display(doc, -1); - lines = sci_get_line_count(doc->editor->sci); - for (line = 0; line < lines; line++) + line_buf = g_strstrip(sci_get_line(doc->editor->sci, line)); + token = tokens; + while (*token != NULL) { - line_buf = g_strstrip(sci_get_line(doc->editor->sci, line)); - token = tokens; - while (*token != NULL) + if (NZV(*token) && strstr(line_buf, *token) != NULL) { - if (NZV(*token) && strstr(line_buf, *token) != NULL) - { - context = g_strstrip(sci_get_line(doc->editor->sci, line + 1)); - setptr(context, g_strconcat( - _("Context:"), "\n", line_buf, "\n", context, NULL)); - tooltip = g_markup_escape_text(context, -1); + context = g_strstrip(sci_get_line(doc->editor->sci, line + 1)); + setptr(context, g_strconcat( + _("Context:"), "\n", line_buf, "\n", context, NULL)); + tooltip = g_markup_escape_text(context, -1);
- gtk_list_store_insert_with_values(priv->store, NULL, -1, - TLIST_COL_FILENAME, DOC_FILENAME(doc), - TLIST_COL_DISPLAY_FILENAME, display_name, - TLIST_COL_LINE, line + 1, - TLIST_COL_NAME, line_buf, - TLIST_COL_TOOLTIP, tooltip, - -1); - g_free(context); - g_free(tooltip); - } - token++; + gtk_list_store_insert_with_values(priv->store, NULL, -1, + TLIST_COL_FILENAME, DOC_FILENAME(doc), + TLIST_COL_DISPLAY_FILENAME, display_name, + TLIST_COL_LINE, line + 1, + TLIST_COL_NAME, line_buf, + TLIST_COL_TOOLTIP, tooltip, + -1); + g_free(context); + g_free(tooltip); } - g_free(line_buf); + token++; } - g_free(display_name); + g_free(line_buf); } + g_free(display_name); } }
+void ao_tasks_update(AoTasks *t, G_GNUC_UNUSED GeanyDocument *cur_doc) +{ + AoTasksPrivate *priv = AO_TASKS_GET_PRIVATE(t); + + if (! priv->active) + return; + + if (cur_doc != NULL) + { + /* TODO handle renaming of files, probably we need a new signal for this */ + ao_tasks_remove(t, cur_doc); + update_tasks_for_doc(t, cur_doc); + } + else + { + GeanyDocument *doc; + guint i; + + /* clear all */ + gtk_list_store_clear(priv->store); + /* iterate over all docs */ + for (i = 0; i < geany->documents_array->len; i++) + { + doc = document_index(i); + update_tasks_for_doc(t, doc); + } + } +} + + static void ao_tasks_init(AoTasks *self) { AoTasksPrivate *priv = AO_TASKS_GET_PRIVATE(self);
Modified: trunk/geany-plugins/addons/src/ao_tasks.h =================================================================== --- trunk/geany-plugins/addons/src/ao_tasks.h 2009-11-29 13:40:56 UTC (rev 1068) +++ trunk/geany-plugins/addons/src/ao_tasks.h 2009-11-29 21:35:35 UTC (rev 1069) @@ -38,6 +38,7 @@ GType ao_tasks_get_type (void); AoTasks* ao_tasks_new (gboolean enable); void ao_tasks_update (AoTasks *t, GeanyDocument *cur_doc); +void ao_tasks_remove (AoTasks *t, GeanyDocument *cur_doc); void ao_tasks_activate (AoTasks *t);
G_END_DECLS
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org