Angel Ezquerra  committed 373e8e2

commit: select QNew for the working dir and QRefresh for the topmost applied patch

This patch tries to fix some recent comments by Phil Currier regarding the
automatic switch to the commit widget when the topmost applied patch is selected.

The patch changes the behaviour of the commit widget to reduce the chances of
a user getting confused in the following two scenarios:

1.- When the user selects the working dir and the selected mode is "QRefresh":
This could lead to a user to refresh a patch by accident when in fact it wanted
to create a new patch.

2.- When the user selects the topmost patch while the "commit" button on the
commit widget is set to "QNew":
This could lead the user to believe that the selected patch has different
contents than expected.

  • Participants
  • Parent commits 321088d
  • Branches stable

Comments (0)

Files changed (2)

File tortoisehg/hgqt/

     output = pyqtSignal(QString, QString)
     makeLogVisible = pyqtSignal(bool)
-    def __init__(self, repo, pats, opts, embedded=False, parent=None):
+    def __init__(self, repo, pats, opts, embedded=False, parent=None, rev=None):
         QWidget.__init__(self, parent=parent)
         self.repo = repo
+        self._rev = rev
         self.lastAction = None
         self.lastCommitMsg = ''
         self.currentAction = None
             QShortcut(QKeySequence('Ctrl+Enter'), self,
+    @property
+    def rev(self):
+        """Return current revision"""
+        return self._rev
+    def selectRev(self, rev):
+        """
+        Select the revision that must be set when the dialog is shown again
+        """
+        self._rev = rev
+    @pyqtSlot(int)
+    @pyqtSlot(object)
+    def setRev(self, rev):
+        """Change revision to show"""
+        self.selectRev(rev)
+        if self.hasmqbutton:
+            preferredActionName = self._getPreferredActionName()
+            curractionName = self.mqgroup.checkedAction()._name
+            if curractionName != preferredActionName:
+                self.mqSetAction(refresh=True,
+                    actionName=preferredActionName)
+    def _getPreferredActionName(self):
+        """Select the preferred action, depending on the selected revision"""
+        if not self.hasmqbutton:
+            return 'commit'
+        else:
+            pctx = self.repo.changectx('.')
+            ispatch = 'qtip' in pctx.tags()
+            if not ispatch:
+                # Set the button to Commit
+                return 'commit'
+            elif self.rev is None:
+                # Set the button to QNew
+                return 'qnew'
+            else:
+                # Set the button to QRefresh
+                return 'qref'
     def mqSetupButton(self):
         ispatch = lambda r: 'qtip' in r.changectx('.').tags()
         notpatch = lambda r: 'qtip' not in r.changectx('.').tags()
             action._enablefunc = a[3]
-            if a[3] and a[3](self.repo):
-                action.setChecked(True)
-        self.mqSetAction()
+        self.mqSetAction(actionName=self._getPreferredActionName())
         sc = QShortcut(QKeySequence('Ctrl+Return'), self, self.mqPerformAction)
         sc = QShortcut(QKeySequence('Ctrl+Enter'), self, self.mqPerformAction)
         return mqtb
-    def mqSetAction(self, refresh=False):
+    def mqSetAction(self, refresh=False, actionName=None):
+        if actionName:
+            selectedAction = \
+                [act for act in self.mqgroup.actions() \
+                    if act._name == actionName][0]
+            selectedAction.setChecked(True)
         curraction = self.mqgroup.checkedAction()
         oldpctx = self.stwidget.pctx
         pctx = self.repo.changectx('.')
         Create the command line to change or create the selected branch unless
         it is the selected branch
         Verify whether a branch exists on a repo. If it doesn't ask the user
         to confirm that it wants to create the branch. If it does and it is not
         the current branch as the user whether it wants to change to that branch.
         elif resp == 2:
             return None, False
         return commandlines, newbranch
     def mqPerformAction(self):
         curraction = self.mqgroup.checkedAction()
         # Check if we need to change branch first
         commandlines = []
         if self.branchop:
-            commandlines, newbranch = self.getBranchCommandLine(self.branchop, 
+            commandlines, newbranch = self.getBranchCommandLine(self.branchop,
             if commandlines is None:

File tortoisehg/hgqt/

     def createCommitWidget(self):
         pats, opts = {}, {}
-        cw = CommitWidget(self.repo, pats, opts, True, self)
+        cw = CommitWidget(self.repo, pats, opts, True, self, rev=self.rev)
         if cw.hasmqbutton:
-            if type(rev) != str: # unapplied patch
+            if type(rev) != str:
+                # Regular patch or working directory
                 if self.manifestDemand.isHidden():
                     self.manifestDemand.forward('selectRev', rev)
                     self.manifestDemand.forward('setRev', rev)
                 self.grepDemand.forward('setRevision', rev)
                 self.syncDemand.forward('refreshTargets', rev)
+                self.commitDemand.forward('setRev', rev)
+                # unapplied patch
                 if self.manifestDemand.isHidden():
                     self.manifestDemand.forward('selectRev', None)