[meld/meld-3-20] ui.filechooser: Force default to UTF-8 on Windows (#337)



commit 227fd5bf7eaa5c667f2f8e7b7fddda85ac5c219f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Jun 21 08:59:23 2019 +1000

    ui.filechooser: Force default to UTF-8 on Windows (#337)
    
    On Unix, the current charset is a sensible default for the file chooser,
    because it represents the user's environment properly. On Windows, this
    is always the ANSI code page, even if the user reasonably thinks they're
    using UTF-8 or similar.

 meld/ui/filechooser.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/meld/ui/filechooser.py b/meld/ui/filechooser.py
index 6fcc1501..816ae6f8 100644
--- a/meld/ui/filechooser.py
+++ b/meld/ui/filechooser.py
@@ -15,6 +15,8 @@
 
 """This module provides file choosers that let users select a text encoding."""
 
+import sys
+
 from gi.repository import Gtk
 from gi.repository import GtkSource
 
@@ -52,10 +54,19 @@ class MeldFileChooserDialog(Gtk.FileChooserDialog):
 
     def make_encoding_combo(self):
         """Create the combo box for text encoding selection"""
-        codecs = []
-        current = GtkSource.encoding_get_current()
-        codecs.append((current.to_string(), current.get_charset()))
-        codecs.append((None, None))
+
+        # On Windows, the "current" encoding is the "system default
+        # ANSI code-page", which is probably not what the user wants,
+        # so we default to UTF-8.
+        if sys.platform == 'win32':
+            current = GtkSource.encoding_get_utf8()
+        else:
+            current = GtkSource.encoding_get_current()
+
+        codecs = [
+            (current.to_string(), current.get_charset()),
+            (None, None),
+        ]
         for encoding in GtkSource.encoding_get_all():
             codecs.append((encoding.to_string(), encoding.get_charset()))
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]