Added a "position" argument.

2004-02-27  Federico Mena Quintero  <federico@ximian.com>

	* 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.
This commit is contained in:
Federico Mena Quintero 2004-02-27 20:48:22 +00:00 committed by Federico Mena Quintero
parent cc7c7d2263
commit c9e88e4e67
9 changed files with 171 additions and 41 deletions

View File

@ -1,3 +1,23 @@
2004-02-27 Federico Mena Quintero <federico@ximian.com>
* 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 <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_relayout):

View File

@ -1,3 +1,23 @@
2004-02-27 Federico Mena Quintero <federico@ximian.com>
* 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 <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_relayout):

View File

@ -1,3 +1,23 @@
2004-02-27 Federico Mena Quintero <federico@ximian.com>
* 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 <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_relayout):

View File

@ -1,3 +1,23 @@
2004-02-27 Federico Mena Quintero <federico@ximian.com>
* 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 <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_relayout):

View File

@ -1,3 +1,23 @@
2004-02-27 Federico Mena Quintero <federico@ximian.com>
* 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 <maclas@gmx.de>
* gtk/gtkcombobox.c (gtk_combo_box_relayout):

View File

@ -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);
}
}

View File

@ -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,
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.

View File

@ -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,

View File

@ -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,
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,18 +1103,24 @@ gtk_file_system_unix_add_bookmark (GtkFileSystem *file_system,
bookmark = l->data;
if (strcmp (bookmark, uri) == 0)
break;
{
g_set_error (error,
GTK_FILE_SYSTEM_ERROR,
GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS,
"%s already exists in the bookmarks list",
uri);
goto out;
}
}
if (!l)
{
bookmarks = g_slist_append (bookmarks, g_strdup (uri));
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;
}
if (l)
{
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);
}
else
result = TRUE;
goto out;
}
}
g_set_error (error,
GTK_FILE_SYSTEM_ERROR,
GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
"%s does not exist in the bookmarks list",
uri);
out:
g_free (uri);
bookmark_list_free (bookmarks);
if (result)
g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
return result;
}