[PATCH] - Add drag drop of bookmarks to places sidebar
- From: Jamie McCracken <jamiemcc blueyonder co uk>
- To: "nautilus-list gnome org" <nautilus-list gnome org>
- Cc: Alexander Larsson <alexl redhat com>
- Subject: [PATCH] - Add drag drop of bookmarks to places sidebar
- Date: Fri, 08 Jul 2005 16:13:51 +0100
Attached is patch to allow drag drop of folder uris to blank rows in the
places sidebar.
Also added some ints to sidebar for later use.
--
Mr Jamie McCracken
http://www.advogato.org/person/jamiemcc/
Index: src/nautilus-places-sidebar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-places-sidebar.c,v
retrieving revision 1.1
diff -u -r1.1 nautilus-places-sidebar.c
--- src/nautilus-places-sidebar.c 1 Jul 2005 14:13:49 -0000 1.1
+++ src/nautilus-places-sidebar.c 8 Jul 2005 15:08:45 -0000
@@ -28,12 +28,14 @@
#include <eel/eel-glib-extensions.h>
#include <eel/eel-preferences.h>
#include <eel/eel-string.h>
+#include <eel/eel-stock-dialogs.h>
#include <gtk/gtkalignment.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkvbox.h>
#include <gtk/gtkcellrendererpixbuf.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkliststore.h>
+#include <gtk/gtkmessagedialog.h>
#include <gtk/gtksizegroup.h>
#include <gtk/gtkstock.h>
#include <gtk/gtktreemodel.h>
@@ -62,6 +64,9 @@
GtkListStore *store;
NautilusWindowInfo *window;
NautilusBookmarkList *bookmarks;
+ int bookmark_count;
+ int bookmark_index;
+ int place_count;
} NautilusPlacesSidebar;
typedef struct {
@@ -92,6 +97,12 @@
PLACES_SEPARATOR
} PlaceType;
+static const GtkTargetEntry dest_targets[] = {
+ { "text/uri-list", 0, 0}
+};
+
+#define MAX_BOOKMARK_LENGTH 80
+
static void nautilus_places_sidebar_iface_init (NautilusSidebarIface *iface);
static void sidebar_provider_iface_init (NautilusSidebarProviderIface *iface);
static GType nautilus_places_sidebar_provider_get_type (void);
@@ -104,7 +115,6 @@
G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SIDEBAR_PROVIDER,
sidebar_provider_iface_init));
-
static GtkTreeIter
add_place (GtkListStore *store, PlaceType place_type,
const char *name, const char *icon, const char *uri)
@@ -135,12 +145,13 @@
GnomeVFSVolumeMonitor *volume_monitor;
GList *volumes, *l;
GnomeVFSVolume *volume;
- int bookmark_count, index;
+ int place_count, index;
char *location, *icon, *mount_uri, *name, *desktop_path;
selection = gtk_tree_view_get_selection (sidebar->tree_view);
gtk_list_store_clear (sidebar->store);
location = nautilus_window_info_get_current_location (sidebar->window);
+ place_count = 0;
/* add built in bookmarks */
@@ -150,6 +161,7 @@
mount_uri = gnome_vfs_get_uri_from_local_path (g_get_home_dir ());
last_iter = add_place (sidebar->store, PLACES_BUILT_IN,
_("Home"), "gnome-fs-home", mount_uri);
+ place_count++;
if (strcmp (location, mount_uri) == 0) {
gtk_tree_selection_select_iter (selection, &last_iter);
}
@@ -159,6 +171,7 @@
mount_uri = gnome_vfs_get_uri_from_local_path (desktop_path);
last_iter = add_place (sidebar->store, PLACES_BUILT_IN,
_("Desktop"), "gnome-fs-desktop", mount_uri);
+ place_count++;
if (strcmp (location, mount_uri) == 0) {
gtk_tree_selection_select_iter (selection, &last_iter);
}
@@ -168,6 +181,7 @@
mount_uri = "file:///"; // No need to strdup
last_iter = add_place (sidebar->store, PLACES_BUILT_IN,
_("Filesystem"), "gnome-fs-blockdev", mount_uri);
+ place_count++;
if (strcmp (location, mount_uri) == 0) {
gtk_tree_selection_select_iter (selection, &last_iter);
}
@@ -188,6 +202,7 @@
name = gnome_vfs_volume_get_display_name (volume);
last_iter = add_place (sidebar->store, PLACES_MOUNTED_VOLUME,
name, icon, mount_uri);
+ place_count++;
if (strcmp (location, mount_uri) == 0) {
gtk_tree_selection_select_iter (selection, &last_iter);
}
@@ -206,11 +221,11 @@
gtk_list_store_set (sidebar->store, &iter,
PLACES_SIDEBAR_COLUMN_ROW_TYPE, PLACES_SEPARATOR,
-1);
-
+
/* add bookmarks */
-
- bookmark_count = nautilus_bookmark_list_length (sidebar->bookmarks);
- for (index = 0; index < bookmark_count; ++index) {
+ sidebar->bookmark_index = place_count;
+ sidebar->bookmark_count = nautilus_bookmark_list_length (sidebar->bookmarks);
+ for (index = 0; index < sidebar->bookmark_count; ++index) {
bookmark = nautilus_bookmark_list_item_at (sidebar->bookmarks, index);
name = nautilus_bookmark_get_name (bookmark);
@@ -218,6 +233,7 @@
mount_uri = nautilus_bookmark_get_uri (bookmark);
last_iter = add_place (sidebar->store, PLACES_BOOKMARK,
name, icon, mount_uri);
+ place_count++;
if (strcmp (location, mount_uri) == 0) {
gtk_tree_selection_select_iter (selection, &last_iter);
}
@@ -225,9 +241,11 @@
g_free (icon);
g_free (mount_uri);
}
-
+
g_free (location);
+ sidebar->place_count = place_count;
+
}
static gboolean
@@ -361,6 +379,80 @@
}
+static gboolean
+is_uri_directory (const char *uri)
+{
+ gboolean result;
+ NautilusFile *file;
+
+ file = nautilus_file_get (uri);
+ if (!file) {
+ return FALSE;
+ }
+ result = nautilus_file_is_directory (file);
+ nautilus_file_unref (file);
+ return result;
+}
+
+static void
+drag_data_received_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time_,
+ gpointer user_data)
+{
+ NautilusPlacesSidebar *sidebar;
+ GtkListStore *store;
+ gboolean abort_drag_drop;
+
+ sidebar = NAUTILUS_PLACES_SIDEBAR (user_data);
+ store = GTK_LIST_STORE (gtk_tree_view_get_model (sidebar->tree_view));
+ abort_drag_drop = FALSE;
+
+ if (!gtk_tree_view_get_path_at_pos (sidebar->tree_view, x, y, NULL, NULL, NULL, NULL)) {
+ if (selection_data->target == gdk_atom_intern ("text/uri-list", FALSE)) {
+
+ char **uris;
+ int i;
+
+ uris = g_uri_list_extract_uris (selection_data->data);
+ for (i = 0; uris[i]; i++) {
+ char *uri;
+ char *name;
+ NautilusBookmark *bookmark;
+
+ uri = uris[i];
+ if (!is_uri_directory (uri)) {
+ abort_drag_drop = TRUE;
+ break;
+ }
+ name = nautilus_compute_title_for_uri (uri);
+ name = eel_str_middle_truncate (name, MAX_BOOKMARK_LENGTH);
+ bookmark = nautilus_bookmark_new (uri, name);
+ g_free (name);
+ if (!nautilus_bookmark_list_contains (sidebar->bookmarks, bookmark)) {
+ nautilus_bookmark_list_append (sidebar->bookmarks, bookmark);
+ }
+ }
+ g_strfreev (uris);
+ if (abort_drag_drop) {
+ eel_run_simple_dialog (
+ GTK_WIDGET (sidebar),
+ FALSE,
+ GTK_MESSAGE_ERROR,
+ _("Only folders can be set as bookmarks"),
+ _("You have attempted to add a non-folder as a bookmark"),
+ _("Bookmark Error"),
+ GTK_STOCK_OK, NULL);
+ }
+ }
+ }
+ g_signal_stop_emission_by_name (widget, "drag-data-received");
+}
+
static void
nautilus_places_sidebar_init (NautilusPlacesSidebar *sidebar)
{
@@ -433,10 +525,19 @@
selection = gtk_tree_view_get_selection (tree_view);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
+ gtk_drag_dest_set (GTK_WIDGET (tree_view),
+ GTK_DEST_DEFAULT_ALL,
+ dest_targets,
+ 1,
+ GDK_ACTION_COPY);
+
g_signal_connect_object
(tree_view, "row_activated",
G_CALLBACK (row_activated_callback), sidebar, 0);
+ g_signal_connect (tree_view, "drag-data-received",
+ G_CALLBACK (drag_data_received_callback), sidebar);
+
eel_preferences_add_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
click_policy_changed_callback,
sidebar);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]