Plugins/VcsPlugins/vcsMercurial/StripExtension/HgStripDialog.py

changeset 5268
748e4c50523b
child 5270
7758f0c7d9f6
diff -r c2abca3b5e7b -r 748e4c50523b Plugins/VcsPlugins/vcsMercurial/StripExtension/HgStripDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/StripExtension/HgStripDialog.py	Mon Oct 24 19:55:05 2016 +0200
@@ -0,0 +1,170 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to enter the data to strip changesets.
+"""
+
+from __future__ import unicode_literals
+
+from PyQt5.QtCore import pyqtSlot
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox
+
+from .Ui_HgStripDialog import Ui_HgStripDialog
+
+
+class HgStripDialog(QDialog, Ui_HgStripDialog):
+    """
+    Class documentation goes here.
+    """
+    def __init__(self, tagsList, branchesList, bookmarksList=None,
+                 parent=None):
+        """
+        Constructor
+        
+        @param tagsList list of tags (list of strings)
+        @param branchesList list of branches (list of strings)
+        @param bookmarksList list of bookmarks (list of strings)
+        @param parent reference to the parent widget (QWidget)
+        """
+        super(HgStripDialog, self).__init__(parent)
+        self.setupUi(self)
+        
+        self.tagCombo.addItems(sorted(tagsList))
+        self.branchCombo.addItems(["default"] + sorted(branchesList))
+        if bookmarksList is not None:
+            self.bookmarkCombo.addItems([""] + sorted(bookmarksList))
+        
+        msh = self.minimumSizeHint()
+        self.resize(max(self.width(), msh.width()), msh.height())
+        
+        self.__updateOK()
+        
+        self.idEdit.setFocus()
+    
+    def __updateOK(self):
+        """
+        Private slot to update the OK button.
+        """
+        enabled = True
+        if self.numberButton.isChecked():
+            enabled = enabled and self.numberSpinBox.value() >= 0
+        elif self.idButton.isChecked():
+            enabled = enabled and self.idEdit.text() != ""
+        elif self.tagButton.isChecked():
+            enabled = enabled and self.tagCombo.currentText() != ""
+        elif self.branchButton.isChecked():
+            enabled = enabled and self.branchCombo.currentText() != ""
+        
+        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled)
+    
+    @pyqtSlot(bool)
+    def on_numberButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the Number select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(bool)
+    def on_idButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the ID select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(bool)
+    def on_tagButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the Tag select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(bool)
+    def on_branchButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the Branch select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(int)
+    def on_numberSpinBox_valueChanged(self, val):
+        """
+        Private slot to handle changes of the Number spin box.
+        
+        @param val value of the spin box
+        @type int
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(str)
+    def on_idEdit_textChanged(self, txt):
+        """
+        Private slot to handle changes of the ID edit.
+        
+        @param txt text of the edit (string)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(str)
+    def on_tagCombo_editTextChanged(self, txt):
+        """
+        Private slot to handle changes of the Tag combo.
+        
+        @param txt text of the combo (string)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(str)
+    def on_branchCombo_editTextChanged(self, txt):
+        """
+        Private slot to handle changes of the Branch combo.
+        
+        @param txt text of the combo (string)
+        """
+        self.__updateOK()
+    
+    def __getRevision(self):
+        """
+        Private method to generate the revision.
+        
+        @return revision (string)
+        """
+        if self.numberButton.isChecked():
+            return "rev({0})".format(self.numberSpinBox.value())
+        elif self.idButton.isChecked():
+            return "id({0})".format(self.idEdit.text())
+        elif self.tagButton.isChecked():
+            return self.tagCombo.currentText()
+        elif self.branchButton.isChecked():
+            return self.branchCombo.currentText()
+        else:
+            # should not happen
+            return ""
+    
+    def getData(self):
+        """
+        Public method to retrieve the data for the strip action.
+        
+        @return tuple with the revision, a bookmark name, a flag indicating
+            to enforce the strip action, a flag indicating to omit the creation
+            of backup bundles and a flag indicating to not modify the working
+            directory
+        @rtype tuple (str, str, bool, bool, bool)
+        """
+        return (
+            self.__getRevision(),
+            self.bookmarkCombo.currentText(),
+            self.forceCheckBox.isChecked(),
+            self.noBackupCheckBox.isChecked(),
+            self.keepCheckBox.isChecked(),
+        )

eric ide

mercurial