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

extract class RevDisplay into new changeset.py

Changeset 3f5e69db8fde

Parent bc305895d2aa

by Adrian Buehlmann

Changes to 4 files · Browse files at 3f5e69db8fde Showing diff from parent bc305895d2aa Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​changeset.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,180 @@
+# Copyright (c) 2009-2010 LOGILAB S.A. (Paris, FRANCE). +# http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +from mercurial.node import short as short_hex + +from PyQt4 import QtCore, QtGui +Qt = QtCore.Qt +connect = QtCore.QObject.connect +SIGNAL = QtCore.SIGNAL + +from tortoisehg.util.util import format_desc, xml_escape + +from tortoisehg.hgqt.config import HgConfig + + +class RevDisplay(QtGui.QTextBrowser): + """ + Display metadata for one revision (rev, author, description, etc.) + """ + def __init__(self, parent=None): + QtGui.QTextBrowser.__init__(self, parent) + self.descwidth = 60 # number of chars displayed for parent/child descriptions + connect(self, + SIGNAL('anchorClicked(const QUrl &)'), + self.anchorClicked) + + def anchorClicked(self, qurl): + """ + Callback called when a link is clicked in the text browser + """ + rev = str(qurl.toString()) + if rev.startswith('diff_'): + self.diffrev = int(rev[5:]) + self.refreshDisplay() + # TODO: emit a signal to recompute the diff + self.emit(SIGNAL('parentRevisionSelected'), self.diffrev) + else: + self.emit(SIGNAL('revisionSelected'), int(rev)) + + def setDiffRevision(self, rev): + if rev != self.diffrev: + self.diffrev = rev + self.refreshDisplay() + + def displayRevision(self, ctx): + self.ctx = ctx + self.diffrev = ctx.parents()[0].rev() + if hasattr(self.ctx._repo, "mq"): + self.mqseries = self.ctx._repo.mq.series[:] + self.mqunapplied = [x[1] for x in self.ctx._repo.mq.unapplied(self.ctx._repo)] + mqpatch = set(self.ctx.tags()).intersection(self.mqseries) + if mqpatch: + self.mqpatch = mqpatch.pop() + else: + self.mqpatch = None + else: + self.mqseries = [] + self.mqunapplied = [] + self.mqpatch = None + + self.refreshDisplay() + + def selectNone(self): + cursor = self.textCursor() + cursor.clearSelection() + cursor.setPosition(0) + self.setTextCursor(cursor) + self.setExtraSelections([]) + + def searchString(self, text): + self.selectNone() + if text in unicode(self.toPlainText()): + clist = [] + while self.find(text): + eselect = self.ExtraSelection() + eselect.cursor = self.textCursor() + eselect.format.setBackground(QtGui.QColor('#ffffbb')) + clist.append(eselect) + self.selectNone() + self.setExtraSelections(clist) + def finditer(self, text): + if text: + while True: + if self.find(text): + yield self.ctx.rev(), None + else: + break + return finditer(self, text) + + def refreshDisplay(self): + ctx = self.ctx + rev = ctx.rev() + buf = "<table width=100%>\n" + if self.mqpatch: + buf += '<tr bgcolor=%s>' % HgConfig(ctx._repo.ui).getMQFGColor() + buf += '<td colspan=3 width=100%><b>Patch queue:</b>&nbsp;' + for p in self.mqseries: + if p in self.mqunapplied: + p = "<i>%s</i>" % p + elif p == self.mqpatch: + p = "<b>%s</b>" % p + buf += '&nbsp;%s&nbsp;' % (p) + buf += '</td></tr>\n' + + buf += '<tr>' + if rev is None: + buf += "<td><b>Working Directory</b></td>\n" + else: + buf += '<td><b>Revision:</b>&nbsp;'\ + '<span class="rev_number">%d</span>:'\ + '<span class="rev_hash">%s</span></td>'\ + '\n' % (ctx.rev(), short_hex(ctx.node())) + + buf += '<td><b>Author:</b>&nbsp;'\ + '%s</td>'\ + '\n' % unicode(ctx.user(), 'utf-8', 'replace') + buf += '<td><b>Branch:</b>&nbsp;%s</td>' % ctx.branch() + buf += '</tr>' + buf += "</table>\n" + buf += "<table width=100%>\n" + parents = [p for p in ctx.parents() if p] + for p in parents: + if p.rev() > -1: + short = short_hex(p.node()) + desc = format_desc(p.description(), self.descwidth) + p_rev = p.rev() + p_fmt = '<span class="rev_number">%s</span>:'\ + '<a href="%s" class="rev_hash">%s</a>' + if p_rev == self.diffrev: + p_rev = '<b>%s</b>' % (p_fmt % (p_rev, p_rev, short)) + else: + p_rev = p_fmt % ('<a href="diff_%s" class="rev_diff">%s</a>' % (p_rev, p_rev), p_rev, short) + buf += '<tr><td width=50 class="label"><b>Parent:</b></td>'\ + '<td colspan=5>%s&nbsp;'\ + '<span class="short_desc"><i>%s</i></span></td></tr>'\ + '\n' % (p_rev, desc) + if len(parents) == 2: + p = parents[0].ancestor(parents[1]) + short = short_hex(p.node()) + desc = format_desc(p.description(), self.descwidth) + p_rev = p.rev() + p_fmt = '<span class="rev_number">%s</span>:'\ + '<a href="%s" class="rev_hash">%s</a>' + if p_rev == self.diffrev: + p_rev = '<b>%s</b>' % (p_fmt % (p_rev, p_rev, short)) + else: + p_rev = p_fmt % ('<a href="diff_%s" class="rev_diff">%s</a>' % (p_rev, p_rev), p_rev, short) + buf += '<tr><td width=50 class="label"><b>Ancestor:</b></td>'\ + '<td colspan=5>%s&nbsp;'\ + '<span class="short_desc"><i>%s</i></span></td></tr>'\ + '\n' % (p_rev, desc) + + for p in ctx.children(): + if p.rev() > -1: + short = short_hex(p.node()) + desc = format_desc(p.description(), self.descwidth) + buf += '<tr><td class="label"><b>Child:</b></td>'\ + '<td colspan=5><span class="rev_number">%d</span>:'\ + '<a href="%s" class="rev_hash">%s</a>&nbsp;'\ + '<span class="short_desc"><i>%s</i></span></td></tr>'\ + '\n' % (p.rev(), p.rev(), short, desc) + + buf += "</table>\n" + desc = xml_escape(unicode(ctx.description(), 'utf-8', 'replace')) + desc = desc.replace('\n', '<br/>\n') + buf += '<div class="diff_desc"><p>%s</p></div>\n' % desc + self.setHtml(buf)
 
13
14
15
16
17
18
19
20
21
22
23
24
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
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
 
13
14
15
 
 
 
 
16
 
17
18
19
 
23
24
25
 
26
 
 
 
 
27
 
28
29
30
 
297
298
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -13,12 +13,7 @@
 # You should have received a copy of the GNU General Public License along with  # this program; if not, write to the Free Software Foundation, Inc.,  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -""" -Qt4 high level widgets for hg repo changelogs and filelogs -""" -import sys   -from mercurial.node import hex, short as short_hex, bin as short_bin  try:   from mercurial.error import RepoError  except ImportError: # old API @@ -28,14 +23,8 @@
 Qt = QtCore.Qt  connect = QtCore.QObject.connect  SIGNAL = QtCore.SIGNAL -nullvariant = QtCore.QVariant()   -from tortoisehg.util.util import format_desc, xml_escape - -from tortoisehg.hgqt.decorators import timeit -from tortoisehg.hgqt.config import HgConfig  from tortoisehg.hgqt import icon as geticon -from tortoisehg.hgqt.manifestdialog import ManifestDialog  from tortoisehg.hgqt.quickbar import QuickBar    class GotoQuickBar(QuickBar): @@ -308,157 +297,3 @@
  def prevRev(self):   row = self.currentIndex().row()   self.setCurrentIndex(self.model().index(max(row - 1, 0), 0)) - - -class RevDisplay(QtGui.QTextBrowser): - """ - Display metadata for one revision (rev, author, description, etc.) - """ - def __init__(self, parent=None): - QtGui.QTextBrowser.__init__(self, parent) - self.descwidth = 60 # number of chars displayed for parent/child descriptions - connect(self, - SIGNAL('anchorClicked(const QUrl &)'), - self.anchorClicked) - - def anchorClicked(self, qurl): - """ - Callback called when a link is clicked in the text browser - """ - rev = str(qurl.toString()) - if rev.startswith('diff_'): - self.diffrev = int(rev[5:]) - self.refreshDisplay() - # TODO: emit a signal to recompute the diff - self.emit(SIGNAL('parentRevisionSelected'), self.diffrev) - else: - self.emit(SIGNAL('revisionSelected'), int(rev)) - - def setDiffRevision(self, rev): - if rev != self.diffrev: - self.diffrev = rev - self.refreshDisplay() - - def displayRevision(self, ctx): - self.ctx = ctx - self.diffrev = ctx.parents()[0].rev() - if hasattr(self.ctx._repo, "mq"): - self.mqseries = self.ctx._repo.mq.series[:] - self.mqunapplied = [x[1] for x in self.ctx._repo.mq.unapplied(self.ctx._repo)] - mqpatch = set(self.ctx.tags()).intersection(self.mqseries) - if mqpatch: - self.mqpatch = mqpatch.pop() - else: - self.mqpatch = None - else: - self.mqseries = [] - self.mqunapplied = [] - self.mqpatch = None - - self.refreshDisplay() - - def selectNone(self): - cursor = self.textCursor() - cursor.clearSelection() - cursor.setPosition(0) - self.setTextCursor(cursor) - self.setExtraSelections([]) - - def searchString(self, text): - self.selectNone() - if text in unicode(self.toPlainText()): - clist = [] - while self.find(text): - eselect = self.ExtraSelection() - eselect.cursor = self.textCursor() - eselect.format.setBackground(QtGui.QColor('#ffffbb')) - clist.append(eselect) - self.selectNone() - self.setExtraSelections(clist) - def finditer(self, text): - if text: - while True: - if self.find(text): - yield self.ctx.rev(), None - else: - break - return finditer(self, text) - - def refreshDisplay(self): - ctx = self.ctx - rev = ctx.rev() - buf = "<table width=100%>\n" - if self.mqpatch: - buf += '<tr bgcolor=%s>' % HgConfig(ctx._repo.ui).getMQFGColor() - buf += '<td colspan=3 width=100%><b>Patch queue:</b>&nbsp;' - for p in self.mqseries: - if p in self.mqunapplied: - p = "<i>%s</i>" % p - elif p == self.mqpatch: - p = "<b>%s</b>" % p - buf += '&nbsp;%s&nbsp;' % (p) - buf += '</td></tr>\n' - - buf += '<tr>' - if rev is None: - buf += "<td><b>Working Directory</b></td>\n" - else: - buf += '<td><b>Revision:</b>&nbsp;'\ - '<span class="rev_number">%d</span>:'\ - '<span class="rev_hash">%s</span></td>'\ - '\n' % (ctx.rev(), short_hex(ctx.node())) - - buf += '<td><b>Author:</b>&nbsp;'\ - '%s</td>'\ - '\n' % unicode(ctx.user(), 'utf-8', 'replace') - buf += '<td><b>Branch:</b>&nbsp;%s</td>' % ctx.branch() - buf += '</tr>' - buf += "</table>\n" - buf += "<table width=100%>\n" - parents = [p for p in ctx.parents() if p] - for p in parents: - if p.rev() > -1: - short = short_hex(p.node()) - desc = format_desc(p.description(), self.descwidth) - p_rev = p.rev() - p_fmt = '<span class="rev_number">%s</span>:'\ - '<a href="%s" class="rev_hash">%s</a>' - if p_rev == self.diffrev: - p_rev = '<b>%s</b>' % (p_fmt % (p_rev, p_rev, short)) - else: - p_rev = p_fmt % ('<a href="diff_%s" class="rev_diff">%s</a>' % (p_rev, p_rev), p_rev, short) - buf += '<tr><td width=50 class="label"><b>Parent:</b></td>'\ - '<td colspan=5>%s&nbsp;'\ - '<span class="short_desc"><i>%s</i></span></td></tr>'\ - '\n' % (p_rev, desc) - if len(parents) == 2: - p = parents[0].ancestor(parents[1]) - short = short_hex(p.node()) - desc = format_desc(p.description(), self.descwidth) - p_rev = p.rev() - p_fmt = '<span class="rev_number">%s</span>:'\ - '<a href="%s" class="rev_hash">%s</a>' - if p_rev == self.diffrev: - p_rev = '<b>%s</b>' % (p_fmt % (p_rev, p_rev, short)) - else: - p_rev = p_fmt % ('<a href="diff_%s" class="rev_diff">%s</a>' % (p_rev, p_rev), p_rev, short) - buf += '<tr><td width=50 class="label"><b>Ancestor:</b></td>'\ - '<td colspan=5>%s&nbsp;'\ - '<span class="short_desc"><i>%s</i></span></td></tr>'\ - '\n' % (p_rev, desc) - - for p in ctx.children(): - if p.rev() > -1: - short = short_hex(p.node()) - desc = format_desc(p.description(), self.descwidth) - buf += '<tr><td class="label"><b>Child:</b></td>'\ - '<td colspan=5><span class="rev_number">%d</span>:'\ - '<a href="%s" class="rev_hash">%s</a>&nbsp;'\ - '<span class="short_desc"><i>%s</i></span></td></tr>'\ - '\n' % (p.rev(), p.rev(), short, desc) - - buf += "</table>\n" - desc = xml_escape(unicode(ctx.description(), 'utf-8', 'replace')) - desc = desc.replace('\n', '<br/>\n') - buf += '<div class="diff_desc"><p>%s</p></div>\n' % desc - self.setHtml(buf)
 
234
235
236
237
 
238
239
240
 
234
235
236
 
237
238
239
240
@@ -234,7 +234,7 @@
  <customwidget>   <class>RevDisplay</class>   <extends>QTextBrowser</extends> - <header>repoview.h</header> + <header>changeset.h</header>   </customwidget>   <customwidget>   <class>HgFileListView</class>
 
2
3
4
5
 
6
7
8
 
141
142
143
 
144
145
146
 
147
 
2
3
4
 
5
6
7
8
 
141
142
143
144
145
146
 
147
148
@@ -2,7 +2,7 @@
   # Form implementation generated from reading ui file 'C:\Users\adi\hgrepos\thg-qt\tortoisehg\hgqt\workbench.ui'  # -# Created: Sun May 02 14:21:29 2010 +# Created: Sun May 02 16:24:14 2010  # by: PyQt4 UI code generator 4.7.3  #  # WARNING! All changes made in this file will be lost! @@ -141,7 +141,8 @@
  self.actionDisplayAllBranches.setText(QtGui.QApplication.translate("MainWindow", "displayAllBranches", None, QtGui.QApplication.UnicodeUTF8))   self.actionHelp.setText(QtGui.QApplication.translate("MainWindow", "Help", None, QtGui.QApplication.UnicodeUTF8))   +from changeset import RevDisplay  from filelistview import HgFileListView  from fileview import HgFileView -from repoview import HgRepoView, RevDisplay +from repoview import HgRepoView  import workbench_rc