Skip to content

Commit

Permalink
Merge pull request #284 from eht16/addons_bookmark_refresh_fix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eht16 committed Sep 20, 2015
2 parents 37aa25a + 0ecdc42 commit 38bf4b0
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions addons/src/ao_bookmarklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -401,39 +409,72 @@ 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)
{
add_line(bm, sci, line_nr);
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);
}
}


void ao_bookmark_list_update_marker(AoBookmarkList *bm, GeanyEditor *editor, SCNotification *nt)
{
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);
}
}
}
Expand All @@ -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;
}


Expand Down

0 comments on commit 38bf4b0

Please sign in to comment.