Commits

Steve Borho  committed f9ff9db

fileview: unify diff/file/and annotate views

Use a single QSci instance for all three modes. This fixes the margin text and
color issues in the manifest widget as well. For whatever reason, you have to
rebuild the style each time the margin is refreshed, and it is also necessary to
set the font before setting the margin width else the margin size will be too
wide.

  • Participants
  • Parent commits 3d9722a

Comments (0)

Files changed (2)

File tortoisehg/hgqt/annotate.py

     @pyqtSlot(bool)
     def setAnnotationEnabled(self, enabled):
         """Enable / disable annotation"""
-        if bool(enabled) == self.isAnnotationEnabled():
+        enable = bool(enabled)
+        if enabled == self.isAnnotationEnabled():
             return
-        self._annotation_enabled = bool(enabled)
+        self._annotation_enabled = enabled
         self._updateannotation()
         self._updatemarginwidth()
+        self.setMouseTracking(enabled)
         if not self.isAnnotationEnabled():
+            self.annfile = None
             self.markerDeleteAll()
 
     def isAnnotationEnabled(self):
 
     def _updaterevmargin(self):
         """Update the content of margin area showing revisions"""
+        style = self._margin_style()
         for i, (fctx, _origline) in enumerate(self._links):
-            self.setMarginText(i, str(fctx.rev()), self._margin_style)
+            self.setMarginText(i, str(fctx.rev()), style)
 
     def _updatemarkers(self):
         """Update markers which colorizes each line"""
             for fctx in fctxs:
                 self._revmarkers[fctx.rev()] = i
 
-    @util.propertycache
     def _margin_style(self):
         """Style for margin area"""
         s = QsciStyle()
 
     @pyqtSlot()
     def _updatemarginwidth(self):
+        self.setMarginsFont(self.font())
         def lentext(s):
             return 'M' * (len(str(s)) + 2)  # 2 for margin
         self.setMarginWidth(1, lentext(self.lines()))

File tortoisehg/hgqt/fileview.py

         l.addLayout(hbox)
 
         self.blk = blockmatcher.BlockList(self)
+        self.sci = annotate.AnnotateView(repo, self)
         hbox.addWidget(self.blk)
+        hbox.addWidget(self.sci, 1)
+
+        for name in ('searchRequested', 'editSelected', 'grepRequested'):
+            getattr(self.sci, name).connect(getattr(self, name))
+        self.sci.revisionHint.connect(self.showMessage)
+        self.sci.sourceChanged.connect(self.sourceChanged)
+        self.sci.setAnnotationEnabled(False)
+
+        self.blk.linkScrollBar(self.sci.verticalScrollBar())
         self.blk.setVisible(False)
 
-        self._stacked = QStackedWidget()
-        hbox.addWidget(self._stacked, 1)
-
-        self.sci = qscilib.Scintilla(self)
-        self.blk.linkScrollBar(self.sci.verticalScrollBar())
-        self._stacked.addWidget(self.sci)
-
         self.sci.setFrameStyle(0)
         self.sci.setReadOnly(True)
         self.sci.setUtf8(True)
         self.sci.setMarginType(0, qsci.SymbolMargin)
         self.sci.setMarginWidth(0, 0)
 
-        self._annotate = annotate.AnnotateView(repo, self)
-        for name in ('searchRequested', 'editSelected', 'grepRequested'):
-            getattr(self._annotate, name).connect(getattr(self, name))
-        self._annotate.revisionHint.connect(self.showMessage)
-        self._annotate.sourceChanged.connect(self.sourceChanged)
-        self._annotate.setAnnotationEnabled(True)
-        self._stacked.addWidget(self._annotate)
-
         self.searchbar = qscilib.SearchToolBar(hidable=True)
         self.searchbar.hide()
         self.searchbar.searchRequested.connect(self.find)
         self.actionNextDiff.setEnabled(mode == 'file')
         self.actionPrevDiff.setEnabled(False)
         self.blk.setVisible(mode == 'file')
-        if mode == 'ann':
-            self._stacked.setCurrentWidget(self._annotate)
-        else:
-            self._stacked.setCurrentWidget(self.sci)
+        self.sci.setAnnotationEnabled(mode == 'ann')
         if mode != self._mode:
             self._mode = mode
             if not self._lostMode:
         self.actionNextDiff.setEnabled(False)
         self.actionPrevDiff.setEnabled(False)
         self.blk.setVisible(mode == 'file')
-        self._stacked.setCurrentWidget(self.sci)
+        self.sci.setAnnotationEnabled(False)
 
     def setContext(self, ctx):
         self._ctx = ctx
         # from disappearing during refresh, and tool layouts bouncing
         self.filenamelabel.setText(' ')
         self.extralabel.hide()
-        self.sci.setMarginLineNumbers(1, False)
-        self.sci.setMarginWidth(1, '')
         self._diffs = []
 
     def displayFile(self, filename=None, rev=None, status=None):
                     self.actionAnnMode.trigger()
                 self._lostMode = None
 
-        if self._mode == 'ann':
-            self._annotate.setSource(filename, ctx.rev())
-        elif self._mode == 'diff':
+        if self._mode == 'diff':
+            self.sci.setMarginWidth(1, 0)
             lexer = lexers.get_diff_lexer(self)
             self.sci.setLexer(lexer)
             # trim first three lines, for example:
             self.sci.setText(hglib.tounicode(noheader))
         elif fd.contents is None:
             return
+        elif self._mode == 'ann':
+            self.sci.setSource(filename, ctx.rev())
         else:
             lexer = lexers.get_lexer(filename, fd.contents, self)
             self.sci.setLexer(lexer)
-            nlines = fd.contents.count('\n')
-            # margin 1 is used for line numbers
-            self.sci.setMarginLineNumbers(1, True)
-            self.sci.setMarginWidth(1, str(nlines)+'0')
             self.sci.setText(fd.contents)
+            self.sci._updatemarginwidth()
 
         self.highlightText(*self._lastSearch)
         uf = hglib.tounicode(self._filename)
 
     @pyqtSlot(unicode, bool, bool, bool)
     def find(self, exp, icase=True, wrap=False, forward=True):
-        if self._mode == 'ann':
-            self._annotate.find(exp, icase, wrap, forward)
-        else:
-            self.sci.find(exp, icase, wrap, forward)
+        self.sci.find(exp, icase, wrap, forward)
 
     @pyqtSlot(unicode, bool)
     def highlightText(self, match, icase=False):
         self._lastSearch = match, icase
-        if self._mode == 'ann':
-            self._annotate.highlightText(match, icase)
-        else:
-            self.sci.highlightText(match, icase)
+        self.sci.highlightText(match, icase)
 
     def verticalScrollBar(self):
         return self.sci.verticalScrollBar()