eric6/Plugins/VcsPlugins/vcsGit/GitNewProjectOptionsDialog.py

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

eric ide

mercurial