Commits

Yuya Nishihara committed e22f93b

thgconfig, hglib: disallow to enable known bad extensions (fixes #1547)

hglib.validateextensions() returns the dict of known bad extensions
based on the given list of the enabled extensions.

thgconfig updates the availability of checkboxes according to it.
It also provides the reason via tooltip.

Comments (0)

Files changed (2)

tortoisehg/hgtk/thgconfig.py

             shortdesc = allexts[name]
             ck = gtk.CheckButton(name, use_underline=False)
             ck.connect('toggled', self.dirty_event)
+            ck.connect('toggled', self._validateextensions)
             ck.connect('focus-in-event', self.set_help,
                        hglib.toutf(shortdesc))
             col, row = i / maxrows, i % maxrows
             extstable.attach(ck, col, col + 1, row, row + 1)
-            self.tooltips.set_tip(ck, hglib.toutf(shortdesc))
             self.extensionschecks[name] = ck
 
     def _enabledextensions(self):
 
     def refresh_extensions_frame(self):
         enabledexts = self._enabledextensions()
+        for name, ck in self.extensionschecks.iteritems():
+            ck.set_active(name in enabledexts)
+
+        self._validateextensions()
+
+    def _validateextensions(self, *args):
+        enabledexts = self._enabledextensions()
+        selectedexts = set(name for name, ck
+                           in self.extensionschecks.iteritems()
+                           if ck.get_active())
+        invalidexts = hglib.validateextensions(selectedexts)
+
         def getinival(name):
             if 'extensions' not in self.ini:
                 return None
             elif name in enabledexts and curval is None:
                 # re-disabling ext is not supported
                 return False
+            elif name in invalidexts and name not in selectedexts:
+                # disallow to enable bad exts, but allow to disable it
+                return False
             else:
                 return True
 
+        allexts = hglib.allextensions()
         for name, ck in self.extensionschecks.iteritems():
-            ck.set_active(name in enabledexts)
             ck.set_sensitive(changable(name))
+            self.tooltips.set_tip(ck, invalidexts.get(name)
+                                  or hglib.toutf(allexts[name]))
 
     def apply_extensions_changes(self):
         enabledexts = self._enabledextensions()

tortoisehg/util/hglib.py

     exts.update(enabledexts)
     return exts
 
+def validateextensions(enabledexts):
+    """Report extensions which should be disabled
+
+    Returns the dict {name: message} of extensions expected to be disabled.
+    message is 'utf-8'-encoded string.
+    """
+    from tortoisehg.util.i18n import _  # avoid cyclic dependency
+    exts = {}
+    if os.name != 'posix':
+        exts['inotify'] = _('inotify is not supported on this platform')
+    if 'win32text' in enabledexts:
+        exts['eol'] = _('eol is incompatible with win32text')
+    if 'eol' in enabledexts:
+        exts['win32text'] = _('win32text is incompatible with eol')
+    return exts
+
 def loadextension(ui, name):
     # Between Mercurial revisions 1.2 and 1.3, extensions.load() stopped
     # calling uisetup() after loading an extension.  This could do