nautilus-list-view.c 95.9 KB
Newer Older
1 2
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

3
/* fm-list-view.c - implementation of list view of directory.
4 5

   Copyright (C) 2000 Eazel, Inc.
Anders Carlsson's avatar
Anders Carlsson committed
6 7
   Copyright (C) 2001, 2002 Anders Carlsson <andersca@gnu.org>
   
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: John Sullivan <sullivan@eazel.com>
Anders Carlsson's avatar
Anders Carlsson committed
24
            Anders Carlsson <andersca@gnu.org>
25
	    David Emory Watson <dwatson@cs.ucr.edu>
26 27
*/

28
#include <config.h>
29
#include "nautilus-list-view.h"
30

31
#include "nautilus-list-model.h"
32
#include "nautilus-error-reporting.h"
33
#include "nautilus-view-dnd.h"
34 35
#include "nautilus-view-factory.h"

36
#include <string.h>
37
#include <eel/eel-vfs-extensions.h>
38
#include <eel/eel-gdk-extensions.h>
39
#include <eel/eel-glib-extensions.h>
40
#include <gdk/gdk.h>
41
#include <gdk/gdkkeysyms.h>
42
#include <gtk/gtk.h>
43
#include <glib/gi18n.h>
44
#include <glib-object.h>
45
#include <libnautilus-extension/nautilus-column-provider.h>
46
#include <libnautilus-private/nautilus-clipboard-monitor.h>
47 48
#include <libnautilus-private/nautilus-column-chooser.h>
#include <libnautilus-private/nautilus-column-utilities.h>
49
#include <libnautilus-private/nautilus-dnd.h>
50
#include <libnautilus-private/nautilus-file-dnd.h>
51 52
#include <libnautilus-private/nautilus-file-utilities.h>
#include <libnautilus-private/nautilus-ui-utilities.h>
53 54
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-metadata.h>
55
#include <libnautilus-private/nautilus-module.h>
56
#include <libnautilus-private/nautilus-tree-view-drag-dest.h>
57
#include <libnautilus-private/nautilus-clipboard.h>
58

59 60 61
#define DEBUG_FLAG NAUTILUS_DEBUG_LIST_VIEW
#include <libnautilus-private/nautilus-debug.h>

62
struct NautilusListViewDetails {
Anders Carlsson's avatar
Anders Carlsson committed
63
	GtkTreeView *tree_view;
64
	NautilusListModel *model;
65 66
	GtkActionGroup *list_action_group;
	guint list_merge_id;
67

68
	GtkTreeViewColumn   *file_name_column;
69
	int file_name_column_num;
70 71 72

	GtkCellRendererPixbuf *pixbuf_cell;
	GtkCellRendererText   *file_name_cell;
73
	GList *cells;
74
	GtkCellEditable *editable_widget;
75 76

	NautilusZoomLevel zoom_level;
77

78
	NautilusTreeViewDragDest *drag_dest;
79 80

	GtkTreePath *double_click_path[2]; /* Both clicks in a double click need to be on the same row */
81 82 83

	GtkTreePath *new_selection_path;   /* Path of the new selection after removing a file */

84 85
	GtkTreePath *hover_path;

86 87 88 89 90
	guint drag_button;
	int drag_x;
	int drag_y;

	gboolean drag_started;
91
	gboolean ignore_button_release;
92
	gboolean row_selected_on_button_down;
93
	gboolean menus_ready;
94
	gboolean active;
95 96 97
	
	GHashTable *columns;
	GtkWidget *column_editor;
98 99

	char *original_name;
100 101 102 103
	
	NautilusFile *renaming_file;
	gboolean rename_done;
	guint renaming_file_activate_timeout;
104

105 106
	gulong clipboard_handler_id;

107
	GQuark last_sort_attr;
Anders Carlsson's avatar
Anders Carlsson committed
108
};
109

110 111 112 113 114
struct SelectionForeachData {
	GList *list;
	GtkTreeSelection *selection;
};

115 116 117 118 119
/*
 * The row height should be large enough to not clip emblems.
 * Computing this would be costly, so we just choose a number
 * that works well with the set of emblems we've designed.
 */
Anders Carlsson's avatar
Anders Carlsson committed
120
#define LIST_VIEW_MINIMUM_ROW_HEIGHT	28
121

122 123 124
/* We wait two seconds after row is collapsed to unload the subdirectory */
#define COLLAPSE_TO_UNLOAD_DELAY 2

125 126 127
/* Wait for the rename to end when activating a file being renamed */
#define WAIT_FOR_RENAME_ON_ACTIVATE 200

128
static GdkCursor *              hand_cursor = NULL;
129

130 131
static GtkTargetList *          source_target_list = NULL;

132 133 134 135 136 137 138 139 140 141 142
static GList *nautilus_list_view_get_selection                   (NautilusView   *view);
static GList *nautilus_list_view_get_selection_for_file_transfer (NautilusView   *view);
static void   nautilus_list_view_set_zoom_level                  (NautilusListView        *view,
								  NautilusZoomLevel  new_level,
								  gboolean           always_set_level);
static void   nautilus_list_view_scroll_to_file                  (NautilusListView        *view,
								  NautilusFile      *file);
static void   nautilus_list_view_rename_callback                 (NautilusFile      *file,
								  GFile             *result_location,
								  GError            *error,
								  gpointer           callback_data);
143

Diego González's avatar
Diego González committed
144

145
G_DEFINE_TYPE (NautilusListView, nautilus_list_view, NAUTILUS_TYPE_VIEW);
146

147 148 149 150 151 152 153 154
static const char * default_trash_visible_columns[] = {
	"name", "size", "type", "trashed_on", "trash_orig_path", NULL
};

static const char * default_trash_columns_order[] = {
	"name", "size", "type", "trashed_on", "trash_orig_path", NULL
};

155 156 157
static const gchar*
get_default_sort_order (NautilusFile *file, gboolean *reversed)
{
158 159
	NautilusFileSortType default_sort_order;
	gboolean default_sort_reversed;
160
	const gchar *retval;
161 162 163 164 165 166 167 168 169 170
	const char *attributes[] = {
		"name", /* is really "manually" which doesn't apply to lists */
		"name",
		"size",
		"type",
		"date_modified",
		"date_accessed",
		"trashed_on",
		NULL
	};
171 172 173 174

	retval = nautilus_file_get_default_sort_attribute (file, reversed);

	if (retval == NULL) {
175 176 177 178 179 180 181
		default_sort_order = g_settings_get_enum (nautilus_preferences,
							  NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
		default_sort_reversed = g_settings_get_boolean (nautilus_preferences,
								NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);

		retval = attributes[default_sort_order];
		*reversed = default_sort_reversed;
182 183 184 185 186
	}

	return retval;
}

187
static void
Anders Carlsson's avatar
Anders Carlsson committed
188
list_selection_changed_callback (GtkTreeSelection *selection, gpointer user_data)
189
{
190
	NautilusView *view;
191

192
	view = NAUTILUS_VIEW (user_data);
193

194
	nautilus_view_notify_selection_changed (view);
195 196
}

197 198
/* Move these to eel? */

199
static void
200 201 202 203 204 205 206 207 208 209
tree_selection_foreach_set_boolean (GtkTreeModel *model,
				    GtkTreePath *path,
				    GtkTreeIter *iter,
				    gpointer callback_data)
{
	* (gboolean *) callback_data = TRUE;
}

static gboolean
tree_selection_not_empty (GtkTreeSelection *selection)
210
{
211
	gboolean not_empty;
212

213 214 215 216 217 218 219 220 221 222 223 224
	not_empty = FALSE;
	gtk_tree_selection_selected_foreach (selection,
					     tree_selection_foreach_set_boolean,
					     &not_empty);
	return not_empty;
}

static gboolean
tree_view_has_selection (GtkTreeView *view)
{
	return tree_selection_not_empty (gtk_tree_view_get_selection (view));
}
225

226 227 228 229 230 231 232
static void
preview_selected_items (NautilusListView *view)
{
	GList *file_list;
	
	file_list = nautilus_list_view_get_selection (NAUTILUS_VIEW (view));

233 234 235 236 237
	if (file_list != NULL) {
		nautilus_view_preview_files (NAUTILUS_VIEW (view),
					     file_list, NULL);
		nautilus_file_list_free (file_list);
	}
238 239
}

240
static void
241
activate_selected_items (NautilusListView *view)
242 243 244
{
	GList *file_list;
	
245
	file_list = nautilus_list_view_get_selection (NAUTILUS_VIEW (view));
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

	
	if (view->details->renaming_file) {
		/* We're currently renaming a file, wait until the rename is
		   finished, or the activation uri will be wrong */
		if (view->details->renaming_file_activate_timeout == 0) {
			view->details->renaming_file_activate_timeout =
				g_timeout_add (WAIT_FOR_RENAME_ON_ACTIVATE, (GSourceFunc) activate_selected_items, view);
		}
		return;
	}
	
	if (view->details->renaming_file_activate_timeout != 0) {
		g_source_remove (view->details->renaming_file_activate_timeout);
		view->details->renaming_file_activate_timeout = 0;
	}
	
263 264
	nautilus_view_activate_files (NAUTILUS_VIEW (view),
				      file_list,
265
				      0, TRUE);
266 267 268 269 270
	nautilus_file_list_free (file_list);

}

static void
271
activate_selected_items_alternate (NautilusListView *view,
272 273
				   NautilusFile *file,
				   gboolean open_in_tab)
274 275
{
	GList *file_list;
276
	NautilusWindowOpenFlags flags;
277

278 279
	flags = 0;

280 281
	if (open_in_tab) {
		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
282
	} else {
283
		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
284
	}
285 286 287 288 289

	if (file != NULL) {
		nautilus_file_ref (file);
		file_list = g_list_prepend (NULL, file);
	} else {
290
		file_list = nautilus_list_view_get_selection (NAUTILUS_VIEW (view));
291
	}
292 293 294 295
	nautilus_view_activate_files (NAUTILUS_VIEW (view),
				      file_list,
				      flags,
				      TRUE);
296 297 298 299 300 301 302 303 304 305
	nautilus_file_list_free (file_list);

}

static gboolean
button_event_modifies_selection (GdkEventButton *event)
{
	return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
}

306 307 308 309 310 311 312
static int
get_click_policy (void)
{
	return g_settings_get_enum (nautilus_preferences,
				    NAUTILUS_PREFERENCES_CLICK_POLICY);
}

313
static void
314 315
nautilus_list_view_did_not_drag (NautilusListView *view,
				 GdkEventButton *event)
316 317 318 319 320 321 322 323 324 325
{
	GtkTreeView *tree_view;
	GtkTreeSelection *selection;
	GtkTreePath *path;
	
	tree_view = view->details->tree_view;
	selection = gtk_tree_view_get_selection (tree_view);

	if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
					   &path, NULL, NULL, NULL)) {
326 327 328
		if ((event->button == 1 || event->button == 2)
		    && ((event->state & GDK_CONTROL_MASK) != 0 ||
			(event->state & GDK_SHIFT_MASK) == 0)
329
		    && view->details->row_selected_on_button_down) {
330 331 332 333 334 335
			if (!button_event_modifies_selection (event)) {
				gtk_tree_selection_unselect_all (selection);
				gtk_tree_selection_select_path (selection, path);
			} else {
				gtk_tree_selection_unselect_path (selection, path);
			}
336 337
		}

338
		if ((get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
339
		    && !button_event_modifies_selection(event)) {
340 341 342
			if (event->button == 1) {
				activate_selected_items (view);
			} else if (event->button == 2) {
343
				activate_selected_items_alternate (view, NULL, TRUE);
344
			}
345 346 347 348 349 350 351 352 353 354 355 356 357
		}
		gtk_tree_path_free (path);
	}
	
}

static void 
drag_data_get_callback (GtkWidget *widget,
			GdkDragContext *context,
			GtkSelectionData *selection_data,
			guint info,
			guint time)
{
358 359
	GtkTreeView *tree_view;
	GtkTreeModel *model;
360
	GList *selection_cache;
361

362
	tree_view = GTK_TREE_VIEW (widget);
363
  
364
	model = gtk_tree_view_get_model (tree_view);
365
  
366 367 368
	if (model == NULL) {
		return;
	}
369

370 371
	selection_cache = g_object_get_data (G_OBJECT (context), "drag-info");
	if (selection_cache == NULL) {
372 373
		return;
	}
374

375
	nautilus_drag_drag_data_get_from_cache (selection_cache, context, selection_data, info, time);
376 377 378
}

static void
379
stop_drag_check (NautilusListView *view)
380 381 382 383 384
{		
	view->details->drag_button = 0;
}

static GdkPixbuf *
385
get_drag_pixbuf (NautilusListView *view)
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
{
	GtkTreeModel *model;
	GtkTreePath *path;
	GtkTreeIter iter;
	GdkPixbuf *ret;
	GdkRectangle cell_area;
	
	ret = NULL;
	
	if (gtk_tree_view_get_path_at_pos (view->details->tree_view, 
					   view->details->drag_x,
					   view->details->drag_y,
					   &path, NULL, NULL, NULL)) {
		model = gtk_tree_view_get_model (view->details->tree_view);
		gtk_tree_model_get_iter (model, &iter, path);
		gtk_tree_model_get (model, &iter,
402
				    nautilus_list_model_get_column_id_from_zoom_level (view->details->zoom_level),
403 404 405 406 407 408 409 410
				    &ret,
				    -1);

		gtk_tree_view_get_cell_area (view->details->tree_view,
					     path, 
					     view->details->file_name_column, 
					     &cell_area);

Dave Camp's avatar
Dave Camp committed
411
		gtk_tree_path_free (path);
412 413 414 415 416
	}

	return ret;
}

417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
/* iteration glue struct */
typedef struct {
	NautilusListView *view;
	NautilusDragEachSelectedItemDataGet iteratee;
	gpointer iteratee_data;
} ListGetDataBinderContext;

static void
item_get_data_binder (GtkTreeModel *model,
		      GtkTreePath *path,
		      GtkTreeIter *iter,
		      gpointer data)
{
	ListGetDataBinderContext *context = data;
	NautilusFile *file;
	GtkTreeView *treeview;
	GtkTreeViewColumn *column;
	GdkRectangle cell_area;
	int drag_begin_y  = 0;
	char *uri;

	treeview = nautilus_list_model_get_drag_view (context->view->details->model,
						      NULL,
						      &drag_begin_y);
	column = gtk_tree_view_get_column (treeview, 0);

	file = nautilus_list_model_file_for_path (NAUTILUS_LIST_MODEL (model), path);
	if (file == NULL) {
		return;
	}

	gtk_tree_view_get_cell_area (treeview,
				     path,
				     column,
				     &cell_area);

	uri = nautilus_file_get_uri (file);
	nautilus_file_unref (file);

	/* pass the uri, mouse-relative x/y and icon width/height */
	context->iteratee (uri,
			   0,
			   cell_area.y - drag_begin_y,
			   cell_area.width,
			   cell_area.height,
			   context->iteratee_data);

	g_free (uri);
}

static void
each_item_get_data_binder (NautilusDragEachSelectedItemDataGet iteratee,
			   gpointer iterator_context,
			   gpointer data)
{
	NautilusListView *view = NAUTILUS_LIST_VIEW (iterator_context);
	ListGetDataBinderContext context;
	GtkTreeSelection *selection;

	context.view = view;
	context.iteratee = iteratee;
	context.iteratee_data = data;

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view->details->tree_view));
	gtk_tree_selection_selected_foreach (selection, item_get_data_binder, &context);
}


485 486 487
static void
drag_begin_callback (GtkWidget *widget,
		     GdkDragContext *context,
488
		     NautilusListView *view)
489
{
490
	GList *selection_cache;
491 492 493 494 495 496 497 498 499 500 501 502 503 504
	GdkPixbuf *pixbuf;

	pixbuf = get_drag_pixbuf (view);
	if (pixbuf) {
		gtk_drag_set_icon_pixbuf (context,
					  pixbuf,
					  0, 0);
		g_object_unref (pixbuf);
	} else {
		gtk_drag_set_icon_default (context);
	}

	stop_drag_check (view);
	view->details->drag_started = TRUE;
505 506 507 508

	selection_cache = nautilus_drag_create_selection_cache (view,
								each_item_get_data_binder);

509 510
	g_object_set_data_full (G_OBJECT (context),
				"drag-info",
511 512
				selection_cache,
				(GDestroyNotify)nautilus_drag_destroy_selection_list);
513 514
}

515 516 517 518 519
static gboolean
motion_notify_callback (GtkWidget *widget,
			GdkEventMotion *event,
			gpointer callback_data)
{
520
	NautilusListView *view;
521
	
522
	view = NAUTILUS_LIST_VIEW (callback_data);
523

524 525 526 527
	if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget))) {
		return FALSE;
	}

528
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
529
		GtkTreePath *old_hover_path;
530

531
		old_hover_path = view->details->hover_path;
532 533 534 535 536
		gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
					       event->x, event->y,
					       &view->details->hover_path,
					       NULL, NULL, NULL);

537 538
		if ((old_hover_path != NULL) != (view->details->hover_path != NULL)) {
			if (view->details->hover_path != NULL) {
539
				gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
540
			} else {
541
				gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
542 543 544
			}
		}

545 546 547
		if (old_hover_path != NULL) {
			gtk_tree_path_free (old_hover_path);
		}
548 549
	}

550
	if (view->details->drag_button != 0) {
551
		if (!source_target_list) {
552
			source_target_list = nautilus_list_model_get_drag_target_list ();
553 554
		}

555 556 557 558 559
		if (gtk_drag_check_threshold (widget,
					      view->details->drag_x,
					      view->details->drag_y,
					      event->x, 
					      event->y)) {
560
			gtk_drag_begin
561
				(widget,
562
				 source_target_list,
563 564 565 566
				 GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK,
				 view->details->drag_button,
				 (GdkEvent*)event);
		}		      
Alexander Larsson's avatar
Alexander Larsson committed
567
		return TRUE;
568
	}
Alexander Larsson's avatar
Alexander Larsson committed
569 570
	
	return FALSE;
571 572
}

573 574 575 576 577
static gboolean
leave_notify_callback (GtkWidget *widget,
		       GdkEventCrossing *event,
		       gpointer callback_data)
{
578
	NautilusListView *view;
579

580
	view = NAUTILUS_LIST_VIEW (callback_data);
581

582
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE &&
583 584 585
	    view->details->hover_path != NULL) {
		gtk_tree_path_free (view->details->hover_path);
		view->details->hover_path = NULL;
586
	}
587

588 589 590 591 592 593 594 595
	return FALSE;
}

static gboolean
enter_notify_callback (GtkWidget *widget,
		       GdkEventCrossing *event,
		       gpointer callback_data)
{
596
	NautilusListView *view;
597

598
	view = NAUTILUS_LIST_VIEW (callback_data);
599

600
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
601 602 603 604 605 606 607 608 609 610
		if (view->details->hover_path != NULL) {
			gtk_tree_path_free (view->details->hover_path);
		}

		gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
					       event->x, event->y,
					       &view->details->hover_path,
					       NULL, NULL, NULL);

		if (view->details->hover_path != NULL) {
611
			gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
612
		}
613 614 615 616 617
	}

	return FALSE;
}

618
static void
619
do_popup_menu (GtkWidget *widget, NautilusListView *view, GdkEventButton *event)
620 621
{
 	if (tree_view_has_selection (GTK_TREE_VIEW (widget))) {
622
		nautilus_view_pop_up_selection_context_menu (NAUTILUS_VIEW (view), event);
623
	} else {
624
                nautilus_view_pop_up_background_context_menu (NAUTILUS_VIEW (view), event);
625 626 627
	}
}

628 629 630 631 632 633 634
static void
row_activated_callback (GtkTreeView *treeview, GtkTreePath *path, 
			GtkTreeViewColumn *column, NautilusListView *view)
{
	activate_selected_items (view);
}

635 636 637
static gboolean
button_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer callback_data)
{
638
	NautilusListView *view;
639 640
	GtkTreeView *tree_view;
	GtkTreePath *path;
641
	GtkTreeSelection *selection;
642
	GtkWidgetClass *tree_view_class;
643 644 645 646
	gint64 current_time;
	static gint64 last_click_time = 0;
	static int click_count = 0;
	int double_click_time;
647 648 649 650
	int expander_size, horizontal_separator;
	gboolean call_parent, on_expander;
	gboolean is_simple_click, path_selected;
	NautilusFile *file;
651

652
	view = NAUTILUS_LIST_VIEW (callback_data);
653
	tree_view = GTK_TREE_VIEW (widget);
654
	tree_view_class = GTK_WIDGET_GET_CLASS (tree_view);
655
	selection = gtk_tree_view_get_selection (tree_view);
656

657 658 659 660 661
	/* Don't handle extra mouse buttons here */
	if (event->button > 5) {
		return FALSE;
	}

662 663 664 665
	if (event->window != gtk_tree_view_get_bin_window (tree_view)) {
		return FALSE;
	}

666 667
	nautilus_list_model_set_drag_view
		(NAUTILUS_LIST_MODEL (gtk_tree_view_get_model (tree_view)),
Dave Camp's avatar
Dave Camp committed
668 669
		 tree_view,
		 event->x, event->y);
670 671

	g_object_get (G_OBJECT (gtk_widget_get_settings (widget)),
672 673 674 675
		      "gtk-double-click-time", &double_click_time,
		      NULL);

	/* Determine click count */
676
	current_time = g_get_monotonic_time ();
677 678 679 680 681 682 683 684 685 686
	if (current_time - last_click_time < double_click_time * 1000) {
		click_count++;
	} else {
		click_count = 0;
	}

	/* Stash time for next compare */
	last_click_time = current_time;

	/* Ignore double click if we are in single click mode */
687
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE && click_count >= 2) {
688 689
		return TRUE;
	}
Dave Camp's avatar
Dave Camp committed
690

691 692 693 694 695 696 697 698
	view->details->ignore_button_release = FALSE;
	is_simple_click = ((event->button == 1 || event->button == 2) && (event->type == GDK_BUTTON_PRESS));

	/* No item at this position */
	if (!gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
					    &path, NULL, NULL, NULL)) {
		if (is_simple_click) {
			g_clear_pointer (&view->details->double_click_path[1], gtk_tree_path_free);
699
			view->details->double_click_path[1] = view->details->double_click_path[0];
700
			view->details->double_click_path[0] = NULL;
701
		}
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749

		/* Deselect if people click outside any row. It's OK to
		   let default code run; it won't reselect anything. */
		gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (tree_view));
		tree_view_class->button_press_event (widget, event);

		if (event->button == 3) {
			do_popup_menu (widget, view, event);
		}

		return TRUE;
	}

	call_parent = TRUE;
	path_selected = gtk_tree_selection_path_is_selected (selection, path);

	gtk_widget_style_get (widget,
			      "expander-size", &expander_size,
			      "horizontal-separator", &horizontal_separator,
			      NULL);
	/* TODO we should not hardcode this extra padding. It is
	 * EXPANDER_EXTRA_PADDING from GtkTreeView.
	 */
	expander_size += 4;
	on_expander = (event->x <= horizontal_separator / 2 +
		       gtk_tree_path_get_depth (path) * expander_size);

	/* Keep track of path of last click so double clicks only happen
	 * on the same item */
	if (is_simple_click) {
		g_clear_pointer (&view->details->double_click_path[1], gtk_tree_path_free);
		view->details->double_click_path[1] = view->details->double_click_path[0];
		view->details->double_click_path[0] = gtk_tree_path_copy (path);
	}

	if (event->type == GDK_2BUTTON_PRESS) {
		/* Double clicking does not trigger a D&D action. */
		view->details->drag_button = 0;

		/* NOTE: Activation can actually destroy the view if we're switching */
		if (!on_expander &&
		    view->details->double_click_path[1] &&
		    gtk_tree_path_compare (view->details->double_click_path[0], view->details->double_click_path[1]) == 0) {
			if ((event->button == 1) && button_event_modifies_selection (event)) {
				file = nautilus_list_model_file_for_path (view->details->model, path);
				if (file != NULL) {
					activate_selected_items_alternate (view, file, TRUE);
					nautilus_file_unref (file);
750
				}
751
			} else {
752 753 754 755 756
				if ((event->button == 1 || event->button == 3)) {
					activate_selected_items (view);
				} else if (event->button == 2) {
					activate_selected_items_alternate (view, NULL, TRUE);
				}
757
			}
758
		} else {
759 760 761 762 763 764 765 766 767 768 769 770
			tree_view_class->button_press_event (widget, event);
		}
	} else {
		/* We're going to filter out some situations where
		 * we can't let the default code run because all
		 * but one row would be would be deselected. We don't
		 * want that; we want the right click menu or single
		 * click to apply to everything that's currently selected.
		 */
		if (event->button == 3 && path_selected) {
			call_parent = FALSE;
		}
771

772 773 774
		if ((event->button == 1 || event->button == 2) &&
		    ((event->state & GDK_CONTROL_MASK) != 0 || (event->state & GDK_SHIFT_MASK) == 0)) {
			view->details->row_selected_on_button_down = path_selected;
775

776 777 778 779 780 781 782 783 784 785 786 787
			if (path_selected) {
				call_parent = on_expander;
				view->details->ignore_button_release = on_expander;
			} else if ((event->state & GDK_CONTROL_MASK) != 0) {
				GList *selected_rows, *l;

				call_parent = FALSE;
				if ((event->state & GDK_SHIFT_MASK) != 0) {
					GtkTreePath *cursor;
					gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
					if (cursor != NULL) {
						gtk_tree_selection_select_range (selection, cursor, path);
788 789 790
					} else {
						gtk_tree_selection_select_path (selection, path);
					}
791 792 793 794
				} else {
					gtk_tree_selection_select_path (selection, path);
				}
				selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
795

796 797
				/* This unselects everything */
				gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
798

799 800 801
				/* So select it again */
				for (l = selected_rows; l != NULL; l = l->next) {
					gtk_tree_selection_select_path (selection, l->data);
802
				}
803 804 805
				g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
			} else {
				view->details->ignore_button_release = on_expander;
806
			}
807
		}
808
		
809 810 811 812 813 814
		if (call_parent) {
			g_signal_handlers_block_by_func (tree_view, row_activated_callback, view);
			tree_view_class->button_press_event (widget, event);
			g_signal_handlers_unblock_by_func (tree_view, row_activated_callback, view);
		} else if (path_selected) {
			gtk_widget_grab_focus (widget);
815 816
		}

817 818 819 820 821
		if (is_simple_click) {
			view->details->drag_started = FALSE;
			view->details->drag_button = event->button;
			view->details->drag_x = event->x;
			view->details->drag_y = event->y;
822
		}
823 824 825 826

		if (event->button == 3) {
			do_popup_menu (widget, view, event);
		}
827
	}
828 829 830

	gtk_tree_path_free (path);

831 832 833
	/* We chained to the default handler in this method, so never
	 * let the default handler run */ 
	return TRUE;
834 835
}

836 837 838 839 840
static gboolean
button_release_callback (GtkWidget *widget, 
			 GdkEventButton *event, 
			 gpointer callback_data)
{
841
	NautilusListView *view;
842
	
843
	view = NAUTILUS_LIST_VIEW (callback_data);
844 845 846

	if (event->button == view->details->drag_button) {
		stop_drag_check (view);
847 848
		if (!view->details->drag_started &&
		    !view->details->ignore_button_release) {
849
			nautilus_list_view_did_not_drag (view, event);
850 851 852 853 854
		}
	}
	return FALSE;
}

855 856 857
static gboolean
popup_menu_callback (GtkWidget *widget, gpointer callback_data)
{
858
 	NautilusListView *view;
859

860
	view = NAUTILUS_LIST_VIEW (callback_data);
861 862

	do_popup_menu (widget, view, NULL);
Dave Camp's avatar
Dave Camp committed
863 864

	return TRUE;
865 866
}

Alexander Larsson's avatar
Alexander Larsson committed
867
static void
868
subdirectory_done_loading_callback (NautilusDirectory *directory, NautilusListView *view)
Alexander Larsson's avatar
Alexander Larsson committed
869
{
870
	nautilus_list_model_subdirectory_done_loading (view->details->model, directory);
Alexander Larsson's avatar
Alexander Larsson committed
871 872
}

873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
static void
row_expanded_callback (GtkTreeView *treeview,
		       GtkTreeIter *iter,
		       GtkTreePath *path,
		       gpointer callback_data)
{
	NautilusListView *view;
	NautilusDirectory *directory;
	char *uri;

	view = NAUTILUS_LIST_VIEW (callback_data);

	if (!nautilus_list_model_load_subdirectory (view->details->model, path, &directory)) {
		return;
	}

	uri = nautilus_directory_get_uri (directory);
	DEBUG ("Row expaded callback for uri %s", uri);
	g_free (uri);

	nautilus_view_add_subdirectory (NAUTILUS_VIEW (view), directory);

	if (nautilus_directory_are_all_files_seen (directory)) {
		nautilus_list_model_subdirectory_done_loading (view->details->model,
							       directory);
	} else {
		g_signal_connect_object (directory, "done-loading",
					 G_CALLBACK (subdirectory_done_loading_callback),
					 view, 0);
	}

	nautilus_directory_unref (directory);
}

typedef struct {
908
	NautilusFile *file;
909
	NautilusDirectory *directory;
910
	NautilusListView *view;
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
} UnloadDelayData;

static void
unload_delay_data_free (UnloadDelayData *unload_data)
{
	if (unload_data->view != NULL) {
		g_object_remove_weak_pointer (G_OBJECT (unload_data->view),
					      (gpointer *) &unload_data->view);
	}

	nautilus_directory_unref (unload_data->directory);
	nautilus_file_unref (unload_data->file);

	g_slice_free (UnloadDelayData, unload_data);
}

static UnloadDelayData *
unload_delay_data_new (NautilusFile *file,
		       NautilusDirectory *parent_directory,
		       NautilusListView *view)
{
	UnloadDelayData *unload_data;

	unload_data = g_slice_new0 (UnloadDelayData);
	unload_data->view = view;
	unload_data->file = nautilus_file_ref (file);
	unload_data->directory = nautilus_directory_ref (parent_directory);

	g_object_add_weak_pointer (G_OBJECT (unload_data->view),
				   (gpointer *) &unload_data->view);

	return unload_data;
}

static gboolean
unload_file_timeout (gpointer data)
{
	UnloadDelayData *unload_data = data;
	GtkTreeIter iter;
	NautilusListModel *model;
	GtkTreePath *path;

	if (unload_data->view == NULL) {
		goto out;
	}

	model = unload_data->view->details->model;
	if (nautilus_list_model_get_tree_iter_from_file (model,
							 unload_data->file,
							 unload_data->directory,
							 &iter)) {
		path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
		if (!gtk_tree_view_row_expanded (unload_data->view->details->tree_view,
						 path)) {
			nautilus_list_model_unload_subdirectory (model, &iter);
		}
		gtk_tree_path_free (path);
	}

 out:
	unload_delay_data_free (unload_data);
	return FALSE;
}

static void
row_collapsed_callback (GtkTreeView *treeview,
			GtkTreeIter *iter,
			GtkTreePath *path,
			gpointer callback_data)
{
	NautilusListView *view;
	NautilusFile *file;
	NautilusDirectory *directory;
	GtkTreeIter parent;
	UnloadDelayData *unload_data;
	GtkTreeModel *model;
	char *uri;

	view = NAUTILUS_LIST_VIEW (callback_data);
	model = GTK_TREE_MODEL (view->details->model);

	gtk_tree_model_get (model, iter,
			    NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
			    -1);

	uri = nautilus_file_get_uri (file);
	DEBUG ("Row collapsed callback for uri %s", uri);
	g_free (uri);

	directory = NULL;
	if (gtk_tree_model_iter_parent (model, &parent, iter)) {
		gtk_tree_model_get (model, &parent,
				    NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN, &directory,
				    -1);
	}

	unload_data = unload_delay_data_new (file, directory, view);
	g_timeout_add_seconds (COLLAPSE_TO_UNLOAD_DELAY,
			       unload_file_timeout,
			       unload_data);

	nautilus_file_unref (file);
	nautilus_directory_unref (directory);
}
1015 1016

static void
1017
subdirectory_unloaded_callback (NautilusListModel *model,
1018 1019 1020
				NautilusDirectory *directory,
				gpointer callback_data)
{
1021
	NautilusListView *view;
1022
	
1023
	g_return_if_fail (NAUTILUS_IS_LIST_MODEL (model));
1024 1025
	g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));

1026
	view = NAUTILUS_LIST_VIEW(callback_data);
1027 1028 1029 1030
	
	g_signal_handlers_disconnect_by_func (directory,
					      G_CALLBACK (subdirectory_done_loading_callback),
					      view);
1031
	nautilus_view_remove_subdirectory (NAUTILUS_VIEW (view), directory);
Alexander Larsson's avatar
Alexander Larsson committed
1032 1033
}

1034 1035 1036
static gboolean
key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer callback_data)
{
1037
	NautilusView *view;
1038
	GdkEventButton button_event = { 0 };
1039
	gboolean handled;
1040 1041 1042 1043
	GtkTreeView *tree_view;
	GtkTreePath *path;

	tree_view = GTK_TREE_VIEW (widget);
1044

1045
	view = NAUTILUS_VIEW (callback_data);
1046
	handled = FALSE;
1047

1048
	switch (event->keyval) {
1049
	case GDK_KEY_F10:
1050
		if (event->state & GDK_CONTROL_MASK) {
1051
			nautilus_view_pop_up_background_context_menu (view, &button_event);
1052
			handled = TRUE;
1053 1054
		}
		break;
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
	case GDK_KEY_Right:
		gtk_tree_view_get_cursor (tree_view, &path, NULL);
		if (path) {
			gtk_tree_view_expand_row (tree_view, path, FALSE);
			gtk_tree_path_free (path);
		}
		handled = TRUE;
		break;
	case GDK_KEY_Left:
		gtk_tree_view_get_cursor (tree_view, &path, NULL);
		if (path) {
			if (!gtk_tree_view_collapse_row (tree_view, path)) {
				/* if the row is already collapsed or doesn't have any children,
				 * jump to the parent row instead.
				 */
				if ((gtk_tree_path_get_depth (path) > 1) && gtk_tree_path_up (path)) {
					gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
				}
			}

			gtk_tree_path_free (path);
		}
		handled = TRUE;
		break;
1079
	case GDK_KEY_space:
1080
		if (event->state & GDK_CONTROL_MASK) {
1081 1082
			handled = FALSE;
			break;
1083
		}
1084
		if (!gtk_widget_has_focus (GTK_WIDGET (NAUTILUS_LIST_VIEW (view)->details->tree_view))) {
1085 1086
			handled = FALSE;
			break;
1087
		}
1088
		if ((event->state & GDK_SHIFT_MASK) != 0) {
1089
			activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
1090
		} else {
1091
			preview_selected_items (NAUTILUS_LIST_VIEW (view));
1092
		}
1093 1094
		handled = TRUE;
		break;
1095 1096
	case GDK_KEY_Return:
	case GDK_KEY_KP_Enter:
1097
		if ((event->state & GDK_SHIFT_MASK) != 0) {
1098
			activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
1099
		} else {
1100
			activate_selected_items (NAUTILUS_LIST_VIEW (view));
1101
		}
1102 1103
		handled = TRUE;
		break;
1104
	case GDK_KEY_v:
1105
		/* Eat Control + v to not enable type ahead */
1106
		if ((event->state & GDK_CONTROL_MASK) != 0) {
1107
			handled = TRUE;
1108 1109
		}
		break;
1110 1111

	default:
1112
		handled = FALSE;
1113
	}
1114

1115
	return handled;
1116 1117
}

1118
static void
1119
nautilus_list_view_reveal_selection (NautilusView *view)
1120 1121 1122
{
	GList *selection;

1123
	g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
1124

1125
        selection = nautilus_view_get_selection (view);
1126 1127 1128

	/* Make sure at least one of the selected items is scrolled into view */
	if (selection != NULL) {
1129
		NautilusListView *list_view;
1130 1131 1132 1133
		NautilusFile *file;
		GtkTreeIter iter;
		GtkTreePath *path;
		
1134
		list_view = NAUTILUS_LIST_VIEW (view);
1135
		file = selection->data;
1136
		if (nautilus_list_model_get_first_iter_for_file (list_view->details->model, file, &iter)) {
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
			path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_view->details->model), &iter);

			gtk_tree_view_scroll_to_cell (list_view->details->tree_view, path, NULL, FALSE, 0.0, 0.0);
			
			gtk_tree_path_free (path);
		}
	}

        nautilus_file_list_free (selection);
}

1148 1149 1150 1151 1152 1153
static gboolean
sort_criterion_changes_due_to_user (GtkTreeView *tree_view)
{
	GList *columns, *p;
	GtkTreeViewColumn *column;
	GSignalInvocationHint *ihint;
1154
	gboolean ret;
1155

1156 1157
	ret = FALSE;

1158 1159 1160 1161 1162
	columns = gtk_tree_view_get_columns (tree_view);
	for (p = columns; p != NULL; p = p->next) {
		column = p->data;
		ihint = g_signal_get_invocation_hint (column);
		if (ihint != NULL) {
1163 1164
			ret = TRUE;
			break;
1165 1166
		}
	}
1167
	g_list_free (columns);
1168

1169
	return ret;
1170 1171
}

Diego González's avatar
Diego González committed
1172
static void
1173
sort_column_changed_callback (GtkTreeSortable *sortable, 
1174
			      NautilusListView *view)
Diego González's avatar
Diego González committed
1175 1176
{
	NautilusFile *file;
1177
	gint sort_column_id, default_sort_column_id;
1178
	GtkSortType reversed;
1179
	GQuark sort_attr, default_sort_attr;
1180
	char *reversed_attr, *default_reversed_attr;
1181
	gboolean default_sort_reversed;
Diego González's avatar
Diego González committed
1182

1183
	file = nautilus_view_get_directory_as_file (NAUTILUS_VIEW (view));
Diego González's avatar
Diego González committed
1184

1185
	gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &reversed);
1186
	sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, sort_column_id);
1187

1188
	default_sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (view->details->model,
1189
										  g_quark_from_string (get_default_sort_order (file, &default_sort_reversed)));
1190
	default_sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, default_sort_column_id);
1191
	nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
1192
				    g_quark_to_string (default_sort_attr), g_quark_to_string (sort_attr));
Diego González's avatar
Diego González committed
1193

1194
	default_reversed_attr = (default_sort_reversed ? "true" : "false");
1195 1196 1197 1198 1199 1200 1201 1202

	if (view->details->last_sort_attr != sort_attr &&
	    sort_criterion_changes_due_to_user (view->details->tree_view)) {
		/* at this point, the sort order is always GTK_SORT_ASCENDING, if the sort column ID
		 * switched. Invert the sort order, if it's the default criterion with a reversed preference,
		 * or if it makes sense for the attribute (i.e. date). */
		if (sort_attr == default_sort_attr) {
			/* use value from preferences */
1203 1204
			reversed = g_settings_get_boolean (nautilus_preferences,
							   NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
		} else {
			reversed = nautilus_file_is_date_sort_attribute_q (sort_attr);
		}

		if (reversed) {
			g_signal_handlers_block_by_func (sortable, sort_column_changed_callback, view);
			gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (view->details->model),
							      sort_column_id,
							      GTK_SORT_DESCENDING);
			g_signal_handlers_unblock_by_func (sortable, sort_column_changed_callback, view);
		}
	}


1219 1220 1221
	reversed_attr = (reversed ? "true" : "false");
	nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
				    default_reversed_attr, reversed_attr);
1222

1223
	/* Make sure selected item(s) is visible after sort */
1224
	nautilus_list_view_reveal_selection (NAUTILUS_VIEW (view));
1225 1226

	view->details->last_sort_attr = sort_attr;
Diego González's avatar
Diego González committed
1227 1228
}

1229 1230 1231 1232 1233 1234 1235 1236
static void
editable_focus_out_cb (GtkWidget *widget,
		       GdkEvent *event,
		       gpointer user_data)
{
	NautilusListView *view = user_data;

	view->details->editable_widget = NULL;
1237 1238 1239

	nautilus_view_set_is_renaming (NAUTILUS_VIEW (view), FALSE);
	nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1240 1241
}

1242 1243 1244 1245
static void
cell_renderer_editing_started_cb (GtkCellRenderer *renderer,
				  GtkCellEditable *editable,
				  const gchar *path_str,
1246
				  NautilusListView *list_view)
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
{
	GtkEntry *entry;

	entry = GTK_ENTRY (editable);
	list_view->details->editable_widget = editable;

	/* Free a previously allocated original_name */
	g_free (list_view->details->original_name);

	list_view->details->original_name = g_strdup (gtk_entry_get_text (entry));

1258 1259 1260
	g_signal_connect (entry, "focus-out-event",
			  G_CALLBACK (editable_focus_out_cb), list_view);

1261 1262
	nautilus_clipboard_set_up_editable
		(GTK_EDITABLE (entry),
1263
		 nautilus_view_get_ui_manager (NAUTILUS_VIEW (list_view)),
1264 1265 1266
		 FALSE);
}

1267 1268
static void
cell_renderer_editing_canceled (GtkCellRendererText *cell,
1269
				NautilusListView    *view)
1270
{
1271 1272
	view->details->editable_widget = NULL;

1273
	nautilus_view_set_is_renaming (NAUTILUS_VIEW (view), FALSE);
1274
	nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1275 1276
}

1277 1278 1279 1280
static void
cell_renderer_edited (GtkCellRendererText *cell,
		      const char          *path_str,
		      const char          *new_text,
1281
		      NautilusListView    *view)
1282 1283 1284 1285
{
	GtkTreePath *path;
	NautilusFile *file;
	GtkTreeIter iter;
1286

1287
	view->details->editable_widget = NULL;
1288
	nautilus_view_set_is_renaming (NAUTILUS_VIEW (view), FALSE);
1289

1290 1291 1292 1293 1294 1295 1296
	/* Don't allow a rename with an empty string. Revert to original 
	 * without notifying the user.
	 */
	if (new_text[0] == '\0') {
		g_object_set (G_OBJECT (view->details->file_name_cell),
			      "editable", FALSE,
			      NULL);
1297
		nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1298 1299 1300
		return;
	}
	
1301 1302 1303 1304 1305 1306 1307 1308 1309
	path = gtk_tree_path_new_from_string (path_str);

	gtk_tree_model_get_iter (GTK_TREE_MODEL (view->details->model),
				 &iter, path);

	gtk_tree_path_free (path);
	
	gtk_tree_model_get (GTK_TREE_MODEL (view->details->model),
			    &iter,
1310
			    NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
1311 1312
			    -1);

1313 1314
	/* Only rename if name actually changed */
	if (strcmp (new_text, view->details->original_name) != 0) {
1315 1316
		view->details->renaming_file = nautilus_file_ref (file);
		view->details->rename_done = FALSE;
1317
		nautilus_rename_file (file, new_text, nautilus_list_view_rename_callback, g_object_ref (view));
1318 1319
		g_free (view->details->original_name);
		view->details->original_name = g_strdup (new_text);
1320
	}
1321 1322
	
	nautilus_file_unref (file);
1323 1324 1325 1326 1327 1328

	/*We're done editing - make the filename-cells readonly again.*/
	g_object_set (G_OBJECT (view->details->file_name_cell),
		      "editable", FALSE,
		      NULL);

1329
	nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1330 1331
}

1332 1333 1334 1335
static char *
get_root_uri_callback (NautilusTreeViewDragDest *dest,
		       gpointer user_data)
{
1336
	NautilusListView *view;
1337
	
1338
	view = NAUTILUS_LIST_VIEW (user_data);
1339

1340
	return nautilus_view_get_uri (NAUTILUS_VIEW (view));
1341 1342 1343 1344 1345 1346 1347
}

static NautilusFile *
get_file_for_path_callback (NautilusTreeViewDragDest *dest,
			    GtkTreePath *path,
			    gpointer user_data)
{
1348
	NautilusListView *view;
1349
	
1350
	view = NAUTILUS_LIST_VIEW (user_data);
1351

1352
	return nautilus_list_model_file_for_path (view->details->model, path);
1353 1354
}

1355 1356
/* Handles an URL received from Mozilla */
static void
1357
list_view_handle_netscape_url (NautilusTreeViewDragDest *dest, const char *encoded_url,
1358
			       const char *target_uri, GdkDragAction action, int x, int y, NautilusListView *view)
1359
{
1360 1361
	nautilus_view_handle_netscape_url_drop (NAUTILUS_VIEW (view),
						encoded_url, target_uri, action, x, y);
1362 1363 1364 1365
}

static void
list_view_handle_uri_list (NautilusTreeViewDragDest *dest, const char *item_uris,
1366
			   const char *target_uri,
1367
			   GdkDragAction action, int x, int y, NautilusListView *view)
1368
{
1369 1370
	nautilus_view_handle_uri_list_drop (NAUTILUS_VIEW (view),
					    item_uris, target_uri, action, x, y);
1371 1372
}

1373 1374
static void
list_view_handle_text (NautilusTreeViewDragDest *dest, const char *text,
1375
		       const char *target_uri,
1376
		       GdkDragAction action, int x, int y, NautilusListView *view)
1377
{
1378 1379
	nautilus_view_handle_text_drop (NAUTILUS_VIEW (view),
					text, target_uri, action, x, y);
1380
}
1381

James Dietrich's avatar
James Dietrich committed
1382 1383
static void
list_view_handle_raw (NautilusTreeViewDragDest *dest, const char *raw_data,
1384
		      int length, const char *target_uri, const char *direct_save_uri,
1385
		      GdkDragAction action, int x, int y, NautilusListView *view)
James Dietrich's avatar
James Dietrich committed
1386
{
1387 1388 1389
	nautilus_view_handle_raw_drop (NAUTILUS_VIEW (view),
				       raw_data, length, target_uri, direct_save_uri,
				       action, x, y);
James Dietrich's avatar
James Dietrich committed
1390 1391
}

1392 1393 1394 1395