eric7/Plugins/VcsPlugins/vcsMercurial/HgAddSubrepositoryDialog.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) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to add a sub-repository.
8 """
9
10 import os
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
14
15 from E5Gui import E5MessageBox
16 from E5Gui.E5PathPicker import E5PathPickerModes
17
18 import Utilities
19
20 from .Ui_HgAddSubrepositoryDialog import Ui_HgAddSubrepositoryDialog
21
22
23 class HgAddSubrepositoryDialog(QDialog, Ui_HgAddSubrepositoryDialog):
24 """
25 Class implementing a dialog to add a sub-repository.
26 """
27 def __init__(self, projectPath, parent=None):
28 """
29 Constructor
30
31 @param projectPath project directory name (string)
32 @param parent reference to the parent widget (QWidget)
33 """
34 super().__init__(parent)
35 self.setupUi(self)
36
37 self.pathPicker.setMode(E5PathPickerModes.DirectoryMode)
38 self.pathPicker.setDefaultDirectory(projectPath)
39
40 self.__ok = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
41 self.__ok.setEnabled(False)
42
43 self.__projectPath = Utilities.toNativeSeparators(projectPath)
44
45 self.typeCombo.addItem("Mercurial", "hg")
46 self.typeCombo.addItem("GIT", "git")
47 self.typeCombo.addItem("Subversion", "svn")
48
49 msh = self.minimumSizeHint()
50 self.resize(max(self.width(), msh.width()), msh.height())
51
52 def __updateOk(self):
53 """
54 Private slot to update the state of the OK button.
55 """
56 path = self.pathPicker.text()
57 url = self.urlEdit.text()
58
59 self.__ok.setEnabled(
60 path != "" and
61 not os.path.isabs(path) and
62 url != ""
63 )
64
65 @pyqtSlot(str)
66 def on_pathPicker_textChanged(self, p0):
67 """
68 Private slot to handle the update of the path.
69
70 @param p0 text of the path edit (string)
71 """
72 self.__updateOk()
73
74 @pyqtSlot(str)
75 def on_urlEdit_textChanged(self, p0):
76 """
77 Private slot to handle the update of the URL.
78
79 @param p0 text of the URL edit (string)
80 """
81 self.__updateOk()
82
83 @pyqtSlot(str)
84 def on_pathPicker_pathSelected(self, path):
85 """
86 Private slot handling the selection of a subrepository path.
87
88 @param path path of the subrepository
89 @type str
90 """
91 if path.startswith(self.__projectPath + os.sep):
92 path = path.replace(self.__projectPath + os.sep, "")
93 self.pathPicker.setText(path)
94 else:
95 E5MessageBox.critical(
96 self,
97 self.tr("Add Sub-repository"),
98 self.tr("""The sub-repository path must be inside"""
99 """ the project."""))
100 self.pathPicker.setText("")
101
102 def getData(self):
103 """
104 Public method to get the data.
105
106 @return tuple containing the relative path within the project, the
107 sub-repository type and the sub-repository URL (string, string,
108 string)
109 """
110 return (
111 self.pathPicker.text(),
112 self.typeCombo.itemData(self.typeCombo.currentIndex()),
113 self.urlEdit.text()
114 )

eric ide

mercurial