[meld/meld-3-20] ui.filechooser: Default to autodetecting encoding (#350)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/meld-3-20] ui.filechooser: Default to autodetecting encoding (#350)
- Date: Fri, 26 Jul 2019 22:59:52 +0000 (UTC)
commit cccafb911009544a62f7830f02abb88eb63ff019
Author: Me <me example com>
Date: Sat Jul 27 08:52:22 2019 +1000
ui.filechooser: Default to autodetecting encoding (#350)
When we added the custom file chooser that allowed encoding selection,
the default encoding behaviour changed. Previously, there would be no
custom encoding, so the default behaviour would be used: try the user-
configured encodings, then try the GtkSourceView list for the current
locale.
With the custom filechooser, the default encoding selection was whatever
the current locale was, and so instead of using the user-configured
encoding list, we would always try the current locale encoding. This is
fine in most scenarios because users' locale encoding is typically
UTF-8... but if a user had something more exciting as their locale
things would go badly.
More importantly, because the user had chosen a locale, we didn't try
the user-configured locales. While this behaviour is arguably correct
for when the user actually chooses an encoding, it's definitely not
right when the user just doesn't select one and gets the locale-default
encoding.
This change fixes all of this by simply adding an "Autodetect" option to
the custom filechooser, and using that by default.
meld/ui/filechooser.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/meld/ui/filechooser.py b/meld/ui/filechooser.py
index 816ae6f8..15976dbd 100644
--- a/meld/ui/filechooser.py
+++ b/meld/ui/filechooser.py
@@ -20,6 +20,8 @@ import sys
from gi.repository import Gtk
from gi.repository import GtkSource
+from meld.conf import _
+
FILE_ACTIONS = {
Gtk.FileChooserAction.OPEN,
@@ -64,7 +66,12 @@ class MeldFileChooserDialog(Gtk.FileChooserDialog):
current = GtkSource.encoding_get_current()
codecs = [
- (current.to_string(), current.get_charset()),
+ (_('Autodetect Encoding'), None),
+ (None, None),
+ (
+ _('Current Locale ({})').format(current.get_charset()),
+ current.get_charset()
+ ),
(None, None),
]
for encoding in GtkSource.encoding_get_all():
@@ -80,7 +87,7 @@ class MeldFileChooserDialog(Gtk.FileChooserDialog):
combo.pack_start(cell, True)
combo.add_attribute(cell, 'text', 0)
combo.set_row_separator_func(
- lambda model, it, data: not model.get_value(it, 1), None)
+ lambda model, it, data: not model.get_value(it, 0), None)
combo.props.active = 0
return combo
@@ -90,6 +97,8 @@ class MeldFileChooserDialog(Gtk.FileChooserDialog):
if not combo:
return None
charset = self.encoding_store.get_value(combo.get_active_iter(), 1)
+ if not charset:
+ return None
return GtkSource.Encoding.get_from_charset(charset)
def action_changed_cb(self, *args):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]