Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.0 on 2022-01-18 at 14:00 UTC+1 (a few minutes of down time)

Commit c4fb1cbd authored by Steve Borho's avatar Steve Borho
Browse files

fileview: move file mode toolbar to the fileview header

pros:

* the toolbar is now above the data it toggles
* the mode buttons can be disabled when appropriate for given content
* the next/prev buttons finally work correctly in all cases
* the commit tool now has a diff/file toggle (we could allow it to be an editor)
* all the signals are local to one widget, much simpler than before
* makes room above the file list for a file list toolbar (soon to be used)

cons:

* the toolbar is a little taller than the text used to be
* the previous mode is lost when a 'force' switch is made (view an A or R file)

This latter can be fixed
parent df8f6a8e2ac2
......@@ -157,11 +157,6 @@ class FileLogDialog(_AbstractFileDialog):
self.editToolbar.addSeparator()
self.editToolbar.addAction(self.actionBack)
self.editToolbar.addAction(self.actionForward)
self.editToolbar.addSeparator()
self.editToolbar.addAction(self.actionDiffMode)
self.editToolbar.addAction(self.actionAnnMode)
self.editToolbar.addAction(self.actionNextDiff)
self.editToolbar.addAction(self.actionPrevDiff)
def setupModels(self):
self.filerevmodel = FileRevModel(self.repo, parent=self)
......@@ -170,7 +165,7 @@ class FileLogDialog(_AbstractFileDialog):
self.repoview.revisionActivated.connect(self.revisionActivated)
self.filerevmodel.showMessage.connect(self.statusBar().showMessage)
self.filerevmodel.filled.connect(self.modelFilled)
self.textView.setMode('file')
self.textView.forceMode('file')
self.findToolbar.setModel(self.filerevmodel)
self.findToolbar.setFilterFiles([self.filename])
self.findToolbar.setMode('file')
......@@ -186,22 +181,6 @@ class FileLogDialog(_AbstractFileDialog):
self.actionForward = QAction(_('Forward'), self, enabled=False,
icon=geticon('forward'))
self.repoview.revisionSelected.connect(self._updateHistoryActions)
self.actionDiffMode = QAction('Diff mode', self)
self.actionDiffMode.setCheckable(True)
self.actionDiffMode.toggled.connect(self.setMode)
self.actionAnnMode = QAction('Annotate', self)
self.actionAnnMode.setCheckable(True)
self.actionAnnMode.toggled.connect(self.textView.setAnnotate)
self.actionNextDiff = QAction(geticon('down'), 'Next diff', self)
self.actionNextDiff.setShortcut('Alt+Down')
self.actionNextDiff.triggered.connect(self.nextDiff)
self.actionPrevDiff = QAction(geticon('up'), 'Previous diff', self)
self.actionPrevDiff.setShortcut('Alt+Up')
self.actionPrevDiff.triggered.connect(self.prevDiff)
self.actionBack.triggered.connect(self.repoview.back)
self.actionForward.triggered.connect(self.repoview.forward)
......@@ -226,11 +205,6 @@ class FileLogDialog(_AbstractFileDialog):
self.textView.setContext(ctx)
self.textView.displayFile(self.filerevmodel.graph.filename(rev))
self.textView.verticalScrollBar().setValue(pos)
self.actionPrevDiff.setEnabled(False)
def textfilled():
enabled = self.textView.fileMode() and self.textView.nDiffs()
self.actionNextDiff.setEnabled(enabled)
self.textView.filled.connect(textfilled)
def goto(self, rev):
index = self.filerevmodel.indexFromRev(rev)
......@@ -239,25 +213,6 @@ class FileLogDialog(_AbstractFileDialog):
else:
self._show_rev = rev
def setMode(self, mode):
self.textView.setMode(mode)
self.actionAnnMode.setEnabled(not mode)
self.actionNextDiff.setEnabled(not mode)
self.actionPrevDiff.setEnabled(not mode)
def nextDiff(self):
notlast = self.textView.nextDiff()
mode = self.textView.fileMode()
ndiffs = self.textView.nDiffs()
self.actionNextDiff.setEnabled(mode and notlast and ndiffs)
self.actionPrevDiff.setEnabled(mode and ndiffs)
def prevDiff(self):
notfirst = self.textView.prevDiff()
mode = self.textView.fileMode()
ndiffs = self.textView.nDiffs()
self.actionPrevDiff.setEnabled(mode and notfirst and ndiffs)
self.actionNextDiff.setEnabled(mode and ndiffs)
class FileDiffDialog(_AbstractFileDialog):
......
......@@ -33,7 +33,7 @@ from tortoisehg.util import hglib, patchctx
from tortoisehg.hgqt.i18n import _
from tortoisehg.hgqt.lexers import get_lexer, get_diff_lexer
from tortoisehg.hgqt.blockmatcher import BlockList
from tortoisehg.hgqt import qscilib
from tortoisehg.hgqt import qscilib, qtlib
qsci = Qsci.QsciScintilla
chunkhdrre = re.compile('^@@ -(\d+).*@@$')
......@@ -115,6 +115,11 @@ class HgFileView(QFrame):
hbox.setContentsMargins(0,0,0,0)
hbox.setSpacing(2)
self.topLayout.addLayout(hbox)
self.diffToolbar = QToolBar(_('Diff Toolbar'))
self.diffToolbar.setIconSize(QSize(16,16))
hbox.addWidget(self.diffToolbar)
self.filenamelabel = w = QLabel()
w.setWordWrap(True)
f = w.textInteractionFlags()
......@@ -201,9 +206,38 @@ class HgFileView(QFrame):
self._ctx = None
self._filename = None
self._status = None
self._annotate = False
self._find_text = None
self._mode = "diff" # can be 'diff' or 'file'
self.actionDiffMode = QAction('Diff', self)
self.actionDiffMode.setCheckable(True)
self.actionFileMode = QAction('File', self)
self.actionFileMode.setCheckable(True)
self.actionAnnMode = QAction('Ann', self)
self.actionAnnMode.setCheckable(True)
self.modeToggleGroup = QActionGroup(self)
self.modeToggleGroup.addAction(self.actionDiffMode)
self.modeToggleGroup.addAction(self.actionFileMode)
self.modeToggleGroup.addAction(self.actionAnnMode)
self.modeToggleGroup.triggered.connect(self.setMode)
# Next/Prev diff (in full file mode)
self.actionNextDiff = QAction(qtlib.geticon('down'), 'Next diff', self)
self.actionNextDiff.setShortcut('Alt+Down')
self.actionNextDiff.triggered.connect(self.nextDiff)
self.actionPrevDiff = QAction(qtlib.geticon('up'), 'Previous diff', self)
self.actionPrevDiff.setShortcut('Alt+Up')
self.actionPrevDiff.triggered.connect(self.prevDiff)
self.forceMode('diff')
tb = self.diffToolbar
tb.addAction(self.actionDiffMode)
tb.addAction(self.actionFileMode)
tb.addAction(self.actionAnnMode)
tb.addSeparator()
tb.addAction(self.actionNextDiff)
tb.addAction(self.actionPrevDiff)
self.timer = QTimer()
self.timer.setSingleShot(False)
......@@ -225,32 +259,39 @@ class HgFileView(QFrame):
self._spacer.setMinimumHeight(h)
self._spacer.setMaximumHeight(h)
def setMode(self, mode):
if isinstance(mode, bool):
mode = ['file', 'diff'][mode]
assert mode in ('diff', 'file')
@pyqtSlot(QAction)
def setMode(self, action):
'One of the mode toolbar buttons has been toggled'
mode = {'Diff':'diff', 'File':'file', 'Ann':'ann'}[str(action.text())]
self.actionNextDiff.setEnabled(mode != 'diff')
self.actionPrevDiff.setEnabled(False)
self.blk.setVisible(mode != 'diff')
self.ann.setVisible(mode == 'ann')
if mode != self._mode:
self._mode = mode
self.blk.setVisible(self._mode == 'file')
self.ann.setVisible(self._mode == 'file' and self._annotate)
self.displayFile()
def getMode(self):
return self._mode
def setAnnotate(self, ann):
self._annotate = ann
self.blk.setVisible(self._mode == 'file')
self.ann.setVisible(self._mode == 'file' and self._annotate)
self.displayFile()
def getAnnotate(self):
return self._annotate
def forceMode(self, mode):
'Force into file or diff mode, based on content constaints'
assert mode in ('diff', 'file')
self._mode = mode
if mode == 'diff':
self.actionDiffMode.setChecked(True)
else:
self.actionFileMode.setChecked(True)
self.actionDiffMode.setEnabled(False)
self.actionFileMode.setEnabled(False)
self.actionAnnMode.setEnabled(False)
self.actionNextDiff.setEnabled(False)
self.actionPrevDiff.setEnabled(False)
self.blk.setVisible(mode == 'file')
self.ann.setVisible(False)
def setContext(self, ctx):
self._ctx = ctx
self._p_rev = None
self.sci.setTabWidth(ctx._repo.tabwidth)
self.actionAnnMode.setVisible(ctx.rev() != None)
def rev(self):
return self._ctx.rev()
......@@ -263,7 +304,7 @@ class HgFileView(QFrame):
self.displayFile(rev=rev)
def mouseMoveEvent(self, event):
if self._mode == 'file' and self._annotate and self.ann.fctxann:
if self._mode == 'ann' and self.ann.fctxann:
# Calculate row index from the scroll offset and mouse position
scroll_offset = self.sci.verticalScrollBar().value()
idx = scroll_offset + event.pos().y() / self.sci.textHeight(0)
......@@ -279,7 +320,7 @@ class HgFileView(QFrame):
qsci.mouseMoveEvent(self.sci, event)
def leaveEvent(self, event):
if self._mode == 'file' and self._annotate:
if self._mode == 'ann':
self.lastrev = None
self.showDescSignal.emit('')
......@@ -306,8 +347,7 @@ class HgFileView(QFrame):
self.clearDisplay()
if filename is None:
self.sci.setMarginLineNumbers(1, False)
self.sci.setMarginWidth(1, '')
self.forceMode('file')
return
ctx = self._ctx
......@@ -327,11 +367,20 @@ class HgFileView(QFrame):
self.filenamelabel.setText(fd.flabel)
if not fd.isValid():
self.ann.setVisible(False)
self.sci.setText(fd.error)
self.forceMode('file')
return
if self._mode == 'diff' and fd.diff:
if fd.diff and not fd.contents:
self.forceMode('diff')
elif fd.contents and not fd.diff:
self.forceMode('file')
else:
self.actionDiffMode.setEnabled(True)
self.actionFileMode.setEnabled(True)
self.actionAnnMode.setEnabled(True)
if self._mode == 'diff':
lexer = get_diff_lexer(self)
self.sci.setLexer(lexer)
# trim first three lines, for example:
......@@ -356,11 +405,10 @@ class HgFileView(QFrame):
uf = hglib.tounicode(self._filename)
self.fileDisplayed.emit(uf, fd.contents or QString())
if self._mode != 'file':
if self._mode == 'diff':
return
if self._annotate:
self.ann.setVisible(self._annotate)
if self._mode == 'ann':
if lexer is not None:
self.ann.setFont(lexer.font(0))
else:
......@@ -380,30 +428,34 @@ class HgFileView(QFrame):
self.timer.start()
def nextDiff(self):
if self._mode == 'file':
row, column = self.sci.getCursorPosition()
for i, (lo, hi) in enumerate(self._diffs):
if lo > row:
last = (i == (len(self._diffs)-1))
break
else:
return False
self.sci.setCursorPosition(lo, 0)
self.sci.verticalScrollBar().setValue(lo)
return not last
if self._mode == 'diff' or not self._diffs:
self.actionNextDiff.setEnabled(False)
self.actionPrevDiff.setEnabled(False)
return
row, column = self.sci.getCursorPosition()
for i, (lo, hi) in enumerate(self._diffs):
if lo > row:
last = (i == (len(self._diffs)-1))
self.sci.setCursorPosition(lo, 0)
self.sci.verticalScrollBar().setValue(lo)
break
self.actionNextDiff.setEnabled(not last)
self.actionPrevDiff.setEnabled(True)
def prevDiff(self):
if self._mode == 'file':
row, column = self.sci.getCursorPosition()
for i, (lo, hi) in enumerate(reversed(self._diffs)):
if hi < row:
first = (i == (len(self._diffs)-1))
break
else:
return False
self.sci.setCursorPosition(lo, 0)
self.sci.verticalScrollBar().setValue(lo)
return not first
if self._mode == 'diff' or not self._diffs:
self.actionNextDiff.setEnabled(False)
self.actionPrevDiff.setEnabled(False)
return
row, column = self.sci.getCursorPosition()
for i, (lo, hi) in enumerate(reversed(self._diffs)):
if hi < row:
first = (i == (len(self._diffs)-1))
self.sci.setCursorPosition(lo, 0)
self.sci.verticalScrollBar().setValue(lo)
break
self.actionNextDiff.setEnabled(True)
self.actionPrevDiff.setEnabled(not first)
def nextLine(self):
x, y = self.sci.getCursorPosition()
......@@ -491,6 +543,8 @@ class HgFileView(QFrame):
self.blk.setUpdatesEnabled(False)
for n in range(30): # burst pool
if self._diff is None or not self._diff.get_opcodes():
self.actionNextDiff.setEnabled(bool(self._diffs))
self.actionPrevDiff.setEnabled(False)
self._diff = None
self.timer.stop()
self.filled.emit()
......
......@@ -83,8 +83,8 @@ class RevDetailsWidget(QWidget):
self.filelist_splitter.setOrientation(Qt.Horizontal)
self.filelist_splitter.setChildrenCollapsible(False)
self.diffToolbar = QToolBar(_('Diff Toolbar'))
self.diffToolbar.setIconSize(QSize(16,16))
self.mergeToolBar = QToolBar(_('Merge Toolbar'))
self.mergeToolBar.setIconSize(QSize(16,16))
self.filelist = HgFileListView()
self.tbarFileListFrame = QFrame(self.filelist_splitter)
......@@ -98,7 +98,7 @@ class RevDetailsWidget(QWidget):
vbox = QVBoxLayout()
vbox.setSpacing(0)
vbox.setMargin(0)
vbox.addWidget(self.diffToolbar)
vbox.addWidget(self.mergeToolBar)
vbox.addWidget(self.filelist)
self.tbarFileListFrame.setLayout(vbox)
......@@ -173,33 +173,6 @@ class RevDetailsWidget(QWidget):
self.filelist.clearDisplay.connect(self.fileview.clearDisplay)
def createActions(self):
self.actionDiffMode = QAction('Diff', self)
self.actionDiffMode.setCheckable(True)
self.actionFileMode = QAction('File', self)
self.actionFileMode.setCheckable(True)
self.actionAnnMode = QAction('Ann', self)
self.actionAnnMode.setCheckable(True)
self.modeToggleGroup = QActionGroup(self)
self.modeToggleGroup.addAction(self.actionDiffMode)
self.modeToggleGroup.addAction(self.actionFileMode)
self.modeToggleGroup.addAction(self.actionAnnMode)
self.modeToggleGroup.triggered.connect(self.setMode)
# Next/Prev diff (in full file mode)
self.actionNextDiff = QAction(geticon('down'), 'Next diff', self)
self.actionNextDiff.setShortcut('Alt+Down')
self.actionNextDiff.triggered.connect(self.nextDiff)
def filled():
self.actionNextDiff.setEnabled(
self.fileview.fileMode() and self.fileview.nDiffs())
self.fileview.filled.connect(filled)
self.actionPrevDiff = QAction(geticon('up'), 'Previous diff', self)
self.actionPrevDiff.setShortcut('Alt+Up')
self.actionPrevDiff.triggered.connect(self.prevDiff)
self.actionDiffMode.setChecked(True)
# navigate in file viewer
self.actionNextLine = QAction('Next line', self)
self.actionNextLine.setShortcut(Qt.SHIFT + Qt.Key_Down)
......@@ -227,25 +200,6 @@ class RevDetailsWidget(QWidget):
lambda self=self:
self.filelist.fileActivated(self.filelist.currentIndex(),
alternate=True))
# toolbar
tb = self.diffToolbar
tb.addAction(self.actionDiffMode)
tb.addAction(self.actionFileMode)
tb.addAction(self.actionAnnMode)
tb.addSeparator()
tb.addAction(self.actionNextDiff)
tb.addAction(self.actionPrevDiff)
@pyqtSlot(QAction)
def setMode(self, action):
diffmode = action.text() == 'Diff'
self.fileview.setMode(diffmode)
self.fileview.setAnnotate(action.text() == 'Ann')
self.actionNextDiff.setDisabled(diffmode)
self.actionPrevDiff.setDisabled(diffmode)
def getMode(self):
return self.fileview.getMode()
@pyqtSlot()
def toggleSearchBar(self):
......@@ -263,20 +217,6 @@ class RevDetailsWidget(QWidget):
self.fileview.highlightText(self.searchbar.pattern(),
self.searchbar.caseInsensitive())
def nextDiff(self):
notlast = self.fileview.nextDiff()
filemode = self.fileview.fileMode()
nDiffs = self.fileview.nDiffs()
self.actionNextDiff.setEnabled(filemode and notlast and nDiffs)
self.actionPrevDiff.setEnabled(filemode and nDiffs)
def prevDiff(self):
notfirst = self.fileview.prevDiff()
filemode = self.fileview.fileMode()
nDiffs = self.fileview.nDiffs()
self.actionPrevDiff.setEnabled(filemode and notfirst and nDiffs)
self.actionNextDiff.setEnabled(filemode and nDiffs)
def create_models(self):
self.filelistmodel = HgFileListModel(self.repo, parent=self)
......@@ -296,22 +236,9 @@ class RevDetailsWidget(QWidget):
self.revpanel.update(repo = self.repo)
self.message.setHtml('<pre>%s</pre>'
% self._deschtmlize(ctx.description()))
if type(ctx.rev()) == str:
self.actionDiffMode.setChecked(True)
self.actionDiffMode.setEnabled(False)
self.actionFileMode.setEnabled(False)
self.actionAnnMode.setEnabled(False)
else:
self.actionDiffMode.setEnabled(True)
self.actionFileMode.setEnabled(True)
self.actionAnnMode.setEnabled(True)
self.fileview.setContext(ctx)
self.filelistmodel.setContext(ctx)
mode = self.getMode()
self.actionNextDiff.setEnabled(mode != 'diff')
self.actionPrevDiff.setEnabled(mode != 'diff')
@pyqtSlot()
def _updatedeschtmlizer(self):
self._deschtmlize = descriptionhtmlizer(self.repo.ui)
......
......@@ -172,7 +172,7 @@ class StatusWidget(QWidget):
self.fileview.showMessage.connect(self.showMessage)
self.fileview.linkActivated.connect(self.linkActivated)
self.fileview.fileDisplayed.connect(self.fileDisplayed)
self.fileview.setMode('diff')
self.fileview.setContext(self.repo[None])
vbox.addWidget(self.fileview, 1)
lbltext = u'<a href="shelve:">' + _('shelve tool') + u'</a>'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment