nautilus-list-view.c 102 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
   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,
20
   see <http://www.gnu.org/licenses/>.
21 22

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

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

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

35
#include <string.h>
36
#include <eel/eel-vfs-extensions.h>
37
#include <eel/eel-gdk-extensions.h>
38
#include <eel/eel-glib-extensions.h>
39
#include <gdk/gdk.h>
40
#include <gdk/gdkkeysyms.h>
41
#include <gtk/gtk.h>
42
#include <glib/gi18n.h>
43
#include <glib-object.h>
44
#include <libgd/gd.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
	GtkTreeViewColumn   *file_name_column;
67
	int file_name_column_num;
68 69 70

	GtkCellRendererPixbuf *pixbuf_cell;
	GtkCellRendererText   *file_name_cell;
71
	GList *cells;
72
	GtkCellEditable *editable_widget;
73

74
	NautilusListZoomLevel zoom_level;
75

76
	NautilusTreeViewDragDest *drag_dest;
77 78

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

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

82 83
	GtkTreePath *hover_path;

84 85 86 87 88
	guint drag_button;
	int drag_x;
	int drag_y;

	gboolean drag_started;
89
	gboolean ignore_button_release;
90
	gboolean row_selected_on_button_down;
91
	gboolean active;
92 93 94
	
	GHashTable *columns;
	GtkWidget *column_editor;
95 96

	char *original_name;
97 98 99 100
	
	NautilusFile *renaming_file;
	gboolean rename_done;
	guint renaming_file_activate_timeout;
101

102 103
	gulong clipboard_handler_id;

104
	GQuark last_sort_attr;
Anders Carlsson's avatar
Anders Carlsson committed
105
};
106

107 108 109 110 111
struct SelectionForeachData {
	GList *list;
	GtkTreeSelection *selection;
};

112 113 114 115 116
/*
 * 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
117
#define LIST_VIEW_MINIMUM_ROW_HEIGHT	28
118

119 120 121
/* We wait two seconds after row is collapsed to unload the subdirectory */
#define COLLAPSE_TO_UNLOAD_DELAY 2

122 123 124
/* Wait for the rename to end when activating a file being renamed */
#define WAIT_FOR_RENAME_ON_ACTIVATE 200

125
static GdkCursor *              hand_cursor = NULL;
126

127 128
static GtkTargetList *          source_target_list = NULL;

129 130
static GList *nautilus_list_view_get_selection                   (NautilusView   *view);
static GList *nautilus_list_view_get_selection_for_file_transfer (NautilusView   *view);
131 132
static void   nautilus_list_view_set_zoom_level                  (NautilusListView        *view,
								  NautilusListZoomLevel    new_level);
133 134 135 136 137 138
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);
139

140 141 142 143 144 145 146 147
static void   apply_columns_settings                             (NautilusListView *list_view,
                                                                  char **column_order,
                                                                  char **visible_columns);
static char **get_visible_columns                                (NautilusListView *list_view);
static char **get_default_visible_columns                        (NautilusListView *list_view);
static char **get_column_order                                   (NautilusListView *list_view);
static char **get_default_column_order                           (NautilusListView *list_view);

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

149
G_DEFINE_TYPE (NautilusListView, nautilus_list_view, NAUTILUS_TYPE_VIEW);
150

151
static const char * default_search_visible_columns[] = {
152
	"name", "size", "where", NULL
153 154 155
};

static const char * default_search_columns_order[] = {
156
	"name", "size", "where", NULL
157 158
};

159
static const char * default_trash_visible_columns[] = {
160
	"name", "size", "trash_orig_path", "trashed_on", NULL
161 162 163
};

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

167 168 169
static const gchar*
get_default_sort_order (NautilusFile *file, gboolean *reversed)
{
170 171
	NautilusFileSortType default_sort_order;
	gboolean default_sort_reversed;
172
	const gchar *retval;
173 174 175 176 177 178 179 180 181 182
	const char *attributes[] = {
		"name", /* is really "manually" which doesn't apply to lists */
		"name",
		"size",
		"type",
		"date_modified",
		"date_accessed",
		"trashed_on",
		NULL
	};
183 184 185 186

	retval = nautilus_file_get_default_sort_attribute (file, reversed);

	if (retval == NULL) {
187 188 189 190 191 192 193
		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;
194 195 196 197 198
	}

	return retval;
}

199
static void
Anders Carlsson's avatar
Anders Carlsson committed
200
list_selection_changed_callback (GtkTreeSelection *selection, gpointer user_data)
201
{
202
	NautilusView *view;
203

204
	view = NAUTILUS_VIEW (user_data);
205

206
	nautilus_view_notify_selection_changed (view);
207 208
}

209 210
/* Move these to eel? */

211
static void
212 213 214 215 216 217 218 219 220 221
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)
222
{
223
	gboolean not_empty;
224

225 226 227 228 229 230 231 232 233 234 235 236
	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));
}
237

238 239 240 241 242 243 244
static void
preview_selected_items (NautilusListView *view)
{
	GList *file_list;
	
	file_list = nautilus_list_view_get_selection (NAUTILUS_VIEW (view));

245 246 247 248 249
	if (file_list != NULL) {
		nautilus_view_preview_files (NAUTILUS_VIEW (view),
					     file_list, NULL);
		nautilus_file_list_free (file_list);
	}
250 251
}

252
static void
253
activate_selected_items (NautilusListView *view)
254 255 256
{
	GList *file_list;
	
257
	file_list = nautilus_list_view_get_selection (NAUTILUS_VIEW (view));
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274

	
	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;
	}
	
275 276
	nautilus_view_activate_files (NAUTILUS_VIEW (view),
				      file_list,
277
				      0, TRUE);
278 279 280 281 282
	nautilus_file_list_free (file_list);

}

static void
283
activate_selected_items_alternate (NautilusListView *view,
284 285
				   NautilusFile *file,
				   gboolean open_in_tab)
286 287
{
	GList *file_list;
288
	NautilusWindowOpenFlags flags;
289

290 291
	flags = 0;

292 293
	if (open_in_tab) {
		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
294
	} else {
295
		flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
296
	}
297 298 299 300 301

	if (file != NULL) {
		nautilus_file_ref (file);
		file_list = g_list_prepend (NULL, file);
	} else {
302
		file_list = nautilus_list_view_get_selection (NAUTILUS_VIEW (view));
303
	}
304 305 306 307
	nautilus_view_activate_files (NAUTILUS_VIEW (view),
				      file_list,
				      flags,
				      TRUE);
308 309 310 311 312 313 314 315 316 317
	nautilus_file_list_free (file_list);

}

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

318 319 320 321 322 323 324
static int
get_click_policy (void)
{
	return g_settings_get_enum (nautilus_preferences,
				    NAUTILUS_PREFERENCES_CLICK_POLICY);
}

325
static void
326 327
nautilus_list_view_did_not_drag (NautilusListView *view,
				 GdkEventButton *event)
328 329 330 331 332 333 334 335 336 337
{
	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)) {
338 339 340
		if ((event->button == 1 || event->button == 2)
		    && ((event->state & GDK_CONTROL_MASK) != 0 ||
			(event->state & GDK_SHIFT_MASK) == 0)
341
		    && view->details->row_selected_on_button_down) {
342 343 344 345 346 347
			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);
			}
348 349
		}

350
		if ((get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
351
		    && !button_event_modifies_selection(event)) {
352 353 354
			if (event->button == 1) {
				activate_selected_items (view);
			} else if (event->button == 2) {
355
				activate_selected_items_alternate (view, NULL, TRUE);
356
			}
357 358 359 360 361 362 363 364 365 366 367 368 369
		}
		gtk_tree_path_free (path);
	}
	
}

static void 
drag_data_get_callback (GtkWidget *widget,
			GdkDragContext *context,
			GtkSelectionData *selection_data,
			guint info,
			guint time)
{
370 371
	GtkTreeView *tree_view;
	GtkTreeModel *model;
372
	GList *selection_cache;
373

374
	tree_view = GTK_TREE_VIEW (widget);
375
  
376
	model = gtk_tree_view_get_model (tree_view);
377
  
378 379 380
	if (model == NULL) {
		return;
	}
381

382 383
	selection_cache = g_object_get_data (G_OBJECT (context), "drag-info");
	if (selection_cache == NULL) {
384 385
		return;
	}
386

387
	nautilus_drag_drag_data_get_from_cache (selection_cache, context, selection_data, info, time);
388 389 390
}

static void
391
stop_drag_check (NautilusListView *view)
392 393 394 395
{		
	view->details->drag_button = 0;
}

396 397
static cairo_surface_t *
get_drag_surface (NautilusListView *view)
398 399 400 401
{
	GtkTreeModel *model;
	GtkTreePath *path;
	GtkTreeIter iter;
402
        cairo_surface_t *ret;
403 404 405 406 407 408 409 410 411 412 413
	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,
414
				    nautilus_list_model_get_column_id_from_zoom_level (view->details->zoom_level),
415 416 417 418 419 420 421 422
				    &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
423
		gtk_tree_path_free (path);
424 425 426 427 428
	}

	return ret;
}

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
/* 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);

465 466 467 468 469
	if (nautilus_file_is_nautilus_link (file)) {
		uri = nautilus_file_get_uri (file);
	} else {
		uri = nautilus_file_get_activation_uri (file);
	}
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
	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);
}


501 502 503
static void
drag_begin_callback (GtkWidget *widget,
		     GdkDragContext *context,
504
		     NautilusListView *view)
505
{
506
	GList *selection_cache;
507 508 509 510 511 512
	cairo_surface_t *surface;

	surface = get_drag_surface (view);
	if (surface) {
		gtk_drag_set_icon_surface (context, surface);
		cairo_surface_destroy (surface);
513 514 515 516 517 518
	} else {
		gtk_drag_set_icon_default (context);
	}

	stop_drag_check (view);
	view->details->drag_started = TRUE;
519 520 521 522

	selection_cache = nautilus_drag_create_selection_cache (view,
								each_item_get_data_binder);

523 524
	g_object_set_data_full (G_OBJECT (context),
				"drag-info",
525 526
				selection_cache,
				(GDestroyNotify)nautilus_drag_destroy_selection_list);
527 528
}

529 530 531 532 533
static gboolean
motion_notify_callback (GtkWidget *widget,
			GdkEventMotion *event,
			gpointer callback_data)
{
534
	NautilusListView *view;
535
	
536
	view = NAUTILUS_LIST_VIEW (callback_data);
537

538 539 540 541
	if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget))) {
		return FALSE;
	}

542
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
543
		GtkTreePath *old_hover_path;
544

545
		old_hover_path = view->details->hover_path;
546 547 548 549 550
		gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
					       event->x, event->y,
					       &view->details->hover_path,
					       NULL, NULL, NULL);

551 552
		if ((old_hover_path != NULL) != (view->details->hover_path != NULL)) {
			if (view->details->hover_path != NULL) {
553
				gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
554
			} else {
555
				gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
556 557 558
			}
		}

559 560 561
		if (old_hover_path != NULL) {
			gtk_tree_path_free (old_hover_path);
		}
562 563
	}

564
	if (view->details->drag_button != 0) {
565
		if (!source_target_list) {
566
			source_target_list = nautilus_list_model_get_drag_target_list ();
567 568
		}

569 570 571 572 573
		if (gtk_drag_check_threshold (widget,
					      view->details->drag_x,
					      view->details->drag_y,
					      event->x, 
					      event->y)) {
574
			gtk_drag_begin
575
				(widget,
576
				 source_target_list,
577 578 579 580
				 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
581
		return TRUE;
582
	}
Alexander Larsson's avatar
Alexander Larsson committed
583 584
	
	return FALSE;
585 586
}

587 588 589 590 591
static gboolean
leave_notify_callback (GtkWidget *widget,
		       GdkEventCrossing *event,
		       gpointer callback_data)
{
592
	NautilusListView *view;
593

594
	view = NAUTILUS_LIST_VIEW (callback_data);
595

596
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE &&
597 598 599
	    view->details->hover_path != NULL) {
		gtk_tree_path_free (view->details->hover_path);
		view->details->hover_path = NULL;
600
	}
601

602 603 604 605 606 607 608 609
	return FALSE;
}

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

612
	view = NAUTILUS_LIST_VIEW (callback_data);
613

614
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
615 616 617 618 619 620 621 622 623 624
		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) {
625
			gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
626
		}
627 628 629 630 631
	}

	return FALSE;
}

632
static void
633
do_popup_menu (GtkWidget *widget, NautilusListView *view, GdkEventButton *event)
634 635
{
 	if (tree_view_has_selection (GTK_TREE_VIEW (widget))) {
636
		nautilus_view_pop_up_selection_context_menu (NAUTILUS_VIEW (view), event);
637
	} else {
638
                nautilus_view_pop_up_background_context_menu (NAUTILUS_VIEW (view), event);
639 640 641
	}
}

642 643 644 645 646 647 648
static void
row_activated_callback (GtkTreeView *treeview, GtkTreePath *path, 
			GtkTreeViewColumn *column, NautilusListView *view)
{
	activate_selected_items (view);
}

649 650 651
static gboolean
button_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer callback_data)
{
652
	NautilusListView *view;
653 654
	GtkTreeView *tree_view;
	GtkTreePath *path;
655
	GtkTreeSelection *selection;
656
	GtkWidgetClass *tree_view_class;
657 658 659 660
	gint64 current_time;
	static gint64 last_click_time = 0;
	static int click_count = 0;
	int double_click_time;
661
	gboolean call_parent, on_expander, show_expanders;
662 663
	gboolean is_simple_click, path_selected;
	NautilusFile *file;
664

665
	view = NAUTILUS_LIST_VIEW (callback_data);
666
	tree_view = GTK_TREE_VIEW (widget);
667
	tree_view_class = GTK_WIDGET_GET_CLASS (tree_view);
668
	selection = gtk_tree_view_get_selection (tree_view);
669

670 671 672 673 674
	/* Don't handle extra mouse buttons here */
	if (event->button > 5) {
		return FALSE;
	}

675 676 677 678
	if (event->window != gtk_tree_view_get_bin_window (tree_view)) {
		return FALSE;
	}

679 680
	nautilus_list_model_set_drag_view
		(NAUTILUS_LIST_MODEL (gtk_tree_view_get_model (tree_view)),
Dave Camp's avatar
Dave Camp committed
681 682
		 tree_view,
		 event->x, event->y);
683 684

	g_object_get (G_OBJECT (gtk_widget_get_settings (widget)),
685 686 687 688
		      "gtk-double-click-time", &double_click_time,
		      NULL);

	/* Determine click count */
689
	current_time = g_get_monotonic_time ();
690 691 692 693 694 695 696 697 698 699
	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 */
700
	if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE && click_count >= 2) {
701 702
		return TRUE;
	}
Dave Camp's avatar
Dave Camp committed
703

704 705 706 707 708 709 710 711
	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);
712
			view->details->double_click_path[1] = view->details->double_click_path[0];
713
			view->details->double_click_path[0] = NULL;
714
		}
715 716 717 718 719 720 721 722 723 724 725 726 727 728

		/* 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;
729
	on_expander = FALSE;
730
	path_selected = gtk_tree_selection_path_is_selected (selection, path);
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
	show_expanders = g_settings_get_boolean (nautilus_list_view_preferences,
						 NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);

	if (show_expanders) {
		int expander_size, horizontal_separator;
		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);
	}
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768

	/* 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);
769
				}
770
			} else {
771 772 773 774 775
				if ((event->button == 1 || event->button == 3)) {
					activate_selected_items (view);
				} else if (event->button == 2) {
					activate_selected_items_alternate (view, NULL, TRUE);
				}
776
			}
777
		} else {
778 779 780 781 782 783 784 785 786 787 788 789
			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;
		}
790

791 792 793
		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;
794

795 796 797 798 799 800 801 802 803 804 805 806
			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);
807 808 809
					} else {
						gtk_tree_selection_select_path (selection, path);
					}
810 811 812 813
				} else {
					gtk_tree_selection_select_path (selection, path);
				}
				selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
814

815 816
				/* This unselects everything */
				gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
817

818 819 820
				/* So select it again */
				for (l = selected_rows; l != NULL; l = l->next) {
					gtk_tree_selection_select_path (selection, l->data);
821
				}
822 823 824
				g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
			} else {
				view->details->ignore_button_release = on_expander;
825
			}
826
		}
827
		
828 829 830 831 832 833
		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);
834 835
		}

836
		if (is_simple_click && !on_expander) {
837 838 839 840
			view->details->drag_started = FALSE;
			view->details->drag_button = event->button;
			view->details->drag_x = event->x;
			view->details->drag_y = event->y;
841
		}
842 843 844 845

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

	gtk_tree_path_free (path);

850 851 852
	/* We chained to the default handler in this method, so never
	 * let the default handler run */ 
	return TRUE;
853 854
}

855 856 857 858 859
static gboolean
button_release_callback (GtkWidget *widget, 
			 GdkEventButton *event, 
			 gpointer callback_data)
{
860
	NautilusListView *view;
861
	
862
	view = NAUTILUS_LIST_VIEW (callback_data);
863 864 865

	if (event->button == view->details->drag_button) {
		stop_drag_check (view);
866 867
		if (!view->details->drag_started &&
		    !view->details->ignore_button_release) {
868
			nautilus_list_view_did_not_drag (view, event);
869 870 871 872 873
		}
	}
	return FALSE;
}

874 875 876
static gboolean
popup_menu_callback (GtkWidget *widget, gpointer callback_data)
{
877
 	NautilusListView *view;
878

879
	view = NAUTILUS_LIST_VIEW (callback_data);
880 881

	do_popup_menu (widget, view, NULL);
Dave Camp's avatar
Dave Camp committed
882 883

	return TRUE;
884 885
}

Alexander Larsson's avatar
Alexander Larsson committed
886
static void
887
subdirectory_done_loading_callback (NautilusDirectory *directory, NautilusListView *view)
Alexander Larsson's avatar
Alexander Larsson committed
888
{
889
	nautilus_list_model_subdirectory_done_loading (view->details->model, directory);
Alexander Larsson's avatar
Alexander Larsson committed
890 891
}

892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
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 {
927
	NautilusFile *file;
928
	NautilusDirectory *directory;
929
	NautilusListView *view;
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 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
} 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);
}
1034 1035

static void
1036
subdirectory_unloaded_callback (NautilusListModel *model,
1037 1038 1039
				NautilusDirectory *directory,
				gpointer callback_data)
{
1040
	NautilusListView *view;
1041
	
1042
	g_return_if_fail (NAUTILUS_IS_LIST_MODEL (model));
1043 1044
	g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));

1045
	view = NAUTILUS_LIST_VIEW(callback_data);
1046 1047 1048 1049
	
	g_signal_handlers_disconnect_by_func (directory,
					      G_CALLBACK (subdirectory_done_loading_callback),
					      view);
1050
	nautilus_view_remove_subdirectory (NAUTILUS_VIEW (view), directory);
Alexander Larsson's avatar
Alexander Larsson committed
1051 1052
}

1053 1054 1055
static gboolean
key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer callback_data)
{
1056
	NautilusView *view;
1057
	GdkEventButton button_event = { 0 };
1058
	gboolean handled;
1059 1060 1061 1062
	GtkTreeView *tree_view;
	GtkTreePath *path;

	tree_view = GTK_TREE_VIEW (widget);
1063

1064
	view = NAUTILUS_VIEW (callback_data);
1065
	handled = FALSE;
1066

1067
	switch (event->keyval) {
1068
	case GDK_KEY_F10:
1069
		if (event->state & GDK_CONTROL_MASK) {
1070
			nautilus_view_pop_up_background_context_menu (view, &button_event);
1071
			handled = TRUE;
1072 1073
		}
		break;
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
	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;
1098
	case GDK_KEY_space:
1099
		if (event->state & GDK_CONTROL_MASK) {
1100 1101
			handled = FALSE;
			break;
1102
		}
1103
		if (!gtk_widget_has_focus (GTK_WIDGET (NAUTILUS_LIST_VIEW (view)->details->tree_view))) {
1104 1105
			handled = FALSE;
			break;
1106
		}
1107
		if ((event->state & GDK_SHIFT_MASK) != 0) {
1108
			activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
1109
		} else {
1110
			preview_selected_items (NAUTILUS_LIST_VIEW (view));
1111
		}
1112 1113
		handled = TRUE;
		break;
1114 1115
	case GDK_KEY_Return:
	case GDK_KEY_KP_Enter:
1116
		if ((event->state & GDK_SHIFT_MASK) != 0) {
1117
			activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
1118
		} else {
1119
			activate_selected_items (NAUTILUS_LIST_VIEW (view));
1120
		}
1121 1122
		handled = TRUE;
		break;
1123
	case GDK_KEY_v:
1124
		/* Eat Control + v to not enable type ahead */
1125
		if ((event->state & GDK_CONTROL_MASK) != 0) {
1126
			handled = TRUE;
1127 1128
		}
		break;
1129 1130

	default:
1131
		handled = FALSE;
1132
	}
1133

1134
	return handled;
1135 1136
}

1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
static gboolean
test_expand_row_callback (GtkTreeView *tree_view,
			  GtkTreeIter *iter,
			  GtkTreePath *path,
			  gboolean user_data)
{
	return !g_settings_get_boolean (nautilus_list_view_preferences,
					NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
}

1147
static void
1148
nautilus_list_view_reveal_selection (NautilusView *view)
1149 1150 1151
{
	GList *selection;

1152
	g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
1153

1154
        selection = nautilus_view_get_selection (view);
1155 1156 1157

	/* Make sure at least one of the selected items is scrolled into view */
	if (selection != NULL) {
1158
		NautilusListView *list_view;
1159 1160 1161 1162
		NautilusFile *file;
		GtkTreeIter iter;
		GtkTreePath *path;
		
1163
		list_view = NAUTILUS_LIST_VIEW (view);
1164
		file = selection->data;
1165
		if (nautilus_list_model_get_first_iter_for_file (list_view->details->model, file, &iter)) {
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
			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);
}

1177 1178 1179 1180 1181 1182
static gboolean
sort_criterion_changes_due_to_user (GtkTreeView *tree_view)
{
	GList *columns, *p;
	GtkTreeViewColumn *column;
	GSignalInvocationHint *ihint;
1183
	gboolean ret;
1184

1185 1186
	ret = FALSE;

1187 1188 1189 1190 1191
	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) {
1192 1193
			ret = TRUE;
			break;
1194 1195
		}
	}
1196
	g_list_free (columns);
1197

1198
	return ret;
1199 1200
}

Diego González's avatar
Diego González committed
1201
static void
1202
sort_column_changed_callback (GtkTreeSortable *sortable, 
1203
			      NautilusListView *view)
Diego González's avatar
Diego González committed
1204 1205
{
	NautilusFile *file;
1206
	gint sort_column_id, default_sort_column_id;
1207
	GtkSortType reversed;
1208
	GQuark sort_attr, default_sort_attr;
1209
	char *reversed_attr, *default_reversed_attr;
1210
	gboolean default_sort_reversed;
Diego González's avatar
Diego González committed
1211

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

1214
	gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &reversed);
1215
	sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, sort_column_id);
1216

1217
	default_sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (view->details->model,
1218
										  g_quark_from_string (get_default_sort_order (file, &default_sort_reversed)));
1219
	default_sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, default_sort_column_id);
1220
	nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
1221
				    g_quark_to_string (default_sort_attr), g_quark_to_string (sort_attr));
Diego González's avatar
Diego González committed
1222

1223
	default_reversed_attr = (default_sort_reversed ? "true" : "false");
1224 1225 1226 1227 1228 1229 1230 1231

	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 */
1232 1233
			reversed = g_settings_get_boolean (nautilus_preferences,
							   NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
		} 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);
		}
	}


1248 1249 1250
	reversed_attr = (reversed ? "true" : "false");
	nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
				    default_reversed_attr, reversed_attr);
1251

1252
	/* Make sure selected item(s) is visible after sort */
1253
	nautilus_list_view_reveal_selection (NAUTILUS_VIEW (view));
1254 1255

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

1258
static gboolean
1259 1260 1261 1262 1263 1264 1265
editable_focus_out_cb (GtkWidget *widget,
		       GdkEvent *event,
		       gpointer user_data)
{
	NautilusListView *view = user_data;

	view->details->editable_widget = NULL;
1266 1267 1268

	nautilus_view_set_is_renaming (NAUTILUS_VIEW (view), FALSE);
	nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1269 1270

	return FALSE;
1271 1272
}

1273 1274 1275 1276
static void
cell_renderer_editing_started_cb (GtkCellRenderer *renderer,
				  GtkCellEditable *editable,
				  const gchar *path_str,
1277
				  NautilusListView *list_view)
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
{
	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));

1289 1290
	g_signal_connect (entry, "focus-out-event",
			  G_CALLBACK (editable_focus_out_cb), list_view);
1291 1292
}

1293 1294
static void
cell_renderer_editing_canceled (GtkCellRendererText *cell,
1295
				NautilusListView    *view)
1296
{
1297 1298
	view->details->editable_widget = NULL;

1299
	nautilus_view_set_is_renaming (NAUTILUS_VIEW (view), FALSE);
1300
	nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1301 1302
}

1303 1304 1305 1306
static void
cell_renderer_edited (GtkCellRendererText *cell,
		      const char          *path_str,
		      const char          *new_text,
1307
		      NautilusListView    *view)
1308 1309 1310 1311
{
	GtkTreePath *path;
	NautilusFile *file;
	GtkTreeIter iter;
1312

1313
	view->details->editable_widget = NULL;
1314
	nautilus_view_set_is_renaming (NAUTILUS_VIEW (view), FALSE);
1315

1316 1317 1318 1319 1320 1321 1322
	/* 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);
1323
		nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1324 1325 1326
		return;
	}
	
1327 1328 1329 1330 1331 1332 1333 1334 1335
	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,
1336
			    NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
1337 1338
			    -1);

1339 1340
	/* Only rename if name actually changed */
	if (strcmp (new_text, view->details->original_name) != 0) {
1341 1342
		view->details->renaming_file = nautilus_file_ref (file);
		view->details->rename_done = FALSE;
1343
		nautilus_rename_file (file, new_text, nautilus_list_view_rename_callback, g_object_ref (view));
1344 1345
		g_free (view->details->original_name);
		view->details->original_name = g_strdup (new_text);
1346
	}
1347 1348
	
	nautilus_file_unref (file);
1349 1350 1351 1352 1353 1354

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

1355
	nautilus_view_unfreeze_updates (NAUTILUS_VIEW (view));
1356 1357
}

1358 1359 1360 1361
static char *
get_root_uri_callback (NautilusTreeViewDragDest *dest,
		       gpointer user_data)
{
1362
	NautilusListView *view;
1363
	
1364
	view = NAUTILUS_LIST_VIEW (user_data);
1365

1366
	return nautilus_view_get_uri (NAUTILUS_VIEW (view));
1367 1368 1369 1370 1371 1372 1373
}

static NautilusFile *
get_file_for_path_callback (NautilusTreeViewDragDest *dest,
			    GtkTreePath *path,
			    gpointer user_data)
{
1374
	NautilusListView *view;
1375
	
1376
	view = NAUTILUS_LIST_VIEW (user_data);
1377

1378
	return nautilus_list_model_file_for_path (view->details->model, path);
1379 1380
}

1381 1382
/* Handles an URL received from Mozilla */
static void