Commits

Yuya Nishihara committed 89fa569

quickop: run commands by using RepoAgent

Comments (0)

Files changed (1)

tortoisehg/hgqt/quickop.py

 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
 
-import os
 import sys
 
 from mercurial import util
 
 from tortoisehg.util import hglib, shlib
 from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt import qtlib, status, cmdui, lfprompt
+from tortoisehg.hgqt import qtlib, status, cmdcore, cmdui, lfprompt
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
         self.setWindowFlags(Qt.Window)
         self.pats = pats
         self._repoagent = repoagent
+        self._cmdsession = cmdcore.nullCmdSession()
+        self._cmddialog = cmdui.CmdSessionDialog(self)
         repo = repoagent.rawRepo()
-        os.chdir(repo.root)
 
         # Handle rm alias
         if command == 'rm':
         self.statusbar = cmdui.ThgStatusBar(self)
         stwidget.showMessage.connect(self.statusbar.showMessage)
 
-        self.cmd = cmd = cmdui.Runner(True, self)
-        cmd.commandStarted.connect(self.commandStarted)
-        cmd.commandFinished.connect(self.commandFinished)
-        cmd.progress.connect(self.statusbar.progress)
-
         BB = QDialogButtonBox
         bb = QDialogButtonBox(BB.Ok|BB.Close)
         bb.accepted.connect(self.accept)
             lopts['large'] = True
             cmdlines.append(hglib.buildcmdargs(self.command, *lfiles, **lopts))
         self.files = files + lfiles
-        self.cmd.run(*cmdlines)
 
-    def commandStarted(self):
+        ucmdlines = [map(hglib.tounicode, xs) for xs in cmdlines]
+        self._cmdsession = sess = self._repoagent.runCommandSequence(ucmdlines,
+                                                                     self)
+        sess.commandFinished.connect(self.commandFinished)
+        sess.progressReceived.connect(self.statusbar.progress)
+        self._cmddialog.setSession(sess)
         self.bb.button(QDialogButtonBox.Ok).setEnabled(False)
 
     def commandFinished(self, ret):
         if ret == 0:
             shlib.shell_notify(self.files)
             self.reject()
+        else:
+            self._cmddialog.show()
 
     def accept(self):
         cmdopts = {}
             self.reject()
 
     def reject(self):
-        if self.cmd.core.running():
-            self.cmd.core.cancel()
+        if not self._cmdsession.isFinished():
+            self._cmdsession.abort()
         elif not self.stwidget.canExit():
             return
         else: