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:
committed by
Federico Mena Quintero
parent
cc7c7d2263
commit
c9e88e4e67
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user