eric7/Plugins/VcsPlugins/vcsGit/GitNewProjectOptionsDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Git Options Dialog for a new project from the
8 repository.
9 """
10
11 from PyQt5.QtCore import pyqtSlot, QUrl
12 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
13
14 from E5Gui.E5Completers import E5DirCompleter
15 from E5Gui import E5FileDialog
16
17 from .Ui_GitNewProjectOptionsDialog import Ui_GitNewProjectOptionsDialog
18 from .Config import ConfigGitSchemes
19
20 import Utilities
21 import Preferences
22 import UI.PixmapCache
23
24
25 class GitNewProjectOptionsDialog(QDialog, Ui_GitNewProjectOptionsDialog):
26 """
27 Class implementing the Options Dialog for a new project from the
28 repository.
29 """
30 def __init__(self, vcs, parent=None):
31 """
32 Constructor
33
34 @param vcs reference to the version control object
35 @param parent parent widget (QWidget)
36 """
37 super().__init__(parent)
38 self.setupUi(self)
39
40 self.__vcs = vcs
41
42 self.projectDirButton.setIcon(UI.PixmapCache.getIcon("open"))
43 self.vcsUrlButton.setIcon(UI.PixmapCache.getIcon("open"))
44 self.vcsUrlClearHistoryButton.setIcon(
45 UI.PixmapCache.getIcon("editDelete"))
46
47 vcsUrlHistory = self.__vcs.getPlugin().getPreferences(
48 "RepositoryUrlHistory")
49 self.vcsUrlCombo.addItems(vcsUrlHistory)
50 self.vcsUrlCombo.setEditText("")
51
52 self.vcsDirectoryCompleter = E5DirCompleter(self.vcsUrlCombo)
53 self.vcsProjectDirCompleter = E5DirCompleter(self.vcsProjectDirEdit)
54
55 ipath = (
56 Preferences.getMultiProject("Workspace") or
57 Utilities.getHomeDir()
58 )
59 self.__initPaths = [
60 Utilities.fromNativeSeparators(ipath),
61 Utilities.fromNativeSeparators(ipath) + "/",
62 ]
63 self.vcsProjectDirEdit.setText(
64 Utilities.toNativeSeparators(self.__initPaths[0]))
65
66 self.buttonBox.button(
67 QDialogButtonBox.StandardButton.Ok).setEnabled(False)
68
69 msh = self.minimumSizeHint()
70 self.resize(max(self.width(), msh.width()), msh.height())
71
72 @pyqtSlot(str)
73 def on_vcsProjectDirEdit_textChanged(self, txt):
74 """
75 Private slot to handle a change of the project directory.
76
77 @param txt name of the project directory (string)
78 """
79 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
80 bool(txt) and
81 Utilities.fromNativeSeparators(txt) not in self.__initPaths)
82
83 @pyqtSlot()
84 def on_vcsUrlButton_clicked(self):
85 """
86 Private slot to display a selection dialog.
87 """
88 directory = E5FileDialog.getExistingDirectory(
89 self,
90 self.tr("Select Repository-Directory"),
91 self.vcsUrlCombo.currentText(),
92 E5FileDialog.Options(E5FileDialog.ShowDirsOnly))
93
94 if directory:
95 self.vcsUrlCombo.setEditText(
96 Utilities.toNativeSeparators(directory))
97
98 @pyqtSlot()
99 def on_projectDirButton_clicked(self):
100 """
101 Private slot to display a directory selection dialog.
102 """
103 directory = E5FileDialog.getExistingDirectory(
104 self,
105 self.tr("Select Project Directory"),
106 self.vcsProjectDirEdit.text(),
107 E5FileDialog.Options(E5FileDialog.ShowDirsOnly))
108
109 if directory:
110 self.vcsProjectDirEdit.setText(
111 Utilities.toNativeSeparators(directory))
112
113 @pyqtSlot(str)
114 def on_vcsUrlCombo_editTextChanged(self, txt):
115 """
116 Private slot to handle changes of the URL.
117
118 @param txt current text of the combo box
119 @type str
120 """
121 enable = False
122 vcsUrlEnable = False
123
124 if txt:
125 url = QUrl.fromUserInput(txt)
126 if url.isValid():
127 if url.scheme() in ConfigGitSchemes:
128 enable = True
129 vcsUrlEnable = url.scheme() == "file"
130 elif ':' in txt:
131 # assume scp like repository URL
132 enable = True
133 else:
134 vcsUrlEnable = True
135
136 self.buttonBox.button(
137 QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
138 self.vcsUrlButton.setEnabled(vcsUrlEnable)
139
140 @pyqtSlot()
141 def on_vcsUrlClearHistoryButton_clicked(self):
142 """
143 Private slot to clear the history of entered repository URLs.
144 """
145 currentVcsUrl = self.vcsUrlCombo.currentText()
146 self.vcsUrlCombo.clear()
147 self.vcsUrlCombo.setEditText(currentVcsUrl)
148
149 self.__saveHistory()
150
151 def getData(self):
152 """
153 Public slot to retrieve the data entered into the dialog.
154
155 @return a tuple of a string (project directory) and a dictionary
156 containing the data entered.
157 """
158 self.__saveHistory()
159
160 vcsdatadict = {
161 "url": self.vcsUrlCombo.currentText().replace("\\", "/"),
162 }
163 return (self.vcsProjectDirEdit.text(), vcsdatadict)
164
165 def __saveHistory(self):
166 """
167 Private method to save the repository URL history.
168 """
169 url = self.vcsUrlCombo.currentText()
170 vcsUrlHistory = []
171 for index in range(self.vcsUrlCombo.count()):
172 vcsUrlHistory.append(self.vcsUrlCombo.itemText(index))
173 if url not in vcsUrlHistory:
174 vcsUrlHistory.insert(0, url)
175
176 # max. list sizes is hard coded to 20 entries
177 newVcsUrlHistory = [url for url in vcsUrlHistory if url]
178 if len(newVcsUrlHistory) > 20:
179 newVcsUrlHistory = newVcsUrlHistory[:20]
180
181 self.__vcs.getPlugin().setPreferences(
182 "RepositoryUrlHistory", newVcsUrlHistory)

eric ide

mercurial