eric6/Plugins/VcsPlugins/vcsPySvn/SvnNewProjectOptionsDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2019 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 from __future__ import unicode_literals
12
13 import os
14
15 from PyQt5.QtCore import QDir, pyqtSlot
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
17
18 from E5Gui.E5PathPicker import E5PathPickerModes
19
20 from .Ui_SvnNewProjectOptionsDialog import Ui_SvnNewProjectOptionsDialog
21 from .Config import ConfigSvnProtocols
22
23 import Utilities
24 import Preferences
25
26
27 class SvnNewProjectOptionsDialog(QDialog, Ui_SvnNewProjectOptionsDialog):
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(SvnNewProjectOptionsDialog, self).__init__(parent)
40 self.setupUi(self)
41
42 self.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode)
43 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode)
44
45 self.protocolCombo.addItems(ConfigSvnProtocols)
46
47 hd = Utilities.toNativeSeparators(QDir.homePath())
48 hd = os.path.join(hd, 'subversionroot')
49 self.vcsUrlPicker.setText(hd)
50
51 self.vcs = vcs
52
53 self.localPath = hd
54 self.networkPath = "localhost/"
55 self.localProtocol = True
56
57 ipath = Preferences.getMultiProject("Workspace") or \
58 Utilities.getHomeDir()
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(QDialogButtonBox.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_vcsProjectDirPicker_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.Ok).setEnabled(
80 bool(txt) and
81 Utilities.fromNativeSeparators(txt) not in self.__initPaths)
82
83 @pyqtSlot()
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.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(str)
113 def on_protocolCombo_activated(self, protocol):
114 """
115 Private slot to switch the status of the directory selection button.
116
117 @param protocol name of the selected protocol (string)
118 """
119 if protocol == "file://":
120 self.networkPath = self.vcsUrlPicker.text()
121 self.vcsUrlPicker.setText(self.localPath)
122 self.vcsUrlLabel.setText(self.tr("Pat&h:"))
123 self.localProtocol = True
124 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode)
125 else:
126 if self.localProtocol:
127 self.localPath = self.vcsUrlPicker.text()
128 self.vcsUrlPicker.setText(self.networkPath)
129 self.vcsUrlLabel.setText(self.tr("&URL:"))
130 self.localProtocol = False
131 self.vcsUrlPicker.setMode(E5PathPickerModes.CustomMode)
132
133 @pyqtSlot(str)
134 def on_vcsUrlPicker_textChanged(self, txt):
135 """
136 Private slot to handle changes of the URL.
137
138 @param txt current text of the line edit (string)
139 """
140 enable = "://" not in txt
141 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
142
143 def getData(self):
144 """
145 Public slot to retrieve the data entered into the dialog.
146
147 @return a tuple of a string (project directory) and a dictionary
148 containing the data entered.
149 """
150 scheme = self.protocolCombo.currentText()
151 url = self.vcsUrlPicker.text()
152 vcsdatadict = {
153 "url": '{0}{1}'.format(scheme, url),
154 "tag": self.vcsTagEdit.text(),
155 "standardLayout": self.layoutCheckBox.isChecked(),
156 }
157 return (self.vcsProjectDirPicker.text(), vcsdatadict)

eric ide

mercurial