[nautilus] places-sidebar: allow dropping of files to bookmarks
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] places-sidebar: allow dropping of files to bookmarks
- Date: Mon, 11 Jun 2012 17:25:32 +0000 (UTC)
commit 8151dc038c78c8dfc5106d80217ae3e38491ad61
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Jun 11 13:20:20 2012 -0400
places-sidebar: allow dropping of files to bookmarks
Change the way DnD works in the places sidebar.
After this commit, DnD on the bookmarks area will always mean
"copy/move the DnD source into the bookmark" instead of "add a bookmark
to this location" (DnD of bookmark rows in their section will still
reorder them), since that's the most common action you want to do.
This also makes it consistent with the default action obtained by
dropping on the built-in places below.
https://bugzilla.gnome.org/show_bug.cgi?id=645353
src/nautilus-places-sidebar.c | 108 ++++-------------------------------------
1 files changed, 10 insertions(+), 98 deletions(-)
---
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index 853e7b4..73223dc 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -1096,11 +1096,12 @@ compute_drop_position (GtkTreeView *tree_view,
PLACES_SIDEBAR_COLUMN_SECTION_TYPE, §ion_type,
-1);
- if (place_type == PLACES_HEADING && section_type != SECTION_BOOKMARKS) {
+ if (section_type != SECTION_BOOKMARKS &&
+ place_type == PLACES_HEADING) {
/* never drop on headings, but special case the bookmarks heading,
- * so we can drop bookmarks in between it and the first item.
+ * so we can drop bookmarks in between it and the first item when
+ * reordering.
*/
-
gtk_tree_path_free (*path);
*path = NULL;
@@ -1111,27 +1112,20 @@ compute_drop_position (GtkTreeView *tree_view,
sidebar->drag_data_received &&
sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
/* don't allow dropping bookmarks into non-bookmark areas */
-
gtk_tree_path_free (*path);
*path = NULL;
return FALSE;
}
- if (section_type == SECTION_BOOKMARKS) {
+ if (sidebar->drag_data_received &&
+ sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
+ /* bookmark rows can only be reordered */
*pos = GTK_TREE_VIEW_DROP_AFTER;
} else {
- /* non-bookmark shortcuts can only be dragged into */
*pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
}
- if (*pos != GTK_TREE_VIEW_DROP_BEFORE &&
- sidebar->drag_data_received &&
- sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
- /* bookmark rows are never dragged into other bookmark rows */
- *pos = GTK_TREE_VIEW_DROP_AFTER;
- }
-
return TRUE;
}
@@ -1168,36 +1162,6 @@ free_drag_data (NautilusPlacesSidebar *sidebar)
}
static gboolean
-can_accept_file_as_bookmark (NautilusFile *file)
-{
- return (nautilus_file_is_directory (file) &&
- !is_built_in_bookmark (file));
-}
-
-static gboolean
-can_accept_items_as_bookmarks (const GList *items)
-{
- int max;
- char *uri;
- NautilusFile *file;
-
- /* Iterate through selection checking if item will get accepted as a bookmark.
- * If more than 100 items selected, return an over-optimistic result.
- */
- for (max = 100; items != NULL && max >= 0; items = items->next, max--) {
- uri = ((NautilusDragSelectionItem *)items->data)->uri;
- file = nautilus_file_get_by_uri (uri);
- if (!can_accept_file_as_bookmark (file)) {
- nautilus_file_unref (file);
- return FALSE;
- }
- nautilus_file_unref (file);
- }
-
- return TRUE;
-}
-
-static gboolean
drag_motion_callback (GtkTreeView *tree_view,
GdkDragContext *context,
int x,
@@ -1225,13 +1189,10 @@ drag_motion_callback (GtkTreeView *tree_view,
goto out;
}
- if (pos == GTK_TREE_VIEW_DROP_BEFORE ||
- pos == GTK_TREE_VIEW_DROP_AFTER ) {
+ if (pos == GTK_TREE_VIEW_DROP_AFTER ) {
if (sidebar->drag_data_received &&
sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
action = GDK_ACTION_MOVE;
- } else if (can_accept_items_as_bookmarks (sidebar->drag_list)) {
- action = GDK_ACTION_COPY;
} else {
action = 0;
}
@@ -1279,54 +1240,10 @@ drag_leave_callback (GtkTreeView *tree_view,
NautilusPlacesSidebar *sidebar)
{
free_drag_data (sidebar);
- gtk_tree_view_set_drag_dest_row (tree_view, NULL, GTK_TREE_VIEW_DROP_BEFORE);
+ gtk_tree_view_set_drag_dest_row (tree_view, NULL, 0);
g_signal_stop_emission_by_name (tree_view, "drag-leave");
}
-/* Parses a "text/uri-list" string and inserts its URIs as bookmarks */
-static void
-bookmarks_drop_uris (NautilusPlacesSidebar *sidebar,
- GtkSelectionData *selection_data,
- int position)
-{
- NautilusBookmark *bookmark;
- NautilusFile *file;
- char *uri;
- char **uris;
- int i;
- GFile *location;
-
- uris = gtk_selection_data_get_uris (selection_data);
- if (!uris)
- return;
-
- for (i = 0; uris[i]; i++) {
- uri = uris[i];
- file = nautilus_file_get_by_uri (uri);
-
- if (!can_accept_file_as_bookmark (file)) {
- nautilus_file_unref (file);
- continue;
- }
-
- uri = nautilus_file_get_drop_target_uri (file);
- location = g_file_new_for_uri (uri);
- nautilus_file_unref (file);
-
- bookmark = nautilus_bookmark_new (location, NULL, NULL);
-
- if (!nautilus_bookmark_list_contains (sidebar->bookmarks, bookmark)) {
- nautilus_bookmark_list_insert_item (sidebar->bookmarks, bookmark, position++);
- }
-
- g_object_unref (location);
- g_object_unref (bookmark);
- g_free (uri);
- }
-
- g_strfreev (uris);
-}
-
static GList *
uri_list_from_selection (GList *selection)
{
@@ -1457,8 +1374,7 @@ drag_data_received_callback (GtkWidget *widget,
success = FALSE;
- if (tree_pos == GTK_TREE_VIEW_DROP_BEFORE ||
- tree_pos == GTK_TREE_VIEW_DROP_AFTER) {
+ if (tree_pos == GTK_TREE_VIEW_DROP_AFTER) {
model = gtk_tree_view_get_model (tree_view);
if (!gtk_tree_model_get_iter (model, &iter, tree_path)) {
@@ -1481,10 +1397,6 @@ drag_data_received_callback (GtkWidget *widget,
}
switch (info) {
- case TEXT_URI_LIST:
- bookmarks_drop_uris (sidebar, selection_data, position);
- success = TRUE;
- break;
case GTK_TREE_MODEL_ROW:
reorder_bookmarks (sidebar, position);
success = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]