src/eric7/Plugins/VcsPlugins/vcsGit/GitFetchDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 15
16 class GitFetchDialog(QDialog, Ui_GitFetchDialog): 16 class GitFetchDialog(QDialog, Ui_GitFetchDialog):
17 """ 17 """
18 Class implementing a dialog to enter data for a Fetch operation. 18 Class implementing a dialog to enter data for a Fetch operation.
19 """ 19 """
20
20 def __init__(self, vcs, repodir, parent=None): 21 def __init__(self, vcs, repodir, parent=None):
21 """ 22 """
22 Constructor 23 Constructor
23 24
24 @param vcs reference to the git object 25 @param vcs reference to the git object
25 @param repodir directory name of the local repository (string) 26 @param repodir directory name of the local repository (string)
26 @param parent reference to the parent widget (QWidget) 27 @param parent reference to the parent widget (QWidget)
27 """ 28 """
28 super().__init__(parent) 29 super().__init__(parent)
29 self.setupUi(self) 30 self.setupUi(self)
30 31
31 self.__vcs = vcs 32 self.__vcs = vcs
32 self.__repodir = repodir 33 self.__repodir = repodir
33 34
34 self.__all = self.tr("<All>") 35 self.__all = self.tr("<All>")
35 self.__custom = self.tr("<Custom>") 36 self.__custom = self.tr("<Custom>")
36 37
37 remoteUrlsList = self.__vcs.gitGetRemoteUrlsList(self.__repodir) 38 remoteUrlsList = self.__vcs.gitGetRemoteUrlsList(self.__repodir)
38 self.__repos = {name: url for name, url in remoteUrlsList} 39 self.__repos = {name: url for name, url in remoteUrlsList}
39 40
40 self.__okButton = self.buttonBox.button( 41 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
41 QDialogButtonBox.StandardButton.Ok) 42
42
43 self.remotesComboBox.addItems(sorted(self.__repos.keys())) 43 self.remotesComboBox.addItems(sorted(self.__repos.keys()))
44 self.remotesComboBox.addItem(self.__all) 44 self.remotesComboBox.addItem(self.__all)
45 self.remotesComboBox.addItem(self.__custom) 45 self.remotesComboBox.addItem(self.__custom)
46 46
47 index = self.remotesComboBox.findText("origin") 47 index = self.remotesComboBox.findText("origin")
48 if index == -1: 48 if index == -1:
49 index = 0 49 index = 0
50 self.remotesComboBox.setCurrentIndex(index) 50 self.remotesComboBox.setCurrentIndex(index)
51 51
52 localBranches = self.__vcs.gitGetBranchesList( 52 localBranches = self.__vcs.gitGetBranchesList(self.__repodir, withMaster=True)
53 self.__repodir, withMaster=True)
54 self.localBranchComboBox.addItems([""] + sorted(localBranches)) 53 self.localBranchComboBox.addItems([""] + sorted(localBranches))
55 self.localBranchComboBox.setEnabled(False) 54 self.localBranchComboBox.setEnabled(False)
56 55
57 def __okButtonEnable(self): 56 def __okButtonEnable(self):
58 """ 57 """
59 Private slot to set the enabled state of the OK button. 58 Private slot to set the enabled state of the OK button.
60 """ 59 """
61 self.__okButton.setEnabled( 60 self.__okButton.setEnabled(
62 self.remoteBranchesList.count() > 0 or 61 self.remoteBranchesList.count() > 0
63 self.remotesComboBox.currentText() == self.__all 62 or self.remotesComboBox.currentText() == self.__all
64 ) 63 )
65 64
66 def __updateButtonEnable(self): 65 def __updateButtonEnable(self):
67 """ 66 """
68 Private slot to set the enabled state of the update button. 67 Private slot to set the enabled state of the update button.
69 """ 68 """
70 remote = self.remotesComboBox.currentText() 69 remote = self.remotesComboBox.currentText()
71 enable = remote != self.__all 70 enable = remote != self.__all
72 if remote == self.__custom: 71 if remote == self.__custom:
73 enable = self.remoteEdit.text() != "" 72 enable = self.remoteEdit.text() != ""
74 73
75 self.updateButton.setEnabled(enable) 74 self.updateButton.setEnabled(enable)
76 75
77 @pyqtSlot(str) 76 @pyqtSlot(str)
78 def on_remotesComboBox_currentTextChanged(self, txt): 77 def on_remotesComboBox_currentTextChanged(self, txt):
79 """ 78 """
80 Private slot to handle changes of the selected repository. 79 Private slot to handle changes of the selected repository.
81 80
82 @param txt current text of the combo box (string) 81 @param txt current text of the combo box (string)
83 """ 82 """
84 self.remoteEdit.setReadOnly(txt != self.__custom) 83 self.remoteEdit.setReadOnly(txt != self.__custom)
85 self.remoteBranchesList.setEnabled(txt != self.__all) 84 self.remoteBranchesList.setEnabled(txt != self.__all)
86 self.remoteEdit.clear() 85 self.remoteEdit.clear()
87 self.remoteBranchesList.clear() 86 self.remoteBranchesList.clear()
88 self.__updateButtonEnable() 87 self.__updateButtonEnable()
89 self.__okButtonEnable() 88 self.__okButtonEnable()
90 89
91 if txt not in [self.__all, self.__custom]: 90 if txt not in [self.__all, self.__custom]:
92 remoteBranches = self.__vcs.gitGetRemoteBranchesList( 91 remoteBranches = self.__vcs.gitGetRemoteBranchesList(self.__repodir, txt)
93 self.__repodir, txt)
94 self.remoteBranchesList.addItems(sorted(remoteBranches)) 92 self.remoteBranchesList.addItems(sorted(remoteBranches))
95 93
96 if txt in self.__repos: 94 if txt in self.__repos:
97 self.remoteEdit.setText(self.__repos[txt]) 95 self.remoteEdit.setText(self.__repos[txt])
98 96
99 @pyqtSlot(str) 97 @pyqtSlot(str)
100 def on_remoteEdit_textChanged(self, txt): 98 def on_remoteEdit_textChanged(self, txt):
101 """ 99 """
102 Private slot to handle changes of the URL edit. 100 Private slot to handle changes of the URL edit.
103 101
104 @param txt current text of the URL edit (string) 102 @param txt current text of the URL edit (string)
105 """ 103 """
106 self.__updateButtonEnable() 104 self.__updateButtonEnable()
107 105
108 if ( 106 if self.remotesComboBox.currentText() == self.__custom and txt != "":
109 self.remotesComboBox.currentText() == self.__custom and 107 remoteBranches = self.__vcs.gitGetRemoteBranchesList(self.__repodir, txt)
110 txt != ""
111 ):
112 remoteBranches = self.__vcs.gitGetRemoteBranchesList(
113 self.__repodir, txt)
114 self.remoteBranchesList.clear() 108 self.remoteBranchesList.clear()
115 self.remoteBranchesList.addItems(sorted(remoteBranches)) 109 self.remoteBranchesList.addItems(sorted(remoteBranches))
116 110
117 self.__okButtonEnable() 111 self.__okButtonEnable()
118 112
119 @pyqtSlot() 113 @pyqtSlot()
120 def on_remoteBranchesList_itemSelectionChanged(self): 114 def on_remoteBranchesList_itemSelectionChanged(self):
121 """ 115 """
122 Private slot to handle a change of selected remote branches. 116 Private slot to handle a change of selected remote branches.
123 """ 117 """
124 singleSelection = len(self.remoteBranchesList.selectedItems()) == 1 118 singleSelection = len(self.remoteBranchesList.selectedItems()) == 1
125 self.localBranchComboBox.setEnabled(singleSelection) 119 self.localBranchComboBox.setEnabled(singleSelection)
126 txt = ( 120 txt = (
127 self.remoteBranchesList.selectedItems()[0].text() 121 self.remoteBranchesList.selectedItems()[0].text() if singleSelection else ""
128 if singleSelection else
129 ""
130 ) 122 )
131 index = self.localBranchComboBox.findText(txt) 123 index = self.localBranchComboBox.findText(txt)
132 if index == -1: 124 if index == -1:
133 self.localBranchComboBox.setEditText(txt) 125 self.localBranchComboBox.setEditText(txt)
134 else: 126 else:
135 self.localBranchComboBox.setCurrentIndex(index) 127 self.localBranchComboBox.setCurrentIndex(index)
136 128
137 @pyqtSlot() 129 @pyqtSlot()
138 def on_updateButton_clicked(self): 130 def on_updateButton_clicked(self):
139 """ 131 """
140 Private slot to update the list of remote branches. 132 Private slot to update the list of remote branches.
141 """ 133 """
142 remote = self.remotesComboBox.currentText() 134 remote = self.remotesComboBox.currentText()
143 if remote == self.__all: 135 if remote == self.__all:
144 # shouldn't happen 136 # shouldn't happen
145 return 137 return
146 138
147 if remote == self.__custom: 139 if remote == self.__custom:
148 remote = self.remoteEdit.text() 140 remote = self.remoteEdit.text()
149 if remote == "": 141 if remote == "":
150 # shouldn't happen either 142 # shouldn't happen either
151 return 143 return
152 144
153 remoteBranches = self.__vcs.gitGetRemoteBranchesList( 145 remoteBranches = self.__vcs.gitGetRemoteBranchesList(self.__repodir, remote)
154 self.__repodir, remote)
155 self.remoteBranchesList.clear() 146 self.remoteBranchesList.clear()
156 self.remoteBranchesList.addItems(sorted(remoteBranches)) 147 self.remoteBranchesList.addItems(sorted(remoteBranches))
157 148
158 self.__okButtonEnable() 149 self.__okButtonEnable()
159 150
160 def getData(self): 151 def getData(self):
161 """ 152 """
162 Public method to get the entered data. 153 Public method to get the entered data.
163 154
164 @return tuple of remote name, remote url (for custom remotes), 155 @return tuple of remote name, remote url (for custom remotes),
165 remote branches, local branch, a flag indicating to fetch from 156 remote branches, local branch, a flag indicating to fetch from
166 all repositories, a flag indicating to remove obsolete tracking 157 all repositories, a flag indicating to remove obsolete tracking
167 references and a flag indicating to fetch tags as well 158 references and a flag indicating to fetch tags as well
168 (string, string, list of strings, string, boolean, boolean, 159 (string, string, list of strings, string, boolean, boolean,
171 remote = "" 162 remote = ""
172 url = "" 163 url = ""
173 remoteBranches = [] 164 remoteBranches = []
174 allRepos = False 165 allRepos = False
175 localBranch = "" 166 localBranch = ""
176 167
177 remoteRepo = self.remotesComboBox.currentText() 168 remoteRepo = self.remotesComboBox.currentText()
178 if remoteRepo == self.__all: 169 if remoteRepo == self.__all:
179 allRepos = True 170 allRepos = True
180 else: 171 else:
181 if remoteRepo == self.__custom: 172 if remoteRepo == self.__custom:
184 remote = remoteRepo 175 remote = remoteRepo
185 for itm in self.remoteBranchesList.selectedItems(): 176 for itm in self.remoteBranchesList.selectedItems():
186 remoteBranches.append(itm.text()) 177 remoteBranches.append(itm.text())
187 if len(remoteBranches) == 1: 178 if len(remoteBranches) == 1:
188 localBranch = self.localBranchComboBox.currentText() 179 localBranch = self.localBranchComboBox.currentText()
189 180
190 return (remote, url, remoteBranches, localBranch, allRepos, 181 return (
191 self.pruneCheckBox.isChecked(), self.tagsCheckBox.isChecked()) 182 remote,
183 url,
184 remoteBranches,
185 localBranch,
186 allRepos,
187 self.pruneCheckBox.isChecked(),
188 self.tagsCheckBox.isChecked(),
189 )

eric ide

mercurial