Implement bookmark reordering, at least the core

The drag-and-drop part is missing; that still needs de-nautilus-ifying.
Signed-off-by: Federico Mena Quintero's avatarFederico Mena Quintero <federico@gnome.org>
parent 8b1eb6db
......@@ -382,6 +382,55 @@ _gtk_bookmarks_manager_remove_bookmark (GtkBookmarksManager *manager,
return TRUE;
}
gboolean
_gtk_bookmarks_manager_reorder_bookmark (GtkBookmarksManager *manager,
GFile *file,
gint new_position,
GError **error)
{
GSList *link;
GFile *bookmarks_file;
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (!manager->bookmarks)
return FALSE;
link = find_bookmark_link_for_file (manager->bookmarks, file);
if (link)
{
GtkBookmark *bookmark = link->data;
manager->bookmarks = g_slist_remove_link (manager->bookmarks, link);
g_slist_free_1 (link);
manager->bookmarks = g_slist_insert (manager->bookmarks, bookmark, new_position);
}
else
{
gchar *uri = g_file_get_uri (file);
g_set_error (error,
GTK_FILE_CHOOSER_ERROR,
GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
"%s does not exist in the bookmarks list",
uri);
g_free (uri);
return FALSE;
}
bookmarks_file = get_bookmarks_file ();
save_bookmarks (bookmarks_file, manager->bookmarks);
g_object_unref (bookmarks_file);
notify_changed (manager);
return TRUE;
}
gchar *
_gtk_bookmarks_manager_get_bookmark_label (GtkBookmarksManager *manager,
GFile *file)
......
......@@ -64,6 +64,11 @@ gboolean _gtk_bookmarks_manager_remove_bookmark (GtkBookmarksManager *manager,
GFile *file,
GError **error);
gboolean _gtk_bookmarks_manager_reorder_bookmark (GtkBookmarksManager *manager,
GFile *file,
gint new_position,
GError **error);
gchar * _gtk_bookmarks_manager_get_bookmark_label (GtkBookmarksManager *manager,
GFile *file);
......
......@@ -32,6 +32,8 @@
*
* * Fix FIXMEs
*
* * Grep for "NULL-GError" and see if they should be taken care of
*
* * Nautilus needs to use gtk_places_sidebar_set_uri() instead of built-in
* notification from the NautilusWindowSlot.
*/
......@@ -1437,10 +1439,9 @@ static void
reorder_bookmarks (GtkPlacesSidebar *sidebar,
int new_position)
{
#if DO_NOT_COMPILE
GtkTreeIter iter;
PlaceType type;
int old_position;
char *uri;
GFile *file;
/* Get the selected path */
if (!get_selected_iter (sidebar, &iter)) {
......@@ -1448,19 +1449,14 @@ reorder_bookmarks (GtkPlacesSidebar *sidebar,
}
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
PLACES_SIDEBAR_COLUMN_INDEX, &old_position,
PLACES_SIDEBAR_COLUMN_URI, &uri,
-1);
if (type != PLACES_BOOKMARK ||
old_position < 0 ||
old_position >= nautilus_bookmark_list_length (sidebar->bookmarks)) {
return;
}
file = g_file_new_for_uri (uri);
_gtk_bookmarks_manager_reorder_bookmark (sidebar->bookmarks_manager, file, new_position, NULL); /* NULL-GError */
nautilus_bookmark_list_move_item (sidebar->bookmarks, old_position,
new_position);
#endif
g_object_unref (file);
g_free (uri);
}
static void
......
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