Yuya Nishihara committed 01099e9

qscilib: convert to local encoding on reading/writing file (fixes #1719) and write() do not convert character encoding. Editing
it will mess up the content because the GUI encoding is UTF-8.

Currently readFile() has no except block because hglib.tounicode() never raise

Comments (0)

Files changed (1)


         return False
-    if not
+    data = str(f.readAll())
+    if f.error():
         qtlib.WarningMsgBox(_('Unable to read file'),
                             _('An error occurred while reading the file.'),
                             f.errorString(), parent=editor)
         return False
+    text = hglib.tounicode(data)
+    editor.setText(text)
     return True
 def writeFile(editor, filename):
+    text = editor.text()
+    try:
+        data = hglib.fromunicode(text)
+    except UnicodeEncodeError, inst:
+        qtlib.WarningMsgBox(_('Unable to write file'),
+                            _('Could not translate the file content to '
+                              'native encoding.'),
+                            hglib.tounicode(str(inst)), parent=editor)
+        return False
     f = QFile(filename)
     if not
         qtlib.WarningMsgBox(_('Unable to write file'),
                             _('Could not open the specified file for writing.'),
                             f.errorString(), parent=editor)
         return False
-    if not editor.write(f):
+    if f.write(data) < 0:
         qtlib.WarningMsgBox(_('Unable to write file'),
                             _('An error occurred while writing the file.'),
                             f.errorString(), parent=editor)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.