Plugins/VcsPlugins/vcsGit/GitPullDialog.py

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

eric ide

mercurial