12 import os |
12 import os |
13 |
13 |
14 from PyQt5.QtCore import pyqtSlot |
14 from PyQt5.QtCore import pyqtSlot |
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
16 |
16 |
17 from E5Gui import E5FileDialog, E5MessageBox |
17 from E5Gui import E5MessageBox |
|
18 from E5Gui.E5PathPicker import E5PathPickerModes |
18 |
19 |
19 import Utilities |
20 import Utilities |
20 import UI.PixmapCache |
|
21 |
21 |
22 from .Ui_HgAddSubrepositoryDialog import Ui_HgAddSubrepositoryDialog |
22 from .Ui_HgAddSubrepositoryDialog import Ui_HgAddSubrepositoryDialog |
23 |
23 |
24 |
24 |
25 class HgAddSubrepositoryDialog(QDialog, Ui_HgAddSubrepositoryDialog): |
25 class HgAddSubrepositoryDialog(QDialog, Ui_HgAddSubrepositoryDialog): |
34 @param parent reference to the parent widget (QWidget) |
34 @param parent reference to the parent widget (QWidget) |
35 """ |
35 """ |
36 super(HgAddSubrepositoryDialog, self).__init__(parent) |
36 super(HgAddSubrepositoryDialog, self).__init__(parent) |
37 self.setupUi(self) |
37 self.setupUi(self) |
38 |
38 |
39 self.pathButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
39 self.pathPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
40 self.pathPicker.setDefaultDirectory(projectPath) |
40 |
41 |
41 self.__ok = self.buttonBox.button(QDialogButtonBox.Ok) |
42 self.__ok = self.buttonBox.button(QDialogButtonBox.Ok) |
42 self.__ok.setEnabled(False) |
43 self.__ok.setEnabled(False) |
43 |
44 |
44 self.__projectPath = projectPath |
45 self.__projectPath = Utilities.toNativeSeparators(projectPath) |
45 |
46 |
46 self.typeCombo.addItem("Mercurial", "hg") |
47 self.typeCombo.addItem("Mercurial", "hg") |
47 self.typeCombo.addItem("GIT", "git") |
48 self.typeCombo.addItem("GIT", "git") |
48 self.typeCombo.addItem("Subversion", "svn") |
49 self.typeCombo.addItem("Subversion", "svn") |
49 |
50 |
52 |
53 |
53 def __updateOk(self): |
54 def __updateOk(self): |
54 """ |
55 """ |
55 Private slot to update the state of the OK button. |
56 Private slot to update the state of the OK button. |
56 """ |
57 """ |
57 path = self.pathEdit.text() |
58 path = self.pathPicker.text() |
58 url = self.urlEdit.text() |
59 url = self.urlEdit.text() |
59 |
60 |
60 self.__ok.setEnabled( |
61 self.__ok.setEnabled( |
61 path != "" and |
62 path != "" and |
62 not os.path.isabs(path) and |
63 not os.path.isabs(path) and |
63 url != "" |
64 url != "" |
64 ) |
65 ) |
65 |
66 |
66 @pyqtSlot(str) |
67 @pyqtSlot(str) |
67 def on_pathEdit_textChanged(self, p0): |
68 def on_pathPicker_textChanged(self, p0): |
68 """ |
69 """ |
69 Private slot to handle the update of the path. |
70 Private slot to handle the update of the path. |
70 |
71 |
71 @param p0 text of the path edit (string) |
72 @param p0 text of the path edit (string) |
72 """ |
73 """ |
79 |
80 |
80 @param p0 text of the URL edit (string) |
81 @param p0 text of the URL edit (string) |
81 """ |
82 """ |
82 self.__updateOk() |
83 self.__updateOk() |
83 |
84 |
84 @pyqtSlot() |
85 @pyqtSlot(str) |
85 def on_pathButton_clicked(self): |
86 def on_pathPicker_pathSelected(self, path): |
86 """ |
87 """ |
87 Private slot to handle the path selection via a directory selection |
88 Private slot handling the selection of a subrepository path. |
88 dialog. |
89 |
|
90 @param path path of the subrepository |
|
91 @type str |
89 """ |
92 """ |
90 path = E5FileDialog.getExistingDirectory( |
93 if path.startswith(self.__projectPath + os.sep): |
91 self, |
94 path = path.replace(self.__projectPath + os.sep, "") |
92 self.tr("Add Sub-repository"), |
95 self.pathPicker.setText(path) |
93 os.path.join(self.__projectPath, self.pathEdit.text()), |
96 else: |
94 E5FileDialog.Options(E5FileDialog.Option(0))) |
97 E5MessageBox.critical( |
95 |
98 self, |
96 if path: |
99 self.tr("Add Sub-repository"), |
97 path = Utilities.toNativeSeparators(path) |
100 self.tr("""The sub-repository path must be inside""" |
98 if path.startswith(self.__projectPath): |
101 """ the project.""")) |
99 path = path.replace(self.__projectPath, "")[1:] |
102 self.pathPicker.setText("") |
100 self.pathEdit.setText(path) |
|
101 else: |
|
102 E5MessageBox.critical( |
|
103 self, |
|
104 self.tr("Add Sub-repository"), |
|
105 self.tr("""The sub-repository path must be inside""" |
|
106 """ the project.""")) |
|
107 return |
|
108 |
103 |
109 def getData(self): |
104 def getData(self): |
110 """ |
105 """ |
111 Public method to get the data. |
106 Public method to get the data. |
112 |
107 |
113 @return tuple containing the relative path within the project, the |
108 @return tuple containing the relative path within the project, the |
114 sub-repository type and the sub-repository URL (string, string, |
109 sub-repository type and the sub-repository URL (string, string, |
115 string) |
110 string) |
116 """ |
111 """ |
117 return ( |
112 return ( |
118 self.pathEdit.text(), |
113 self.pathPicker.text(), |
119 self.typeCombo.itemData(self.typeCombo.currentIndex()), |
114 self.typeCombo.itemData(self.typeCombo.currentIndex()), |
120 self.urlEdit.text() |
115 self.urlEdit.text() |
121 ) |
116 ) |