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

annotate: color lines by author/age

QTextFormat.FullWidthSelection is not working, and I cannot figure out why.
If I do not tell it to select the 'LineUnderCursor', it colors nothing. I may have
to pad lines to a uniform width to make this work.

Changeset 67650c5ac7c5

Parent d55825254dc1

by Steve Borho

Changes to one file · Browse files at 67650c5ac7c5 Showing diff from parent d55825254dc1 Diff from another changeset...

 
11
12
13
14
 
15
16
17
 
86
87
88
89
 
90
91
 
 
 
 
 
 
 
92
93
94
 
110
111
112
113
 
114
115
116
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
119
120
121
122
 
 
123
124
125
 
126
127
128
 
187
188
189
190
191
 
192
193
 
194
195
196
 
11
12
13
 
14
15
16
17
 
86
87
88
 
89
90
91
92
93
94
95
96
97
98
99
100
101
 
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
 
207
208
209
 
 
210
211
212
213
214
215
216
@@ -11,7 +11,7 @@
 from mercurial import ui, hg, error, commands, cmdutil, util    from tortoisehg.hgqt import htmlui, visdiff, qtlib, htmllistview -from tortoisehg.util import paths, hglib +from tortoisehg.util import paths, hglib, colormap  from tortoisehg.hgqt.i18n import _    from PyQt4.QtCore import * @@ -86,9 +86,16 @@
    self.thread = None   - def annotateFileAtRev(self, fctx): + def annotateFileAtRev(self, repo, ctx, wfile):   if self.thread is not None:   return + fctx = ctx[wfile] + curdate = fctx.date()[0] + basedate = repo.filectx(wfile, fileid=0).date()[0] + agedays = (curdate - fctx.date()[0]) / (24 * 60 * 60) + self.cm = colormap.AnnotateColorSaturation(agedays) + self.curdate = curdate + self.repo = repo   self.loadBegin.emit()   self.thread = AnnotateThread(fctx)   self.thread.done.connect(self.finished) @@ -110,19 +117,32 @@
  return super(AnnotateView, self).keyPressEvent(event)     def fillModel(self, data): - lines = [] + sels = []   revs = []   for fctx, origline, text in data: - revs.append(str(fctx.linkrev())) - lines.append(text) + self.edit.appendPlainText(text[:-1]) + self.edit.moveCursor(QTextCursor.NextBlock) + rev = fctx.linkrev() + ctx = self.repo[rev] + rgb = self.cm.get_color(ctx, self.curdate) + sel = QTextEdit.ExtraSelection() + sel.bgcolor = QColor(rgb) # save a reference + sel.format.setBackground(sel.bgcolor) + sel.format.setProperty(QTextFormat.FullWidthSelection, True) + sel.cursor = self.edit.textCursor() + sel.cursor.select(QTextCursor.LineUnderCursor) + sels.append(sel) + revs.append(str(rev)) + self.colorsels = sels   width = max([len(r) for r in revs]) * self.edit.charwidth + 3   self.revarea.width = width   self.revarea.setFixedWidth(width) - self.edit.setPlainText(''.join(lines))   self.edit.revs = revs + self.edit.setExtraSelections(self.colorsels) + self.edit.verticalScrollBar().setValue(0)     def searchText(self, regexp, icase): - extraSelections = [] + extraSelections = self.colorsels[:]   color = QColor(Qt.yellow)   flags = QTextDocument.FindFlags()   if not icase: @@ -187,10 +207,10 @@
  try:   repo = hg.repository(ui.ui(), path=paths.find_root())   ctx = repo[opts.get('rev', '.')] - fctx = ctx[pats[0]] - av.annotateFileAtRev(fctx) + fctx = ctx[pats[0]] # just for validation   except Exception, e:   self.status.setText(hglib.tounicode(str(e))) + av.annotateFileAtRev(repo, ctx, pats[0])     s = QSettings()   self.restoreGeometry(s.value('annotate/geom').toByteArray())