Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

status: pull status info into a simple class

Changeset caff3cf3f225

Parent 6441845063cf

by Steve Borho

Changes to one file · Browse files at caff3cf3f225 Showing diff from parent 6441845063cf Diff from another changeset...

 
41
42
43
44
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
47
48
 
53
54
55
56
 
57
58
59
 
61
62
63
64
65
 
 
 
 
66
67
68
 
108
109
110
111
112
113
 
 
 
 
114
115
116
 
118
119
120
121
122
 
 
 
123
124
 
125
126
127
 
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
 
411
412
413
414
 
415
416
 
417
418
419
 
425
426
427
428
429
 
 
430
431
432
 
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
 
77
78
79
 
80
81
82
83
 
85
86
87
 
 
88
89
90
91
92
93
94
 
134
135
136
 
 
 
137
138
139
140
141
142
143
 
145
146
147
 
 
148
149
150
151
 
152
153
154
155
 
345
346
347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
349
350
 
403
404
405
 
406
407
 
408
409
410
411
 
417
418
419
 
 
420
421
422
423
424
@@ -41,8 +41,32 @@
 # Toolbar  # double-click visual diffs   -statusTypes = ('M modified', 'A added', 'R removed', '! deleted', - '? unknown', 'I ignored', 'C clean') +class StatusType(object): + preferredOrder = 'MAR?!ICS' + def __init__(self, name, icon, desc, uilabel): + self.name = name + self.icon = icon + self.desc = desc + self.uilabel = uilabel + +statusTypes = { + 'M' : StatusType('modified', 'menucommit.ico', _('%s is modified'), + 'status.modified'), + 'A' : StatusType('added', 'fileadd.ico', _('%s is added'), + 'status.added'), + 'R' : StatusType('removed', 'filedelete.ico', _('%s is removed'), + 'status.removed'), + '?' : StatusType('unknown', 'shelve.ico', _('%s is not tracked (unknown)'), + 'status.unknown'), + '!' : StatusType('deleted', 'menudelete.ico', _('%s is missing!'), + 'status.deleted'), + 'I' : StatusType('ignored', 'ignore.ico', _('%s is ignored'), + 'status.ignored'), + 'C' : StatusType('clean', '', _('%s is not modified (clean)'), + 'status.clean'), + 'S' : StatusType('subrepo', 'hg.ico', _('%s is a dirty subrepo'), + 'status.subrepo'), +}    class StatusWidget(QWidget):   def __init__(self, pats, opts, parent=None): @@ -53,7 +77,7 @@
  self.repo = hg.repository(ui.ui(), path=root)   self.wctx = self.repo[None]   self.opts = dict(modified=True, added=True, removed=True, deleted=True, - unknown=True, clean=False, ignored=False) + unknown=True, clean=False, ignored=False, subrepo=True)   self.opts.update(opts)   self.pats = pats   self.ms = {} @@ -61,8 +85,10 @@
  # determine the user configured status colors   # (in the future, we could support full rich-text tags)   qtlib.configstyles(self.repo.ui) - for stat in color_labels.keys(): - effect = qtlib.geteffect(color_labels[stat]) + labels = [(stat, val.uilabel) for stat, val in statusTypes.items()] + labels.extend([('r', 'resolve.resolved'), ('u', 'resolve.unresolved')]) + for stat, label in labels: + effect = qtlib.geteffect(label)   for e in effect.split(';'):   if e.startswith('color:'):   colors[stat] = QColor(e[7:]) @@ -108,9 +134,10 @@
    def setButtonText():   text = '' - for stat in statusTypes: - if self.opts[stat[2:]]: - text += stat[0] + for stat in StatusType.preferredOrder: + name = statusTypes[stat].name + if self.opts[name]: + text += stat   pb.setText(text)   def statusTypeTrigger(isChecked):   txt = hglib.fromunicode(self.sender().text()) @@ -118,10 +145,11 @@
  self.refreshWctx()   setButtonText()   menu = QMenu() - for stat in statusTypes: - a = menu.addAction(stat) + for stat in StatusType.preferredOrder: + val = statusTypes[stat] + a = menu.addAction('%s %s' % (stat, val.name))   a.setCheckable(True) - a.setChecked(self.opts[stat[2:]]) + a.setChecked(self.opts[val.name])   a.triggered.connect(statusTypeTrigger)   pb.setMenu(menu)   setButtonText() @@ -317,42 +345,6 @@
 COL_PATH_DISPLAY = 3  COL_PATH = 4   -tips = { - 'M': _('%s is modified'), - 'A': _('%s is added'), - 'R': _('%s is removed'), - '?': _('%s is not tracked (unknown)'), - '!': _('%s is missing!'), - 'I': _('%s is ignored'), - 'C': _('%s is not modified (clean)'), - 'S': _('%s is a dirty subrepo'), -} - -# TODO: We need real icons here -icons = { - 'M': 'menucommit.ico', - 'A': 'fileadd.ico', - 'R': 'filedelete.ico', - '?': 'shelve.ico', - '!': 'menudelete.ico', - 'I': 'ignore.ico', - 'C': '', - 'S': 'hg.ico', -} - -color_labels = { - 'M': 'status.modified', - 'A': 'status.added', - 'R': 'status.removed', - '?': 'status.unknown', - '!': 'status.deleted', - 'I': 'status.ignored', - 'C': 'status.clean', - 'S': 'status.subrepo', - 'r': 'resolve.resolved', - 'u': 'resolve.unresolved', -} -  colors = {}    class WctxModel(QAbstractTableModel): @@ -411,9 +403,9 @@
  return Qt.Unchecked   elif role == Qt.DecorationRole and index.column() == COL_STATUS:   status = self.rows[index.row()][COL_STATUS] - if status in icons: + if status in statusTypes:   ico = QIcon() - ico.addPixmap(QPixmap('icons/' + icons[status])) + ico.addPixmap(QPixmap('icons/' + statusTypes[status].icon))   return QVariant(ico)   elif role == Qt.DisplayRole:   return QVariant(self.rows[index.row()][index.column()]) @@ -425,8 +417,8 @@
  else:   return colors.get(status, QColor('black'))   elif role == Qt.ToolTipRole: - if status in tips: - tip = tips[status] % upath + if status in statusTypes: + tip = statusTypes[status].desc % upath   if mst == 'R':   tip += _(', resolved merge')   elif mst == 'U':