|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Mercurial 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, QComboBox |
|
15 |
|
16 from E5Gui.E5PathPicker import E5PathPickerModes |
|
17 |
|
18 from .Ui_HgNewProjectOptionsDialog import Ui_HgNewProjectOptionsDialog |
|
19 from .Config import ConfigHgSchemes |
|
20 |
|
21 import Utilities |
|
22 import Preferences |
|
23 import UI.PixmapCache |
|
24 |
|
25 |
|
26 class HgNewProjectOptionsDialog(QDialog, Ui_HgNewProjectOptionsDialog): |
|
27 """ |
|
28 Class implementing the Options Dialog for a new project from the |
|
29 repository. |
|
30 """ |
|
31 def __init__(self, vcs, parent=None): |
|
32 """ |
|
33 Constructor |
|
34 |
|
35 @param vcs reference to the version control object |
|
36 @param parent parent widget (QWidget) |
|
37 """ |
|
38 super(HgNewProjectOptionsDialog, self).__init__(parent) |
|
39 self.setupUi(self) |
|
40 |
|
41 self.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
42 |
|
43 self.__vcs = vcs |
|
44 |
|
45 vcsUrlHistory = self.__vcs.getPlugin().getPreferences( |
|
46 "RepositoryUrlHistory") |
|
47 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
48 self.vcsUrlPicker.setInsertPolicy(QComboBox.InsertAtTop) |
|
49 self.vcsUrlPicker.setSizeAdjustPolicy( |
|
50 QComboBox.AdjustToMinimumContentsLength) |
|
51 self.vcsUrlPicker.setPathsList(vcsUrlHistory) |
|
52 self.vcsUrlClearHistoryButton.setIcon( |
|
53 UI.PixmapCache.getIcon("editDelete.png")) |
|
54 self.vcsUrlPicker.setText("") |
|
55 |
|
56 ipath = Preferences.getMultiProject("Workspace") or \ |
|
57 Utilities.getHomeDir() |
|
58 self.__initPaths = [ |
|
59 Utilities.fromNativeSeparators(ipath), |
|
60 Utilities.fromNativeSeparators(ipath) + "/", |
|
61 ] |
|
62 self.vcsProjectDirPicker.setText(self.__initPaths[0]) |
|
63 |
|
64 self.lfNoteLabel.setVisible( |
|
65 self.__vcs.isExtensionActive("largefiles")) |
|
66 self.largeCheckBox.setVisible( |
|
67 self.__vcs.isExtensionActive("largefiles")) |
|
68 |
|
69 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
70 |
|
71 msh = self.minimumSizeHint() |
|
72 self.resize(max(self.width(), msh.width()), msh.height()) |
|
73 |
|
74 @pyqtSlot(str) |
|
75 def on_vcsProjectDirPicker_textChanged(self, txt): |
|
76 """ |
|
77 Private slot to handle a change of the project directory. |
|
78 |
|
79 @param txt name of the project directory (string) |
|
80 """ |
|
81 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
82 bool(txt) and |
|
83 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
|
84 |
|
85 @pyqtSlot(str) |
|
86 def on_vcsUrlPicker_textChanged(self, txt): |
|
87 """ |
|
88 Private slot to handle changes of the URL. |
|
89 |
|
90 @param txt current text of the line edit (string) |
|
91 """ |
|
92 url = QUrl.fromUserInput(txt) |
|
93 enable = url.isValid() and url.scheme() in ConfigHgSchemes |
|
94 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
95 |
|
96 self.vcsUrlPicker.setPickerEnabled(url.scheme() == "file" or |
|
97 len(txt) == 0) |
|
98 |
|
99 @pyqtSlot() |
|
100 def on_vcsUrlClearHistoryButton_clicked(self): |
|
101 """ |
|
102 Private slot to clear the history of entered repository URLs. |
|
103 """ |
|
104 currentVcsUrl = self.vcsUrlPicker.text() |
|
105 self.vcsUrlPicker.clear() |
|
106 self.vcsUrlPicker.setText(currentVcsUrl) |
|
107 |
|
108 self.__saveHistory() |
|
109 |
|
110 def getData(self): |
|
111 """ |
|
112 Public slot to retrieve the data entered into the dialog and to |
|
113 save the history of entered repository URLs. |
|
114 |
|
115 @return a tuple of a string (project directory) and a dictionary |
|
116 containing the data entered. |
|
117 """ |
|
118 self.__saveHistory() |
|
119 |
|
120 url = QUrl.fromUserInput(self.vcsUrlPicker.text().replace("\\", "/")) |
|
121 vcsdatadict = { |
|
122 "url": url.toString(QUrl.None_), |
|
123 "revision": self.vcsRevisionEdit.text(), |
|
124 "largefiles": self.largeCheckBox.isChecked(), |
|
125 } |
|
126 return (self.vcsProjectDirPicker.text(), vcsdatadict) |
|
127 |
|
128 def __saveHistory(self): |
|
129 """ |
|
130 Private method to save the repository URL history. |
|
131 """ |
|
132 url = self.vcsUrlPicker.text() |
|
133 vcsUrlHistory = self.vcsUrlPicker.getPathItems() |
|
134 if url not in vcsUrlHistory: |
|
135 vcsUrlHistory.insert(0, url) |
|
136 |
|
137 # max. list sizes is hard coded to 20 entries |
|
138 newVcsUrlHistory = [url for url in vcsUrlHistory if url] |
|
139 if len(newVcsUrlHistory) > 20: |
|
140 newVcsUrlHistory = newVcsUrlHistory[:20] |
|
141 |
|
142 self.__vcs.getPlugin().setPreferences( |
|
143 "RepositoryUrlHistory", newVcsUrlHistory) |