Skip to content

Commit 708ac12

Browse files
author
Me
committed
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.
1 parent d0370bf commit 708ac12

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

meld/ui/filechooser.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from gi.repository import Gtk
2121
from gi.repository import GtkSource
2222

23+
from meld.conf import _
24+
2325

2426
FILE_ACTIONS = {
2527
Gtk.FileChooserAction.OPEN,
@@ -65,7 +67,12 @@ def make_encoding_combo(self):
6567
current = GtkSource.encoding_get_current()
6668

6769
codecs = [
68-
(current.to_string(), current.get_charset()),
70+
(_('Autodetect Encoding'), None),
71+
(None, None),
72+
(
73+
_('Current Locale ({})').format(current.get_charset()),
74+
current.get_charset()
75+
),
6976
(None, None),
7077
]
7178
for encoding in GtkSource.encoding_get_all():
@@ -81,7 +88,7 @@ def make_encoding_combo(self):
8188
combo.pack_start(cell, True)
8289
combo.add_attribute(cell, 'text', 0)
8390
combo.set_row_separator_func(
84-
lambda model, it, data: not model.get_value(it, 1), None)
91+
lambda model, it, data: not model.get_value(it, 0), None)
8592
combo.props.active = 0
8693
return combo
8794

@@ -91,6 +98,8 @@ def get_encoding(self):
9198
if not combo:
9299
return None
93100
charset = self.encoding_store.get_value(combo.get_active_iter(), 1)
101+
if not charset:
102+
return None
94103
return GtkSource.Encoding.get_from_charset(charset)
95104

96105
def action_changed_cb(self, *args):

0 commit comments

Comments
 (0)