|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to add a subrepository. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import pyqtSlot |
|
13 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
14 |
|
15 from E5Gui import E5FileDialog, E5MessageBox |
|
16 |
|
17 import Utilities |
|
18 |
|
19 from .Ui_HgAddSubrepositoryDialog import Ui_HgAddSubrepositoryDialog |
|
20 |
|
21 |
|
22 class HgAddSubrepositoryDialog(QDialog, Ui_HgAddSubrepositoryDialog): |
|
23 """ |
|
24 Class implementing a dialog to add a subrepository. |
|
25 """ |
|
26 def __init__(self, projectPath, parent=None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param parent reference to the parent widget (QWidget) |
|
31 """ |
|
32 super().__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.__ok = self.buttonBox.button(QDialogButtonBox.Ok) |
|
36 self.__ok.setEnabled(False) |
|
37 |
|
38 self.__projectPath = projectPath |
|
39 |
|
40 self.typeCombo.addItem("Mercurial", "hg") |
|
41 self.typeCombo.addItem("GIT", "git") |
|
42 self.typeCombo.addItem("Subversion", "svn") |
|
43 |
|
44 def __updateOk(self): |
|
45 """ |
|
46 Private slot to update the state of the OK button. |
|
47 """ |
|
48 path = self.pathEdit.text() |
|
49 url = self.urlEdit.text() |
|
50 |
|
51 self.__ok.setEnabled( |
|
52 path != "" and |
|
53 not os.path.isabs(path) and |
|
54 url != "" |
|
55 ) |
|
56 |
|
57 @pyqtSlot(str) |
|
58 def on_pathEdit_textChanged(self, p0): |
|
59 """ |
|
60 Private slot to handle the update of the path. |
|
61 |
|
62 @param p0 text of the path edit (string) |
|
63 """ |
|
64 self.__updateOk() |
|
65 |
|
66 @pyqtSlot(str) |
|
67 def on_urlEdit_textChanged(self, p0): |
|
68 """ |
|
69 Private slot to handle the update of the URL. |
|
70 |
|
71 @param p0 text of the URL edit (string) |
|
72 """ |
|
73 self.__updateOk() |
|
74 |
|
75 @pyqtSlot() |
|
76 def on_pathButton_clicked(self): |
|
77 """ |
|
78 Private slot to handle the path selection via a directory selection dialog. |
|
79 """ |
|
80 path = E5FileDialog.getExistingDirectory( |
|
81 self, |
|
82 self.trUtf8("Add Subrepository"), |
|
83 os.path.join(self.__projectPath, self.pathEdit.text()), |
|
84 E5FileDialog.Options(E5FileDialog.Option(0))) |
|
85 |
|
86 if path: |
|
87 if path.startswith(self.__projectPath): |
|
88 path = path.replace(self.__projectPath, "")[1:] |
|
89 self.pathEdit.setText(Utilities.toNativeSeparators(path)) |
|
90 else: |
|
91 E5MessageBox.critical(self, |
|
92 self.trUtf8("Add Subrepository"), |
|
93 self.trUtf8("""The subrepository path must be inside the project.""")) |
|
94 return |
|
95 |
|
96 def getData(self): |
|
97 """ |
|
98 Public method to get the data. |
|
99 |
|
100 @return tuple containing the relative path within the project, the subrepository |
|
101 type and the subrepository URL (string, string, string) |
|
102 """ |
|
103 return ( |
|
104 self.pathEdit.text(), |
|
105 self.typeCombo.itemData(self.typeCombo.currentIndex()), |
|
106 self.urlEdit.text() |
|
107 ) |