Commits

Anonymous committed c5637ab

chunks: add search toolbar

I had to duplicate a bit of code from fileview.py, since the chunks widget uses
its own, similar-but-not-quite-the-same-as-HgFileView widget to display the
chunks.

  • Participants
  • Parent commits 7e16f45

Comments (0)

Files changed (1)

File tortoisehg/hgqt/chunks.py

 from tortoisehg.util.patchctx import patchctx
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import qtlib, thgrepo, qscilib, lexers, visdiff, revert
-from tortoisehg.hgqt import filelistmodel, filelistview, filedata
+from tortoisehg.hgqt import filelistmodel, filelistview, filedata, blockmatcher
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
         w.setTextInteractionFlags(f | Qt.TextSelectableByMouse)
         w.linkActivated.connect(self.linkActivated)
 
+        self.searchbar = qscilib.SearchToolBar(hidable=True)
+        self.searchbar.hide()
+        self.searchbar.searchRequested.connect(self.find)
+        self.searchbar.conditionChanged.connect(self.highlightText)
+
         guifont = qtlib.getfont('fontlist').font()
         self.sumlabel = QLabel()
         self.sumlabel.setFont(guifont)
         self.nonebutton.setText(_('None', 'files'))
         self.nonebutton.setShortcut(QKeySequence.New)
         self.nonebutton.clicked.connect(self.selectNone)
+        self.actionFind = self.searchbar.toggleViewAction()
+        self.actionFind.setIcon(qtlib.geticon('edit-find'))
+        self.actionFind.setToolTip(_('Toggle display of text search bar'))
+        qtlib.newshortcutsforstdkey(QKeySequence.Find, self, self.searchbar.show)
+        self.diffToolbar = QToolBar(_('Diff Toolbar'))
+        self.diffToolbar.setIconSize(QSize(16, 16))
+        self.diffToolbar.setStyleSheet(qtlib.tbstylesheet)
+        self.diffToolbar.addAction(self.actionFind)
+        hbox.addWidget(self.diffToolbar)
         hbox.addStretch(1)
         hbox.addWidget(self.sumlabel)
         hbox.addWidget(self.allbutton)
                (1 << self.vertical) | (1 << self.selcolor) | (1 << self.divider)
         self.sci.setMarginMarkerMask(1, mask)
 
-        self.layout().addWidget(self.sci, 1)
+        self.blksearch = blockmatcher.BlockList(self)
+        self.blksearch.linkScrollBar(self.sci.verticalScrollBar())
+        self.blksearch.setVisible(False)
+
+        hbox = QHBoxLayout()
+        hbox.addWidget(self.sci)
+        hbox.addWidget(self.blksearch)
 
         lexer = lexers.difflexer(self)
         self.sci.setLexer(lexer)
+
+        self.layout().addLayout(hbox)
+        self.layout().addWidget(self.searchbar)
+
         self.clearDisplay()
 
     def menuRequested(self, point):
         self.sci.clear()
         self.filenamelabel.setText(' ')
         self.extralabel.hide()
+        self.blksearch.clear()
 
     def clearChunks(self):
         self.curchunks = []
             if (c.fromline, len(c.before)) in reenable:
                 self.toggleChunk(c)
         self.updateSummary()
+
+    @pyqtSlot(unicode, bool, bool, bool)
+    def find(self, exp, icase=True, wrap=False, forward=True):
+        self.sci.find(exp, icase, wrap, forward)
+
+    @pyqtSlot(unicode, bool)
+    def highlightText(self, match, icase=False):
+        self._lastSearch = match, icase
+        self.sci.highlightText(match, icase)
+        blk = self.blksearch
+        blk.clear()
+        blk.setUpdatesEnabled(False)
+        blk.clear()
+        for l in self.sci.highlightLines:
+            blk.addBlock('s', l, l + 1)
+        blk.setVisible(bool(match))
+        blk.setUpdatesEnabled(True)