[gedit/wip/merge-encoding-settings: 2/3] Add candidate-encodings gsetting
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/merge-encoding-settings: 2/3] Add candidate-encodings gsetting
- Date: Tue, 12 Aug 2014 16:09:48 +0000 (UTC)
commit 29071612c9fae8395480fdfeaff96c20c603a9c7
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Aug 1 16:06:10 2014 +0200
Add candidate-encodings gsetting
https://bugzilla.gnome.org/show_bug.cgi?id=730622
data/org.gnome.gedit.gschema.xml.in | 7 +++++
gedit/gedit-settings.h | 1 +
gedit/gedit-tab.c | 42 +++++++++++++++++++++++++++++-----
3 files changed, 43 insertions(+), 7 deletions(-)
---
diff --git a/data/org.gnome.gedit.gschema.xml.in b/data/org.gnome.gedit.gschema.xml.in
index d078323..9778aea 100644
--- a/data/org.gnome.gedit.gschema.xml.in
+++ b/data/org.gnome.gedit.gschema.xml.in
@@ -247,6 +247,13 @@
<summary>Encodings shown in menu</summary>
<description>List of encodings shown in the Character Encoding menu in open/save file selector. Only
recognized encodings are used.</description>
</key>
+ <key name="candidate-encodings" type="as">
+ <default>['']</default>
+ <summary>Candidate Encodings</summary>
+ <description>List of candidate encodings shown in the Character Encoding menu in the open/save file
chooser.
+ "CURRENT" represents the current locale encoding. Only recognized encodings are used.
+ The default value is the empty list, in which case it should work for most countries and
languages.</description>
+ </key>
</schema>
<schema id="org.gnome.gedit.state" path="/org/gnome/gedit/state/">
<child name="window" schema="org.gnome.gedit.state.window"/>
diff --git a/gedit/gedit-settings.h b/gedit/gedit-settings.h
index 39ee82e..de03f6a 100644
--- a/gedit/gedit-settings.h
+++ b/gedit/gedit-settings.h
@@ -108,6 +108,7 @@ void gedit_settings_set_list (GSettings
*settings,
#define GEDIT_SETTINGS_PRINT_FONT_NUMBERS_PANGO "print-font-numbers-pango"
#define GEDIT_SETTINGS_ENCODING_AUTO_DETECTED "auto-detected"
#define GEDIT_SETTINGS_ENCODING_SHOWN_IN_MENU "shown-in-menu"
+#define GEDIT_SETTINGS_CANDIDATE_ENCODINGS "candidate-encodings"
#define GEDIT_SETTINGS_ACTIVE_PLUGINS "active-plugins"
#define GEDIT_SETTINGS_ENSURE_TRAILING_NEWLINE "ensure-trailing-newline"
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 0ec789c..dcbf61f 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1912,21 +1912,38 @@ end:
}
}
+/* The returned list may contain duplicated encodings. Only the first occurrence
+ * of a duplicated encoding should be kept, like it is done by
+ * gtk_source_file_loader_set_candidate_encodings().
+ */
static GSList *
get_candidate_encodings (GeditTab *tab)
{
GeditDocument *doc;
+ GtkSourceFile *file;
GSettings *enc_settings;
- gchar **enc_strv;
+ gchar **enc_settings_strv;
+ const GtkSourceEncoding *file_encoding;
gchar *metadata_charset;
- GSList *encodings;
+ GSList *all_encodings = NULL;
enc_settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
- enc_strv = g_settings_get_strv (enc_settings, GEDIT_SETTINGS_ENCODING_AUTO_DETECTED);
+ enc_settings_strv = g_settings_get_strv (enc_settings, GEDIT_SETTINGS_CANDIDATE_ENCODINGS);
- encodings = _gedit_utils_encoding_strv_to_list ((const gchar * const *)enc_strv);
+ /* First take the candidate encodings from GSettings. If the gsetting is
+ * empty, take the default candidates of GtkSourceEncoding.
+ */
+ if (enc_settings_strv != NULL && enc_settings_strv[0] != NULL)
+ {
+ all_encodings = _gedit_utils_encoding_strv_to_list ((const gchar * const *)enc_settings_strv);
+ }
+ else
+ {
+ all_encodings = gtk_source_encoding_get_default_candidates ();
+ }
+ /* Then prepend the encoding stored in the metadata. */
doc = gedit_tab_get_document (tab);
metadata_charset = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_ENCODING);
@@ -1938,16 +1955,27 @@ get_candidate_encodings (GeditTab *tab)
if (metadata_enc != NULL)
{
- encodings = g_slist_prepend (encodings, (gpointer)metadata_enc);
+ all_encodings = g_slist_prepend (all_encodings, (gpointer) metadata_enc);
}
g_free (metadata_charset);
}
- g_strfreev (enc_strv);
+ /* Finally prepend the GtkSourceFile's encoding, if previously set by a
+ * file loader or file saver.
+ */
+ file = gedit_document_get_file (doc);
+ file_encoding = gtk_source_file_get_encoding (file);
+
+ if (file_encoding != NULL)
+ {
+ all_encodings = g_slist_prepend (all_encodings, (gpointer) file_encoding);
+ }
+
+ g_strfreev (enc_settings_strv);
g_object_unref (enc_settings);
- return encodings;
+ return all_encodings;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]