Commits

Johan Samyn committed c60cf85

settings: allow 'hgext' prefix for extensions in config file

fixes #185

  • Participants
  • Parent commits 83328ef
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/hgqt/settings.py

     def refresh(self, *args):
         # refresh config values
         self.ini = self.loadIniFile(self.rcpath)
-        self.readonly = not (hasattr(self.ini, 'write') and os.access(self.fn, os.W_OK))
+        self.readonly = not (hasattr(self.ini, 'write')
+                                and os.access(self.fn, os.W_OK))
         self.stack.setDisabled(self.readonly)
         self.fnedit.setText(hglib.tounicode(self.fn))
         for name, info, widgets in self.pages.values():
             if name == 'extensions':
                 extsmentioned = False
                 for row, w in enumerate(widgets):
-                    val = self.readCPath('extensions.' + w.opts['label'])
+                    key = w.opts['label']
+                    for fullkey in (key, 'hgext.%s' % key, 'hgext/%s' % key):
+                        val = self.readCPath('extensions.' + fullkey)
+                        if val != None:
+                            break
                     if val == None:
                         curvalue = False
                     elif len(val) and val[0] == '!':
                         curvalue = True
                         extsmentioned = True
                     w.setValue(curvalue)
+                    if val == None:
+                        w.opts['cpath'] = 'extensions.' + key
+                    else:
+                        w.opts['cpath'] = 'extensions.' + fullkey
                 if not extsmentioned:
                     # make sure widgets are shown properly,
                     # even when no extensions mentioned in the config file
             if (not emitChanged) and chk.isDirty():
                 self.restartRequested.emit(_('Extensions'))
                 emitChanged = True
-            key = chk.opts['label']
+            name = chk.opts['label']
+            section, key = chk.opts['cpath'].split('.', 1)
             newvalue = chk.value()
-            if newvalue and (key in enabledexts):
+            if newvalue and (name in enabledexts):
                 continue    # unchanged
             if newvalue:
                 self.ini.set(section, key, '')
             else:
-                for cand in (key, 'hgext.%s' % key, 'hgext/%s' % key):
-                    try:
-                        del self.ini[section][cand]
-                    except KeyError:
-                        pass
+                try:
+                    del self.ini[section][key]
+                except KeyError:
+                    pass
 
     @pyqtSlot()
     def validateextensions(self):
                            if chk.isChecked())
         invalidexts = hglib.validateextensions(selectedexts)
 
-        def getinival(name):
+        def getinival(cpath):
             if section not in self.ini:
                 return None
-            for cand in (name, 'hgext.%s' % name, 'hgext/%s' % name):
-                try:
-                    return self.ini[section][cand]
-                except KeyError:
-                    pass
+            sect, key = cpath.split('.', 1)
+            try:
+                return self.ini[sect][key]
+            except KeyError:
+                pass
 
-        def changable(name):
-            curval = getinival(name)
+        def changable(name, cpath):
+            curval = getinival(cpath)
             if curval not in ('', None):
                 # enabled or unspecified, official extensions only
                 return False
         allexts = hglib.allextensions()
         for chk in self.pages['extensions'][2]:
             name = chk.opts['label']
-            chk.setEnabled(changable(name))
+            chk.setEnabled(changable(name, chk.opts['cpath']))
             invalmsg = invalidexts.get(name)
             if invalmsg:
                 invalmsg = invalmsg.decode('utf-8')