static void
bookmarks_set_empty (NautilusBookmarksWindow *self,
		     gboolean empty)
{
	GtkTreeIter iter;

	if (empty) {
		setup_empty_list (self);
		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->tree_view), FALSE);
	} else {
		gtk_tree_view_set_model (self->priv->tree_view, GTK_TREE_MODEL (self->priv->model));
		gtk_widget_set_sensitive (GTK_WIDGET (self->priv->tree_view), TRUE);

		if (nautilus_bookmark_list_length (self->priv->bookmarks) > 0 &&
		    !get_selection_exists (self)) {
			gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (self->priv->model),
						       &iter, NULL, 0);
			gtk_tree_selection_select_iter (self->priv->selection, &iter);
		}
	}

	on_selection_changed (self->priv->selection, self);
}
/**
 * create_bookmarks_window:
 * 
 * Create a new bookmark-editing window. 
 * @list: The NautilusBookmarkList that this window will edit.
 *
 * Return value: A pointer to the new window.
 **/
GtkWindow *
create_bookmarks_window (NautilusBookmarkList *list, GObject *undo_manager_source)
{
	GtkWidget         *window;
	GtkTreeViewColumn *col;
	GtkCellRenderer   *rend;
	GtkBuilder        *builder;

	bookmarks = list;

	builder = gtk_builder_new ();
	if (!gtk_builder_add_from_file (builder,
					UIDIR  "/nautilus-bookmarks-window.ui",
					NULL)) {
		return NULL;
	}

	window = (GtkWidget *)gtk_builder_get_object (builder, "bookmarks_dialog");
	bookmark_list_widget = (GtkTreeView *)gtk_builder_get_object (builder, "bookmark_tree_view");
	remove_button = (GtkWidget *)gtk_builder_get_object (builder, "bookmark_delete_button");
	jump_button = (GtkWidget *)gtk_builder_get_object (builder, "bookmark_jump_button");

	set_up_close_accelerator (window);
	nautilus_undo_share_undo_manager (G_OBJECT (window), undo_manager_source);

	gtk_window_set_wmclass (GTK_WINDOW (window), "bookmarks", "Nautilus");
	nautilus_bookmarks_window_restore_geometry (window);

	g_object_weak_ref (G_OBJECT (undo_manager_source), edit_bookmarks_dialog_reset_signals, 
			   undo_manager_source);
	
	bookmark_list_widget = GTK_TREE_VIEW (gtk_builder_get_object (builder, "bookmark_tree_view"));

	rend = gtk_cell_renderer_pixbuf_new ();
	col = gtk_tree_view_column_new_with_attributes ("Icon", 
							rend,
							"gicon", 
							BOOKMARK_LIST_COLUMN_ICON,
							NULL);
	gtk_tree_view_append_column (bookmark_list_widget,
				     GTK_TREE_VIEW_COLUMN (col));
	gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (col),
					      NAUTILUS_ICON_SIZE_SMALLER);

	rend = gtk_cell_renderer_text_new ();
	g_object_set (rend,
		      "ellipsize", PANGO_ELLIPSIZE_END,
		      "ellipsize-set", TRUE,
		      NULL);

	col = gtk_tree_view_column_new_with_attributes ("Icon", 
							rend,
							"text", 
							BOOKMARK_LIST_COLUMN_NAME,
							"style",
							BOOKMARK_LIST_COLUMN_STYLE,
							NULL);
	gtk_tree_view_append_column (bookmark_list_widget,
				     GTK_TREE_VIEW_COLUMN (col));
	
	bookmark_list_store = create_bookmark_store ();
	setup_empty_list ();
	gtk_tree_view_set_model (bookmark_list_widget,
				 GTK_TREE_MODEL (bookmark_empty_list_store));
	
	bookmark_selection =
		GTK_TREE_SELECTION (gtk_tree_view_get_selection (bookmark_list_widget));

	name_field = nautilus_entry_new ();
	
	gtk_widget_show (name_field);
	gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "bookmark_name_placeholder")),
			    name_field, TRUE, TRUE, 0);
	
	gtk_label_set_mnemonic_widget (
		GTK_LABEL (gtk_builder_get_object (builder, "bookmark_name_label")),
		name_field);

	uri_field = nautilus_entry_new ();
	gtk_widget_show (uri_field);
	gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "bookmark_location_placeholder")),
			    uri_field, TRUE, TRUE, 0);

	gtk_label_set_mnemonic_widget (
		GTK_LABEL (gtk_builder_get_object (builder, "bookmark_location_label")),
		uri_field);

	bookmark_list_changed_signal_id =
		g_signal_connect (bookmarks, "changed",
				  G_CALLBACK (on_bookmark_list_changed), NULL);
	row_changed_signal_id =
		g_signal_connect (bookmark_list_store, "row_changed",
				  G_CALLBACK (on_row_changed), NULL);
	row_deleted_signal_id =
		g_signal_connect (bookmark_list_store, "row_deleted",
				  G_CALLBACK (on_row_deleted), NULL);
        row_activated_signal_id =
                g_signal_connect (bookmark_list_widget, "row_activated",
                                  G_CALLBACK (on_row_activated), undo_manager_source);
        button_pressed_signal_id =
                g_signal_connect (bookmark_list_widget, "button_press_event",
                                  G_CALLBACK (on_button_pressed), NULL);
        key_pressed_signal_id =
                g_signal_connect (bookmark_list_widget, "key_press_event",
                                  G_CALLBACK (on_key_pressed), NULL);
	selection_changed_id =
		g_signal_connect (bookmark_selection, "changed",
				  G_CALLBACK (on_selection_changed), NULL);	

	g_signal_connect (window, "delete_event",
			  G_CALLBACK (on_window_delete_event), NULL);
	g_signal_connect (window, "hide",
			  G_CALLBACK (on_window_hide_event), NULL);                    	    
	g_signal_connect (window, "destroy",
			  G_CALLBACK (on_window_destroy_event), NULL);
	g_signal_connect (window, "response",
			  G_CALLBACK (nautilus_bookmarks_window_response_callback), NULL);

	name_field_changed_signal_id =
		g_signal_connect (name_field, "changed",
				  G_CALLBACK (on_name_field_changed), NULL);
                      		    
	g_signal_connect (name_field, "focus_out_event",
			  G_CALLBACK (on_text_field_focus_out_event), NULL);                            
	g_signal_connect (name_field, "activate",
			  G_CALLBACK (name_or_uri_field_activate), NULL);

	uri_field_changed_signal_id = 
		g_signal_connect (uri_field, "changed",
				  G_CALLBACK (on_uri_field_changed), NULL);
                      		    
	g_signal_connect (uri_field, "focus_out_event",
			  G_CALLBACK (on_text_field_focus_out_event), NULL);
	g_signal_connect (uri_field, "activate",
			  G_CALLBACK (name_or_uri_field_activate), NULL);
	g_signal_connect (remove_button, "clicked",
			  G_CALLBACK (on_remove_button_clicked), NULL);
	jump_button_signal_id = 
		g_signal_connect (jump_button, "clicked",
				  G_CALLBACK (on_jump_button_clicked), undo_manager_source);

	gtk_tree_selection_set_mode (bookmark_selection, GTK_SELECTION_BROWSE);
	
	/* Fill in list widget with bookmarks, must be after signals are wired up. */
	repopulate();

	g_object_unref (builder);
	
	return GTK_WINDOW (window);
}
static void
nautilus_bookmarks_window_constructed (GObject *object)
{
	NautilusBookmarksWindow *self = NAUTILUS_BOOKMARKS_WINDOW (object);
	GtkBuilder *builder;
	GError *error = NULL;
	GtkWindow *window;
	GtkWidget *content;
	GtkTreeViewColumn *col;
	GtkCellRenderer *rend;

	G_OBJECT_CLASS (nautilus_bookmarks_window_parent_class)->constructed (object);

	builder = gtk_builder_new ();
	if (!gtk_builder_add_from_resource (builder,
					    "/org/gnome/nautilus/nautilus-bookmarks-window.ui",
					    &error)) {
		g_object_unref (builder);

		g_critical ("Can't load UI description for the bookmarks editor: %s", error->message);
		g_error_free (error);
		return;
	}

	window = GTK_WINDOW (object);
	gtk_window_set_title (window, _("Bookmarks"));
	gtk_window_set_default_size (window, 
				     BOOKMARKS_WINDOW_INITIAL_WIDTH, 
				     BOOKMARKS_WINDOW_INITIAL_HEIGHT);
	gtk_window_set_application (window,
				    gtk_window_get_application (GTK_WINDOW (self->priv->parent_window)));

	gtk_window_set_destroy_with_parent (window, TRUE);
	gtk_window_set_transient_for (window, GTK_WINDOW (self->priv->parent_window));
	gtk_window_set_position (window, GTK_WIN_POS_CENTER_ON_PARENT);
	gtk_container_set_border_width (GTK_CONTAINER (window), 6);

	g_signal_connect (window, "key-press-event",
			  G_CALLBACK (nautilus_bookmarks_window_key_press_event_cb), NULL);

	content = GTK_WIDGET (gtk_builder_get_object (builder, "bookmarks_window_content"));
	gtk_container_add (GTK_CONTAINER (window), content);

	/* tree view */
	self->priv->tree_view = GTK_TREE_VIEW (gtk_builder_get_object (builder, "bookmark_tree_view"));
	self->priv->selection = gtk_tree_view_get_selection (self->priv->tree_view);
	gtk_tree_selection_set_mode (self->priv->selection, GTK_SELECTION_BROWSE);

	rend = gtk_cell_renderer_pixbuf_new ();
	g_object_set (rend, "follow-state", TRUE, NULL);
	col = gtk_tree_view_column_new_with_attributes ("Icon", 
							rend,
							"gicon", 
							BOOKMARK_LIST_COLUMN_ICON,
							NULL);
	gtk_tree_view_append_column (self->priv->tree_view,
				     GTK_TREE_VIEW_COLUMN (col));
	gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (col),
					      NAUTILUS_ICON_SIZE_SMALLER);

	rend = gtk_cell_renderer_text_new ();
	g_object_set (rend,
		      "ellipsize", PANGO_ELLIPSIZE_END,
		      "ellipsize-set", TRUE,
		      NULL);

	col = gtk_tree_view_column_new_with_attributes ("Icon", 
							rend,
							"text", 
							BOOKMARK_LIST_COLUMN_NAME,
							"style",
							BOOKMARK_LIST_COLUMN_STYLE,
							NULL);
	gtk_tree_view_append_column (self->priv->tree_view,
				     GTK_TREE_VIEW_COLUMN (col));

	self->priv->model = create_bookmark_store ();
	setup_empty_list (self);

	/* name entry */
	self->priv->name_field = nautilus_entry_new ();
	gtk_widget_show (self->priv->name_field);
	gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "bookmark_name_placeholder")),
			    self->priv->name_field, TRUE, TRUE, 0);
	
	gtk_label_set_mnemonic_widget (
		GTK_LABEL (gtk_builder_get_object (builder, "bookmark_name_label")),
		self->priv->name_field);

	/* URI entry */
	self->priv->uri_field = nautilus_entry_new ();
	gtk_widget_show (self->priv->uri_field);
	gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (builder, "bookmark_location_placeholder")),
			    self->priv->uri_field, TRUE, TRUE, 0);

	gtk_label_set_mnemonic_widget (
		GTK_LABEL (gtk_builder_get_object (builder, "bookmark_location_label")),
		self->priv->uri_field);

	/* buttons */
	self->priv->remove_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_remove_button"));
	self->priv->up_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_up_button"));
	self->priv->down_button = GTK_WIDGET (gtk_builder_get_object (builder, "bookmark_down_button"));

	g_object_unref (builder);

	/* setup bookmarks list and signals */
	self->priv->bookmarks = nautilus_application_get_bookmarks
		(NAUTILUS_APPLICATION (g_application_get_default ()));
	self->priv->bookmarks_changed_id =
		g_signal_connect (self->priv->bookmarks, "changed",
				  G_CALLBACK (on_bookmark_list_changed), self);

	self->priv->row_changed_id =
		g_signal_connect (self->priv->model, "row-changed",
				  G_CALLBACK (on_row_changed), self);
	self->priv->row_deleted_id =
		g_signal_connect (self->priv->model, "row-deleted",
				  G_CALLBACK (on_row_deleted), self);

        self->priv->row_activated_id =
                g_signal_connect (self->priv->tree_view, "row-activated",
                                  G_CALLBACK (on_row_activated), self);
        self->priv->button_press_id =
                g_signal_connect (self->priv->tree_view, "button-press-event",
                                  G_CALLBACK (on_button_pressed), self);
        self->priv->key_press_id =
                g_signal_connect (self->priv->tree_view, "key-press-event",
                                  G_CALLBACK (on_key_pressed), self);
	self->priv->selection_changed_id =
		g_signal_connect (self->priv->selection, "changed",
				  G_CALLBACK (on_selection_changed), self);

	self->priv->name_changed_id =
		g_signal_connect (self->priv->name_field, "changed",
				  G_CALLBACK (on_name_field_changed), self);
	g_signal_connect (self->priv->name_field, "focus_out_event",
			  G_CALLBACK (on_text_field_focus_out_event), self);
	g_signal_connect (self->priv->name_field, "activate",
			  G_CALLBACK (name_or_uri_field_activate), self);

	self->priv->uri_changed_id =
		g_signal_connect (self->priv->uri_field, "changed",
				  G_CALLBACK (on_uri_field_changed), self);
	g_signal_connect (self->priv->uri_field, "focus_out_event",
			  G_CALLBACK (on_text_field_focus_out_event), self);
	g_signal_connect (self->priv->uri_field, "activate",
			  G_CALLBACK (name_or_uri_field_activate), self);

	g_signal_connect (self->priv->remove_button, "clicked",
			  G_CALLBACK (on_remove_button_clicked), self);
	g_signal_connect (self->priv->up_button, "clicked",
			  G_CALLBACK (on_up_button_clicked), self);
	g_signal_connect (self->priv->down_button, "clicked",
			  G_CALLBACK (on_down_button_clicked), self);
	
	/* Fill in list widget with bookmarks, must be after signals are wired up. */
	repopulate (self);
}
/**
 * create_bookmarks_window:
 * 
 * Create a new bookmark-editing window. 
 * @list: The NautilusBookmarkList that this window will edit.
 *
 * Return value: A pointer to the new window.
 **/
GtkWindow *
create_bookmarks_window (NautilusBookmarkList *list, GObject *undo_manager_source)
{
	GtkWidget         *window;
	GtkTreeViewColumn *col;
	GtkCellRenderer   *rend;
	GladeXML          *gui;

	bookmarks = list;

	gui = eel_glade_get_file (GLADEDIR "/nautilus-bookmarks-window.glade",
				  NULL, NULL,
				  "bookmarks_dialog", &window,
				  "bookmark_tree_view", &bookmark_list_widget,
				  "bookmark_delete_button", &remove_button,
                                  "bookmark_jump_button", &jump_button,
				  NULL);
	if (!gui) {
		return NULL;
	}

	application = NAUTILUS_WINDOW (undo_manager_source)->application;

	if (NAUTILUS_IS_NAVIGATION_WINDOW (undo_manager_source)) {
		parent_is_browser_window = TRUE;
	} else {
		parent_is_browser_window = FALSE;
	}

	set_up_close_accelerator (window);
	nautilus_undo_share_undo_manager (G_OBJECT (window), undo_manager_source);

	gtk_window_set_wmclass (GTK_WINDOW (window), "bookmarks", "Nautilus");
	nautilus_bookmarks_window_restore_geometry (window);

	g_object_weak_ref (G_OBJECT (undo_manager_source), edit_bookmarks_dialog_reset_signals, 
			   undo_manager_source);
	
	bookmark_list_widget = GTK_TREE_VIEW (glade_xml_get_widget (gui, "bookmark_tree_view"));

	rend = gtk_cell_renderer_pixbuf_new ();
	col = gtk_tree_view_column_new_with_attributes ("Icon", 
							rend,
							"pixbuf", 
							BOOKMARK_LIST_COLUMN_ICON,
							NULL);
	gtk_tree_view_append_column (bookmark_list_widget,
				     GTK_TREE_VIEW_COLUMN (col));
	gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (col),
					      NAUTILUS_ICON_SIZE_SMALLER);
	
	rend = gtk_cell_renderer_text_new ();
	col = gtk_tree_view_column_new_with_attributes ("Icon", 
							rend,
							"text", 
							BOOKMARK_LIST_COLUMN_NAME,
							"style",
							BOOKMARK_LIST_COLUMN_STYLE,
							NULL);
	gtk_tree_view_append_column (bookmark_list_widget,
				     GTK_TREE_VIEW_COLUMN (col));
	
	bookmark_list_store = create_bookmark_store ();
	setup_empty_list ();
	gtk_tree_view_set_model (bookmark_list_widget,
				 GTK_TREE_MODEL (bookmark_empty_list_store));
	
	bookmark_selection =
		GTK_TREE_SELECTION (gtk_tree_view_get_selection (bookmark_list_widget));

	name_field = nautilus_entry_new ();
	
	gtk_widget_show (name_field);
	gtk_box_pack_start (GTK_BOX (glade_xml_get_widget (gui, "bookmark_name_placeholder")),
			    name_field, TRUE, TRUE, 0);
	nautilus_undo_editable_set_undo_key (GTK_EDITABLE (name_field), TRUE);
	
	gtk_label_set_mnemonic_widget (
		GTK_LABEL (glade_xml_get_widget (gui, "bookmark_name_label")),
		name_field);

	uri_field = nautilus_entry_new ();
	gtk_widget_show (uri_field);
	gtk_box_pack_start (GTK_BOX (glade_xml_get_widget (gui, "bookmark_location_placeholder")),
			    uri_field, TRUE, TRUE, 0);
	nautilus_undo_editable_set_undo_key (GTK_EDITABLE (uri_field), TRUE);

	gtk_label_set_mnemonic_widget (
		GTK_LABEL (glade_xml_get_widget (gui, "bookmark_location_label")),
		uri_field);

	bookmark_list_changed_signal_id =
		g_signal_connect (bookmarks, "contents_changed",
				  G_CALLBACK (on_bookmark_list_changed), NULL);
	row_changed_signal_id =
		g_signal_connect (bookmark_list_store, "row_changed",
				  G_CALLBACK (on_row_changed), NULL);
	row_deleted_signal_id =
		g_signal_connect (bookmark_list_store, "row_deleted",
				  G_CALLBACK (on_row_deleted), NULL);
        row_activated_signal_id =
                g_signal_connect (bookmark_list_widget, "row_activated",
                                  G_CALLBACK (on_row_activated), undo_manager_source);
        button_pressed_signal_id =
                g_signal_connect (bookmark_list_widget, "button_press_event",
                                  G_CALLBACK (on_button_pressed), NULL);
        key_pressed_signal_id =
                g_signal_connect (bookmark_list_widget, "key_press_event",
                                  G_CALLBACK (on_key_pressed), NULL);
	selection_changed_id =
		g_signal_connect (bookmark_selection, "changed",
				  G_CALLBACK (on_selection_changed), NULL);	

	g_signal_connect (window, "delete_event",
			  G_CALLBACK (on_window_delete_event), NULL);
	g_signal_connect (window, "hide",
			  G_CALLBACK (on_window_hide_event), NULL);                    	    
	g_signal_connect (window, "destroy",
			  G_CALLBACK (on_window_destroy_event), NULL);
	g_signal_connect (window, "response",
			  G_CALLBACK (nautilus_bookmarks_window_response_callback), NULL);

	name_field_changed_signal_id =
		g_signal_connect (name_field, "changed",
				  G_CALLBACK (on_name_field_changed), NULL);
                      		    
	g_signal_connect (name_field, "focus_out_event",
			  G_CALLBACK (on_text_field_focus_out_event), NULL);                            
	g_signal_connect (name_field, "activate",
			  G_CALLBACK (name_or_uri_field_activate), NULL);

	uri_field_changed_signal_id = 
		g_signal_connect (uri_field, "changed",
				  G_CALLBACK (on_uri_field_changed), NULL);
                      		    
	g_signal_connect (uri_field, "focus_out_event",
			  G_CALLBACK (on_text_field_focus_out_event), NULL);
	g_signal_connect (uri_field, "activate",
			  G_CALLBACK (name_or_uri_field_activate), NULL);
	g_signal_connect (remove_button, "clicked",
			  G_CALLBACK (on_remove_button_clicked), NULL);
	jump_button_signal_id = 
		g_signal_connect (jump_button, "clicked",
				  G_CALLBACK (on_jump_button_clicked), undo_manager_source);

	gtk_tree_selection_set_mode (bookmark_selection, GTK_SELECTION_BROWSE);
	
	/* Fill in list widget with bookmarks, must be after signals are wired up. */
	repopulate();

	g_object_unref (G_OBJECT (gui));
	
	return GTK_WINDOW (window);
}