eric7/Plugins/VcsPlugins/vcsSubversion/SvnNewProjectOptionsDialog.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) 2002 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Subversion Options Dialog for a new project from the
8 repository.
9 """
10
11 import os
12
13 from PyQt5.QtCore import QDir, pyqtSlot
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
15
16 from E5Gui.E5PathPicker import E5PathPickerModes
17
18 from .Ui_SvnNewProjectOptionsDialog import Ui_SvnNewProjectOptionsDialog
19 from .Config import ConfigSvnProtocols
20
21 import Utilities
22 import Preferences
23
24
25 class SvnNewProjectOptionsDialog(QDialog, Ui_SvnNewProjectOptionsDialog):
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.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode)
41 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode)
42
43 self.protocolCombo.addItems(ConfigSvnProtocols)
44
45 self.vcs = vcs
46
47 hd = Utilities.toNativeSeparators(QDir.homePath())
48 hd = os.path.join(hd, 'subversionroot')
49 self.vcsUrlPicker.setText(hd)
50
51 self.localPath = hd
52 self.networkPath = "localhost/"
53 self.localProtocol = True
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.vcsProjectDirPicker.setText(self.__initPaths[0])
64
65 self.resize(self.width(), self.minimumSizeHint().height())
66
67 self.buttonBox.button(
68 QDialogButtonBox.StandardButton.Ok).setEnabled(False)
69
70 msh = self.minimumSizeHint()
71 self.resize(max(self.width(), msh.width()), msh.height())
72
73 @pyqtSlot(str)
74 def on_vcsProjectDirPicker_textChanged(self, txt):
75 """
76 Private slot to handle a change of the project directory.
77
78 @param txt name of the project directory (string)
79 """
80 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
81 bool(txt) and
82 Utilities.fromNativeSeparators(txt) not in self.__initPaths)
83
84 def on_vcsUrlPicker_pickerButtonClicked(self):
85 """
86 Private slot to display a repository browser dialog.
87 """
88 from .SvnRepoBrowserDialog import SvnRepoBrowserDialog
89 dlg = SvnRepoBrowserDialog(self.vcs, mode="select", parent=self)
90 dlg.start(
91 self.protocolCombo.currentText() + self.vcsUrlPicker.text())
92 if dlg.exec() == QDialog.DialogCode.Accepted:
93 url = dlg.getSelectedUrl()
94 if url:
95 protocol = url.split("://")[0]
96 path = url.split("://")[1]
97 self.protocolCombo.setCurrentIndex(
98 self.protocolCombo.findText(protocol + "://"))
99 self.vcsUrlPicker.setText(path)
100
101 def on_layoutCheckBox_toggled(self, checked):
102 """
103 Private slot to handle the change of the layout checkbox.
104
105 @param checked flag indicating the state of the checkbox (boolean)
106 """
107 self.vcsTagLabel.setEnabled(checked)
108 self.vcsTagEdit.setEnabled(checked)
109 if not checked:
110 self.vcsTagEdit.clear()
111
112 @pyqtSlot(int)
113 def on_protocolCombo_activated(self, index):
114 """
115 Private slot to switch the status of the directory selection button.
116
117 @param index index of the selected entry
118 @type int
119 """
120 protocol = self.protocolCombo.itemText(index)
121 if protocol == "file://":
122 self.networkPath = self.vcsUrlPicker.text()
123 self.vcsUrlPicker.setText(self.localPath)
124 self.vcsUrlLabel.setText(self.tr("Pat&h:"))
125 self.localProtocol = True
126 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode)
127 else:
128 if self.localProtocol:
129 self.localPath = self.vcsUrlPicker.text()
130 self.vcsUrlPicker.setText(self.networkPath)
131 self.vcsUrlLabel.setText(self.tr("&URL:"))
132 self.localProtocol = False
133 self.vcsUrlPicker.setMode(E5PathPickerModes.CustomMode)
134
135 @pyqtSlot(str)
136 def on_vcsUrlPicker_textChanged(self, txt):
137 """
138 Private slot to handle changes of the URL.
139
140 @param txt current text of the line edit (string)
141 """
142 enable = "://" not in txt
143 self.buttonBox.button(
144 QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
145
146 def getData(self):
147 """
148 Public slot to retrieve the data entered into the dialog.
149
150 @return a tuple of a string (project directory) and a dictionary
151 containing the data entered.
152 """
153 scheme = self.protocolCombo.currentText()
154 url = self.vcsUrlPicker.text()
155 vcsdatadict = {
156 "url": '{0}{1}'.format(scheme, url),
157 "tag": self.vcsTagEdit.text(),
158 "standardLayout": self.layoutCheckBox.isChecked(),
159 }
160 return (self.vcsProjectDirPicker.text(), vcsdatadict)

eric ide

mercurial