[gedit] Replace 'auto-detected' encoding gsetting by 'candidate-encodings'
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Replace 'auto-detected' encoding gsetting by 'candidate-encodings'
- Date: Sun, 12 Apr 2015 10:04:23 +0000 (UTC)
commit be3c6ca77645b30928d8c7109dae181e6b654d3d
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Aug 1 16:06:10 2014 +0200
Replace 'auto-detected' encoding gsetting by 'candidate-encodings'
So that the translation of the default candidate encodings (for each
locale) is only in GtkSourceView, more precisely in
gtk_source_encoding_get_default_candidates().
https://bugzilla.gnome.org/show_bug.cgi?id=730622
data/gedit.convert | 1 -
data/org.gnome.gedit.gschema.xml.in | 23 +++++-------------
gedit/gedit-settings.h | 2 +-
gedit/gedit-tab.c | 42 +++++++++++++++++++++++++----------
4 files changed, 38 insertions(+), 30 deletions(-)
---
diff --git a/data/gedit.convert b/data/gedit.convert
index 811bc91..52ced85 100644
--- a/data/gedit.convert
+++ b/data/gedit.convert
@@ -38,7 +38,6 @@ print-font-header-pango = /apps/gedit-2/preferences/print/fonts/print_font_heade
print-font-numbers-pango = /apps/gedit-2/preferences/print/fonts/print_font_numbers_pango
[org.gnome.gedit.preferences.encodings]
-auto-detected = /apps/gedit-2/preferences/encodings/auto_detected
shown-in-menu = /apps/gedit-2/preferences/encodings/shown_in_menu
[org.gnome.gedit.plugins]
diff --git a/data/org.gnome.gedit.gschema.xml.in b/data/org.gnome.gedit.gschema.xml.in
index a01b3ec..312e3e9 100644
--- a/data/org.gnome.gedit.gschema.xml.in
+++ b/data/org.gnome.gedit.gschema.xml.in
@@ -224,22 +224,6 @@
</key>
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.preferences.encodings"
path="/org/gnome/gedit/preferences/encodings/">
- <key name="auto-detected" type="as">
- <!-- Translators: This is the sorted list of encodings used by gedit
- for automatic detection of the file encoding. You may want to customize it adding
- encodings that are common in your country, for instance the GB18030 encoding
- for the Chinese translation. You may also want to remove the ISO-8859-15 encoding
- (covering English and most Western European languages) if you think people
- in your country will rarely use it.
- "CURRENT" is a magic value used by gedit and it represents the encoding
- for the current locale, so please don't translate the "CURRENT" term.
- Only recognized encodings are used.
- See http://git.gnome.org/browse/gedit/tree/gedit/gedit-encodings.c#n152 for
- a list of supported encodings -->
- <default l10n="messages">['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']</default>
- <summary>Automatically Detected Encodings</summary>
- <description>Sorted list of encodings used by gedit for automatically detecting the encoding of a
file. "CURRENT" represents the current locale encoding. Only recognized encodings are used.</description>
- </key>
<key name="shown-in-menu" type="as">
<!-- Translators: This is the list of encodings shown by default in the Character Encoding
menu in open/save file selector. Only recognized encodings are displayed.-->
@@ -247,6 +231,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 gedit will choose good defaults depending on the
country and language.</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..e882f4e 100644
--- a/gedit/gedit-settings.h
+++ b/gedit/gedit-settings.h
@@ -106,8 +106,8 @@ void gedit_settings_set_list (GSettings
*settings,
#define GEDIT_SETTINGS_PRINT_FONT_BODY_PANGO "print-font-body-pango"
#define GEDIT_SETTINGS_PRINT_FONT_HEADER_PANGO "print-font-header-pango"
#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 f929ecc..d750fc9 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1940,23 +1940,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;
- GSettings *enc_settings;
- gchar **enc_strv;
- gchar *metadata_charset;
GtkSourceFile *file;
+ GSettings *settings;
+ gchar **settings_strv;
+ gchar *metadata_charset;
const GtkSourceEncoding *file_encoding;
- GSList *encodings;
+ GSList *candidates = NULL;
- enc_settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
+ settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
- enc_strv = g_settings_get_strv (enc_settings, GEDIT_SETTINGS_ENCODING_AUTO_DETECTED);
+ settings_strv = g_settings_get_strv (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 (settings_strv != NULL && settings_strv[0] != NULL)
+ {
+ candidates = _gedit_utils_encoding_strv_to_list ((const gchar * const *)settings_strv);
+ }
+ else
+ {
+ candidates = 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);
@@ -1968,23 +1983,26 @@ get_candidate_encodings (GeditTab *tab)
if (metadata_enc != NULL)
{
- encodings = g_slist_prepend (encodings, (gpointer)metadata_enc);
+ candidates = g_slist_prepend (candidates, (gpointer)metadata_enc);
}
}
+ /* 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)
{
- encodings = g_slist_prepend (encodings, (gpointer)file_encoding);
+ candidates = g_slist_prepend (candidates, (gpointer)file_encoding);
}
- g_object_unref (enc_settings);
- g_strfreev (enc_strv);
+ g_object_unref (settings);
+ g_strfreev (settings_strv);
g_free (metadata_charset);
- return encodings;
+ return candidates;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]