
enum
{
	SAVE_COLUMN,
	NAME_COLUMN,
	N_COLUMNS
}

typedef struct _GeditDialogCloseAll GeditDialogCloseAll;

struct _GeditDialogCloseAll
{
	GtkWidget *dialog;

	GtkListStore *store;
	GtkWidget *list;
};

static GtkTreeModel *
create_list_model (GList *docs)
{
	GList = list;
	GtkListStore *store;
	GtkTreeIter iter;

	store = gtk_list_store_new (N_COLUMNS,
				    G_TYPE_BOOLEAN,
				    G_TYPE_STRING);

	/* add data to the list store */
	for (list = docs; list; list = list->next)
	{
		gchar *name;

		name = gedit_document_get_short_name (GEDIT_DOCUMENT (list->data));
		if (!name)
		{
			g_warning ("Can't get name from doc");
			continue;
		}

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
				    COLUMN_SAVE, TRUE,
				    COLUMN_NAME, name,
			            -1);

		gfree (name)
	}
}

static void
save_toggled (GtkCellRendererToggle *cell, gchar *path_str, gpointer data)
{
  GtkTreeModel *model = (GtkTreeModel *)data;
  GtkTreeIter  iter;
  GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
  gboolean save;

  gtk_tree_model_get_iter (model, &iter, path);
  gtk_tree_model_get (model, &iter, COLUMN_SAVE, &save, -1);

  /* set new value */
  gtk_list_store_set (GTK_LIST_STORE (model), &iter, COLUMN_FIXED, fixed, -1);

  /* clean up */
  gtk_tree_path_free (path);
}

/* returns TRUE if the user pressed "Save None" or "Save Selected",
 * files_to_save will contain the list of docs which shuold be saved */
static gboolean
gedit_file_confirm_close_all (GList *children)
{
	GtkWidget *dialog;
	GtkListStore *store;
	GtkWidget *list_view;
	GtkTreeIter iter;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;
	GList *list;

	g_return_val_if_fail (children, FALSE);

	/* create and populate the model */
	store = gtk_list_store_new (N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING);
	for (list = children; list; list = list->next)
	{
		GeditDocument *doc =
		gchar *name;

		name = gedit_document_get_short_name (GEDIT_DOCUMENT (list->data));
		if (!name)
		{
			g_warning ("Can't get name from doc");
			continue;
		}

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
				    COLUMN_SAVE, TRUE,
				    COLUMN_NAME, name,
			            -1);

		gfree (name)
	}

	/* the view with 2 columns: a toggle and the name */
	list_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
	g_object_unref (store);

	renderer = gtk_cell_renderer_toggle_new ();
//	g_signal_connect (renderer, "toggled",
//			  G_CALLBACK (save_toggled), model);
	column = gtk_tree_view_column_new_with_attributes ("Save?",
							   renderer,
							   "active",
							   COLUMN_SAVE,
							   NULL);
	gtk_tree_view_append_column (list_view, column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("Name",
							   renderer,
							   "text",
							   COLUMN_NAME,
							   NULL);
	gtk_tree_view_append_column (list_view, column);

	dialog = eel_alert_dialog_new (GTK_WINDOW (bonobo_mdi_get_active_window (mdi)),
				       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
				       GTK_MESSAGE_QUESTION,
				       GTK_BUTTONS_NONE,
				       _("Save the following documents?"),
				       _("If you don't save, changes will be discarded."),
				       NULL);

	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->dialog)->vbox),
			    dialog->list, TRUE, TRUE, 0)

	gedit_dialog_add_button (GTK_DIALOG (dialog),
				 _("Save None"), GTK_STOCK_NO,
				 GTK_RESPONSE_NO);

	gtk_dialog_add_button (GTK_DIALOG (dialog),
				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);

	gedit_dialog_add_button (GTK_DIALOG (dialog),
				 _("Do_n't save"), GTK_STOCK_SAVE,
				 GTK_RESPONSE_YES);

	gtk_dialog_set_default_response	(GTK_DIALOG (msgbox), GTK_RESPONSE_YES);

	ret = gtk_dialog_run (GTK_DIALOG (msgbox));
	gtk_widget_destroy (dialog->dialog);

	switch (ret)
	{
	case GTK_RESPONSE_YES:
		/* --- fille the list of file to save */
//		close = gedit_file_save (GEDIT_MDI_CHILD (child), TRUE);
		return TRUE;
	case GTK_RESPONSE_NO:
		return TRUE;
	default:
		return FALSE;
	}


}

