eric7/Plugins/VcsPlugins/vcsGit/GitPullDialog.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) 2015 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter data for a Pull operation.
8 """
9
10 from PyQt5.QtCore import pyqtSlot
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
12
13 from .Ui_GitPullDialog import Ui_GitPullDialog
14
15
16 class GitPullDialog(QDialog, Ui_GitPullDialog):
17 """
18 Class implementing a dialog to enter data for a Pull operation.
19 """
20 def __init__(self, vcs, repodir, parent=None):
21 """
22 Constructor
23
24 @param vcs reference to the git object
25 @param repodir directory name of the local repository (string)
26 @param parent reference to the parent widget (QWidget)
27 """
28 super().__init__(parent)
29 self.setupUi(self)
30
31 self.__vcs = vcs
32 self.__repodir = repodir
33
34 self.__all = self.tr("<All>")
35 self.__custom = self.tr("<Custom>")
36
37 remoteUrlsList = self.__vcs.gitGetRemoteUrlsList(self.__repodir)
38 self.__repos = {name: url for name, url in remoteUrlsList}
39
40 self.__okButton = self.buttonBox.button(
41 QDialogButtonBox.StandardButton.Ok)
42
43 self.remotesComboBox.addItems(sorted(self.__repos.keys()))
44 self.remotesComboBox.addItem(self.__all)
45 self.remotesComboBox.addItem(self.__custom)
46
47 index = self.remotesComboBox.findText("origin")
48 if index == -1:
49 index = 0
50 self.remotesComboBox.setCurrentIndex(index)
51
52 def __okButtonEnable(self):
53 """
54 Private slot to set the enabled state of the OK button.
55 """
56 self.__okButton.setEnabled(
57 self.remoteBranchesList.count() > 0 or
58 self.remotesComboBox.currentText() == self.__all
59 )
60
61 def __updateButtonEnable(self):
62 """
63 Private slot to set the enabled state of the update button.
64 """
65 remote = self.remotesComboBox.currentText()
66 enable = remote != self.__all
67 if remote == self.__custom:
68 enable = self.remoteEdit.text() != ""
69
70 self.updateButton.setEnabled(enable)
71
72 @pyqtSlot(str)
73 def on_remotesComboBox_currentTextChanged(self, txt):
74 """
75 Private slot to handle changes of the selected repository.
76
77 @param txt current text of the combo box (string)
78 """
79 self.remoteEdit.setReadOnly(txt != self.__custom)
80 self.remoteBranchesList.setEnabled(txt != self.__all)
81 self.remoteEdit.clear()
82 self.remoteBranchesList.clear()
83 self.__updateButtonEnable()
84 self.__okButtonEnable()
85
86 if txt not in [self.__all, self.__custom]:
87 remoteBranches = self.__vcs.gitGetRemoteBranchesList(
88 self.__repodir, txt)
89 self.remoteBranchesList.addItems(sorted(remoteBranches))
90
91 if txt in self.__repos:
92 self.remoteEdit.setText(self.__repos[txt])
93
94 @pyqtSlot(str)
95 def on_remoteEdit_textChanged(self, txt):
96 """
97 Private slot to handle changes of the URL edit.
98
99 @param txt current text of the URL edit (string)
100 """
101 self.__updateButtonEnable()
102
103 if (
104 self.remotesComboBox.currentText() == self.__custom and
105 txt != ""
106 ):
107 remoteBranches = self.__vcs.gitGetRemoteBranchesList(
108 self.__repodir, txt)
109 self.remoteBranchesList.clear()
110 self.remoteBranchesList.addItems(sorted(remoteBranches))
111
112 self.__okButtonEnable()
113
114 @pyqtSlot()
115 def on_updateButton_clicked(self):
116 """
117 Private slot to update the list of remote branches.
118 """
119 remote = self.remotesComboBox.currentText()
120 if remote == self.__all:
121 # shouldn't happen
122 return
123
124 if remote == self.__custom:
125 remote = self.remoteEdit.text()
126 if remote == "":
127 # shouldn't happen either
128 return
129
130 remoteBranches = self.__vcs.gitGetRemoteBranchesList(
131 self.__repodir, remote)
132 self.remoteBranchesList.clear()
133 self.remoteBranchesList.addItems(sorted(remoteBranches))
134
135 self.__okButtonEnable()
136
137 def getData(self):
138 """
139 Public method to get the entered data.
140
141 @return tuple of remote name, remote url (for custom remotes),
142 remote branches, a flag indicating to pull from all repositories
143 and a flag indicating to remove obsolete tracking references
144 (string, string, list of strings, boolean, boolean)
145 """
146 remote = ""
147 url = ""
148 branches = []
149 allRepos = False
150
151 remoteRepo = self.remotesComboBox.currentText()
152 if remoteRepo == self.__all:
153 allRepos = True
154 else:
155 if remoteRepo == self.__custom:
156 url = self.remoteEdit.text()
157 else:
158 remote = remoteRepo
159 for itm in self.remoteBranchesList.selectedItems():
160 branches.append(itm.text())
161
162 return remote, url, branches, allRepos, self.pruneCheckBox.isChecked()

eric ide

mercurial