Oops, reorder the bookmarks list correctly

Signed-off-by: Federico Mena Quintero's avatarFederico Mena Quintero <federico@gnome.org>
parent 948a7be7
......@@ -277,16 +277,29 @@ _gtk_bookmarks_manager_list_bookmarks (GtkBookmarksManager *manager)
}
GSList *
find_bookmark_link_for_file (GSList *bookmarks, GFile *file)
find_bookmark_link_for_file (GSList *bookmarks, GFile *file, int *position_ret)
{
int pos;
pos = 0;
for (; bookmarks; bookmarks = bookmarks->next)
{
GtkBookmark *bookmark = bookmarks->data;
if (g_file_equal (file, bookmark->file))
return bookmarks;
{
if (position_ret)
*position_ret = pos;
return bookmarks;
}
pos++;
}
if (position_ret)
*position_ret = -1;
return NULL;
}
......@@ -303,7 +316,7 @@ _gtk_bookmarks_manager_insert_bookmark (GtkBookmarksManager *manager,
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
link = find_bookmark_link_for_file (manager->bookmarks, file);
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
if (link)
{
......@@ -349,7 +362,7 @@ _gtk_bookmarks_manager_remove_bookmark (GtkBookmarksManager *manager,
if (!manager->bookmarks)
return FALSE;
link = find_bookmark_link_for_file (manager->bookmarks, file);
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
if (link)
{
GtkBookmark *bookmark = link->data;
......@@ -390,14 +403,19 @@ _gtk_bookmarks_manager_reorder_bookmark (GtkBookmarksManager *manager,
{
GSList *link;
GFile *bookmarks_file;
int old_position;
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (new_position >= 0, FALSE);
if (!manager->bookmarks)
return FALSE;
link = find_bookmark_link_for_file (manager->bookmarks, file);
link = find_bookmark_link_for_file (manager->bookmarks, file, &old_position);
if (new_position == old_position)
return TRUE;
if (link)
{
GtkBookmark *bookmark = link->data;
......@@ -405,6 +423,9 @@ _gtk_bookmarks_manager_reorder_bookmark (GtkBookmarksManager *manager,
manager->bookmarks = g_slist_remove_link (manager->bookmarks, link);
g_slist_free_1 (link);
if (new_position > old_position)
new_position--;
manager->bookmarks = g_slist_insert (manager->bookmarks, bookmark, new_position);
}
else
......@@ -472,7 +493,7 @@ _gtk_bookmarks_manager_set_bookmark_label (GtkBookmarksManager *manager,
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (file != NULL, FALSE);
link = find_bookmark_link_for_file (manager->bookmarks, file);
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
if (link)
{
GtkBookmark *bookmark = link->data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment