[gedit/wip/loader-saver] tab: get candidate encodings when no encoding supplied
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/loader-saver] tab: get candidate encodings when no encoding supplied
- Date: Sat, 28 Jun 2014 14:15:30 +0000 (UTC)
commit 6b40872ed8488d664502129d8aeb4291262b5493
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 28 15:34:05 2014 +0200
tab: get candidate encodings when no encoding supplied
gedit/gedit-tab.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 29a482c..26c8b4b 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1867,28 +1867,68 @@ end:
}
}
+static GSList *
+get_candidate_encodings (GeditTab *tab)
+{
+ GeditDocument *doc;
+ GSettings *enc_settings;
+ gchar **enc_strv;
+ gchar *metadata_charset;
+ GSList *encodings;
+
+ enc_settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
+
+ enc_strv = g_settings_get_strv (enc_settings, GEDIT_SETTINGS_ENCODING_AUTO_DETECTED);
+
+ encodings = _gedit_utils_encoding_strv_to_list ((const gchar * const *)enc_strv);
+
+ doc = gedit_tab_get_document (tab);
+ metadata_charset = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_ENCODING);
+
+ if (metadata_charset != NULL)
+ {
+ const GtkSourceEncoding *metadata_enc;
+
+ metadata_enc = gtk_source_encoding_get_from_charset (metadata_charset);
+
+ if (metadata_enc != NULL)
+ {
+ encodings = g_slist_prepend (encodings, (gpointer)metadata_enc);
+ }
+
+ g_free (metadata_charset);
+ }
+
+ g_strfreev (enc_strv);
+ g_object_unref (enc_settings);
+
+ return encodings;
+}
+
static void
load (GeditTab *tab,
const GtkSourceEncoding *encoding,
gint line_pos,
gint column_pos)
{
+ GSList *candidate_encodings = NULL;
+
g_return_if_fail (GTK_SOURCE_IS_FILE_LOADER (tab->priv->loader));
if (encoding != NULL)
{
tab->priv->user_requested_encoding = TRUE;
-
- GSList *list = g_slist_append (NULL, (gpointer) encoding);
- gtk_source_file_loader_set_candidate_encodings (tab->priv->loader, list);
- g_slist_free (list);
+ candidate_encodings = g_slist_append (NULL, (gpointer) encoding);
}
else
{
tab->priv->user_requested_encoding = FALSE;
- /* TODO */
+ candidate_encodings = get_candidate_encodings (tab);
}
+ gtk_source_file_loader_set_candidate_encodings (tab->priv->loader, candidate_encodings);
+ g_slist_free (candidate_encodings);
+
tab->priv->tmp_line_pos = line_pos;
tab->priv->tmp_column_pos = column_pos;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]