Source

thg-qt-mq / toolssettings.eml

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
Delivered-To: youjah@gmail.com
Received: by 10.64.33.168 with SMTP id s8csp8103iei;
        Sat, 28 Apr 2012 11:31:35 -0700 (PDT)
Return-Path: <thg-dev+bncCJv02ajiEhCG7_D8BBoEH9KjWA@googlegroups.com>
Received-SPF: pass (google.com: domain of thg-dev+bncCJv02ajiEhCG7_D8BBoEH9KjWA@googlegroups.com designates 10.180.94.9 as permitted sender) client-ip=10.180.94.9;
Authentication-Results: mr.google.com; spf=pass (google.com: domain of thg-dev+bncCJv02ajiEhCG7_D8BBoEH9KjWA@googlegroups.com designates 10.180.94.9 as permitted sender) smtp.mail=thg-dev+bncCJv02ajiEhCG7_D8BBoEH9KjWA@googlegroups.com; dkim=pass header.i=thg-dev+bncCJv02ajiEhCG7_D8BBoEH9KjWA@googlegroups.com
Received: from mr.google.com ([10.180.94.9])
        by 10.180.94.9 with SMTP id cy9mr3750037wib.1.1335637894826 (num_hops = 1);
        Sat, 28 Apr 2012 11:31:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=googlegroups.com; s=beta;
        h=x-beenthere:received-spf:mime-version:subject:x-mercurial-node
         :message-id:user-agent:date:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive:sender
         :list-subscribe:list-unsubscribe:content-type
         :content-transfer-encoding;
        bh=mhR+f/M7Cl1ZSoLxCM6LxShrCeLmigVA/CAC0gyq4fA=;
        b=L3FQ8yEkYYXzwgHanoWZTPz2TelGZa4Ya8I2QkqzMDkTCch4Y1pvUKB2okN/25x744
         yuCOaPPN0Lqq5VrzDxsHPS17R0XqopBQbUPkIcG+BzdmqdVYeJbQsyCKNj5deVELmnrT
         7GdrgJIC4F/SLO9Cv+UxEQzEMbhBjdd4G5mKM=
Received: by 10.180.94.9 with SMTP id cy9mr354841wib.1.1335637894789;
        Sat, 28 Apr 2012 11:31:34 -0700 (PDT)
X-BeenThere: thg-dev@googlegroups.com
Received: by 10.180.7.9 with SMTP id f9ls1398194wia.2.canary; Sat, 28 Apr 2012
 11:31:34 -0700 (PDT)
Received: by 10.180.105.71 with SMTP id gk7mr940170wib.0.1335637894525;
        Sat, 28 Apr 2012 11:31:34 -0700 (PDT)
Received: by 10.180.105.71 with SMTP id gk7mr940169wib.0.1335637894505;
        Sat, 28 Apr 2012 11:31:34 -0700 (PDT)
Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com [209.85.212.179])
        by gmr-mx.google.com with ESMTPS id ef4si2381122wib.1.2012.04.28.11.31.34
        (version=TLSv1/SSLv3 cipher=OTHER);
        Sat, 28 Apr 2012 11:31:34 -0700 (PDT)
Received-SPF: pass (google.com: domain of angel.ezquerra@gmail.com designates 209.85.212.179 as permitted sender) client-ip=209.85.212.179;
Received: by mail-wi0-f179.google.com with SMTP id hn6so1380054wib.8
        for <thg-dev@googlegroups.com>; Sat, 28 Apr 2012 11:31:34 -0700 (PDT)
Received: by 10.216.134.24 with SMTP id r24mr4754809wei.84.1335637894397;
        Sat, 28 Apr 2012 11:31:34 -0700 (PDT)
Received: from [192.168.1.34] (61.Red-79-152-149.dynamicIP.rima-tde.net. [79.152.149.61])
        by mx.google.com with ESMTPS id o2sm23048712wiv.11.2012.04.28.11.31.32
        (version=TLSv1/SSLv3 cipher=OTHER);
        Sat, 28 Apr 2012 11:31:33 -0700 (PDT)
MIME-Version: 1.0
Subject: [thg-dev] [PATCH [REBASED]] settings: add 'Tools' panel
X-Mercurial-Node: 0dd296db8c936a761206415b4c1c948e3a102d73
Message-Id: <0dd296db8c936a761206.1335637893@Lucia-PC>
User-Agent: Mercurial-patchbomb/2.2-rc+18-cbf2ea2f5ca1
Date: Sat, 28 Apr 2012 20:31:33 +0200
From: Angel Ezquerra <angel.ezquerra@gmail.com>
To: thg-dev@googlegroups.com
X-Original-Sender: angel.ezquerra@gmail.com
X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com:
 domain of angel.ezquerra@gmail.com designates 209.85.212.179 as permitted
 sender) smtp.mail=angel.ezquerra@gmail.com; dkim=pass header.i=@gmail.com
Reply-To: thg-dev@googlegroups.com
Precedence: list
Mailing-list: list thg-dev@googlegroups.com; contact thg-dev+owners@googlegroups.com
List-ID: <thg-dev.googlegroups.com>
X-Google-Group-Id: 695465234280
List-Post: <http://groups.google.com/group/thg-dev/post?hl=en_US>, <mailto:thg-dev@googlegroups.com>
List-Help: <http://groups.google.com/support/?hl=en_US>, <mailto:thg-dev+help@googlegroups.com>
List-Archive: <http://groups.google.com/group/thg-dev?hl=en_US>
Sender: thg-dev@googlegroups.com
List-Subscribe: <http://groups.google.com/group/thg-dev/subscribe?hl=en_US>, <mailto:thg-dev+subscribe@googlegroups.com>
List-Unsubscribe: <http://groups.google.com/group/thg-dev/subscribe?hl=en_US>, <mailto:googlegroups-manage+695465234280+unsubscribe@googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1333456876 -7200
# Branch stable
# Node ID 0dd296db8c936a761206415b4c1c948e3a102d73
# Parent bc5d8509c8db7659276c2f2bca1ae12405bcef60
settings: add 'Tools' panel

Add a new panel to the settings dialog which allows configuring (adding,
editing, deleting and reordering) TortoiseHg custom tools.

diff --git a/tortoisehg/hgqt/customtoolconfig.py b/tortoisehg/hgqt/customtoolconfig.py
new file mode 100644
--- /dev/null
+++ b/tortoisehg/hgqt/customtoolconfig.py
@@ -0,0 +1,179 @@
+# customtoolconfig.py - Configuration dialog for TortoiseHg custom tools
+#
+# Copyright 2012 Angel Ezquerra <angel.ezquerra@gmail.com>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2, incorporated herein by reference.
+
+from tortoisehg.hgqt.i18n import _
+from tortoisehg.hgqt import qtlib
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+class CustomToolConfigDialog(QDialog):
+    'Dialog for editing the a custom tool configuration'
+
+    _enablemappings = {'All items': 'istrue',
+                        'Working Directory': 'iswd',
+                        'All revisions': 'isrev',
+                        'All contexts': 'isctx',
+                        'Fixed revisions': 'fixed',
+                        'Applied patches': 'applied',
+                        'qgoto': 'qgoto'}
+
+    _locationmappings = {'Everywhere': 'workbench, repowidget',
+                        'Workbench Toolbar': 'workbench',
+                        'Selected Revision context menu': 'repowidget',}
+
+    def __init__(self, parent=None, toolname=None, toolconfig={}):
+        QDialog.__init__(self, parent)
+
+        self.setWindowIcon(qtlib.geticon('tools-spanner-hammer'))
+        self.setWindowTitle('Configure Custom Tool')
+        self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
+
+        self.hbox = QHBoxLayout()
+        vbox = QVBoxLayout()
+
+        command = toolconfig.get('command', '')
+        label = toolconfig.get('label', '')
+        tooltip = toolconfig.get('tooltip', '')
+        ico = toolconfig.get('icon', '')
+        location = toolconfig.get('location', 'workbench repowidget')
+        enable = toolconfig.get('enable', 'all')
+        outputlog = toolconfig.get('outputlog', 'False')
+
+        self.name = self._addConfigItem(vbox, _('Tool name'),
+            QLineEdit(toolname), _('The tool name. It cannot contain spaces.'))
+            # Execute a mercurial command. These _MUST_ start with "hg"
+        self.command = self._addConfigItem(vbox, _('Command'),
+            QLineEdit(command), _('The command that will be executed.\n'
+            'To execute a mercurial command use "hg" (rather than "hg.exe") '
+            'as the executable command.\n'
+            'You can use {ROOT} as an alias of the current repository root and\n'
+            '{REV} as an alias of the selected revision.'))
+        self.label = self._addConfigItem(vbox, _('Tool label'),
+            QLineEdit(label),
+            _('The tool label, which is what will be shown '
+            'on the repowidget context menu.\n'
+            'If no label is set, the tool name will be used as the tool label.\n'
+            'If no tooltip is set, the label will be used as the tooltip as well.'))
+        self.tooltip = self._addConfigItem(vbox, _('Tooltip'),
+            QLineEdit(tooltip),
+            _('The tooltip that will be shown on the tool button.\n'
+            'This is only shown when the tool button is shown on\n'
+            'the workbench toolbar.'))
+        self.icon = self._addConfigItem(vbox, _('Icon'),
+            QLineEdit(ico),
+            _('The tool icon.\n'
+            'You can use any built-in TortoiseHg icon\n'
+            'by setting this value to a vaild TortoiseHg icon name\n'
+            '(e.g. clone, add, remove, sync, thg-logo, hg-update, etc).\n'
+            'You can also set this value to the absoluate path to\n'
+            'any icon on your file system.'))
+
+        combo = self._genCombo(self._locationmappings.keys(),
+            self._location2label(location), 'Everywhere')
+        self.location = self._addConfigItem(vbox, _('Show command in'), combo,
+            _('The location where you want to show'
+            'the command icon or menu entry:\n'
+            '- Workbench: Show a button on the Workbench Custom toolbar.\n'
+            '- Repowidget: Show an entry on the selected revision context menu.'))
+
+        combo = self._genCombo(self._enablemappings.keys(),
+            self._enable2label(enable), 'All items')
+        self.enable = self._addConfigItem(vbox, _('On repowidget, show for'),
+            combo,  _('For which kinds of revisions the tool will be enabled\n'
+            'It is only taken into account when the tool is shown on the\n'
+            'selected revision context menu.'))
+
+        combo = self._genCombo(('True', 'False'), outputlog)
+        self.showoutput = self._addConfigItem(vbox, _('Show Output Log'),
+            combo, _('When enabled, automatically show the Output Log when the'
+            'command is run.\nDefault: False.'))
+
+        self.hbox.addLayout(vbox)
+        vbox = QVBoxLayout()
+        self.okbutton = QPushButton(_('OK'))
+        self.okbutton.clicked.connect(self.okClicked)
+        vbox.addWidget(self.okbutton)
+        self.cancelbutton = QPushButton(_('Cancel'))
+        self.cancelbutton.clicked.connect(self.reject)
+        vbox.addWidget(self.cancelbutton)
+        vbox.addStretch()
+        self.hbox.addLayout(vbox)
+        self.setLayout(self.hbox)
+
+    def value(self):
+        toolname = str(self.name.text()).strip()
+        toolconfig = {
+            'label': str(self.label.text()),
+            'command': str(self.command.text()),
+            'tooltip': str(self.tooltip.text()),
+            'icon': str(self.icon.text()),
+            'location': self._locationmappings[str(self.location.currentText())],
+            'enable': self._enablemappings[str(self.enable.currentText())],
+            'showoutput': str(self.showoutput.currentText()),
+        }
+        return toolname, toolconfig
+
+    def _genCombo(self, items, selecteditem=None, defaultitem=None):
+        print items
+        index = 0
+        if selecteditem:
+            print 'selecteditem: %s' % selecteditem
+            try:
+                index = items.index(selecteditem)
+                print index
+            except:
+                if defaultitem:
+                    try:
+                        print 'defaultitem: %s' % defaultitem
+                        index = items.index(defaultitem)
+                    except:
+                        print 'not found'
+                        pass
+        combo = QComboBox()
+        combo.addItems(items)
+        if index:
+            combo.setCurrentIndex(index)
+        return combo
+
+    def _addConfigItem(self, parent, label, configwidget, tooltip=None):
+        if tooltip:
+            configwidget.setToolTip(tooltip)
+        hbox = QHBoxLayout()
+        hbox.addWidget(QLabel(label))
+        hbox.addWidget(configwidget)
+        parent.addLayout(hbox)
+        return configwidget
+
+    def _enable2label(self, label):
+        return self._dictvalue2key(self._enablemappings, label)
+
+    def _location2label(self, label):
+        return self._dictvalue2key(self._locationmappings, label)
+
+    def _dictvalue2key(self, dictionary, value):
+        for key in dictionary:
+            if value == dictionary[key]:
+                return key
+        return None
+
+    def okClicked(self):
+        errormsg = self.validateForm()
+        if errormsg:
+            qtlib.WarningMsgBox(_('Missing information'), errormsg)
+            return
+        return self.accept()
+
+    def validateForm(self):
+        name, config = self.value()
+        if not name:
+            return _('You must set a tool name.')
+        if name.find(' ') >= 0:
+            return _('The tool name cannot have any spaces in it.')
+        if not config['command']:
+            return _('You must set a command to run.')
+        return '' # No error
diff --git a/tortoisehg/hgqt/settings.py b/tortoisehg/hgqt/settings.py
--- a/tortoisehg/hgqt/settings.py
+++ b/tortoisehg/hgqt/settings.py
@@ -11,7 +11,7 @@ from mercurial import ui, util, error, e
 
 from tortoisehg.util import hglib, settings, paths, wconfig, i18n, bugtraq
 from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt import qtlib, qscilib, thgrepo
+from tortoisehg.hgqt import qtlib, qscilib, thgrepo, customtoolconfig
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
@@ -180,6 +180,7 @@ class PasswordEntry(LineEditBox):
         self.curvalue = None
         self.setEchoMode(QLineEdit.Password)
         self.setMinimumWidth(ENTRY_WIDTH)
+
 class TextEntry(QTextEdit):
     def __init__(self, parent=None, **opts):
         QTextEdit.__init__(self, parent, toolTip=opts['tooltip'])
@@ -307,6 +308,103 @@ class SettingsCheckBox(QCheckBox):
         return self.value() != self.curvalue
 
 
+class ListBox(QListWidget):
+    def __init__(self, parent=None, **opts):
+        QListWidget.__init__(self, parent, **opts)
+        self.opts = opts
+        self.curvalue = None
+        self.setMinimumWidth(ENTRY_WIDTH)
+
+    def values(self):
+        out = []
+        for row in range(self.count()):
+            out.append(self.item(row).text())
+        return out
+
+    ## common APIs for all edit widgets
+    def setValue(self, curvalue):
+        self.curvalue = curvalue
+
+    def value(self):
+        row = self.currentIndex().row()
+        if row < 0:
+            return None
+        else:
+            return self.item(row).text()
+
+    def isDirty(self):
+        return self.value() != self.curvalue
+
+
+class ToolListBox(ListBox):
+    def __init__(self, parent=None, **opts):
+        ListBox.__init__(self, parent, **opts)
+
+        self.curvalue = (None, None)
+        self.tortoisehgtools, self.toolnames = hglib.tortoisehgtools(ui.ui())
+        self.addItems(self.toolnames)
+
+        self.doubleClicked.connect(self.editToolItem)
+
+        # Enable drag and drop to reorder the tools
+        self.setDragEnabled(True)
+        self.setDragDropMode(self.InternalMove)
+        self.setDefaultDropAction(Qt.MoveAction)
+
+    def takeItem(self, p_int):
+        item = self.item(p_int)
+        itemtext = str(item.text())
+        del self.tortoisehgtools[itemtext]
+        print self.tortoisehgtools
+        super(ToolListBox, self).takeItem(p_int)
+
+    def addTool(self):
+        td = customtoolconfig.CustomToolConfigDialog(self)
+        res = td.exec_()
+        if res:
+            row = self.currentIndex().row()
+            toolname, toolconfig = td.value()
+            if row < 0:
+                self.addItem(toolname)
+                self.setCurrentRow(self.count()-1)
+            else:
+                self.insertItem(row+1, toolname)
+                self.setCurrentRow(row+1)
+            self.tortoisehgtools[toolname] = toolconfig
+
+    def editTool(self, row=None):
+        if row is None:
+            row = self.currentIndex().row()
+        if row < 0:
+            return self.addTool()
+        else:
+            item = self.item(row)
+            toolname = item.text()
+            td = customtoolconfig.CustomToolConfigDialog(
+                self, toolname=toolname,
+                toolconfig=self.tortoisehgtools[str(toolname)])
+            res = td.exec_()
+            if res:
+                toolname, toolconfig = td.value()
+                self.takeItem(row)
+                self.insertItem(row, toolname)
+                self.setCurrentRow(row)
+                self.tortoisehgtools[toolname] = toolconfig
+
+    def editToolItem(self, item):
+        self.editTool(item.row())
+
+    def deleteTool(self, row=None):
+        if row is None:
+            row = self.currentIndex().row()
+        if row >= 0:
+            self.takeItem(row)
+
+    ## common APIs for all edit widgets
+    def value(self):
+        return (self.tortoisehgtools, self.values())
+
+
 class BugTraqConfigureEntry(QPushButton):
     def __init__(self, parent=None, **opts):
         QPushButton.__init__(self, parent, toolTip=opts['tooltip'])
@@ -853,6 +951,9 @@ INFO = (
 ({'name': 'extensions', 'label': _('Extensions'), 'icon': 'hg-extensions'}, (
     )),
 
+({'name': 'tools', 'label': _('Tools'), 'icon': 'tools-spanner-hammer'}, (
+    )),
+
 ({'name': 'issue', 'label': _('Issue Tracking'), 'icon': 'edit-file'}, (
     _fi(_('Issue Regex'), 'tortoisehg.issue.regex', genEditCombo,
         _('Defines the regex to match when picking up issue numbers.')),
@@ -1227,6 +1328,9 @@ class SettingsForm(QWidget):
                 # make sure widgets are shown properly,
                 # even when no extensions mentioned in the config file
                 self.validateextensions()
+        elif name == 'tools':
+            self.tortoisehgtools, self.toolnames = hglib.tortoisehgtools(ui.ui())
+            widgets[0].setValue((self.tortoisehgtools, self.toolnames))
         else:
             for row, e in enumerate(info):
                 curvalue = self.readCPath(e.cpath)
@@ -1320,6 +1424,32 @@ class SettingsForm(QWidget):
             widgets.append(w)
         return extsinfo, widgets
 
+    def fillToolsFrame(self):
+        widgets = []
+        frame = QFrame()
+        hbox = QHBoxLayout()
+        frame.setLayout(hbox)
+        self.stack.addWidget(frame)
+
+        toollist = ToolListBox()
+        hbox.addWidget(toollist)
+        vbox = QVBoxLayout()
+
+        addbutton = QPushButton(_('Add'), self)
+        addbutton.clicked.connect(toollist.addTool)
+        editbutton = QPushButton(_('Edit'), self)
+        editbutton.clicked.connect(lambda: toollist.editTool(None))
+        deletebutton = QPushButton(_('Delete'), self)
+        deletebutton.clicked.connect(lambda: toollist.deleteTool(None))
+        vbox.addWidget(addbutton)
+        vbox.addWidget(editbutton)
+        vbox.addWidget(deletebutton)
+        vbox.addStretch()
+        hbox.addLayout(vbox)
+        widgets.append(toollist)
+        toolsinfo = ()
+        return toolsinfo, widgets
+
     def eventFilter(self, obj, event):
         if event.type() in (QEvent.Enter, QEvent.FocusIn):
             self.desctext.setHtml(obj.toolTip())
@@ -1337,6 +1467,9 @@ class SettingsForm(QWidget):
         if name == 'extensions':
             extsinfo, widgets = self.fillExtensionsFrame()
             self.pages[name] = name, extsinfo, widgets
+        elif name == 'tools':
+            toolsinfo, widgets = self.fillToolsFrame()
+            self.pages[name] = name, toolsinfo, widgets
         else:
             widgets = self.fillFrame(info)
             self.pages[name] = name, info, widgets
@@ -1394,6 +1527,8 @@ class SettingsForm(QWidget):
         for name, info, widgets in self.pages.values():
             if name == 'extensions':
                 self.applyChangesForExtensions()
+            elif name == 'tools':
+                self.applyChangesForTools()
             else:
                 for row, e in enumerate(info):
                     newvalue = widgets[row].value()
@@ -1469,6 +1604,41 @@ class SettingsForm(QWidget):
                 invalmsg = invalmsg.decode('utf-8')
             chk.setToolTip(invalmsg or hglib.tounicode(allexts[name]))
 
+    def applyChangesForTools(self):
+        emitChanged = False
+        toollist =  self.pages['tools'][2][0]
+        if not toollist.isDirty():
+            return
+
+        tools, toolnames = toollist.value()
+        curtools, curtoolnames = toollist.curvalue
+
+        # In order to keep the tool order we must delete all existing
+        # custom tool configurations, and then set all the configuration
+        # settings anew:
+        section = 'tortoisehg-tools'
+
+        # 1. Remove the existing tool configurations
+        fieldnames = ('command', 'label', 'tooltip',
+                      'icon', 'location', 'enable', 'showoutput',)
+        for name in curtoolnames:
+            for field in fieldnames:
+                try:
+                    keyname = '%s.%s' % (name, field)
+                    del self.ini[section][keyname]
+                except KeyError:
+                    pass
+
+        # 2. Configure the new configurations
+        for uname in toolnames:
+            name = hglib.fromunicode(uname)
+            for field in sorted(tools[name]):
+                keyname = '%s.%s' % (name, field)
+                value = tools[name][field]
+                if not value is '':
+                    self.ini.set(section, keyname, value)
+
+        self.restartRequested.emit(_('Tools'))
 
 def run(ui, *pats, **opts):
     return SettingsDialog(opts.get('alias') == 'repoconfig',