Source

thg-qt-mq / annot-by-manifest.diff

Full commit
# HG changeset patch
# Parent bcd589c187c9acb4883b15efc1b08752a9bf7575
annotate: provide 'thg annotate' by ManifestDialog

 - use ManifestDialog in place of AnnotateDialog
 - accept empty pats for 'thg annotate' command since ManifestDialog provides
   a way to choose it later.
 - use run.annotate() to open dialog in order to avoid GC issue
 - XXX grep -> manifest -> grep

diff --git a/tortoisehg/hgqt/annotate.py b/tortoisehg/hgqt/annotate.py
--- a/tortoisehg/hgqt/annotate.py
+++ b/tortoisehg/hgqt/annotate.py
@@ -5,24 +5,18 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
 
-import os, re
+import re
 
-from mercurial import ui, error, util
+from mercurial import error, util
 
-from tortoisehg.hgqt import visdiff, qtlib, qscilib, wctxactions, thgrepo, lexers
-from tortoisehg.util import paths, hglib, colormap, thread2
+from tortoisehg.hgqt import qtlib, qscilib, lexers
+from tortoisehg.util import hglib, colormap, thread2
 from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt.grep import SearchWidget
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 from PyQt4.Qsci import QsciScintilla, QsciStyle
 
-# Technical Debt
-#  Pass search parameters to grep
-#  forward/backward history buttons
-#  menu options for viewing appropriate changesets
-
 class AnnotateView(qscilib.Scintilla):
     revisionHint = pyqtSignal(QString)
 
@@ -370,89 +364,3 @@ class _AnnotateThread(QThread):
         finally:
             del self._threadid
             del self._fctx
-
-class AnnotateDialog(QMainWindow):
-    def __init__(self, *pats, **opts):
-        super(AnnotateDialog,self).__init__(opts.get('parent'), Qt.Window)
-
-        root = opts.get('root') or paths.find_root()
-        repo = thgrepo.repository(ui.ui(), path=root)
-        # TODO: handle repo not found
-
-        av = AnnotateView(repo, self, annotationEnabled=True)
-        self.setCentralWidget(av)
-        self.av = av
-
-        status = QStatusBar()
-        self.setStatusBar(status)
-        av.revisionHint.connect(status.showMessage)
-        av.editSelected.connect(self.editSelected)
-        av.grepRequested.connect(self._openSearchWidget)
-
-        self._searchbar = qscilib.SearchToolBar()
-        self.addToolBar(self._searchbar)
-        self._searchbar.setPattern(hglib.tounicode(opts.get('pattern', '')))
-        self._searchbar.searchRequested.connect(self.av.find)
-        self._searchbar.conditionChanged.connect(self.av.highlightText)
-        av.searchRequested.connect(self._searchbar.search)
-
-        self.av.sourceChanged.connect(
-            lambda *args: self.setWindowTitle(_('Annotate %s@%d') % args))
-
-        self.searchwidget = opts.get('searchwidget')
-
-        self.opts = opts
-        line = opts.get('line')
-        if line and isinstance(line, str):
-            line = int(line)
-
-        self.repo = repo
-
-        self.restoreSettings()
-
-        # run heavy operation after the dialog visible
-        path = hglib.tounicode(pats[0])
-        rev = opts.get('rev') or '.'
-        QTimer.singleShot(0, lambda: av.setSource(path, rev, line))
-
-    def closeEvent(self, event):
-        self.storeSettings()
-        super(AnnotateDialog, self).closeEvent(event)
-
-    def editSelected(self, wfile, rev, line):
-        pattern = hglib.fromunicode(self._searchbar._le.text()) or None
-        wfile = hglib.fromunicode(wfile)
-        repo = self.repo
-        try:
-            ctx = repo[rev]
-            fctx = ctx[wfile]
-        except Exception, e:
-            self.statusBar().showMessage(hglib.tounicode(str(e)))
-
-        base, _ = visdiff.snapshot(repo, [wfile], repo[rev])
-        files = [os.path.join(base, wfile)]
-        wctxactions.edit(self, repo.ui, repo, files, line, pattern)
-
-    @pyqtSlot(unicode, dict)
-    def _openSearchWidget(self, pattern, opts):
-        opts = dict((str(k), str(v)) for k, v in opts.iteritems())
-        if self.searchwidget is None:
-            self.searchwidget = SearchWidget([pattern], repo=self.repo,
-                                             **opts)
-            self.searchwidget.show()
-        else:
-            self.searchwidget.setSearch(pattern, **opts)
-            self.searchwidget.show()
-            self.searchwidget.raise_()
-
-    def storeSettings(self):
-        s = QSettings()
-        s.setValue('annotate/geom', self.saveGeometry())
-
-    def restoreSettings(self):
-        s = QSettings()
-        self.restoreGeometry(s.value('annotate/geom').toByteArray())
-
-def run(ui, *pats, **opts):
-    pats = hglib.canonpaths(pats)
-    return AnnotateDialog(*pats, **opts)
diff --git a/tortoisehg/hgqt/grep.py b/tortoisehg/hgqt/grep.py
--- a/tortoisehg/hgqt/grep.py
+++ b/tortoisehg/hgqt/grep.py
@@ -487,7 +487,7 @@ class MatchTree(QTableView):
         menu.exec_(point)
 
     def ann(self, rows):
-        from tortoisehg.hgqt import annotate
+        from tortoisehg.hgqt import run
         repo, ui, pattern = self.repo, self.repo.ui, self.pattern
         seen = set()
         for rev, path, line in rows:
@@ -496,11 +496,8 @@ class MatchTree(QTableView):
                 continue
             else:
                 seen.add(path)
-            dlg = annotate.AnnotateDialog(path, rev=rev, line=line,
-                                          pattern=pattern, parent=self,
-                                          searchwidget=self.searchwidget,
-                                          root=repo.root)
-            dlg.show()
+            run.annotate(ui, canonpats=[path], repo=repo, rev=rev, line=line,
+                         pattern=pattern)
 
     def ctx(self, rows):
         raise NotImplementedError()
diff --git a/tortoisehg/hgqt/manifestdialog.py b/tortoisehg/hgqt/manifestdialog.py
--- a/tortoisehg/hgqt/manifestdialog.py
+++ b/tortoisehg/hgqt/manifestdialog.py
@@ -22,6 +22,11 @@ from tortoisehg.hgqt import qtlib, qscil
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt.manifestmodel import ManifestModel
 
+# Technical Debt
+#  Pass search parameters to grep
+#  forward/backward history buttons
+#  menu options for viewing appropriate changesets
+
 class ManifestDialog(QMainWindow):
     """
     Qt4 dialog to display all files of a repo at a given revision
@@ -85,6 +90,9 @@ class ManifestDialog(QMainWindow):
         """Set search pattern [unicode]"""
         self._searchbar.setPattern(text)
 
+    def setAnnotationEnabled(self, enabled):
+        self._manifest_widget.setAnnotationEnabled(enabled)
+
     @pyqtSlot(unicode, dict)
     def _openSearchWidget(self, pattern, opts):
         opts = dict((str(k), str(v)) for k, v in opts.iteritems())
@@ -182,6 +190,9 @@ class ManifestWidget(QWidget):
     def highlightText(self, pattern, icase=False):
         self._fileview.highlightText(pattern, icase)
 
+    def setAnnotationEnabled(self, enabled):
+        self._action_annotate_mode.setChecked(enabled)
+
     def _setupmodel(self):
         self._treemodel = ManifestModel(self._repo, self._rev,
                                         statusfilter=self._statusfilter.text,
@@ -350,12 +361,13 @@ def run(ui, *pats, **opts):
     # set initial state after dialog visible
     def init():
         try:
-            path = hglib.canonpaths(pats)[0]
+            path = (hglib.canonpaths(pats) + opts.get('canonpats', []))[0]
             line = opts.get('line') and int(opts['line']) or None
             dlg.setSource(path, opts.get('rev'), line)
         except IndexError:
             pass
         dlg.setSearchPattern(hglib.tounicode(opts.get('pattern')) or '')
+        dlg.setAnnotationEnabled(opts.get('annotate', False))
     QTimer.singleShot(0, init)
 
     return dlg
diff --git a/tortoisehg/hgqt/run.py b/tortoisehg/hgqt/run.py
--- a/tortoisehg/hgqt/run.py
+++ b/tortoisehg/hgqt/run.py
@@ -602,11 +602,8 @@ def bisect(ui, *pats, **opts):
 
 def annotate(ui, *pats, **opts):
     """annotate dialog"""
-    from tortoisehg.hgqt.annotate import run
-    if len(pats) != 1:
-        ui.warn(_('annotate requires a single filename\n'))
-        return
-    qtrun(run, ui, *pats, **opts)
+    from tortoisehg.hgqt.manifestdialog import run
+    qtrun(run, ui, *pats, annotate=True, **opts)
 
 def init(ui, *pats, **opts):
     """init dialog"""
diff --git a/tortoisehg/hgqt/wctxactions.py b/tortoisehg/hgqt/wctxactions.py
--- a/tortoisehg/hgqt/wctxactions.py
+++ b/tortoisehg/hgqt/wctxactions.py
@@ -224,9 +224,8 @@ def log(parent, ui, repo, files):
     raise NotImplementedError()
 
 def annotate(parent, ui, repo, files):
-    from tortoisehg.hgqt import annotate
-    dlg = annotate.AnnotateDialog(files[0], parent=parent)
-    dlg.show()
+    from tortoisehg.hgqt import run
+    run.annotate(ui, canonpats=[files[0]], repo=repo)
     return False
 
 def forget(parent, ui, repo, files):