From c9e88e4e67c7dac0a59dbb5d296247725415da0e Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 27 Feb 2004 20:48:22 +0000 Subject: [PATCH] Added a "position" argument. 2004-02-27 Federico Mena Quintero * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a "position" argument. * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. (struct _GtkFileSystemIface): Added a "position" argument to the ::insert_bookmark() method. * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark): Updated; renamed from gtk_file_system_unix_add_bookmark(). Return an error if the path already exists in the bookmarks list. (gtk_file_system_unix_remove_bookmark): Return an error if the path does not exist in the bookmarks list. * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path): For now, use gtk_file_system_insert_bookmark() with -1 for the position. DnD will come next. --- ChangeLog | 20 ++++++++++ ChangeLog.pre-2-10 | 20 ++++++++++ ChangeLog.pre-2-4 | 20 ++++++++++ ChangeLog.pre-2-6 | 20 ++++++++++ ChangeLog.pre-2-8 | 20 ++++++++++ gtk/gtkfilechooserdefault.c | 2 +- gtk/gtkfilesystem.c | 30 ++++++++++----- gtk/gtkfilesystem.h | 7 +++- gtk/gtkfilesystemunix.c | 73 +++++++++++++++++++++++-------------- 9 files changed, 171 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6187b603fa..06e3b77e98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2004-02-27 Federico Mena Quintero + + * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a + "position" argument. + + * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for + GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. + (struct _GtkFileSystemIface): Added a "position" argument to the + ::insert_bookmark() method. + + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark): + Updated; renamed from gtk_file_system_unix_add_bookmark(). Return + an error if the path already exists in the bookmarks list. + (gtk_file_system_unix_remove_bookmark): Return an error if the + path does not exist in the bookmarks list. + + * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path): + For now, use gtk_file_system_insert_bookmark() with -1 for the + position. DnD will come next. + Fri Feb 27 21:42:28 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_relayout): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 6187b603fa..06e3b77e98 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,23 @@ +2004-02-27 Federico Mena Quintero + + * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a + "position" argument. + + * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for + GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. + (struct _GtkFileSystemIface): Added a "position" argument to the + ::insert_bookmark() method. + + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark): + Updated; renamed from gtk_file_system_unix_add_bookmark(). Return + an error if the path already exists in the bookmarks list. + (gtk_file_system_unix_remove_bookmark): Return an error if the + path does not exist in the bookmarks list. + + * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path): + For now, use gtk_file_system_insert_bookmark() with -1 for the + position. DnD will come next. + Fri Feb 27 21:42:28 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_relayout): diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 6187b603fa..06e3b77e98 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,23 @@ +2004-02-27 Federico Mena Quintero + + * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a + "position" argument. + + * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for + GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. + (struct _GtkFileSystemIface): Added a "position" argument to the + ::insert_bookmark() method. + + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark): + Updated; renamed from gtk_file_system_unix_add_bookmark(). Return + an error if the path already exists in the bookmarks list. + (gtk_file_system_unix_remove_bookmark): Return an error if the + path does not exist in the bookmarks list. + + * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path): + For now, use gtk_file_system_insert_bookmark() with -1 for the + position. DnD will come next. + Fri Feb 27 21:42:28 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_relayout): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 6187b603fa..06e3b77e98 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,23 @@ +2004-02-27 Federico Mena Quintero + + * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a + "position" argument. + + * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for + GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. + (struct _GtkFileSystemIface): Added a "position" argument to the + ::insert_bookmark() method. + + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark): + Updated; renamed from gtk_file_system_unix_add_bookmark(). Return + an error if the path already exists in the bookmarks list. + (gtk_file_system_unix_remove_bookmark): Return an error if the + path does not exist in the bookmarks list. + + * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path): + For now, use gtk_file_system_insert_bookmark() with -1 for the + position. DnD will come next. + Fri Feb 27 21:42:28 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_relayout): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 6187b603fa..06e3b77e98 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,23 @@ +2004-02-27 Federico Mena Quintero + + * gtk/gtkfilesystem.c (gtk_file_system_insert_bookmark): Added a + "position" argument. + + * gtk/gtkfilesystem.h (GtkFileSystemError): Added value for + GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. + (struct _GtkFileSystemIface): Added a "position" argument to the + ::insert_bookmark() method. + + * gtk/gtkfilesystemunix.c (gtk_file_system_unix_insert_bookmark): + Updated; renamed from gtk_file_system_unix_add_bookmark(). Return + an error if the path already exists in the bookmarks list. + (gtk_file_system_unix_remove_bookmark): Return an error if the + path does not exist in the bookmarks list. + + * gtk/gtkfilechooserdefault.c (shortcuts_add_bookmark_from_path): + For now, use gtk_file_system_insert_bookmark() with -1 for the + position. DnD will come next. + Fri Feb 27 21:42:28 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_relayout): diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 47012301a6..5055850463 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1232,7 +1232,7 @@ shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl, else { error = NULL; - if (!gtk_file_system_add_bookmark (impl->file_system, path, &error)) + if (!gtk_file_system_insert_bookmark (impl->file_system, path, -1, &error)) error_could_not_add_bookmark_dialog (impl, path, error); } } diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c index 248017c728..8be7443bbf 100644 --- a/gtk/gtkfilesystem.c +++ b/gtk/gtkfilesystem.c @@ -665,36 +665,46 @@ gtk_file_system_render_icon (GtkFileSystem *file_system, } /** - * gtk_file_system_add_bookmark: + * gtk_file_system_insert_bookmark: * @file_system: a #GtkFileSystem - * @bookmark: path of the bookmark to add + * @path: path of the bookmark to add + * @position: index in the bookmarks list at which the @path should be inserted; use 0 + * for the beginning, and -1 or the number of bookmarks itself for the end of the list. * @error: location to store error, or %NULL * - * Adds a bookmark folder to the user's bookmarks list. If the operation succeeds, - * the "bookmarks_changed" signal will be emitted. + * Adds a path for a folder to the user's bookmarks list. If the operation + * succeeds, the "bookmarks_changed" signal will be emitted. Bookmark paths are + * unique; if you try to insert a @path that already exists, the operation will + * fail and the @error will be set to #GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS. To + * reorder the list of bookmarks, use gtk_file_system_remove_bookmark() to + * remove the path in question, and call gtk_file_system_insert_bookmark() with + * the new position for the path. * * Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter case, * the @error value will be set. **/ gboolean -gtk_file_system_add_bookmark (GtkFileSystem *file_system, - const GtkFilePath *path, - GError **error) +gtk_file_system_insert_bookmark (GtkFileSystem *file_system, + const GtkFilePath *path, + gint position, + GError **error) { g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE); g_return_val_if_fail (path != NULL, FALSE); - return GTK_FILE_SYSTEM_GET_IFACE (file_system)->add_bookmark (file_system, path, error); + return GTK_FILE_SYSTEM_GET_IFACE (file_system)->insert_bookmark (file_system, path, position, error); } /** * gtk_file_system_remove_bookmark: * @file_system: a #GtkFileSystem - * @bookmark: path of the bookmark to remove + * @path: path of the bookmark to remove * @error: location to store error, or %NULL * * Removes a bookmark folder from the user's bookmarks list. If the operation - * succeeds, the "bookmarks_changed" signal will be emitted. + * succeeds, the "bookmarks_changed" signal will be emitted. If you try to remove + * a @path which does not exist in the bookmarks list, the operation will fail + * and the @error will be set to GTK_FILE_SYSTEM_ERROR_NONEXISTENT. * * Return value: TRUE if the operation succeeds, FALSE otherwise. In the latter * case, the @error value will be set. diff --git a/gtk/gtkfilesystem.h b/gtk/gtkfilesystem.h index 3dc914b2c9..8503ff1ea0 100644 --- a/gtk/gtkfilesystem.h +++ b/gtk/gtkfilesystem.h @@ -70,6 +70,7 @@ typedef enum GTK_FILE_SYSTEM_ERROR_INVALID_URI, GTK_FILE_SYSTEM_ERROR_BAD_FILENAME, GTK_FILE_SYSTEM_ERROR_FAILED, + GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS } GtkFileSystemError; GQuark gtk_file_system_error_quark (void); @@ -185,8 +186,9 @@ struct _GtkFileSystemIface /* Bookmarks */ - gboolean (*add_bookmark) (GtkFileSystem *file_system, + gboolean (*insert_bookmark) (GtkFileSystem *file_system, const GtkFilePath *path, + gint position, GError **error); gboolean (*remove_bookmark) (GtkFileSystem *file_system, const GtkFilePath *path, @@ -260,8 +262,9 @@ GdkPixbuf *gtk_file_system_render_icon (GtkFileSystem *file_system, gint pixel_size, GError **error); -gboolean gtk_file_system_add_bookmark (GtkFileSystem *file_system, +gboolean gtk_file_system_insert_bookmark (GtkFileSystem *file_system, const GtkFilePath *path, + gint position, GError **error); gboolean gtk_file_system_remove_bookmark (GtkFileSystem *file_system, const GtkFilePath *path, diff --git a/gtk/gtkfilesystemunix.c b/gtk/gtkfilesystemunix.c index 0117ab335f..2becd2dfeb 100644 --- a/gtk/gtkfilesystemunix.c +++ b/gtk/gtkfilesystemunix.c @@ -160,8 +160,9 @@ static GdkPixbuf *gtk_file_system_unix_render_icon (GtkFileSystem *file_syst gint pixel_size, GError **error); -static gboolean gtk_file_system_unix_add_bookmark (GtkFileSystem *file_system, +static gboolean gtk_file_system_unix_insert_bookmark (GtkFileSystem *file_system, const GtkFilePath *path, + gint position, GError **error); static gboolean gtk_file_system_unix_remove_bookmark (GtkFileSystem *file_system, const GtkFilePath *path, @@ -275,7 +276,7 @@ gtk_file_system_unix_iface_init (GtkFileSystemIface *iface) iface->uri_to_path = gtk_file_system_unix_uri_to_path; iface->filename_to_path = gtk_file_system_unix_filename_to_path; iface->render_icon = gtk_file_system_unix_render_icon; - iface->add_bookmark = gtk_file_system_unix_add_bookmark; + iface->insert_bookmark = gtk_file_system_unix_insert_bookmark; iface->remove_bookmark = gtk_file_system_unix_remove_bookmark; iface->list_bookmarks = gtk_file_system_unix_list_bookmarks; } @@ -1069,11 +1070,13 @@ bookmark_list_write (GSList *bookmarks, GError **error) } static gboolean -gtk_file_system_unix_add_bookmark (GtkFileSystem *file_system, - const GtkFilePath *path, - GError **error) +gtk_file_system_unix_insert_bookmark (GtkFileSystem *file_system, + const GtkFilePath *path, + gint position, + GError **error) { GSList *bookmarks; + int num_bookmarks; GSList *l; char *uri; gboolean result; @@ -1087,6 +1090,9 @@ gtk_file_system_unix_add_bookmark (GtkFileSystem *file_system, return FALSE; } + num_bookmarks = g_slist_length (bookmarks); + g_return_val_if_fail (position >= -1 && position <= num_bookmarks, FALSE); + result = FALSE; uri = gtk_file_system_unix_path_to_uri (file_system, path); @@ -1097,19 +1103,25 @@ gtk_file_system_unix_add_bookmark (GtkFileSystem *file_system, bookmark = l->data; if (strcmp (bookmark, uri) == 0) - break; - } - - if (!l) - { - bookmarks = g_slist_append (bookmarks, g_strdup (uri)); - if (bookmark_list_write (bookmarks, error)) { - result = TRUE; - g_signal_emit_by_name (file_system, "bookmarks-changed", 0); + g_set_error (error, + GTK_FILE_SYSTEM_ERROR, + GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS, + "%s already exists in the bookmarks list", + uri); + goto out; } } + bookmarks = g_slist_insert (bookmarks, g_strdup (uri), position); + if (bookmark_list_write (bookmarks, error)) + { + result = TRUE; + g_signal_emit_by_name (file_system, "bookmarks-changed", 0); + } + + out: + g_free (uri); bookmark_list_free (bookmarks); @@ -1139,27 +1151,32 @@ gtk_file_system_unix_remove_bookmark (GtkFileSystem *file_system, bookmark = l->data; if (strcmp (bookmark, uri) == 0) - break; + { + g_free (l->data); + bookmarks = g_slist_remove_link (bookmarks, l); + g_slist_free_1 (l); + + if (bookmark_list_write (bookmarks, error)) + { + result = TRUE; + g_signal_emit_by_name (file_system, "bookmarks-changed", 0); + } + + goto out; + } } - if (l) - { - g_free (l->data); - bookmarks = g_slist_remove_link (bookmarks, l); - g_slist_free_1 (l); + g_set_error (error, + GTK_FILE_SYSTEM_ERROR, + GTK_FILE_SYSTEM_ERROR_NONEXISTENT, + "%s does not exist in the bookmarks list", + uri); - if (bookmark_list_write (bookmarks, error)) - result = TRUE; - } - else - result = TRUE; + out: g_free (uri); bookmark_list_free (bookmarks); - if (result) - g_signal_emit_by_name (file_system, "bookmarks-changed", 0); - return result; }