Skip to content

Commit

Permalink
Merge pull request #1257 from eht16/issue1254_delay_task_update_for_c…
Browse files Browse the repository at this point in the history
…olorising

Addons: Delay updating of tasks list until document has been colorised
  • Loading branch information
eht16 authored Sep 17, 2023
2 parents fc1fcf3 + b1ba03c commit 45a6d0b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
16 changes: 8 additions & 8 deletions addons/src/addons.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ static gboolean ao_editor_notify_cb(GObject *object, GeanyEditor *editor,
static void ao_update_editor_menu_cb(GObject *obj, const gchar *word, gint pos,
GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_open_uri_update_menu(ao_info->openuri, doc, pos);
}


static void ao_document_activate_cb(GObject *obj, GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_bookmark_list_update(ao_info->bookmarklist, doc);
ao_tasks_update_single(ao_info->tasks, doc);
Expand All @@ -154,7 +154,7 @@ static void ao_document_activate_cb(GObject *obj, GeanyDocument *doc, gpointer d

static void ao_document_new_cb(GObject *obj, GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_mark_document_new(ao_info->markword, doc);
ao_color_tip_document_new(ao_info->colortip, doc);
Expand All @@ -163,7 +163,7 @@ static void ao_document_new_cb(GObject *obj, GeanyDocument *doc, gpointer data)

static void ao_document_open_cb(GObject *obj, GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_tasks_update(ao_info->tasks, doc);
ao_mark_document_open(ao_info->markword, doc);
Expand All @@ -173,7 +173,7 @@ static void ao_document_open_cb(GObject *obj, GeanyDocument *doc, gpointer data)

static void ao_document_close_cb(GObject *obj, GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_tasks_remove(ao_info->tasks, doc);
ao_mark_document_close(ao_info->markword, doc);
Expand All @@ -183,23 +183,23 @@ static void ao_document_close_cb(GObject *obj, GeanyDocument *doc, gpointer data

static void ao_document_save_cb(GObject *obj, GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_tasks_update(ao_info->tasks, doc);
}


static void ao_document_before_save_cb(GObject *obj, GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_blanklines_on_document_before_save(obj, doc, data);
}


static void ao_document_reload_cb(GObject *obj, GeanyDocument *doc, gpointer data)
{
g_return_if_fail(doc != NULL && doc->is_valid);
g_return_if_fail(DOC_VALID(doc));

ao_tasks_update(ao_info->tasks, doc);
}
Expand Down
58 changes: 51 additions & 7 deletions addons/src/ao_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ struct _AoTasksPrivate
gboolean ignore_selection_changed;
};


typedef struct
{
AoTasks *t;
GeanyDocument *doc;
gboolean clear;
} AoTasksUpdateTasksForDocArguments;


enum
{
PROP_0,
Expand Down Expand Up @@ -556,15 +565,26 @@ static void create_task(AoTasks *t, GeanyDocument *doc, gint line, const gchar *
}


static void update_tasks_for_doc(AoTasks *t, GeanyDocument *doc)
static gboolean update_tasks_for_doc_idle_cb(gpointer data)
{
AoTasksUpdateTasksForDocArguments *arguments = data;
AoTasksPrivate *priv;
GeanyDocument *doc;
gint lexer, lines, line, last_pos = 0, style;
gchar *line_buf, *display_name, *task_start, *closing_comment = NULL;
gchar **token;
AoTasksPrivate *priv = AO_TASKS_GET_PRIVATE(t);

if (doc->is_valid)
if (! arguments)
return FALSE;

priv = AO_TASKS_GET_PRIVATE(arguments->t);
doc = arguments->doc;

if (DOC_VALID(doc) && priv->active && priv->enable_tasks)
{
if (arguments->clear)
ao_tasks_remove(arguments->t, doc);

display_name = document_get_basename_for_display(doc, -1);
lexer = sci_get_lexer(doc->editor->sci);
lines = sci_get_line_count(doc->editor->sci);
Expand Down Expand Up @@ -594,7 +614,7 @@ static void update_tasks_for_doc(AoTasks *t, GeanyDocument *doc)
(closing_comment = strstr(task_start, doc->file_type->comment_close)) != NULL)
*closing_comment = '\0';
/* create the task */
create_task(t, doc, line, *token, line_buf, task_start, display_name);
create_task(arguments->t, doc, line, *token, line_buf, task_start, display_name);
/* if we found a token, continue on next line */
break;
}
Expand All @@ -603,6 +623,31 @@ static void update_tasks_for_doc(AoTasks *t, GeanyDocument *doc)
}
g_free(display_name);
}
return FALSE;
}


static void free_update_tasks_for_doc_arguments(gpointer data)
{
AoTasksUpdateTasksForDocArguments *arguments = data;
g_slice_free1(sizeof *arguments, arguments);
}


static void update_tasks_for_doc(AoTasks *t, GeanyDocument *doc, gboolean clear)
{
AoTasksUpdateTasksForDocArguments *arguments = g_slice_alloc(sizeof *arguments);
arguments->t = t;
arguments->doc = doc;
arguments->clear = clear;

if (!DOC_VALID(doc))
return;

/* Check for task tokens in an idle callback to wait until Geany applied Scintilla highlighting
* styles as we need them to be set before checking for tasks. */
g_idle_add_full(G_PRIORITY_LOW, update_tasks_for_doc_idle_cb, arguments,
free_update_tasks_for_doc_arguments);
}


Expand Down Expand Up @@ -688,8 +733,7 @@ void ao_tasks_update(AoTasks *t, GeanyDocument *cur_doc)
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);
update_tasks_for_doc(t, cur_doc, TRUE);
}
else
{
Expand All @@ -699,7 +743,7 @@ void ao_tasks_update(AoTasks *t, GeanyDocument *cur_doc)
/* iterate over all docs */
foreach_document(i)
{
update_tasks_for_doc(t, documents[i]);
update_tasks_for_doc(t, documents[i], FALSE);
}
}
/* restore selection */
Expand Down

0 comments on commit 45a6d0b

Please sign in to comment.