Commits

Yuya Nishihara  committed 65f89ea

fileview: save last selected encoding as widget's default (refs #3620)

Still web.encoding overrides the last selection so that user can specify the
repository-specific encoding if any.

  • Participants
  • Parent commits cb078c7
  • Branches stable

Comments (0)

Files changed (2)

File tortoisehg/hgqt/fileencoding.py

     name = codecs.lookup(name).name
     return _SUBSTMAP.get(name, name)
 
-def contentencoding(ui):
+def contentencoding(ui, fallbackenc=None):
     """Preferred encoding of file contents in repository"""
     # assumes web.encoding is the content encoding, not the filename one
     enc = ui.config('web', 'encoding')
             return canonname(enc)
         except LookupError:
             ui.debug('ignoring invalid web.encoding: %s\n' % enc)
-    return canonname(encoding.encoding)
+    return canonname(fallbackenc or encoding.encoding)
 
 def knownencodings():
     """List of encoding names which are likely used"""

File tortoisehg/hgqt/fileview.py

 
     def loadSettings(self, qs, prefix):
         self.sci.loadSettings(qs, prefix)
+        enc = str(qs.value(prefix + '/textencoding').toString())
+        if enc:
+            try:
+                # prefer repository-specific encoding if specified
+                enc = fileencoding.contentencoding(self.repo.ui, enc)
+            except LookupError:
+                enc = ''
+        if enc:
+            self._changeTextEncoding(enc)
 
     def saveSettings(self, qs, prefix):
         self.sci.saveSettings(qs, prefix)
+        qs.setValue(prefix + '/textencoding', self._textEncoding())
 
     @pyqtSlot()
     def _applyRepoConfig(self):
         self.sci.setIndentationWidth(self.repo.tabwidth)
         self.sci.setTabWidth(self.repo.tabwidth)
-        enc = fileencoding.contentencoding(self.repo.ui)
+        enc = fileencoding.contentencoding(self.repo.ui, self._textEncoding())
         self._changeTextEncoding(enc)
 
     def setRepo(self, repo):