gedit-encodings-dialog.c 13.3 KB
Newer Older
Paolo Maggi's avatar
Paolo Maggi committed
1 2 3 4
/*
 * gedit-encodings-dialog.c
 * This file is part of gedit
 *
Paolo Borelli's avatar
Paolo Borelli committed
5
 * Copyright (C) 2002-2005 Paolo Maggi 
Paolo Maggi's avatar
Paolo Maggi committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA 02111-1307, USA. 
 */

/*
Paolo Borelli's avatar
Paolo Borelli committed
24
 * Modified by the gedit Team, 2002-2005. See the AUTHORS file for a 
Paolo Maggi's avatar
Paolo Maggi committed
25 26
 * list of people on the gedit Team.  
 * See the ChangeLog files for a list of changes. 
Paolo Borelli's avatar
Paolo Borelli committed
27 28
 *
 * $Id$
Paolo Maggi's avatar
Paolo Maggi committed
29 30
 */

31 32 33 34
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

Paolo Maggi's avatar
Paolo Maggi committed
35 36
#include <string.h>

37
#include <glib.h>
Paolo Borelli's avatar
Paolo Borelli committed
38
#include <glib/gi18n.h>
Paolo Maggi's avatar
Paolo Maggi committed
39
#include <gtk/gtk.h>
Paolo Maggi's avatar
Paolo Maggi committed
40

Paolo Borelli's avatar
Paolo Borelli committed
41
#include "gedit-encodings-dialog.h"
Paolo Maggi's avatar
Paolo Maggi committed
42
#include "gedit-encodings.h"
Paolo Maggi's avatar
Paolo Maggi committed
43
#include "gedit-prefs-manager.h"
Paolo Borelli's avatar
Paolo Borelli committed
44
#include "gedit-utils.h"
Paolo Maggi's avatar
Paolo Maggi committed
45
#include "gedit-debug.h"
Paolo Borelli's avatar
Paolo Borelli committed
46
#include "gedit-help.h"
47
#include "gedit-dirs.h"
Paolo Maggi's avatar
Paolo Maggi committed
48

Paolo Borelli's avatar
Paolo Borelli committed
49 50 51
#define GEDIT_ENCODINGS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
						   GEDIT_TYPE_ENCODINGS_DIALOG,           \
						   GeditEncodingsDialogPrivate))
Paolo Maggi's avatar
Paolo Maggi committed
52

Paolo Borelli's avatar
Paolo Borelli committed
53 54 55 56 57 58 59 60 61 62
struct _GeditEncodingsDialogPrivate
{
	GtkListStore	*available_liststore;
	GtkListStore	*displayed_liststore;
	GtkWidget	*available_treeview;
	GtkWidget	*displayed_treeview;
	GtkWidget	*add_button;
	GtkWidget	*remove_button;

	GSList		*show_in_menu_list;
Paolo Maggi's avatar
Paolo Maggi committed
63 64
};

Paolo Borelli's avatar
Paolo Borelli committed
65
G_DEFINE_TYPE(GeditEncodingsDialog, gedit_encodings_dialog, GTK_TYPE_DIALOG)
Paolo Maggi's avatar
Paolo Maggi committed
66

Paolo Maggi's avatar
Paolo Maggi committed
67
static void
Paolo Borelli's avatar
Paolo Borelli committed
68
gedit_encodings_dialog_finalize (GObject *object)
Paolo Maggi's avatar
Paolo Maggi committed
69
{
Paolo Borelli's avatar
Paolo Borelli committed
70
	GeditEncodingsDialogPrivate *priv = GEDIT_ENCODINGS_DIALOG (object)->priv;
71

Paolo Borelli's avatar
Paolo Borelli committed
72
	g_slist_free (priv->show_in_menu_list);
73

Paolo Borelli's avatar
Paolo Borelli committed
74 75
	G_OBJECT_CLASS (gedit_encodings_dialog_parent_class)->finalize (object);
}
76

Paolo Borelli's avatar
Paolo Borelli committed
77 78 79 80
static void
gedit_encodings_dialog_class_init (GeditEncodingsDialogClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
81

Paolo Borelli's avatar
Paolo Borelli committed
82
	object_class->finalize = gedit_encodings_dialog_finalize;
83

Paolo Borelli's avatar
Paolo Borelli committed
84
	g_type_class_add_private (object_class, sizeof (GeditEncodingsDialogPrivate));
Paolo Maggi's avatar
Paolo Maggi committed
85
}
Paolo Maggi's avatar
Paolo Maggi committed
86

Paolo Borelli's avatar
Paolo Borelli committed
87 88 89 90 91 92
enum {
	COLUMN_NAME,
	COLUMN_CHARSET,
	N_COLUMNS
};

Paolo Maggi's avatar
Paolo Maggi committed
93
static void
Paolo Borelli's avatar
Paolo Borelli committed
94 95 96 97
count_selected_items_func (GtkTreeModel *model,
			   GtkTreePath  *path,
			   GtkTreeIter  *iter, 
			   gpointer      data)
Paolo Maggi's avatar
Paolo Maggi committed
98 99
{
	int *count = data;
Paolo Maggi's avatar
Paolo Maggi committed
100

Paolo Maggi's avatar
Paolo Maggi committed
101 102
	*count += 1;
}
Paolo Maggi's avatar
Paolo Maggi committed
103 104

static void
Paolo Borelli's avatar
Paolo Borelli committed
105 106
available_selection_changed_callback (GtkTreeSelection     *selection,
				      GeditEncodingsDialog *dialogs)
Paolo Maggi's avatar
Paolo Maggi committed
107
{
Paolo Maggi's avatar
Paolo Maggi committed
108 109 110 111 112 113 114
	int count;

	count = 0;
	gtk_tree_selection_selected_foreach (selection,
					     count_selected_items_func,
					     &count);

Paolo Borelli's avatar
Paolo Borelli committed
115
	gtk_widget_set_sensitive (dialogs->priv->add_button, count > 0);
Paolo Maggi's avatar
Paolo Maggi committed
116 117 118
}

static void
Paolo Borelli's avatar
Paolo Borelli committed
119 120
displayed_selection_changed_callback (GtkTreeSelection     *selection,
				      GeditEncodingsDialog *dialogs)
Paolo Maggi's avatar
Paolo Maggi committed
121
{
Paolo Maggi's avatar
Paolo Maggi committed
122
	int count;
123

Paolo Maggi's avatar
Paolo Maggi committed
124 125 126 127
	count = 0;
	gtk_tree_selection_selected_foreach (selection,
					     count_selected_items_func,
					     &count);
128

Paolo Borelli's avatar
Paolo Borelli committed
129
	gtk_widget_set_sensitive (dialogs->priv->remove_button, count > 0);
Paolo Maggi's avatar
Paolo Maggi committed
130 131 132
}

static void
133
get_selected_encodings_func (GtkTreeModel *model,
Paolo Borelli's avatar
Paolo Borelli committed
134 135 136
			     GtkTreePath  *path,
			     GtkTreeIter  *iter, 
			     gpointer      data)
Paolo Maggi's avatar
Paolo Maggi committed
137 138 139 140
{
	GSList **list = data;
	gchar *charset;
	const GeditEncoding *enc;
Paolo Maggi's avatar
Paolo Maggi committed
141

Paolo Maggi's avatar
Paolo Maggi committed
142 143
	charset = NULL;
	gtk_tree_model_get (model, iter, COLUMN_CHARSET, &charset, -1);
Paolo Maggi's avatar
Paolo Maggi committed
144

Paolo Maggi's avatar
Paolo Maggi committed
145 146
	enc = gedit_encoding_get_from_charset (charset);
	g_free (charset);
Paolo Maggi's avatar
Paolo Maggi committed
147

148
	*list = g_slist_prepend (*list, (gpointer)enc);
Paolo Maggi's avatar
Paolo Maggi committed
149 150 151
}

static void
Paolo Borelli's avatar
Paolo Borelli committed
152 153
update_shown_in_menu_tree_model (GtkListStore *store,
				 GSList       *list)
Paolo Maggi's avatar
Paolo Maggi committed
154 155 156 157
{
	GtkTreeIter iter;

	gtk_list_store_clear (store);
158

Paolo Maggi's avatar
Paolo Maggi committed
159
	while (list != NULL)
160
	{
Paolo Borelli's avatar
Paolo Borelli committed
161
		const GeditEncoding *enc;
162

Paolo Maggi's avatar
Paolo Maggi committed
163
		enc = (const GeditEncoding*) list->data;
Paolo Borelli's avatar
Paolo Borelli committed
164

Paolo Maggi's avatar
Paolo Maggi committed
165 166 167 168 169 170 171 172
		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
				    COLUMN_CHARSET,
				    gedit_encoding_get_charset (enc),
				    COLUMN_NAME,
				    gedit_encoding_get_name (enc), -1);

		list = g_slist_next (list);
Paolo Borelli's avatar
Paolo Borelli committed
173
	}
Paolo Maggi's avatar
Paolo Maggi committed
174 175 176
}

static void
Paolo Borelli's avatar
Paolo Borelli committed
177 178
add_button_clicked_callback (GtkWidget            *button,
			     GeditEncodingsDialog *dialog)
Paolo Maggi's avatar
Paolo Maggi committed
179 180 181 182
{
	GtkTreeSelection *selection;
	GSList *encodings;
	GSList *tmp;
183

Paolo Borelli's avatar
Paolo Borelli committed
184
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->available_treeview));
Paolo Maggi's avatar
Paolo Maggi committed
185 186 187 188 189 190 191 192

	encodings = NULL;
	gtk_tree_selection_selected_foreach (selection,
					     get_selected_encodings_func,
					     &encodings);

	tmp = encodings;
	while (tmp != NULL)
193
	{
Paolo Borelli's avatar
Paolo Borelli committed
194 195 196
		if (g_slist_find (dialog->priv->show_in_menu_list, tmp->data) == NULL)
			dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list,
									   tmp->data);
Paolo Maggi's avatar
Paolo Maggi committed
197 198

		tmp = g_slist_next (tmp);
199
	}
200

Paolo Maggi's avatar
Paolo Maggi committed
201 202
	g_slist_free (encodings);

Paolo Borelli's avatar
Paolo Borelli committed
203 204
	update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore),
					 dialog->priv->show_in_menu_list);
Paolo Maggi's avatar
Paolo Maggi committed
205 206 207
}

static void
Paolo Borelli's avatar
Paolo Borelli committed
208 209
remove_button_clicked_callback (GtkWidget            *button,
				GeditEncodingsDialog *dialog)
Paolo Maggi's avatar
Paolo Maggi committed
210 211 212 213 214
{
	GtkTreeSelection *selection;
	GSList *encodings;
	GSList *tmp;

Paolo Borelli's avatar
Paolo Borelli committed
215
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->displayed_treeview));
Paolo Maggi's avatar
Paolo Maggi committed
216 217 218 219 220 221 222 223

	encodings = NULL;
	gtk_tree_selection_selected_foreach (selection,
					     get_selected_encodings_func,
					     &encodings);

	tmp = encodings;
	while (tmp != NULL) 
224
	{
Paolo Borelli's avatar
Paolo Borelli committed
225 226
		dialog->priv->show_in_menu_list = g_slist_remove (dialog->priv->show_in_menu_list,
								  tmp->data);
227

Paolo Maggi's avatar
Paolo Maggi committed
228
		tmp = g_slist_next (tmp);
229
	}
Paolo Maggi's avatar
Paolo Maggi committed
230 231 232

	g_slist_free (encodings);

Paolo Borelli's avatar
Paolo Borelli committed
233 234
	update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore),
					 dialog->priv->show_in_menu_list);
Paolo Maggi's avatar
Paolo Maggi committed
235 236
}

Paolo Maggi's avatar
Paolo Maggi committed
237
static void
Paolo Borelli's avatar
Paolo Borelli committed
238
init_shown_in_menu_tree_model (GeditEncodingsDialog *dialog)
Paolo Maggi's avatar
Paolo Maggi committed
239 240 241
{
	GtkTreeIter iter;
	GSList *list, *tmp;
242

Paolo Maggi's avatar
Paolo Maggi committed
243
	/* add data to the list store */
244
	list = gedit_prefs_manager_get_shown_in_menu_encodings ();
Paolo Borelli's avatar
Paolo Borelli committed
245

Paolo Maggi's avatar
Paolo Maggi committed
246
	tmp = list;
Paolo Borelli's avatar
Paolo Borelli committed
247

Paolo Maggi's avatar
Paolo Maggi committed
248
	while (tmp != NULL)
Paolo Maggi's avatar
Paolo Maggi committed
249
	{
Paolo Borelli's avatar
Paolo Borelli committed
250
		const GeditEncoding *enc;
Paolo Maggi's avatar
Paolo Maggi committed
251

Paolo Borelli's avatar
Paolo Borelli committed
252 253 254 255 256 257 258 259 260
		enc = (const GeditEncoding *) tmp->data;

		dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list,
								   tmp->data);

		gtk_list_store_append (dialog->priv->displayed_liststore,
				       &iter);
		gtk_list_store_set (dialog->priv->displayed_liststore,
				    &iter,
Paolo Maggi's avatar
Paolo Maggi committed
261 262 263 264
				    COLUMN_CHARSET,
				    gedit_encoding_get_charset (enc),
				    COLUMN_NAME,
				    gedit_encoding_get_name (enc), -1);
265

Paolo Maggi's avatar
Paolo Maggi committed
266
		tmp = g_slist_next (tmp);
Paolo Maggi's avatar
Paolo Maggi committed
267
	}
Paolo Maggi's avatar
Paolo Maggi committed
268 269

	g_slist_free (list);
Paolo Maggi's avatar
Paolo Maggi committed
270 271
}

Paolo Borelli's avatar
Paolo Borelli committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
static void 
response_handler (GtkDialog            *dialog,
		  gint                  response_id,
                  GeditEncodingsDialog *dlg)
{
	if (response_id == GTK_RESPONSE_HELP)
	{
		gedit_help_display (GTK_WINDOW (dialog), "gedit", NULL);
		g_signal_stop_emission_by_name (dialog, "response");
		return;
	}

	if (response_id == GTK_RESPONSE_OK)
	{
		g_return_if_fail (gedit_prefs_manager_shown_in_menu_encodings_can_set ());
		gedit_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list);
	}
}

static void
gedit_encodings_dialog_init (GeditEncodingsDialog *dlg)
Paolo Maggi's avatar
Paolo Maggi committed
293
{
Paolo Borelli's avatar
Paolo Borelli committed
294
	GtkWidget *content;
Paolo Maggi's avatar
Paolo Maggi committed
295 296
	GtkCellRenderer *cell_renderer;
	GtkTreeModel *sort_model;
Paolo Maggi's avatar
Paolo Maggi committed
297
	GtkTreeViewColumn *column;
Paolo Maggi's avatar
Paolo Maggi committed
298
	GtkTreeIter parent_iter;
299
	GtkTreeSelection *selection;
Paolo Maggi's avatar
Paolo Maggi committed
300
	const GeditEncoding *enc;
Paolo Borelli's avatar
Paolo Borelli committed
301 302 303
	GtkWidget *error_widget;
	int i;
	gboolean ret;
304
	gchar *file;
305 306 307 308
	gchar *root_objects[] = {
		"encodings-dialog-contents",
		NULL
	};
Paolo Maggi's avatar
Paolo Maggi committed
309

Paolo Borelli's avatar
Paolo Borelli committed
310 311 312 313 314 315 316 317 318 319 320
	dlg->priv = GEDIT_ENCODINGS_DIALOG_GET_PRIVATE (dlg);
	
	gtk_dialog_add_buttons (GTK_DIALOG (dlg),
				GTK_STOCK_CANCEL, 
				GTK_RESPONSE_CANCEL,
				GTK_STOCK_OK,
				GTK_RESPONSE_OK,
				GTK_STOCK_HELP,
				GTK_RESPONSE_HELP,
				NULL);

321
	gtk_window_set_title (GTK_WINDOW (dlg), _("Character Encodings"));
Paolo Borelli's avatar
Paolo Borelli committed
322 323
	gtk_window_set_default_size (GTK_WINDOW (dlg), 650, 400);
	gtk_dialog_set_has_separator (GTK_DIALOG (dlg), FALSE);
324 325
	
	/* HIG defaults */
326
	gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
327 328 329 330 331
	gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
			     2); /* 2 * 5 + 2 = 12 */
	gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
					5);
	gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6);
Paolo Borelli's avatar
Paolo Borelli committed
332 333 334 335 336 337 338 339 340

	gtk_dialog_set_default_response (GTK_DIALOG (dlg),
					 GTK_RESPONSE_OK);

	g_signal_connect (dlg,
			  "response",
			  G_CALLBACK (response_handler),
			  dlg);

341 342
	file = gedit_dirs_get_ui_file ("gedit-encodings-dialog.ui");
	ret = gedit_utils_get_ui_objects (file,
343 344 345 346 347 348 349 350
					  root_objects,
					  &error_widget,
					  "encodings-dialog-contents", &content,
					  "add-button", &dlg->priv->add_button,
					  "remove-button", &dlg->priv->remove_button,
					  "available-treeview", &dlg->priv->available_treeview,
					  "displayed-treeview", &dlg->priv->displayed_treeview,
					  NULL);
351
	g_free (file);
Paolo Borelli's avatar
Paolo Borelli committed
352 353

	if (!ret)
Paolo Maggi's avatar
Paolo Maggi committed
354
	{
Paolo Borelli's avatar
Paolo Borelli committed
355
		gtk_widget_show (error_widget);
Paolo Maggi's avatar
Paolo Maggi committed
356

357 358 359
		gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
		                    error_widget,
		                    TRUE, TRUE, 0);
360
		gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5);			     
Paolo Maggi's avatar
Paolo Maggi committed
361

Paolo Borelli's avatar
Paolo Borelli committed
362 363
		return;
	}
Paolo Maggi's avatar
Paolo Maggi committed
364

365
	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
Paolo Borelli's avatar
Paolo Borelli committed
366
			    content, TRUE, TRUE, 0);
367
	g_object_unref (content);
368
	gtk_container_set_border_width (GTK_CONTAINER (content), 5);			     
Paolo Maggi's avatar
Paolo Maggi committed
369

Paolo Borelli's avatar
Paolo Borelli committed
370 371
	g_signal_connect (dlg->priv->add_button,
			  "clicked",
Paolo Maggi's avatar
Paolo Maggi committed
372
			  G_CALLBACK (add_button_clicked_callback),
Paolo Borelli's avatar
Paolo Borelli committed
373 374 375
			  dlg);
	g_signal_connect (dlg->priv->remove_button,
			  "clicked",
Paolo Maggi's avatar
Paolo Maggi committed
376
			  G_CALLBACK (remove_button_clicked_callback),
Paolo Borelli's avatar
Paolo Borelli committed
377
			  dlg);
Paolo Maggi's avatar
Paolo Maggi committed
378 379

	/* Tree view of available encodings */
Paolo Borelli's avatar
Paolo Borelli committed
380 381 382
	dlg->priv->available_liststore = gtk_list_store_new (N_COLUMNS,
							     G_TYPE_STRING,
							     G_TYPE_STRING);
Paolo Maggi's avatar
Paolo Maggi committed
383 384 385 386 387 388

	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Description"),
							   cell_renderer,
							   "text", COLUMN_NAME,
							   NULL);
Paolo Borelli's avatar
Paolo Borelli committed
389 390
	gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview),
				     column);
Paolo Maggi's avatar
Paolo Maggi committed
391 392 393 394 395 396 397 398
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);

	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
							   cell_renderer,
							   "text",
							   COLUMN_CHARSET,
							   NULL);
Paolo Borelli's avatar
Paolo Borelli committed
399 400
	gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview),
				     column);
Paolo Maggi's avatar
Paolo Maggi committed
401
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);
Paolo Maggi's avatar
Paolo Maggi committed
402

Paolo Maggi's avatar
Paolo Maggi committed
403 404 405 406
	/* Add the data */
	i = 0;
	while ((enc = gedit_encoding_get_from_index (i)) != NULL) 
	{
Paolo Borelli's avatar
Paolo Borelli committed
407 408 409 410
		gtk_list_store_append (dlg->priv->available_liststore,
				       &parent_iter);
		gtk_list_store_set (dlg->priv->available_liststore,
				    &parent_iter,
Paolo Maggi's avatar
Paolo Maggi committed
411 412 413 414
				    COLUMN_CHARSET,
				    gedit_encoding_get_charset (enc),
				    COLUMN_NAME,
				    gedit_encoding_get_name (enc), -1);
Paolo Maggi's avatar
Paolo Maggi committed
415

Paolo Maggi's avatar
Paolo Maggi committed
416 417
		++i;
	}
Paolo Maggi's avatar
Paolo Maggi committed
418

Paolo Maggi's avatar
Paolo Maggi committed
419
	/* Sort model */
Paolo Borelli's avatar
Paolo Borelli committed
420 421 422
	sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->available_liststore));
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
					      COLUMN_NAME,
Paolo Maggi's avatar
Paolo Maggi committed
423 424
					      GTK_SORT_ASCENDING);

Paolo Borelli's avatar
Paolo Borelli committed
425 426 427
	gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->available_treeview),
				 sort_model);
	g_object_unref (G_OBJECT (dlg->priv->available_liststore));
Paolo Maggi's avatar
Paolo Maggi committed
428 429
	g_object_unref (G_OBJECT (sort_model));

Paolo Borelli's avatar
Paolo Borelli committed
430
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->available_treeview));
Paolo Maggi's avatar
Paolo Maggi committed
431 432 433
	gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
				     GTK_SELECTION_MULTIPLE);

Paolo Borelli's avatar
Paolo Borelli committed
434 435 436 437 438
	available_selection_changed_callback (selection, dlg);
	g_signal_connect (selection,
			  "changed",
			  G_CALLBACK (available_selection_changed_callback),
			  dlg);
Paolo Maggi's avatar
Paolo Maggi committed
439 440

	/* Tree view of selected encodings */
Paolo Borelli's avatar
Paolo Borelli committed
441 442 443
	dlg->priv->displayed_liststore = gtk_list_store_new (N_COLUMNS,
							     G_TYPE_STRING,
							     G_TYPE_STRING);
Paolo Maggi's avatar
Paolo Maggi committed
444 445

	cell_renderer = gtk_cell_renderer_text_new ();
Paolo Borelli's avatar
Paolo Borelli committed
446 447 448 449 450 451
	column = gtk_tree_view_column_new_with_attributes (_("_Description"),
							   cell_renderer,
							   "text", COLUMN_NAME,
							   NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview),
				     column);
Paolo Maggi's avatar
Paolo Maggi committed
452 453 454 455 456 457 458 459
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);

	cell_renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
							   cell_renderer,
							   "text",
							   COLUMN_CHARSET,
							   NULL);
Paolo Borelli's avatar
Paolo Borelli committed
460 461
	gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview),
				     column);
Paolo Maggi's avatar
Paolo Maggi committed
462 463 464
	gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);

	/* Add the data */
Paolo Borelli's avatar
Paolo Borelli committed
465 466
	init_shown_in_menu_tree_model (dlg);

Paolo Maggi's avatar
Paolo Maggi committed
467
	/* Sort model */
Paolo Borelli's avatar
Paolo Borelli committed
468
	sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->displayed_liststore));
Paolo Maggi's avatar
Paolo Maggi committed
469

Paolo Maggi's avatar
Paolo Maggi committed
470 471 472
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
					      (sort_model), COLUMN_NAME,
					      GTK_SORT_ASCENDING);
Paolo Maggi's avatar
Paolo Maggi committed
473

Paolo Borelli's avatar
Paolo Borelli committed
474 475
	gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->displayed_treeview),
				 sort_model);
Paolo Maggi's avatar
Paolo Maggi committed
476
	g_object_unref (G_OBJECT (sort_model));
Paolo Borelli's avatar
Paolo Borelli committed
477
	g_object_unref (G_OBJECT (dlg->priv->displayed_liststore));
478

Paolo Borelli's avatar
Paolo Borelli committed
479
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->displayed_treeview));
Paolo Maggi's avatar
Paolo Maggi committed
480 481
	gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
				     GTK_SELECTION_MULTIPLE);
482

Paolo Borelli's avatar
Paolo Borelli committed
483 484 485 486 487
	displayed_selection_changed_callback (selection, dlg);
	g_signal_connect (selection,
			  "changed",
			  G_CALLBACK (displayed_selection_changed_callback),
			  dlg);
Paolo Maggi's avatar
Paolo Maggi committed
488 489
}

Paolo Borelli's avatar
Paolo Borelli committed
490 491
GtkWidget *
gedit_encodings_dialog_new (void)
Paolo Maggi's avatar
Paolo Maggi committed
492
{
Paolo Borelli's avatar
Paolo Borelli committed
493
	GtkWidget *dlg;
Paolo Maggi's avatar
Paolo Maggi committed
494

Paolo Borelli's avatar
Paolo Borelli committed
495
	dlg = GTK_WIDGET (g_object_new (GEDIT_TYPE_ENCODINGS_DIALOG, NULL));
Paolo Maggi's avatar
Paolo Maggi committed
496

Paolo Borelli's avatar
Paolo Borelli committed
497
	return dlg;
Paolo Maggi's avatar
Paolo Maggi committed
498
}
Paolo Maggi's avatar
Paolo Maggi committed
499

500
/* ex:ts=8:noet: */