Commits

Yuya Nishihara committed d90f45e

hgqt: add configuration point to switch ui language

- set i18n language on startup
- add 'restartneeded' and 'globalonly' flags to definition of config
field
- make recordNewValue() return changed state

  • Participants
  • Parent commits 653ba18

Comments (0)

Files changed (2)

File tortoisehg/hgqt/run.py

 from mercurial import hg, util, fancyopts, cmdutil, extensions, error
 
 from tortoisehg.hgqt.i18n import agettext as _
-from tortoisehg.util import hglib, paths, shlib
+from tortoisehg.util import hglib, paths, shlib, i18n
 from tortoisehg.util import version as thgversion
 from tortoisehg.hgqt import qtlib
 from tortoisehg.hgqt.bugreport import run as bugrun
     cmd, func, args, options, cmdoptions, alias = _parse(ui, args)
     cmdoptions['alias'] = alias
     ui.setconfig("ui", "verbose", str(bool(options["verbose"])))
+    i18n.setlanguage(ui.config('tortoisehg', 'ui.language'))
 
     if options['help']:
         return help_(ui, cmd)

File tortoisehg/hgqt/settings.py

 
 from mercurial import ui, util, error
 
-from tortoisehg.util import hglib, settings, paths, wconfig
+from tortoisehg.util import hglib, settings, paths, wconfig, i18n
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import qtlib, qscilib, thgrepo
 
 
 class _fi(object):
     """Information of each field"""
-    __slots__ = ('label', 'cpath', 'values', 'tooltip')
+    __slots__ = ('label', 'cpath', 'values', 'tooltip',
+                 'restartneeded', 'globalonly')
 
-    def __init__(self, label, cpath, values, tooltip):
+    def __init__(self, label, cpath, values, tooltip,
+                 restartneeded=False, globalonly=False):
         self.label = label
         self.cpath = cpath
         self.values = values
         self.tooltip = tooltip
+        self.restartneeded = restartneeded
+        self.globalonly = globalonly
 
 INFO = (
 ({'name': 'general', 'label': 'TortoiseHg', 'icon': 'thg_logo'}, (
+    _fi(_('UI Language'), 'tortoisehg.ui.language',
+        (genDeferredCombo, i18n.availablelanguages),
+        _('Specify your preferred user interface language (restart needed)'),
+        restartneeded=True, globalonly=True),
     _fi(_('Three-way Merge Tool'), 'ui.merge',
         (genDeferredCombo, findMergeTools),
         _('Graphical merge program for resolving merge conflicts.  If left'
                 func = e.values
                 w = func(opts)
             w.installEventFilter(self)
+            if e.globalonly:
+                w.setEnabled(self.rcpath == util.user_rcpath())
             lbl = QLabel(e.label)
             lbl.installEventFilter(self)
             lbl.setToolTip(e.tooltip)
         return wconfig.readfile(self.fn)
 
     def recordNewValue(self, cpath, newvalue):
+        """Set the given value to ini; returns True if changed"""
         # 'newvalue' is in local encoding
         section, key = cpath.split('.', 1)
         if newvalue == self.ini.get(section, key):
-            return
+            return False
         if newvalue == None:
             try:
                 del self.ini[section][key]
                 pass
         else:
             self.ini.set(section, key, newvalue)
+        return True
 
     def applyChanges(self):
         if self.readonly:
             else:
                 for row, e in enumerate(info):
                     newvalue = widgets[row].value()
-                    self.recordNewValue(e.cpath, newvalue)
+                    changed = self.recordNewValue(e.cpath, newvalue)
+                    if changed and e.restartneeded:
+                        self.restartRequested.emit(e.label)
 
         try:
             wconfig.writefile(self.ini, self.fn)