[gtk+/places-sidebar] Implement bookmark reordering, at least the core
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/places-sidebar] Implement bookmark reordering, at least the core
- Date: Tue, 11 Sep 2012 20:18:30 +0000 (UTC)
commit 6ed2217eda24172e9c21c2ecec56c57c5804b02f
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Sep 11 15:17:03 2012 -0500
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 <federico gnome org>
gtk/gtkbookmarksmanager.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkbookmarksmanager.h | 5 ++++
gtk/gtkplacessidebar.c | 22 ++++++++------------
3 files changed, 63 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkbookmarksmanager.c b/gtk/gtkbookmarksmanager.c
index aa55dac..4cd46f9 100644
--- a/gtk/gtkbookmarksmanager.c
+++ b/gtk/gtkbookmarksmanager.c
@@ -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)
diff --git a/gtk/gtkbookmarksmanager.h b/gtk/gtkbookmarksmanager.h
index 8c00052..005a315 100644
--- a/gtk/gtkbookmarksmanager.h
+++ b/gtk/gtkbookmarksmanager.h
@@ -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);
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 3477764..1f9c30a 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]