Plugins/VcsPlugins/vcsMercurial/HgAddSubrepositoryDialog.py

changeset 1905
7ad9161c5293
child 1906
8487f9c2533b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/HgAddSubrepositoryDialog.py	Sat Jun 16 18:28:31 2012 +0200
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to add a subrepository.
+"""
+
+import os
+
+from PyQt4.QtCore import pyqtSlot
+from PyQt4.QtGui import QDialog, QDialogButtonBox
+
+from E5Gui import E5FileDialog, E5MessageBox
+
+import Utilities
+
+from .Ui_HgAddSubrepositoryDialog import Ui_HgAddSubrepositoryDialog
+
+
+class HgAddSubrepositoryDialog(QDialog, Ui_HgAddSubrepositoryDialog):
+    """
+    Class implementing a dialog to add a subrepository.
+    """
+    def __init__(self, projectPath, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.__ok = self.buttonBox.button(QDialogButtonBox.Ok)
+        self.__ok.setEnabled(False)
+        
+        self.__projectPath = projectPath
+        
+        self.typeCombo.addItem("Mercurial", "hg")
+        self.typeCombo.addItem("GIT", "git")
+        self.typeCombo.addItem("Subversion", "svn")
+    
+    def __updateOk(self):
+        """
+        Private slot to update the state of the OK button.
+        """
+        path = self.pathEdit.text()
+        url = self.urlEdit.text()
+        
+        self.__ok.setEnabled(
+            path != "" and
+            not os.path.isabs(path) and
+            url != ""
+        )
+    
+    @pyqtSlot(str)
+    def on_pathEdit_textChanged(self, p0):
+        """
+        Private slot to handle the update of the path.
+        
+        @param p0 text of the path edit (string)
+        """
+        self.__updateOk()
+    
+    @pyqtSlot(str)
+    def on_urlEdit_textChanged(self, p0):
+        """
+        Private slot to handle the update of the URL.
+        
+        @param p0 text of the URL edit (string)
+        """
+        self.__updateOk()
+    
+    @pyqtSlot()
+    def on_pathButton_clicked(self):
+        """
+        Private slot to handle the path selection via a directory selection dialog.
+        """
+        path = E5FileDialog.getExistingDirectory(
+            self,
+            self.trUtf8("Add Subrepository"),
+            os.path.join(self.__projectPath, self.pathEdit.text()),
+            E5FileDialog.Options(E5FileDialog.Option(0)))
+        
+        if path:
+            if path.startswith(self.__projectPath):
+                path = path.replace(self.__projectPath, "")[1:]
+                self.pathEdit.setText(Utilities.toNativeSeparators(path))
+            else:
+                E5MessageBox.critical(self,
+                    self.trUtf8("Add Subrepository"),
+                    self.trUtf8("""The subrepository path must be inside the project."""))
+                return
+    
+    def getData(self):
+        """
+        Public method to get the data.
+        
+        @return tuple containing the relative path within the project, the subrepository
+            type and the subrepository URL (string, string, string)
+        """
+        return (
+            self.pathEdit.text(),
+            self.typeCombo.itemData(self.typeCombo.currentIndex()),
+            self.urlEdit.text()
+        )

eric ide

mercurial