* plugins/debug-manager/plugin.c:
[anjuta-git-plugin.git] / libanjuta / anjuta-encodings.c
blob2a2e49153e25d66e06cdc969093fab84e1ff95b2
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3 * anjuta-encodings.c
4 * Copyright (C) 2002 Paolo Maggi
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * Modified by the gedit Team, 2002. See the gedit AUTHORS file for a
24 * list of people on the gedit Team.
25 * See the gedit ChangeLog files for a list of changes.
27 /* Stolen from gedit - Naba */
29 /**
30 * SECTION:anjuta-encodings
31 * @title: AnjutaEncoding
32 * @short_description: Text encoding and decoding
33 * @see_also:
34 * @stability: Unstable
35 * @include: libanjuta/anjuta-encodings.h
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
43 #include <gtk/gtktreeview.h>
44 #include <gtk/gtkliststore.h>
45 #include <string.h>
47 #include <libanjuta/anjuta-encodings.h>
48 #include <libanjuta/anjuta-utils.h>
49 #include <libanjuta/anjuta-debug.h>
51 struct _AnjutaEncoding
53 gint idx;
54 gchar *charset;
55 gchar *name;
58 /*
59 * The original versions of the following tables are taken from profterm
61 * Copyright (C) 2002 Red Hat, Inc.
64 typedef enum
67 ANJUTA_ENCODING_ISO_8859_1,
68 ANJUTA_ENCODING_ISO_8859_2,
69 ANJUTA_ENCODING_ISO_8859_3,
70 ANJUTA_ENCODING_ISO_8859_4,
71 ANJUTA_ENCODING_ISO_8859_5,
72 ANJUTA_ENCODING_ISO_8859_6,
73 ANJUTA_ENCODING_ISO_8859_7,
74 ANJUTA_ENCODING_ISO_8859_8,
75 ANJUTA_ENCODING_ISO_8859_8_I,
76 ANJUTA_ENCODING_ISO_8859_9,
77 ANJUTA_ENCODING_ISO_8859_10,
78 ANJUTA_ENCODING_ISO_8859_13,
79 ANJUTA_ENCODING_ISO_8859_14,
80 ANJUTA_ENCODING_ISO_8859_15,
81 ANJUTA_ENCODING_ISO_8859_16,
83 ANJUTA_ENCODING_UTF_7,
84 ANJUTA_ENCODING_UTF_16,
85 ANJUTA_ENCODING_UCS_2,
86 ANJUTA_ENCODING_UCS_4,
88 ANJUTA_ENCODING_ARMSCII_8,
89 ANJUTA_ENCODING_BIG5,
90 ANJUTA_ENCODING_BIG5_HKSCS,
91 ANJUTA_ENCODING_CP_866,
93 ANJUTA_ENCODING_EUC_JP,
94 ANJUTA_ENCODING_EUC_KR,
95 ANJUTA_ENCODING_EUC_TW,
97 ANJUTA_ENCODING_GB18030,
98 ANJUTA_ENCODING_GB2312,
99 ANJUTA_ENCODING_GBK,
100 ANJUTA_ENCODING_GEOSTD8,
101 ANJUTA_ENCODING_HZ,
103 ANJUTA_ENCODING_IBM_850,
104 ANJUTA_ENCODING_IBM_852,
105 ANJUTA_ENCODING_IBM_855,
106 ANJUTA_ENCODING_IBM_857,
107 ANJUTA_ENCODING_IBM_862,
108 ANJUTA_ENCODING_IBM_864,
110 ANJUTA_ENCODING_ISO_2022_JP,
111 ANJUTA_ENCODING_ISO_2022_KR,
112 ANJUTA_ENCODING_ISO_IR_111,
113 ANJUTA_ENCODING_JOHAB,
114 ANJUTA_ENCODING_KOI8_R,
115 ANJUTA_ENCODING_KOI8_U,
117 ANJUTA_ENCODING_SHIFT_JIS,
118 ANJUTA_ENCODING_TCVN,
119 ANJUTA_ENCODING_TIS_620,
120 ANJUTA_ENCODING_UHC,
121 ANJUTA_ENCODING_VISCII,
123 ANJUTA_ENCODING_WINDOWS_1250,
124 ANJUTA_ENCODING_WINDOWS_1251,
125 ANJUTA_ENCODING_WINDOWS_1252,
126 ANJUTA_ENCODING_WINDOWS_1253,
127 ANJUTA_ENCODING_WINDOWS_1254,
128 ANJUTA_ENCODING_WINDOWS_1255,
129 ANJUTA_ENCODING_WINDOWS_1256,
130 ANJUTA_ENCODING_WINDOWS_1257,
131 ANJUTA_ENCODING_WINDOWS_1258,
133 ANJUTA_ENCODING_LAST
135 } AnjutaEncodingIndex;
137 static AnjutaEncoding encodings [] = {
139 { ANJUTA_ENCODING_ISO_8859_1,
140 "ISO-8859-1", N_("Western") },
141 { ANJUTA_ENCODING_ISO_8859_2,
142 "ISO-8859-2", N_("Central European") },
143 { ANJUTA_ENCODING_ISO_8859_3,
144 "ISO-8859-3", N_("South European") },
145 { ANJUTA_ENCODING_ISO_8859_4,
146 "ISO-8859-4", N_("Baltic") },
147 { ANJUTA_ENCODING_ISO_8859_5,
148 "ISO-8859-5", N_("Cyrillic") },
149 { ANJUTA_ENCODING_ISO_8859_6,
150 "ISO-8859-6", N_("Arabic") },
151 { ANJUTA_ENCODING_ISO_8859_7,
152 "ISO-8859-7", N_("Greek") },
153 { ANJUTA_ENCODING_ISO_8859_8,
154 "ISO-8859-8", N_("Hebrew Visual") },
155 { ANJUTA_ENCODING_ISO_8859_8_I,
156 "ISO-8859-8-I", N_("Hebrew") },
157 { ANJUTA_ENCODING_ISO_8859_9,
158 "ISO-8859-9", N_("Turkish") },
159 { ANJUTA_ENCODING_ISO_8859_10,
160 "ISO-8859-10", N_("Nordic") },
161 { ANJUTA_ENCODING_ISO_8859_13,
162 "ISO-8859-13", N_("Baltic") },
163 { ANJUTA_ENCODING_ISO_8859_14,
164 "ISO-8859-14", N_("Celtic") },
165 { ANJUTA_ENCODING_ISO_8859_15,
166 "ISO-8859-15", N_("Western") },
167 { ANJUTA_ENCODING_ISO_8859_16,
168 "ISO-8859-16", N_("Romanian") },
170 { ANJUTA_ENCODING_UTF_7,
171 "UTF-7", N_("Unicode") },
172 { ANJUTA_ENCODING_UTF_16,
173 "UTF-16", N_("Unicode") },
174 { ANJUTA_ENCODING_UCS_2,
175 "UCS-2", N_("Unicode") },
176 { ANJUTA_ENCODING_UCS_4,
177 "UCS-4", N_("Unicode") },
179 { ANJUTA_ENCODING_ARMSCII_8,
180 "ARMSCII-8", N_("Armenian") },
181 { ANJUTA_ENCODING_BIG5,
182 "BIG5", N_("Chinese Traditional") },
183 { ANJUTA_ENCODING_BIG5_HKSCS,
184 "BIG5-HKSCS", N_("Chinese Traditional") },
185 { ANJUTA_ENCODING_CP_866,
186 "CP866", N_("Cyrillic/Russian") },
188 { ANJUTA_ENCODING_EUC_JP,
189 "EUC-JP", N_("Japanese") },
190 { ANJUTA_ENCODING_EUC_KR,
191 "EUC-KR", N_("Korean") },
192 { ANJUTA_ENCODING_EUC_TW,
193 "EUC-TW", N_("Chinese Traditional") },
195 { ANJUTA_ENCODING_GB18030,
196 "GB18030", N_("Chinese Simplified") },
197 { ANJUTA_ENCODING_GB2312,
198 "GB2312", N_("Chinese Simplified") },
199 { ANJUTA_ENCODING_GBK,
200 "GBK", N_("Chinese Simplified") },
201 { ANJUTA_ENCODING_GEOSTD8,
202 "GEORGIAN-ACADEMY", N_("Georgian") }, /* FIXME GEOSTD8 ? */
203 { ANJUTA_ENCODING_HZ,
204 "HZ", N_("Chinese Simplified") },
206 { ANJUTA_ENCODING_IBM_850,
207 "IBM850", N_("Western") },
208 { ANJUTA_ENCODING_IBM_852,
209 "IBM852", N_("Central European") },
210 { ANJUTA_ENCODING_IBM_855,
211 "IBM855", N_("Cyrillic") },
212 { ANJUTA_ENCODING_IBM_857,
213 "IBM857", N_("Turkish") },
214 { ANJUTA_ENCODING_IBM_862,
215 "IBM862", N_("Hebrew") },
216 { ANJUTA_ENCODING_IBM_864,
217 "IBM864", N_("Arabic") },
219 { ANJUTA_ENCODING_ISO_2022_JP,
220 "ISO-2022-JP", N_("Japanese") },
221 { ANJUTA_ENCODING_ISO_2022_KR,
222 "ISO-2022-KR", N_("Korean") },
223 { ANJUTA_ENCODING_ISO_IR_111,
224 "ISO-IR-111", N_("Cyrillic") },
225 { ANJUTA_ENCODING_JOHAB,
226 "JOHAB", N_("Korean") },
227 { ANJUTA_ENCODING_KOI8_R,
228 "KOI8R", N_("Cyrillic") },
229 { ANJUTA_ENCODING_KOI8_U,
230 "KOI8U", N_("Cyrillic/Ukrainian") },
232 { ANJUTA_ENCODING_SHIFT_JIS,
233 "SHIFT_JIS", N_("Japanese") },
234 { ANJUTA_ENCODING_TCVN,
235 "TCVN", N_("Vietnamese") },
236 { ANJUTA_ENCODING_TIS_620,
237 "TIS-620", N_("Thai") },
238 { ANJUTA_ENCODING_UHC,
239 "UHC", N_("Korean") },
240 { ANJUTA_ENCODING_VISCII,
241 "VISCII", N_("Vietnamese") },
243 { ANJUTA_ENCODING_WINDOWS_1250,
244 "WINDOWS-1250", N_("Central European") },
245 { ANJUTA_ENCODING_WINDOWS_1251,
246 "WINDOWS-1251", N_("Cyrillic") },
247 { ANJUTA_ENCODING_WINDOWS_1252,
248 "WINDOWS-1252", N_("Western") },
249 { ANJUTA_ENCODING_WINDOWS_1253,
250 "WINDOWS-1253", N_("Greek") },
251 { ANJUTA_ENCODING_WINDOWS_1254,
252 "WINDOWS-1254", N_("Turkish") },
253 { ANJUTA_ENCODING_WINDOWS_1255,
254 "WINDOWS-1255", N_("Hebrew") },
255 { ANJUTA_ENCODING_WINDOWS_1256,
256 "WINDOWS-1256", N_("Arabic") },
257 { ANJUTA_ENCODING_WINDOWS_1257,
258 "WINDOWS-1257", N_("Baltic") },
259 { ANJUTA_ENCODING_WINDOWS_1258,
260 "WINDOWS-1258", N_("Vietnamese") }
263 static void save_property (void);
265 static void
266 anjuta_encoding_lazy_init (void)
269 static gboolean initialized = FALSE;
270 gint i;
272 if (initialized)
273 return;
275 g_return_if_fail (G_N_ELEMENTS (encodings) == ANJUTA_ENCODING_LAST);
277 i = 0;
278 while (i < ANJUTA_ENCODING_LAST)
280 g_return_if_fail (encodings[i].idx == i);
282 /* Translate the names */
283 encodings[i].name = _(encodings[i].name);
285 ++i;
288 initialized = TRUE;
292 * anjuta_encoding_get_from_charset:
293 * @charset: Character set for the encoding.
295 * Gets #AnjutaEncoding object corresponding to the given character set
297 * Returns: #AnjutaEncoding object for the given charset
299 const AnjutaEncoding *
300 anjuta_encoding_get_from_charset (const gchar *charset)
302 gint i;
304 anjuta_encoding_lazy_init ();
306 i = 0;
307 while (i < ANJUTA_ENCODING_LAST)
309 if (strcmp (charset, encodings[i].charset) == 0)
310 return &encodings[i];
312 ++i;
315 return NULL;
319 * anjuta_encoding_get_from_index:
320 * @idx: Index of the encoding object
322 * Retrieves #AnjutaEncoding object at the given index.
324 * Returns: #AnjutaEncoding object at the index @idx.
326 const AnjutaEncoding *
327 anjuta_encoding_get_from_index (gint idx)
329 g_return_val_if_fail (idx >= 0, NULL);
331 if (idx >= ANJUTA_ENCODING_LAST)
332 return NULL;
334 anjuta_encoding_lazy_init ();
336 return &encodings [idx];
340 * anjuta_encoding_to_string:
341 * @enc: an #AnjutaEncoding object
343 * Returns the string form of the given encoding.
345 * Returns: string name of the encoding.
347 gchar *
348 anjuta_encoding_to_string (const AnjutaEncoding* enc)
350 g_return_val_if_fail (enc != NULL, NULL);
351 g_return_val_if_fail (enc->name != NULL, NULL);
352 g_return_val_if_fail (enc->charset != NULL, NULL);
354 anjuta_encoding_lazy_init ();
356 return g_strdup_printf ("%s (%s)", enc->name, enc->charset);
360 * anjuta_encoding_get_charset:
361 * @enc: an #AnjutaEncoding object
363 * Gets the character set for the given encoding.
365 * Returns: Character set
367 const gchar *
368 anjuta_encoding_get_charset (const AnjutaEncoding* enc)
370 g_return_val_if_fail (enc != NULL, NULL);
371 g_return_val_if_fail (enc->charset != NULL, NULL);
373 anjuta_encoding_lazy_init ();
375 return enc->charset;
379 * anjuta_encoding_get_encodings:
380 * @encodings_strings: List of encoding names.
382 * Returns list of encoding objects for the given names.
384 * Returns: list of #AnjutaEncoding objects
386 GList *
387 anjuta_encoding_get_encodings (GList *encoding_strings)
389 GList *res = NULL;
391 if (encoding_strings != NULL)
393 GList *tmp;
394 const AnjutaEncoding *enc;
396 tmp = encoding_strings;
398 while (tmp)
400 const char *charset = tmp->data;
402 if (strcmp (charset, "current") == 0)
403 g_get_charset (&charset);
405 g_return_val_if_fail (charset != NULL, NULL);
406 enc = anjuta_encoding_get_from_charset (charset);
408 if (enc != NULL)
409 res = g_list_append (res, (gpointer)enc);
411 tmp = g_list_next (tmp);
414 return res;
417 typedef struct
419 AnjutaPreferences *pref;
420 GtkWidget *add_button;
421 GtkWidget *remove_button;
422 GtkWidget *up_button;
423 GtkWidget *down_button;
424 GtkWidget *supported_treeview;
425 GtkWidget *stock_treeview;
426 } AnjutaEncodingsDialog;
428 static AnjutaEncodingsDialog *anjuta_encodings_dialog = NULL;
430 enum
432 COLUMN_ENCODING_NAME = 0,
433 COLUMN_ENCODING_INDEX,
434 ENCODING_NUM_COLS
437 enum
439 COLUMN_SUPPORTED_ENCODING_NAME = 0,
440 COLUMN_SUPPORTED_ENCODING,
441 SUPPORTED_ENCODING_NUM_COLS
444 static GtkTreeModel*
445 create_encodings_treeview_model (void)
447 GtkListStore *store;
448 GtkTreeIter iter;
449 gint i;
450 const AnjutaEncoding* enc;
452 /* create list store */
453 store = gtk_list_store_new (ENCODING_NUM_COLS, G_TYPE_STRING, G_TYPE_INT);
455 i = 0;
456 while ((enc = anjuta_encoding_get_from_index (i)) != NULL)
458 gchar *name;
459 enc = anjuta_encoding_get_from_index (i);
460 name = anjuta_encoding_to_string (enc);
461 gtk_list_store_append (store, &iter);
462 gtk_list_store_set (store, &iter, COLUMN_ENCODING_NAME, name,
463 COLUMN_ENCODING_INDEX, i, -1);
464 g_free (name);
465 ++i;
467 return GTK_TREE_MODEL (store);
470 static void
471 on_add_encodings (GtkButton *button)
473 GValue value = {0, };
474 const AnjutaEncoding* enc;
475 GSList *encs = NULL;
477 GtkTreeIter iter;
478 GtkTreeSelection *selection;
479 GtkTreeModel *model;
482 selection =
483 gtk_tree_view_get_selection (GTK_TREE_VIEW
484 (anjuta_encodings_dialog->stock_treeview));
485 g_return_if_fail (selection != NULL);
487 model = gtk_tree_view_get_model (GTK_TREE_VIEW
488 (anjuta_encodings_dialog->stock_treeview));
489 if (!gtk_tree_model_get_iter_first (model, &iter))
490 return;
492 if (gtk_tree_selection_iter_is_selected (selection, &iter))
494 gtk_tree_model_get_value (model, &iter,
495 COLUMN_ENCODING_INDEX, &value);
496 enc = anjuta_encoding_get_from_index (g_value_get_int (&value));
497 g_return_if_fail (enc != NULL);
498 encs = g_slist_prepend (encs, (gpointer)enc);
500 g_value_unset (&value);
503 while (gtk_tree_model_iter_next (model, &iter))
505 if (gtk_tree_selection_iter_is_selected (selection, &iter))
507 gtk_tree_model_get_value (model, &iter,
508 COLUMN_ENCODING_INDEX, &value);
510 enc = anjuta_encoding_get_from_index (g_value_get_int (&value));
511 g_return_if_fail (enc != NULL);
513 encs = g_slist_prepend (encs, (gpointer)enc);
515 g_value_unset (&value);
519 if (encs != NULL)
521 GSList *node;
522 model = gtk_tree_view_get_model (GTK_TREE_VIEW
523 (anjuta_encodings_dialog->supported_treeview));
524 encs = g_slist_reverse (encs);
525 node = encs;
526 while (node)
528 const AnjutaEncoding *enc;
529 gchar *name;
530 GtkTreeIter iter;
531 enc = (const AnjutaEncoding *) node->data;
533 name = anjuta_encoding_to_string (enc);
535 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
536 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
537 COLUMN_SUPPORTED_ENCODING_NAME, name,
538 COLUMN_SUPPORTED_ENCODING, enc,
539 -1);
540 g_free (name);
542 node = g_slist_next (node);
544 g_slist_free (encs);
545 save_property ();
549 static void
550 on_remove_encodings (GtkButton *button)
552 GtkTreeSelection *selection;
553 GtkTreeModel *model;
554 GtkTreeIter iter;
555 GtkTreeView *treeview;
557 treeview = GTK_TREE_VIEW (anjuta_encodings_dialog->supported_treeview);
558 selection = gtk_tree_view_get_selection (treeview);
559 if (selection &&
560 gtk_tree_selection_get_selected (selection, &model, &iter))
562 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
563 save_property ();
567 static void
568 on_up_encoding (GtkButton *button)
570 GtkTreeSelection *selection;
571 GtkTreeModel *model;
572 GtkTreeIter iter;
573 GtkTreeView *treeview;
575 treeview = GTK_TREE_VIEW (anjuta_encodings_dialog->supported_treeview);
576 selection = gtk_tree_view_get_selection (treeview);
577 if (selection &&
578 gtk_tree_selection_get_selected (selection, &model, &iter))
580 GtkTreePath *path;
582 path = gtk_tree_model_get_path (model, &iter);
583 if (gtk_tree_path_prev (path))
585 GtkTreeIter prev_iter;
586 gtk_tree_model_get_iter (model, &prev_iter, path);
587 gtk_list_store_swap (GTK_LIST_STORE (model), &prev_iter, &iter);
589 gtk_tree_path_free (path);
590 save_property ();
594 static void
595 on_down_encoding (GtkButton *button)
597 GtkTreeSelection *selection;
598 GtkTreeModel *model;
599 GtkTreeIter iter;
600 GtkTreeView *treeview;
602 treeview = GTK_TREE_VIEW (anjuta_encodings_dialog->supported_treeview);
603 selection = gtk_tree_view_get_selection (treeview);
604 if (selection &&
605 gtk_tree_selection_get_selected (selection, &model, &iter))
607 GtkTreeIter next_iter = iter;
608 if (gtk_tree_model_iter_next (model, &next_iter))
610 gtk_list_store_swap (GTK_LIST_STORE (model), &iter, &next_iter);
611 save_property ();
616 static void
617 on_stock_selection_changed (GtkTreeSelection *selection)
619 g_return_if_fail(anjuta_encodings_dialog != NULL);
620 if (gtk_tree_selection_count_selected_rows (selection) > 0)
621 gtk_widget_set_sensitive (anjuta_encodings_dialog->add_button, TRUE);
622 else
623 gtk_widget_set_sensitive (anjuta_encodings_dialog->add_button, FALSE);
626 static void
627 on_supported_selection_changed (GtkTreeSelection *selection)
629 GtkTreeModel *model;
630 GtkTreeIter iter;
632 g_return_if_fail(anjuta_encodings_dialog != NULL);
634 if (gtk_tree_selection_get_selected (selection, &model, &iter) > 0)
636 GtkTreePath *path;
637 gtk_widget_set_sensitive (anjuta_encodings_dialog->remove_button, TRUE);
638 path = gtk_tree_model_get_path (model, &iter);
639 if (gtk_tree_path_prev (path))
640 gtk_widget_set_sensitive (anjuta_encodings_dialog->up_button, TRUE);
641 else
642 gtk_widget_set_sensitive (anjuta_encodings_dialog->up_button, FALSE);
643 gtk_tree_path_free (path);
645 if (gtk_tree_model_iter_next (model, &iter))
646 gtk_widget_set_sensitive (anjuta_encodings_dialog->down_button, TRUE);
647 else
648 gtk_widget_set_sensitive (anjuta_encodings_dialog->down_button, FALSE);
650 else
652 gtk_widget_set_sensitive (anjuta_encodings_dialog->remove_button, FALSE);
653 gtk_widget_set_sensitive (anjuta_encodings_dialog->up_button, FALSE);
654 gtk_widget_set_sensitive (anjuta_encodings_dialog->down_button, FALSE);
658 static gchar *
659 get_current_value (GtkWidget *tree_view)
661 GtkTreeView *treeview;
662 GString *str;
663 GtkTreeIter iter;
664 GtkTreeModel *model;
665 gboolean valid;
666 gchar *value;
668 treeview = GTK_TREE_VIEW (tree_view);
670 str = g_string_new ("");
672 model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
673 valid = gtk_tree_model_get_iter_first (model, &iter);
674 while (valid)
676 AnjutaEncoding *enc;
677 gtk_tree_model_get (model, &iter, COLUMN_SUPPORTED_ENCODING, &enc, -1);
678 g_assert (enc != NULL);
679 g_assert (enc->charset != NULL);
680 str = g_string_append (str, enc->charset);
681 str = g_string_append (str, " ");
682 valid = gtk_tree_model_iter_next (model, &iter);
684 value = g_string_free (str, FALSE);
685 return value;
688 static gchar *
689 get_property (AnjutaProperty *prop)
691 return get_current_value (anjuta_property_get_widget (prop));
694 static void
695 set_property (AnjutaProperty *prop, const gchar *value)
697 GtkTreeView *treeview;
698 GtkTreeModel *model;
699 GList *list, *node;
701 treeview = GTK_TREE_VIEW (anjuta_property_get_widget (prop));
702 model = gtk_tree_view_get_model (treeview);
703 gtk_list_store_clear (GTK_LIST_STORE (model));
705 if (!value || strlen (value) <= 0)
706 return;
708 /* Fill the model */
709 list = anjuta_util_glist_from_string (value);
710 node = list;
711 while (node)
713 const AnjutaEncoding *enc;
714 gchar *name;
715 GtkTreeIter iter;
717 enc = anjuta_encoding_get_from_charset ((gchar *) node->data);
718 name = anjuta_encoding_to_string (enc);
720 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
721 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
722 COLUMN_SUPPORTED_ENCODING_NAME, name,
723 COLUMN_SUPPORTED_ENCODING, enc,
724 -1);
725 g_free (name);
727 node = g_list_next (node);
729 anjuta_util_glist_strings_free (list);
732 static void
733 save_property (void)
735 gchar *value = get_current_value (anjuta_encodings_dialog->supported_treeview);
736 anjuta_preferences_set (anjuta_encodings_dialog->pref,
737 SUPPORTED_ENCODINGS,
738 value);
739 g_free (value);
743 * anjuta_encodings_init:
744 * @pref: an #AnjutaPreferences object.
745 * @gxml: an #GladeXML object holding encodings dialog.
747 * Initializes the encodings system.
749 void
750 anjuta_encodings_init (AnjutaPreferences *pref, GladeXML *gxml)
752 GtkWidget *add_button;
753 GtkWidget *remove_button;
754 GtkWidget *up_button;
755 GtkWidget *down_button;
756 GtkWidget *supported_treeview;
757 GtkWidget *stock_treeview;
758 GtkTreeModel *model;
759 GtkCellRenderer *cell;
760 GtkTreeViewColumn *column;
761 GtkTreeSelection *selection;
763 supported_treeview = glade_xml_get_widget (gxml, "supported_treeview");
764 stock_treeview = glade_xml_get_widget (gxml, "stock_treeview");
765 add_button = glade_xml_get_widget (gxml, "add_button");
766 remove_button = glade_xml_get_widget (gxml, "remove_button");
767 up_button = glade_xml_get_widget (gxml, "up_button");
768 down_button = glade_xml_get_widget (gxml, "down_button");
770 /* Add the encoding column for stock treeview*/
771 cell = gtk_cell_renderer_text_new ();
772 column = gtk_tree_view_column_new_with_attributes (_("Stock Encodings"),
773 cell, "text",
774 COLUMN_ENCODING_NAME,
775 NULL);
776 gtk_tree_view_append_column (GTK_TREE_VIEW (stock_treeview), column);
777 gtk_tree_view_set_search_column (GTK_TREE_VIEW (stock_treeview),
778 COLUMN_ENCODING_NAME);
779 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (stock_treeview));
780 g_return_if_fail (selection != NULL);
781 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
783 model = create_encodings_treeview_model ();
784 gtk_tree_view_set_model (GTK_TREE_VIEW (stock_treeview), model);
785 g_signal_connect (G_OBJECT (selection), "changed",
786 G_CALLBACK (on_stock_selection_changed), NULL);
787 g_object_unref (model);
789 /* Add the encoding column for supported treeview*/
790 cell = gtk_cell_renderer_text_new ();
791 column = gtk_tree_view_column_new_with_attributes (_("Supported Encodings"),
792 cell, "text",
793 COLUMN_ENCODING_NAME,
794 NULL);
795 gtk_tree_view_append_column (GTK_TREE_VIEW (supported_treeview), column);
796 gtk_tree_view_set_search_column (GTK_TREE_VIEW (supported_treeview),
797 COLUMN_ENCODING_NAME);
798 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (supported_treeview));
799 g_return_if_fail (selection != NULL);
800 gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
802 /* create list store */
803 model = GTK_TREE_MODEL (gtk_list_store_new (SUPPORTED_ENCODING_NUM_COLS,
804 G_TYPE_STRING, G_TYPE_POINTER));
805 gtk_tree_view_set_model (GTK_TREE_VIEW (supported_treeview), model);
806 g_signal_connect (G_OBJECT (selection), "changed",
807 G_CALLBACK (on_supported_selection_changed), NULL);
808 g_object_unref (model);
810 anjuta_preferences_register_property_custom (pref, supported_treeview,
811 SUPPORTED_ENCODINGS,
812 "ISO-8859-15",
813 ANJUTA_PROPERTY_DATA_TYPE_TEXT,
815 set_property,
816 get_property);
818 g_signal_connect (G_OBJECT (add_button), "clicked",
819 G_CALLBACK (on_add_encodings), NULL);
820 g_signal_connect (G_OBJECT (remove_button), "clicked",
821 G_CALLBACK (on_remove_encodings), NULL);
822 g_signal_connect (G_OBJECT (up_button), "clicked",
823 G_CALLBACK (on_up_encoding), NULL);
824 g_signal_connect (G_OBJECT (down_button), "clicked",
825 G_CALLBACK (on_down_encoding), NULL);
827 gtk_widget_set_sensitive (add_button, FALSE);
828 gtk_widget_set_sensitive (remove_button, FALSE);
829 gtk_widget_set_sensitive (up_button, FALSE);
830 gtk_widget_set_sensitive (down_button, FALSE);
832 anjuta_encodings_dialog = g_new0 (AnjutaEncodingsDialog, 1);
833 anjuta_encodings_dialog->pref = pref;
834 anjuta_encodings_dialog->add_button = add_button;
835 anjuta_encodings_dialog->remove_button = remove_button;
836 anjuta_encodings_dialog->up_button = up_button;
837 anjuta_encodings_dialog->down_button = down_button;
838 anjuta_encodings_dialog->supported_treeview = supported_treeview;
839 anjuta_encodings_dialog->stock_treeview = stock_treeview;