Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarksInOutDialog.py

changeset 1251
d40491ba96ce
parent 1131
7781e396c903
child 1256
885706dbb69f
--- a/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarksInOutDialog.py	Tue Aug 30 18:48:17 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarksInOutDialog.py	Tue Aug 30 18:50:20 2011 +0200
@@ -52,6 +52,7 @@
         self.process = QProcess()
         self.vcs = vcs
         self.mode = mode
+        self.__hgClient = vcs.getClient()
         
         self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "")
         self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder)
@@ -103,23 +104,35 @@
             raise ValueError("Bad value for mode")
         args.append('--bookmarks')
         
-        self.process.kill()
-        self.process.setWorkingDirectory(repodir)
-        
-        self.process.start('hg', args)
-        procStarted = self.process.waitForStarted()
-        if not procStarted:
+        if self.__hgClient:
             self.inputGroup.setEnabled(False)
             self.inputGroup.hide()
-            E5MessageBox.critical(self,
-                self.trUtf8('Process Generation Error'),
-                self.trUtf8(
-                    'The process {0} could not be started. '
-                    'Ensure, that it is in the search path.'
-                ).format('hg'))
+            
+            out, err = self.__hgClient.runcommand(args)
+            if err:
+                self.__showError(err)
+            if out:
+                for line in out.splitlines():
+                    self.__processOutputLine(line)
+            self.__finish()
         else:
-            self.inputGroup.setEnabled(True)
-            self.inputGroup.show()
+            self.process.kill()
+            self.process.setWorkingDirectory(repodir)
+            
+            self.process.start('hg', args)
+            procStarted = self.process.waitForStarted()
+            if not procStarted:
+                self.inputGroup.setEnabled(False)
+                self.inputGroup.hide()
+                E5MessageBox.critical(self,
+                    self.trUtf8('Process Generation Error'),
+                    self.trUtf8(
+                        'The process {0} could not be started. '
+                        'Ensure, that it is in the search path.'
+                    ).format('hg'))
+            else:
+                self.inputGroup.setEnabled(True)
+                self.inputGroup.show()
     
     def __finish(self):
         """
@@ -157,7 +170,10 @@
         if button == self.buttonBox.button(QDialogButtonBox.Close):
             self.close()
         elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
-            self.__finish()
+            if self.__hgClient:
+                self.__hgClient.cancel()
+            else:
+                self.__finish()
     
     def __procFinished(self, exitCode, exitStatus):
         """
@@ -189,10 +205,9 @@
         @param changeset changeset of the bookmark (string)
         @param name name of the bookmark (string)
         """
-        itm = QTreeWidgetItem(self.bookmarksList, [
+        QTreeWidgetItem(self.bookmarksList, [
             name,
             changeset])
-        itm.setTextAlignment(1, Qt.AlignRight)
     
     def __readStdout(self):
         """
@@ -207,12 +222,20 @@
             s = str(self.process.readLine(),
                     Preferences.getSystem("IOEncoding"),
                     'replace')
-            if s.startswith(" "):
-                l = s.strip().split()
-                changeset = l[-1]
-                del l[-1]
-                name = " ".join(l)
-                self.__generateItem(changeset, name)
+            self.__processOutputLine(s)
+    
+    def __processOutputLine(self, line):
+        """
+        Private method to process the lines of output.
+        
+        @param line output line to be processed (string)
+        """
+        if line.startswith(" "):
+            l = line.strip().split()
+            changeset = l[-1]
+            del l[-1]
+            name = " ".join(l)
+            self.__generateItem(changeset, name)
     
     def __readStderr(self):
         """
@@ -222,12 +245,20 @@
         error pane.
         """
         if self.process is not None:
-            self.errorGroup.show()
             s = str(self.process.readAllStandardError(),
                     Preferences.getSystem("IOEncoding"),
                     'replace')
-            self.errors.insertPlainText(s)
-            self.errors.ensureCursorVisible()
+            self.__showError(s)
+    
+    def __showError(self, out):
+        """
+        Private slot to show some error.
+        
+        @param out error to be shown (string)
+        """
+        self.errorGroup.show()
+        self.errors.insertPlainText(out)
+        self.errors.ensureCursorVisible()
     
     def on_passwordCheckBox_toggled(self, isOn):
         """

eric ide

mercurial