Plugins/VcsPlugins/vcsGit/GitNewProjectOptionsDialog.py

changeset 6020
baf6da1ae288
child 6048
82ad8ec9548c
equal deleted inserted replaced
6019:58ecdaf0b789 6020:baf6da1ae288
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2017 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 url = QUrl.fromUserInput(txt)
121 enable = url.isValid() and url.scheme() in ConfigGitSchemes
122 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
123
124 self.vcsUrlButton.setEnabled(url.scheme() == "file" or len(txt) == 0)
125
126 @pyqtSlot()
127 def on_vcsUrlClearHistoryButton_clicked(self):
128 """
129 Private slot to clear the history of entered repository URLs.
130 """
131 currentVcsUrl = self.vcsUrlCombo.currentText()
132 self.vcsUrlCombo.clear()
133 self.vcsUrlCombo.setEditText(currentVcsUrl)
134
135 self.__saveHistory()
136
137 def getData(self):
138 """
139 Public slot to retrieve the data entered into the dialog.
140
141 @return a tuple of a string (project directory) and a dictionary
142 containing the data entered.
143 """
144 self.__saveHistory()
145
146 url = QUrl.fromUserInput(
147 self.vcsUrlCombo.currentText().replace("\\", "/"))
148 vcsdatadict = {
149 "url": url.toString(QUrl.None_),
150 }
151 return (self.vcsProjectDirEdit.text(), vcsdatadict)
152
153 def __saveHistory(self):
154 """
155 Private method to save the repository URL history.
156 """
157 url = self.vcsUrlCombo.currentText()
158 vcsUrlHistory = []
159 for index in range(self.vcsUrlCombo.count()):
160 vcsUrlHistory.append(self.vcsUrlCombo.itemText(index))
161 if url not in vcsUrlHistory:
162 vcsUrlHistory.insert(0, url)
163
164 # max. list sizes is hard coded to 20 entries
165 newVcsUrlHistory = [url for url in vcsUrlHistory if url]
166 if len(newVcsUrlHistory) > 20:
167 newVcsUrlHistory = newVcsUrlHistory[:20]
168
169 self.__vcs.getPlugin().setPreferences(
170 "RepositoryUrlHistory", newVcsUrlHistory)

eric ide

mercurial