[geany/geany-plugins] 38bf4b: Merge pull request #284 from eht16/addons_bookmark_refresh_fix

Enrico Tröger git-noreply at xxxxx
Sun Sep 20 20:25:23 UTC 2015


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sun, 20 Sep 2015 20:25:23 UTC
Commit:      38bf4b0f3b25bbb2cd6ef69f132e49d82611f986
             https://github.com/geany/geany-plugins/commit/38bf4b0f3b25bbb2cd6ef69f132e49d82611f986

Log Message:
-----------
Merge pull request #284 from eht16/addons_bookmark_refresh_fix

Update bookmark list also on any line changes in the document
    
In addition to updating the bookmark list on document notebook tab change
and adding/removing line markers, also rebuild the bookmark list
when the text in the document changes with lines added or deleted.
    
Should fix SF bugs #129 and #39.


Modified Paths:
--------------
    addons/src/ao_bookmarklist.c

Modified: addons/src/ao_bookmarklist.c
60 lines changed, 51 insertions(+), 9 deletions(-)
===================================================================
@@ -62,8 +62,16 @@ struct _AoBookmarkListPrivate
 
 	gint		 search_line;
 	GtkTreeIter	*search_iter;
+
+	guint refresh_idle_source_id;
 };
 
+typedef struct
+{
+	AoBookmarkList *bm;
+	guint document_id;
+} AoBookmarkListRefreshContainer;
+
 enum
 {
 	PROP_0,
@@ -401,15 +409,19 @@ void ao_bookmark_list_activate(AoBookmarkList *bm)
 }
 
 
-void ao_bookmark_list_update(AoBookmarkList *bm, GeanyDocument *doc)
+static gboolean update_bookmark_list_delayed(gpointer data)
 {
 	gint line_nr = 0;
 	gint mask = 1 << 1;
-	ScintillaObject *sci = doc->editor->sci;
+	AoBookmarkListRefreshContainer *container = data;
+	AoBookmarkList *bm = container->bm;
 	AoBookmarkListPrivate *priv = AO_BOOKMARK_LIST_GET_PRIVATE(bm);
+	GeanyDocument *doc = document_find_by_id(container->document_id);
 
-	if (priv->enable_bookmarklist)
+	if (priv->enable_bookmarklist && doc != NULL)
 	{
+		ScintillaObject *sci = doc->editor->sci;
+
 		gtk_list_store_clear(priv->store);
 		while ((line_nr = scintilla_send_message(sci, SCI_MARKERNEXT, line_nr, mask)) != -1)
 		{
@@ -417,6 +429,28 @@ void ao_bookmark_list_update(AoBookmarkList *bm, GeanyDocument *doc)
 			line_nr++;
 		}
 	}
+
+	g_free(container);
+	priv->refresh_idle_source_id = 0;
+	return FALSE;
+}
+
+
+void ao_bookmark_list_update(AoBookmarkList *bm, GeanyDocument *doc)
+{
+	AoBookmarkListPrivate *priv = AO_BOOKMARK_LIST_GET_PRIVATE(bm);
+
+	if (priv->refresh_idle_source_id == 0)
+	{
+		AoBookmarkListRefreshContainer *container = g_new0(AoBookmarkListRefreshContainer, 1);
+
+		container->bm = bm;
+		container->document_id = doc->id;
+		priv->refresh_idle_source_id = plugin_idle_add(
+			geany_plugin,
+			update_bookmark_list_delayed,
+			container);
+	}
 }
 
 
@@ -424,16 +458,23 @@ void ao_bookmark_list_update_marker(AoBookmarkList *bm, GeanyEditor *editor, SCN
 {
 	AoBookmarkListPrivate *priv = AO_BOOKMARK_LIST_GET_PRIVATE(bm);
 
-	if (priv->enable_bookmarklist &&
-		nt->nmhdr.code == SCN_MODIFIED && nt->modificationType == SC_MOD_CHANGEMARKER)
+	if (priv->enable_bookmarklist && nt->nmhdr.code == SCN_MODIFIED)
 	{
-		if (sci_is_marker_set_at_line(editor->sci, nt->line, 1))
+		if (nt->modificationType == SC_MOD_CHANGEMARKER)
 		{
-			add_line(bm, editor->sci, nt->line);
+			if (sci_is_marker_set_at_line(editor->sci, nt->line, 1))
+			{
+				add_line(bm, editor->sci, nt->line);
+			}
+			else
+			{
+				delete_line(bm, nt->line);
+			}
 		}
-		else
+		else if (nt->linesAdded != 0)
 		{
-			delete_line(bm, nt->line);
+			/* if any lines changed, refresh the whole list as we refer line numbers */
+			ao_bookmark_list_update(bm, editor->document);
 		}
 	}
 }
@@ -444,6 +485,7 @@ static void ao_bookmark_list_init(AoBookmarkList *self)
 	AoBookmarkListPrivate *priv = AO_BOOKMARK_LIST_GET_PRIVATE(self);
 
 	priv->page = NULL;
+	priv->refresh_idle_source_id = 0;
 }
 
 



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