eric6/Plugins/VcsPlugins/vcsMercurial/HgAddSubrepositoryDialog.py

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

eric ide

mercurial