Commits

Yuya Nishihara committed 1b68b06

revdetails: move parent toggle actions under popup menu plus toggle button

Menu items can provide more explanation than toolbar buttons, but less useful
than direct buttons. So new toolbar button acts as tri-state toggle for
faster switching than using popup menu.

Original:

[Mani] [filter... ] [X] [1] [2]

New:

[Mani] [filter... ] [Pn] <- show icon of the selected parent
|Changed by This Commit|
|Compare to 1st Parent |
|Compare to 2nd Parent |

Comments (0)

Files changed (1)

tortoisehg/hgqt/revdetails.py

         # TODO: p1/p2 toggle should be merged with fileview's
         self._parentToggleGroup = QActionGroup(self)
         self._parentToggleGroup.triggered.connect(self._selectParentRevision)
-        for text, tooltip in [('X', _('Show files changed by this commit')),
-                              ('1', _('Show changes from first parent')),
-                              ('2', _('Show changes from second parent'))]:
-            a = self._parentToggleGroup.addAction(text)
+        for i, (icon, text, tip) in enumerate([
+                ('hg-merged-both', _('&Changed by This Commit'),
+                 _('Show files changed by this commit')),
+                ('hg-merged-p1', _('Compare to &1st Parent'),
+                 _('Show changes from first parent')),
+                ('hg-merged-p2', _('Compare to &2nd Parent'),
+                 _('Show changes from second parent'))]):
+            a = self._parentToggleGroup.addAction(qtlib.geticon(icon), text)
             a.setCheckable(True)
-            a.setToolTip(tooltip)
-            tbar.addAction(a)
+            a.setData(i)
+            a.setStatusTip(tip)
+
+        w = QToolButton(self)
+        m = QMenu(w)
+        m.addActions(self._parentToggleGroup.actions())
+        w.setMenu(m)
+        w.setPopupMode(QToolButton.MenuButtonPopup)
+        self._actionParentToggle = a = tbar.addWidget(w)
+        a.setIcon(qtlib.geticon('hg-merged-both'))
+        a.setToolTip(_('Toggle parent to be used as the base revision'))
+        a.triggered.connect(self._toggleParentRevision)
+        w.setDefaultAction(a)
 
     def eventFilter(self, watched, event):
         # switch between filter and list seamlessly
 
     def _setContextToFileList(self, ctx):
         self._parentToggleGroup.setVisible(len(ctx.parents()) == 2)
+        self._actionParentToggle.setVisible(self._parentToggleGroup.isVisible())
 
         m = self.filelist.model()
         # TODO: necessary because of setRepo(bundlerepo)
             m.setChangedFilesOnly(False)
             return
 
-        parentmode = str(self._parentToggleGroup.checkedAction().text())
-        pnum, changedonly = {'X': (0, True),
-                             '1': (0, False),
-                             '2': (1, False)}[parentmode]
+        parentmode = self._parentToggleGroup.checkedAction().data().toInt()[0]
+        pnum, changedonly = [(0, True),
+                             (0, False),
+                             (1, False)][parentmode]
         m.setRev(ctx.rev(), ctx.parents()[pnum].rev())
         m.setChangedFilesOnly(changedonly)
 
+    @pyqtSlot(QAction)
+    def _selectParentRevision(self, action):
+        self._actionParentToggle.setIcon(action.icon())
+        self._setContextToFileList(self.ctx)
+
     @pyqtSlot()
-    def _selectParentRevision(self):
-        self._setContextToFileList(self.ctx)
+    def _toggleParentRevision(self):
+        parentactions = [a for a in self._parentToggleGroup.actions()
+                         if a.isEnabled()]
+        i = parentactions.index(self._parentToggleGroup.checkedAction())
+        parentactions[(i + 1) % len(parentactions)].trigger()
 
     @pyqtSlot()
     def _updatedeschtmlizer(self):