Commits

Angel Ezquerra committed 0011dd0

infobar: convert revision id hashes into links

These links let you select the corresponding revision on the repowidget, to view
its contents, etc. This is particularly useful for error infobar messages.

  • Participants
  • Parent commits 50f1ce3

Comments (0)

Files changed (1)

tortoisehg/hgqt/qtlib.py

 
         self.setLayout(box)
 
+_hashregex = re.compile(r'\b([0-9a-fA-F]{12,})')
+
+def linkifyMessage(message):
+    """Convert revision id hashes in messages into 'cset' links"""
+    message = unicode(message)
+    message = _hashregex.sub(
+        r'<a href="cset:\1">\1</a>',
+        message)
+    return message
+
 class InfoBar(QFrame):
     """Non-modal confirmation/alert (like web flash or Chrome's InfoBar)
 
     """Show status message"""
     def __init__(self, message, parent=None):
         super(StatusInfoBar, self).__init__(parent)
-        self._msglabel = QLabel(message, self, wordWrap=True,
+        self._msglabel = QLabel(linkifyMessage(message), self,
+                                wordWrap=True,
                                 textInteractionFlags=Qt.TextSelectableByMouse \
                                 | Qt.LinksAccessibleByMouse)
         self._msglabel.linkActivated.connect(self.linkActivated)
     def __init__(self, message, parent=None):
         super(CommandErrorInfoBar, self).__init__(parent)
 
-        self._msglabel = QLabel(message, self, wordWrap=True,
+        self._msglabel = QLabel(linkifyMessage(message), self,
+                                wordWrap=True,
                                 textInteractionFlags=Qt.TextSelectableByMouse \
                                 | Qt.LinksAccessibleByMouse)
         self._msglabel.linkActivated.connect(self.linkActivated)
 
         # no wordWrap=True and stretch=1, which inserts unwanted space
         # between _msglabel and _buttons.
-        self._msglabel = QLabel(message, self,
+        self._msglabel = QLabel(linkifyMessage(message), self,
                                 textInteractionFlags=Qt.TextSelectableByMouse \
                                 | Qt.LinksAccessibleByMouse)
         self._msglabel.linkActivated.connect(self.linkActivated)