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

changest: port link detection from hgtk code

Changeset d1c651c88898

Parent b68fdb48a168

by Adrian Buehlmann

Changes to 2 files · Browse files at d1c651c88898 Showing diff from parent b68fdb48a168 Diff from another changeset...

 
14
15
16
 
 
17
18
19
 
235
236
237
 
 
 
 
 
 
 
 
238
239
240
 
244
245
246
 
247
248
249
250
 
 
 
 
 
 
 
 
 
 
251
252
253
 
258
259
260
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
263
264
 
14
15
16
17
18
19
20
21
 
237
238
239
240
241
242
243
244
245
246
247
248
249
250
 
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
 
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
@@ -14,6 +14,8 @@
 # this program; if not, write to the Free Software Foundation, Inc.,  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.   +import re +  from mercurial.node import short as short_hex    from PyQt4 import QtCore, QtGui @@ -235,6 +237,14 @@
  return buf     +# initialize changeset and url link regex +csmatch = r'(\b[0-9a-f]{12}(?:[0-9a-f]{28})?\b)' +httpmatch = r'(\b(http|https)://([-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]))' +regexp = r'%s|%s' % (csmatch, httpmatch) +bodyre = re.compile(regexp) + +revhashprefix = 'rev_hash_' +  class RevMessage(QtGui.QWidget):     def __init__(self, parent=None): @@ -244,10 +254,21 @@
  vb.setMargin(0)     self._message = w = QtGui.QTextBrowser() + w.setOpenLinks(False)   vb.addWidget(w)     self.setLayout(vb)   + connect(self._message, SIGNAL('anchorClicked(QUrl)'), self.anchorClicked) + + def anchorClicked(self, qurl): + link = str(qurl.toString()) + if link.startswith(revhashprefix): + rev = link[len(revhashprefix):] + self.emit(SIGNAL('revisionSelected'), rev) + else: + QtGui.QDesktopServices.openUrl(qurl) +   def setEditable(self, editable):   self._message.setReadOnly(not editable)   @@ -258,7 +279,25 @@
  self.ctx = ctx   desc = xml_escape(unicode(ctx.description(), 'utf-8', 'replace'))   desc = desc.replace('\n', '<br/>\n') - buf = '<div class="diff_desc"><p>%s</p></div>' % desc + + buf = '' + pos = 0 + for m in bodyre.finditer(desc): + a, b = m.span() + if a >= pos: + buf += desc[pos:a] + pos = b + groups = m.groups() + if groups[0]: + cslink = groups[0] + buf += '<a href="%s%s">%s</a>' % (revhashprefix, cslink, cslink) + if groups[1]: + urllink = groups[1] + buf += '<a href="%s">%s</a>' % (urllink, urllink) + if pos < len(desc): + buf += desc[pos:] + + buf = '<div class="diff_desc"><p>%s</p></div>' % buf   self._message.setHtml(buf)     def selectNone(self):
 
68
69
70
 
 
71
72
73
 
68
69
70
71
72
73
74
75
@@ -68,6 +68,8 @@
    self.textview_header.commitsignal.connect(self.commit)   + connect(self.message, SIGNAL('revisionSelected'), self.tableView_revisions.goto) +   # setup tables and views   self.setupHeaderTextview()   connect(self.textview_status, SIGNAL('fileDisplayed'),