Source

thg-qt-mq / revsetlabeltry.diff

Full commit
# HG changeset patch
# Parent 7f044c2bbed287a04e0a7f9f772aae5292c30223
repofilter: annotate how query text is interpreted (INCOMPLETE) (refs #2019)

This shows "Revision Set" or "Keyword Search" in the right corner of the input
box. It will help to find out why simple query fails.

BUGs:

- it should catch resizeEvent to update geometry of the label
- duplicating "'(' in query" is really bad
- maybe bad on RTL language?

diff --git a/tortoisehg/hgqt/repofilter.py b/tortoisehg/hgqt/repofilter.py
--- a/tortoisehg/hgqt/repofilter.py
+++ b/tortoisehg/hgqt/repofilter.py
@@ -72,6 +72,10 @@ class RepoFilterBar(QToolBar):
         combo.activated.connect(self.comboSelectionActivated)
         self.revsetle = le
 
+        self.revsettypelabel = QLabel(le)
+        self.revsetcombo.editTextChanged.connect(self._updateRevsetType)
+        self._updateRevsetType()
+
         self.clearBtn = QToolButton(self)
         self.clearBtn.setIcon(qtlib.geticon('filedelete'))
         self.clearBtn.setToolTip(_('Clear current query and query text'))
@@ -192,6 +196,24 @@ class RepoFilterBar(QToolBar):
         self.revsetcombo.addItems(full)
         self.revsetcombo.setCurrentIndex(self.revsetcombo.findText(query))
 
+    @pyqtSlot()
+    def _updateRevsetType(self):
+        query = unicode(self.revsetcombo.currentText())
+        isrevset = '(' in query  # XXX copied from RevsetThread.run()
+        label = self.revsettypelabel
+        label.setText(isrevset and _('Revision Set') or _('Keyword Search'))
+        label.setVisible(bool(query))
+        colormap = {  # TODO pick nice colors
+            False: ('#cccccc', '#eeeeee'),  # gray
+            True:  ('#e0e075', '#ffffb7'),  # yellow
+            }
+        label.setStyleSheet('border: 1px solid %s; background: %s; '
+                            'color: black;' % colormap[isrevset])
+        # show in right corner
+        le = self.revsetcombo.lineEdit()
+        w = label.minimumSizeHint().width()
+        label.setGeometry(le.width() - w - 1, 1, w, le.height() - 2)
+
     def loadSettings(self, s):
         repoid = str(self._repo[0])
         self.entrydlg.restoreGeometry(s.value('revset/' + repoid + '/geom').toByteArray())