15 |
15 |
16 class GitPullDialog(QDialog, Ui_GitPullDialog): |
16 class GitPullDialog(QDialog, Ui_GitPullDialog): |
17 """ |
17 """ |
18 Class implementing a dialog to enter data for a Pull operation. |
18 Class implementing a dialog to enter data for a Pull 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 def __okButtonEnable(self): |
52 def __okButtonEnable(self): |
53 """ |
53 """ |
54 Private slot to set the enabled state of the OK button. |
54 Private slot to set the enabled state of the OK button. |
55 """ |
55 """ |
56 self.__okButton.setEnabled( |
56 self.__okButton.setEnabled( |
57 self.remoteBranchesList.count() > 0 or |
57 self.remoteBranchesList.count() > 0 |
58 self.remotesComboBox.currentText() == self.__all |
58 or self.remotesComboBox.currentText() == self.__all |
59 ) |
59 ) |
60 |
60 |
61 def __updateButtonEnable(self): |
61 def __updateButtonEnable(self): |
62 """ |
62 """ |
63 Private slot to set the enabled state of the update button. |
63 Private slot to set the enabled state of the update button. |
64 """ |
64 """ |
65 remote = self.remotesComboBox.currentText() |
65 remote = self.remotesComboBox.currentText() |
66 enable = remote != self.__all |
66 enable = remote != self.__all |
67 if remote == self.__custom: |
67 if remote == self.__custom: |
68 enable = self.remoteEdit.text() != "" |
68 enable = self.remoteEdit.text() != "" |
69 |
69 |
70 self.updateButton.setEnabled(enable) |
70 self.updateButton.setEnabled(enable) |
71 |
71 |
72 @pyqtSlot(str) |
72 @pyqtSlot(str) |
73 def on_remotesComboBox_currentTextChanged(self, txt): |
73 def on_remotesComboBox_currentTextChanged(self, txt): |
74 """ |
74 """ |
75 Private slot to handle changes of the selected repository. |
75 Private slot to handle changes of the selected repository. |
76 |
76 |
77 @param txt current text of the combo box (string) |
77 @param txt current text of the combo box (string) |
78 """ |
78 """ |
79 self.remoteEdit.setReadOnly(txt != self.__custom) |
79 self.remoteEdit.setReadOnly(txt != self.__custom) |
80 self.remoteBranchesList.setEnabled(txt != self.__all) |
80 self.remoteBranchesList.setEnabled(txt != self.__all) |
81 self.remoteEdit.clear() |
81 self.remoteEdit.clear() |
82 self.remoteBranchesList.clear() |
82 self.remoteBranchesList.clear() |
83 self.__updateButtonEnable() |
83 self.__updateButtonEnable() |
84 self.__okButtonEnable() |
84 self.__okButtonEnable() |
85 |
85 |
86 if txt not in [self.__all, self.__custom]: |
86 if txt not in [self.__all, self.__custom]: |
87 remoteBranches = self.__vcs.gitGetRemoteBranchesList( |
87 remoteBranches = self.__vcs.gitGetRemoteBranchesList(self.__repodir, txt) |
88 self.__repodir, txt) |
|
89 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
88 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
90 |
89 |
91 if txt in self.__repos: |
90 if txt in self.__repos: |
92 self.remoteEdit.setText(self.__repos[txt]) |
91 self.remoteEdit.setText(self.__repos[txt]) |
93 |
92 |
94 @pyqtSlot(str) |
93 @pyqtSlot(str) |
95 def on_remoteEdit_textChanged(self, txt): |
94 def on_remoteEdit_textChanged(self, txt): |
96 """ |
95 """ |
97 Private slot to handle changes of the URL edit. |
96 Private slot to handle changes of the URL edit. |
98 |
97 |
99 @param txt current text of the URL edit (string) |
98 @param txt current text of the URL edit (string) |
100 """ |
99 """ |
101 self.__updateButtonEnable() |
100 self.__updateButtonEnable() |
102 |
101 |
103 if ( |
102 if self.remotesComboBox.currentText() == self.__custom and txt != "": |
104 self.remotesComboBox.currentText() == self.__custom and |
103 remoteBranches = self.__vcs.gitGetRemoteBranchesList(self.__repodir, txt) |
105 txt != "" |
|
106 ): |
|
107 remoteBranches = self.__vcs.gitGetRemoteBranchesList( |
|
108 self.__repodir, txt) |
|
109 self.remoteBranchesList.clear() |
104 self.remoteBranchesList.clear() |
110 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
105 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
111 |
106 |
112 self.__okButtonEnable() |
107 self.__okButtonEnable() |
113 |
108 |
114 @pyqtSlot() |
109 @pyqtSlot() |
115 def on_updateButton_clicked(self): |
110 def on_updateButton_clicked(self): |
116 """ |
111 """ |
117 Private slot to update the list of remote branches. |
112 Private slot to update the list of remote branches. |
118 """ |
113 """ |
119 remote = self.remotesComboBox.currentText() |
114 remote = self.remotesComboBox.currentText() |
120 if remote == self.__all: |
115 if remote == self.__all: |
121 # shouldn't happen |
116 # shouldn't happen |
122 return |
117 return |
123 |
118 |
124 if remote == self.__custom: |
119 if remote == self.__custom: |
125 remote = self.remoteEdit.text() |
120 remote = self.remoteEdit.text() |
126 if remote == "": |
121 if remote == "": |
127 # shouldn't happen either |
122 # shouldn't happen either |
128 return |
123 return |
129 |
124 |
130 remoteBranches = self.__vcs.gitGetRemoteBranchesList( |
125 remoteBranches = self.__vcs.gitGetRemoteBranchesList(self.__repodir, remote) |
131 self.__repodir, remote) |
|
132 self.remoteBranchesList.clear() |
126 self.remoteBranchesList.clear() |
133 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
127 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
134 |
128 |
135 self.__okButtonEnable() |
129 self.__okButtonEnable() |
136 |
130 |
137 def getData(self): |
131 def getData(self): |
138 """ |
132 """ |
139 Public method to get the entered data. |
133 Public method to get the entered data. |
140 |
134 |
141 @return tuple of remote name, remote url (for custom remotes), |
135 @return tuple of remote name, remote url (for custom remotes), |
142 remote branches, a flag indicating to pull from all repositories |
136 remote branches, a flag indicating to pull from all repositories |
143 and a flag indicating to remove obsolete tracking references |
137 and a flag indicating to remove obsolete tracking references |
144 (string, string, list of strings, boolean, boolean) |
138 (string, string, list of strings, boolean, boolean) |
145 """ |
139 """ |
146 remote = "" |
140 remote = "" |
147 url = "" |
141 url = "" |
148 branches = [] |
142 branches = [] |
149 allRepos = False |
143 allRepos = False |
150 |
144 |
151 remoteRepo = self.remotesComboBox.currentText() |
145 remoteRepo = self.remotesComboBox.currentText() |
152 if remoteRepo == self.__all: |
146 if remoteRepo == self.__all: |
153 allRepos = True |
147 allRepos = True |
154 else: |
148 else: |
155 if remoteRepo == self.__custom: |
149 if remoteRepo == self.__custom: |
156 url = self.remoteEdit.text() |
150 url = self.remoteEdit.text() |
157 else: |
151 else: |
158 remote = remoteRepo |
152 remote = remoteRepo |
159 for itm in self.remoteBranchesList.selectedItems(): |
153 for itm in self.remoteBranchesList.selectedItems(): |
160 branches.append(itm.text()) |
154 branches.append(itm.text()) |
161 |
155 |
162 return remote, url, branches, allRepos, self.pruneCheckBox.isChecked() |
156 return remote, url, branches, allRepos, self.pruneCheckBox.isChecked() |