Commits

Yuya Nishihara committed dc776a0

rename: migrate to CmdControlDialog and RepoAgent-based command runner

command output and progress are sent directly by RepoAgent.

Comments (0)

Files changed (1)

tortoisehg/hgqt/rename.py

         return self._repoagent.runCommand(cmdline, self)
 
 
-class RenameDialog(QDialog):
+class RenameDialog(cmdui.CmdControlDialog):
     """TortoiseHg rename dialog"""
 
-    output = pyqtSignal(QString, QString)
-    makeLogVisible = pyqtSignal(bool)
-    progress = pyqtSignal(QString, object, QString, QString, object)
-
     def __init__(self, repoagent, pats, parent=None, iscopy=False):
         super(RenameDialog, self).__init__(parent)
         self._repoagent = repoagent
         os.chdir(self.repo.root)  # TODO: delete
 
+        self.layout().setSizeConstraint(QLayout.SetFixedSize)
+        self.setWindowIcon(qtlib.geticon('hg-rename'))
+        self.setObjectName('rename')
         cmdwidget = RenameWidget(repoagent, pats, self, iscopy)
-        self._cmdwidget = cmdwidget
-        self.keep_open_chk = QCheckBox(_('Always show output'))
+        cmdwidget.commandChanged.connect(self._updateUi)
+        self.setCommandWidget(cmdwidget)
+        self.commandFinished.connect(self._checkKnownError)
+        self._updateUi()
 
-        # command widget
-        self.cmd = cmdui.Widget(True, False, self)
-        self.cmd.commandStarted.connect(self.command_started)
-        self.cmd.commandFinished.connect(self.command_finished)
-        self.cmd.commandCanceling.connect(self.command_canceling)
-        self.cmd.output.connect(self.output)
-        self.cmd.makeLogVisible.connect(self.makeLogVisible)
-        self.cmd.progress.connect(self.progress)
-        self.cmd.setHidden(True)
-
-        # bottom buttons
-        self.rename_btn = QPushButton('')
-        self.rename_btn.setDefault(True)
-        self.rename_btn.setFocus(True)
-        self.close_btn = QPushButton(_('&Close'))
-        self.close_btn.setAutoDefault(False)
-        self.detail_btn = QPushButton(_('&Detail'))
-        self.detail_btn.setAutoDefault(False)
-        self.detail_btn.setHidden(True)
-        self.cancel_btn = QPushButton(_('Cancel'))
-        self.cancel_btn.setAutoDefault(False)
-        self.cancel_btn.setHidden(True)
-
-        # connecting slots
-        self.rename_btn.clicked.connect(self.rename)
-        self.detail_btn.clicked.connect(self.detail_clicked)
-        self.close_btn.clicked.connect(self.close)
-        self.cancel_btn.clicked.connect(self.cancel_clicked)
-        cmdwidget.commandChanged.connect(self._updateUi)
-
-        # main layout
-        self.hbox = QHBoxLayout()
-        self.hbox.addWidget(self.detail_btn)
-        self.hbox.addStretch(0)
-        self.hbox.addWidget(self.rename_btn)
-        self.hbox.addWidget(self.close_btn)
-        self.hbox.addWidget(self.cancel_btn)
-        self.vbox = QVBoxLayout()
-        self.vbox.setSpacing(6)
-        self.vbox.addWidget(cmdwidget)
-        self.vbox.addWidget(self.keep_open_chk)
-        self.vbox.addWidget(self.cmd)
-        self.vbox.addLayout(self.hbox)
-
-        # dialog setting
-        self.setWindowIcon(qtlib.geticon('hg-rename'))
-        self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
-        self.setLayout(self.vbox)
-        self.layout().setSizeConstraint(QLayout.SetFixedSize)
-        self._readsettings()
-        self._updateUi()
+    @pyqtSlot(int)
+    def _checkKnownError(self, ret):
+        if ret == 1:
+            # occurs if _some_ of the files cannot be copied
+            cmdui.errorMessageBox(self.lastFinishedSession(), self)
 
     @pyqtSlot()
     def _updateUi(self):
-        if self._cmdwidget.isCopyCommand():
+        if self.commandWidget().isCopyCommand():
             bt = _('Copy')
             wt = _('Copy - %s')
         else:
             bt = _('Rename')
             wt = _('Rename - %s')
-        self.rename_btn.setText(bt)
+        self.setRunButtonText(bt)
         self.setWindowTitle(wt % self.repo.displayname)
 
     @property
     def repo(self):
         return self._repoagent.rawRepo()
-
-    def rename(self):
-        """execute the rename"""
-        cmdline = self._cmdwidget.rename()
-        self.cmd.run(cmdline)
-
-    def detail_clicked(self):
-        if self.cmd.outputShown():
-            self.cmd.setShowOutput(False)
-        else:
-            self.cmd.setShowOutput(True)
-
-    def cancel_clicked(self):
-        self.cmd.cancel()
-
-    def command_started(self):
-        self._cmdwidget.setEnabled(False)
-        self.cmd.setShown(True)
-        self.rename_btn.setHidden(True)
-        self.close_btn.setHidden(True)
-        self.cancel_btn.setShown(True)
-        self.detail_btn.setShown(True)
-
-    def command_finished(self, ret):
-        if (ret != 0 or self.cmd.outputShown()
-                or self.keep_open_chk.isChecked()):
-            if not self.cmd.outputShown():
-                self.detail_btn.click()
-            self.cancel_btn.setHidden(True)
-            self.close_btn.setShown(True)
-            self.close_btn.setAutoDefault(True)
-            self.close_btn.setFocus()
-        else:
-            self.reject()
-
-    def command_canceling(self):
-        self.cancel_btn.setDisabled(True)
-
-    def closeEvent(self, event):
-        self._writesettings()
-        super(RenameDialog, self).closeEvent(event)
-
-    def _readsettings(self):
-        s = QSettings()
-        self.restoreGeometry(s.value('rename/geom').toByteArray())
-
-    def _writesettings(self):
-        s = QSettings()
-        s.setValue('rename/geom', self.saveGeometry())