Commits

Yuya Nishihara committed 0fa3e79

resolve: sync buttons' properties with corresponding actions

Comments (0)

Files changed (1)

tortoisehg/hgqt/resolve.py

         vbox = QVBoxLayout()
         vbox.setContentsMargins(*MARGINS)
         hbox.addLayout(vbox)
-        auto = QPushButton(_('Mercurial Re&solve'))
-        auto.setToolTip(_('Attempt automatic (trivial) merge'))
-        auto.clicked.connect(lambda: self.merge('internal:merge'))
-        manual = QPushButton(_('Tool &Resolve'))
-        manual.setToolTip(_('Merge using selected merge tool'))
-        manual.clicked.connect(self.merge)
-        local = QPushButton(_('&Take Local'))
-        local.setToolTip(_('Accept the local file version (yours)'))
-        local.clicked.connect(lambda: self.merge('internal:local'))
-        other = QPushButton(_('Take &Other'))
-        other.setToolTip(_('Accept the other file version (theirs)'))
-        other.clicked.connect(lambda: self.merge('internal:other'))
-        res = QPushButton(_('&Mark as Resolved'))
-        res.setToolTip(_('Mark this file as resolved'))
-        res.clicked.connect(self.markresolved)
-        vbox.addWidget(auto)
-        vbox.addWidget(manual)
-        vbox.addWidget(local)
-        vbox.addWidget(other)
-        vbox.addWidget(res)
+        for action in [cmauto, cmmanual, cmlocal, cmother, cmres]:
+            vbox.addWidget(ActionPushButton(action, self))
         vbox.addStretch(1)
-        self.ubuttons = (auto, manual, local, other, res)
 
         res = qtlib.LabeledSeparator(_('Resolved conflicts'))
         self.layout().addWidget(res)
         vbox = QVBoxLayout()
         vbox.setContentsMargins(*MARGINS)
         hbox.addLayout(vbox)
-        edit = QPushButton(_('&Edit File'))
-        edit.setToolTip(_('Edit resolved file'))
-        edit.clicked.connect(self.edit)
-        v3way = QPushButton(_('3-&Way Diff'))
-        v3way.setToolTip(_('Visual three-way diff'))
-        v3way.clicked.connect(self.v3way)
-        vp0 = QPushButton(_('Diff to &Local'))
-        vp0.setToolTip(_('Visual diff between resolved file and first parent'))
-        vp0.clicked.connect(self.vp0)
-        vp1 = QPushButton(_('&Diff to Other'))
-        vp1.setToolTip(_('Visual diff between resolved file and second parent'))
-        vp1.clicked.connect(self.vp1)
-        ures = QPushButton(_('Mark as &Unresolved'))
-        ures.setToolTip(_('Mark this file as unresolved'))
-        ures.clicked.connect(self.markunresolved)
-        vbox.addWidget(edit)
-        vbox.addWidget(v3way)
-        vbox.addWidget(vp0)
-        vbox.addWidget(vp1)
-        vbox.addWidget(ures)
+        for action in [cmedit, cmv3way, cmvp0, cmvp1, cmures]:
+            vbox.addWidget(ActionPushButton(action, self))
         vbox.addStretch(1)
-        self.rbuttons = (edit, vp0, ures)
-        self.rmbuttons = (vp1, v3way)
 
         hbox = QHBoxLayout()
         hbox.setContentsMargins(*MARGINS)
         @pyqtSlot(QItemSelection, QItemSelection)
         def uchanged(selected, deselected):
             enable = self.utree.selectionModel().hasSelection()
-            for b in self.ubuttons:
-                b.setEnabled(enable)
             for c in self.umenuitems:
                 c.setEnabled(enable)
         smodel.selectionChanged.connect(uchanged)
         @pyqtSlot(QItemSelection, QItemSelection)
         def rchanged(selected, deselected):
             enable = self.rtree.selectionModel().hasSelection()
-            for b in self.rbuttons:
-                b.setEnabled(enable)
             for c in self.rmenuitems:
                 c.setEnabled(enable)
             merge = len(self.repo.parents()) > 1
-            for b in self.rmbuttons:
-                b.setEnabled(enable and merge)
             for c in self.rmmenuitems:
                 c.setEnabled(enable and merge)
         smodel.selectionChanged.connect(rchanged)
         row = index.row()
         return self.rows[row][2], self.rows[row][0]
 
+
+class ActionPushButton(QPushButton):
+    def __init__(self, action, parent=None):
+        super(ActionPushButton, self).__init__(parent)
+        self._defaultAction = action
+        self.addAction(action)
+        self.clicked.connect(action.trigger)
+        self._copyActionProps()
+
+    def actionEvent(self, event):
+        if (event.type() == QEvent.ActionChanged
+            and event.action() is self._defaultAction):
+            self._copyActionProps()
+        super(ActionPushButton, self).actionEvent(event)
+
+    def _copyActionProps(self):
+        action = self._defaultAction
+        self.setEnabled(action.isEnabled())
+        self.setText(action.text())
+        self.setToolTip(action.toolTip())
+
+
 class ToolsCombo(QComboBox):
     def __init__(self, repo, parent):
         QComboBox.__init__(self, parent)