summaryrefslogtreecommitdiff
path: root/gtk/gtkbookmarksmanager.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2012-10-20 14:09:34 -0500
committerFederico Mena Quintero <federico@gnome.org>2012-10-20 14:09:34 -0500
commitd02f884d225e55c0e4bbe30bd2c57a011b4c8f53 (patch)
tree8f5dfc01828b1a9f0b537d7e9087b0ea706661bf /gtk/gtkbookmarksmanager.c
parent948a7be7f7093a7df0b54df33a649f92be929f9b (diff)
downloadgtk+-d02f884d225e55c0e4bbe30bd2c57a011b4c8f53.tar.gz
Oops, reorder the bookmarks list correctly
Signed-off-by: Federico Mena Quintero <federico@gnome.org>
Diffstat (limited to 'gtk/gtkbookmarksmanager.c')
-rw-r--r--gtk/gtkbookmarksmanager.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/gtk/gtkbookmarksmanager.c b/gtk/gtkbookmarksmanager.c
index 4cd46f9a18..4341c38ce0 100644
--- a/gtk/gtkbookmarksmanager.c
+++ b/gtk/gtkbookmarksmanager.c
@@ -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;