src/eric7/Plugins/VcsPlugins/vcsGit/GitSubmoduleAddDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
23 23
24 class GitSubmoduleAddDialog(QDialog, Ui_GitSubmoduleAddDialog): 24 class GitSubmoduleAddDialog(QDialog, Ui_GitSubmoduleAddDialog):
25 """ 25 """
26 Class implementing a dialog to enter the data to add a submodule. 26 Class implementing a dialog to enter the data to add a submodule.
27 """ 27 """
28
28 def __init__(self, vcs, repodir, parent=None): 29 def __init__(self, vcs, repodir, parent=None):
29 """ 30 """
30 Constructor 31 Constructor
31 32
32 @param vcs reference to the version control object 33 @param vcs reference to the version control object
33 @type Git 34 @type Git
34 @param repodir directory containing the superproject 35 @param repodir directory containing the superproject
35 @type str 36 @type str
36 @param parent reference to the parent widget 37 @param parent reference to the parent widget
37 @type QWidget 38 @type QWidget
38 """ 39 """
39 super().__init__(parent) 40 super().__init__(parent)
40 self.setupUi(self) 41 self.setupUi(self)
41 42
42 self.__vcs = vcs 43 self.__vcs = vcs
43 self.__repodir = repodir 44 self.__repodir = repodir
44 45
45 self.submoduleDirButton.setIcon(UI.PixmapCache.getIcon("open")) 46 self.submoduleDirButton.setIcon(UI.PixmapCache.getIcon("open"))
46 self.submoduleUrlButton.setIcon(UI.PixmapCache.getIcon("open")) 47 self.submoduleUrlButton.setIcon(UI.PixmapCache.getIcon("open"))
47 self.submoduleUrlClearHistoryButton.setIcon( 48 self.submoduleUrlClearHistoryButton.setIcon(
48 UI.PixmapCache.getIcon("editDelete")) 49 UI.PixmapCache.getIcon("editDelete")
49 50 )
51
50 submoduleUrlHistory = self.__vcs.getPlugin().getPreferences( 52 submoduleUrlHistory = self.__vcs.getPlugin().getPreferences(
51 "RepositoryUrlHistory") 53 "RepositoryUrlHistory"
54 )
52 self.submoduleUrlCombo.addItems(submoduleUrlHistory) 55 self.submoduleUrlCombo.addItems(submoduleUrlHistory)
53 self.submoduleUrlCombo.setEditText("") 56 self.submoduleUrlCombo.setEditText("")
54 57
55 self.submoduleUrlDirCompleter = EricDirCompleter( 58 self.submoduleUrlDirCompleter = EricDirCompleter(self.submoduleUrlCombo)
56 self.submoduleUrlCombo) 59 self.submoduleDirCompleter = EricDirCompleter(self.submoduleDirEdit)
57 self.submoduleDirCompleter = EricDirCompleter( 60
58 self.submoduleDirEdit) 61 ipath = Preferences.getMultiProject("Workspace") or Utilities.getHomeDir()
59
60 ipath = (
61 Preferences.getMultiProject("Workspace") or
62 Utilities.getHomeDir()
63 )
64 self.__initPaths = [ 62 self.__initPaths = [
65 Utilities.fromNativeSeparators(ipath), 63 Utilities.fromNativeSeparators(ipath),
66 Utilities.fromNativeSeparators(ipath) + "/", 64 Utilities.fromNativeSeparators(ipath) + "/",
67 ] 65 ]
68 66
69 self.buttonBox.button( 67 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
70 QDialogButtonBox.StandardButton.Ok).setEnabled(False) 68
71
72 msh = self.minimumSizeHint() 69 msh = self.minimumSizeHint()
73 self.resize(max(self.width(), msh.width()), msh.height()) 70 self.resize(max(self.width(), msh.width()), msh.height())
74 71
75 @pyqtSlot(str) 72 @pyqtSlot(str)
76 def on_submoduleUrlCombo_editTextChanged(self, txt): 73 def on_submoduleUrlCombo_editTextChanged(self, txt):
77 """ 74 """
78 Private slot to handle changes of the submodule repository URL. 75 Private slot to handle changes of the submodule repository URL.
79 76
80 @param txt current text of the combo box 77 @param txt current text of the combo box
81 @type str 78 @type str
82 """ 79 """
83 enable = False 80 enable = False
84 vcsUrlEnable = False 81 vcsUrlEnable = False
85 82
86 if txt: 83 if txt:
87 url = QUrl.fromUserInput(txt) 84 url = QUrl.fromUserInput(txt)
88 if url.isValid(): 85 if url.isValid():
89 if url.scheme() in ConfigGitSchemes: 86 if url.scheme() in ConfigGitSchemes:
90 enable = True 87 enable = True
91 vcsUrlEnable = url.scheme() == "file" 88 vcsUrlEnable = url.scheme() == "file"
92 elif ':' in txt: 89 elif ":" in txt:
93 # assume scp like repository URL 90 # assume scp like repository URL
94 enable = True 91 enable = True
95 else: 92 else:
96 vcsUrlEnable = True 93 vcsUrlEnable = True
97 94
98 self.buttonBox.button( 95 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
99 QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
100 self.submoduleUrlButton.setEnabled(vcsUrlEnable) 96 self.submoduleUrlButton.setEnabled(vcsUrlEnable)
101 97
102 @pyqtSlot() 98 @pyqtSlot()
103 def on_submoduleUrlButton_clicked(self): 99 def on_submoduleUrlButton_clicked(self):
104 """ 100 """
105 Private slot to display a directory selection dialog. 101 Private slot to display a directory selection dialog.
106 """ 102 """
107 directory = EricFileDialog.getExistingDirectory( 103 directory = EricFileDialog.getExistingDirectory(
108 self, 104 self,
109 self.tr("Select Submodule Repository Directory"), 105 self.tr("Select Submodule Repository Directory"),
110 self.submoduleUrlCombo.currentText(), 106 self.submoduleUrlCombo.currentText(),
111 EricFileDialog.ShowDirsOnly) 107 EricFileDialog.ShowDirsOnly,
112 108 )
109
113 if directory: 110 if directory:
114 self.submoduleUrlCombo.setEditText( 111 self.submoduleUrlCombo.setEditText(Utilities.toNativeSeparators(directory))
115 Utilities.toNativeSeparators(directory)) 112
116
117 @pyqtSlot() 113 @pyqtSlot()
118 def on_submoduleUrlClearHistoryButton_clicked(self): 114 def on_submoduleUrlClearHistoryButton_clicked(self):
119 """ 115 """
120 Private slot to clear the history of entered repository URLs. 116 Private slot to clear the history of entered repository URLs.
121 """ 117 """
122 currentUrl = self.submoduleUrlCombo.currentText() 118 currentUrl = self.submoduleUrlCombo.currentText()
123 self.submoduleUrlCombo.clear() 119 self.submoduleUrlCombo.clear()
124 self.submoduleUrlCombo.setEditText(currentUrl) 120 self.submoduleUrlCombo.setEditText(currentUrl)
125 121
126 self.__saveHistory() 122 self.__saveHistory()
127 123
128 @pyqtSlot() 124 @pyqtSlot()
129 def on_submoduleDirButton_clicked(self): 125 def on_submoduleDirButton_clicked(self):
130 """ 126 """
131 Private slot to display a directory selection dialog. 127 Private slot to display a directory selection dialog.
132 """ 128 """
133 directory = EricFileDialog.getExistingDirectory( 129 directory = EricFileDialog.getExistingDirectory(
134 self, 130 self,
135 self.tr("Select Submodule Directory"), 131 self.tr("Select Submodule Directory"),
136 self.submoduleDirEdit.text(), 132 self.submoduleDirEdit.text(),
137 EricFileDialog.ShowDirsOnly) 133 EricFileDialog.ShowDirsOnly,
138 134 )
135
139 if directory: 136 if directory:
140 self.submoduleDirEdit.setText( 137 self.submoduleDirEdit.setText(Utilities.toNativeSeparators(directory))
141 Utilities.toNativeSeparators(directory)) 138
142
143 def getData(self): 139 def getData(self):
144 """ 140 """
145 Public method to get the entered data. 141 Public method to get the entered data.
146 142
147 @return tuple containing the repository URL, optional branch name, 143 @return tuple containing the repository URL, optional branch name,
148 optional logical name, optional submodule path and a flag 144 optional logical name, optional submodule path and a flag
149 indicating to enforce the operation 145 indicating to enforce the operation
150 @rtype tuple of (str, str, str, str, bool) 146 @rtype tuple of (str, str, str, str, bool)
151 """ 147 """
152 self.__saveHistory() 148 self.__saveHistory()
153 149
154 path = self.submoduleDirEdit.text() 150 path = self.submoduleDirEdit.text()
155 if path: 151 if path:
156 path = self.__getRelativePath(path) 152 path = self.__getRelativePath(path)
157 153
158 return ( 154 return (
159 self.submoduleUrlCombo.currentText().replace("\\", "/"), 155 self.submoduleUrlCombo.currentText().replace("\\", "/"),
160 self.branchEdit.text(), 156 self.branchEdit.text(),
161 self.nameEdit.text(), 157 self.nameEdit.text(),
162 path, 158 path,
163 self.forceCheckBox.isChecked(), 159 self.forceCheckBox.isChecked(),
164 ) 160 )
165 161
166 def __saveHistory(self): 162 def __saveHistory(self):
167 """ 163 """
168 Private method to save the repository URL history. 164 Private method to save the repository URL history.
169 """ 165 """
170 url = self.submoduleUrlCombo.currentText() 166 url = self.submoduleUrlCombo.currentText()
171 submoduleUrlHistory = [] 167 submoduleUrlHistory = []
172 for index in range(self.submoduleUrlCombo.count()): 168 for index in range(self.submoduleUrlCombo.count()):
173 submoduleUrlHistory.append(self.submoduleUrlCombo.itemText(index)) 169 submoduleUrlHistory.append(self.submoduleUrlCombo.itemText(index))
174 if url not in submoduleUrlHistory: 170 if url not in submoduleUrlHistory:
175 submoduleUrlHistory.insert(0, url) 171 submoduleUrlHistory.insert(0, url)
176 172
177 # max. list sizes is hard coded to 20 entries 173 # max. list sizes is hard coded to 20 entries
178 newSubmoduleUrlHistory = [url for url in submoduleUrlHistory if url] 174 newSubmoduleUrlHistory = [url for url in submoduleUrlHistory if url]
179 if len(newSubmoduleUrlHistory) > 20: 175 if len(newSubmoduleUrlHistory) > 20:
180 newSubmoduleUrlHistory = newSubmoduleUrlHistory[:20] 176 newSubmoduleUrlHistory = newSubmoduleUrlHistory[:20]
181 177
182 self.__vcs.getPlugin().setPreferences( 178 self.__vcs.getPlugin().setPreferences(
183 "RepositoryUrlHistory", newSubmoduleUrlHistory) 179 "RepositoryUrlHistory", newSubmoduleUrlHistory
184 180 )
181
185 def __getRelativePath(self, path): 182 def __getRelativePath(self, path):
186 """ 183 """
187 Private method to convert a file path to a relative path. 184 Private method to convert a file path to a relative path.
188 185
189 @param path file or directory name to convert 186 @param path file or directory name to convert
190 @type str 187 @type str
191 @return relative path or unchanged path, if path doesn't 188 @return relative path or unchanged path, if path doesn't
192 belong to the project 189 belong to the project
193 @rtype str 190 @rtype str
194 """ 191 """
195 if path == self.__repodir: 192 if path == self.__repodir:
196 return "" 193 return ""
197 elif ( 194 elif Utilities.normcasepath(Utilities.toNativeSeparators(path)).startswith(
198 Utilities.normcasepath(Utilities.toNativeSeparators(path)) 195 Utilities.normcasepath(Utilities.toNativeSeparators(self.__repodir + "/"))
199 .startswith(Utilities.normcasepath(
200 Utilities.toNativeSeparators(self.__repodir + "/")))
201 ): 196 ):
202 relpath = path[len(self.__repodir):] 197 relpath = path[len(self.__repodir) :]
203 if relpath.startswith(("/", "\\")): 198 if relpath.startswith(("/", "\\")):
204 relpath = relpath[1:] 199 relpath = relpath[1:]
205 return relpath 200 return relpath
206 else: 201 else:
207 return path 202 return path

eric ide

mercurial