|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data for a rebase session. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QButtonGroup |
|
12 |
|
13 from .Ui_HgRebaseDialog import Ui_HgRebaseDialog |
|
14 |
|
15 |
|
16 class HgRebaseDialog(QDialog, Ui_HgRebaseDialog): |
|
17 """ |
|
18 Class implementing a dialog to enter the data for a rebase session. |
|
19 """ |
|
20 def __init__(self, tagsList, branchesList, bookmarksList, version, |
|
21 parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param tagsList list of tags |
|
26 @type list of str |
|
27 @param branchesList list of branches |
|
28 @type list of str |
|
29 @param bookmarksList list of bookmarks |
|
30 @type list of str |
|
31 @param version tuple giving the Mercurial version |
|
32 @type tuple of int |
|
33 @param parent reference to the parent widget |
|
34 @type QWidget |
|
35 """ |
|
36 super().__init__(parent) |
|
37 self.setupUi(self) |
|
38 |
|
39 self.__sourceRevisionButtonGroup = QButtonGroup(self) |
|
40 self.__sourceRevisionButtonGroup.addButton(self.parentButton) |
|
41 self.__sourceRevisionButtonGroup.addButton(self.sourceButton) |
|
42 self.__sourceRevisionButtonGroup.addButton(self.baseButton) |
|
43 |
|
44 self.tag1Combo.addItems(sorted(tagsList)) |
|
45 self.tag2Combo.addItems(sorted(tagsList)) |
|
46 self.branch1Combo.addItems(["default"] + sorted(branchesList)) |
|
47 self.branch2Combo.addItems(["default"] + sorted(branchesList)) |
|
48 self.bookmark1Combo.addItems(sorted(bookmarksList)) |
|
49 self.bookmark2Combo.addItems(sorted(bookmarksList)) |
|
50 |
|
51 self.dryRunGroup.setEnabled(version >= (4, 7, 0)) |
|
52 |
|
53 msh = self.minimumSizeHint() |
|
54 self.resize(max(self.width(), msh.width()), msh.height()) |
|
55 |
|
56 def __updateOK(self): |
|
57 """ |
|
58 Private slot to update the OK button. |
|
59 """ |
|
60 enabled = True |
|
61 if not self.parentButton.isChecked(): |
|
62 if self.id1Button.isChecked(): |
|
63 enabled = enabled and self.id1Edit.text() != "" |
|
64 elif self.tag1Button.isChecked(): |
|
65 enabled = enabled and self.tag1Combo.currentText() != "" |
|
66 elif self.branch1Button.isChecked(): |
|
67 enabled = enabled and self.branch1Combo.currentText() != "" |
|
68 elif self.bookmark1Button.isChecked(): |
|
69 enabled = enabled and self.bookmark1Combo.currentText() != "" |
|
70 |
|
71 if self.id2Button.isChecked(): |
|
72 enabled = enabled and self.id2Edit.text() != "" |
|
73 elif self.tag2Button.isChecked(): |
|
74 enabled = enabled and self.tag2Combo.currentText() != "" |
|
75 elif self.branch2Button.isChecked(): |
|
76 enabled = enabled and self.branch2Combo.currentText() != "" |
|
77 elif self.bookmark2Button.isChecked(): |
|
78 enabled = enabled and self.bookmark2Combo.currentText() != "" |
|
79 |
|
80 self.buttonBox.button( |
|
81 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) |
|
82 |
|
83 @pyqtSlot(bool) |
|
84 def on_id1Button_toggled(self, checked): |
|
85 """ |
|
86 Private slot to handle changes of the ID1 select button. |
|
87 |
|
88 @param checked state of the button (boolean) |
|
89 """ |
|
90 self.__updateOK() |
|
91 |
|
92 @pyqtSlot(bool) |
|
93 def on_id2Button_toggled(self, checked): |
|
94 """ |
|
95 Private slot to handle changes of the ID2 select button. |
|
96 |
|
97 @param checked state of the button (boolean) |
|
98 """ |
|
99 self.__updateOK() |
|
100 |
|
101 @pyqtSlot(bool) |
|
102 def on_tag1Button_toggled(self, checked): |
|
103 """ |
|
104 Private slot to handle changes of the Tag1 select button. |
|
105 |
|
106 @param checked state of the button (boolean) |
|
107 """ |
|
108 self.__updateOK() |
|
109 |
|
110 @pyqtSlot(bool) |
|
111 def on_tag2Button_toggled(self, checked): |
|
112 """ |
|
113 Private slot to handle changes of the Tag2 select button. |
|
114 |
|
115 @param checked state of the button (boolean) |
|
116 """ |
|
117 self.__updateOK() |
|
118 |
|
119 @pyqtSlot(bool) |
|
120 def on_branch1Button_toggled(self, checked): |
|
121 """ |
|
122 Private slot to handle changes of the Branch1 select button. |
|
123 |
|
124 @param checked state of the button (boolean) |
|
125 """ |
|
126 self.__updateOK() |
|
127 |
|
128 @pyqtSlot(bool) |
|
129 def on_branch2Button_toggled(self, checked): |
|
130 """ |
|
131 Private slot to handle changes of the Branch2 select button. |
|
132 |
|
133 @param checked state of the button (boolean) |
|
134 """ |
|
135 self.__updateOK() |
|
136 |
|
137 @pyqtSlot(bool) |
|
138 def on_bookmark1Button_toggled(self, checked): |
|
139 """ |
|
140 Private slot to handle changes of the Bookmark1 select button. |
|
141 |
|
142 @param checked state of the button (boolean) |
|
143 """ |
|
144 self.__updateOK() |
|
145 |
|
146 @pyqtSlot(bool) |
|
147 def on_bookmark2Button_toggled(self, checked): |
|
148 """ |
|
149 Private slot to handle changes of the Bookmark2 select button. |
|
150 |
|
151 @param checked state of the button (boolean) |
|
152 """ |
|
153 self.__updateOK() |
|
154 |
|
155 @pyqtSlot(str) |
|
156 def on_id1Edit_textChanged(self, txt): |
|
157 """ |
|
158 Private slot to handle changes of the ID1 edit. |
|
159 |
|
160 @param txt text of the edit (string) |
|
161 """ |
|
162 self.__updateOK() |
|
163 |
|
164 @pyqtSlot(str) |
|
165 def on_id2Edit_textChanged(self, txt): |
|
166 """ |
|
167 Private slot to handle changes of the ID2 edit. |
|
168 |
|
169 @param txt text of the edit (string) |
|
170 """ |
|
171 self.__updateOK() |
|
172 |
|
173 @pyqtSlot(str) |
|
174 def on_tag1Combo_editTextChanged(self, txt): |
|
175 """ |
|
176 Private slot to handle changes of the Tag1 combo. |
|
177 |
|
178 @param txt text of the combo (string) |
|
179 """ |
|
180 self.__updateOK() |
|
181 |
|
182 @pyqtSlot(str) |
|
183 def on_tag2Combo_editTextChanged(self, txt): |
|
184 """ |
|
185 Private slot to handle changes of the Tag2 combo. |
|
186 |
|
187 @param txt text of the combo (string) |
|
188 """ |
|
189 self.__updateOK() |
|
190 |
|
191 @pyqtSlot(str) |
|
192 def on_branch1Combo_editTextChanged(self, txt): |
|
193 """ |
|
194 Private slot to handle changes of the Branch1 combo. |
|
195 |
|
196 @param txt text of the combo (string) |
|
197 """ |
|
198 self.__updateOK() |
|
199 |
|
200 @pyqtSlot(str) |
|
201 def on_branch2Combo_editTextChanged(self, txt): |
|
202 """ |
|
203 Private slot to handle changes of the Branch2 combo. |
|
204 |
|
205 @param txt text of the combo (string) |
|
206 """ |
|
207 self.__updateOK() |
|
208 |
|
209 @pyqtSlot(str) |
|
210 def on_bookmark1Combo_editTextChanged(self, txt): |
|
211 """ |
|
212 Private slot to handle changes of the Bookmark1 combo. |
|
213 |
|
214 @param txt text of the combo (string) |
|
215 """ |
|
216 self.__updateOK() |
|
217 |
|
218 @pyqtSlot(str) |
|
219 def on_bookmark2Combo_editTextChanged(self, txt): |
|
220 """ |
|
221 Private slot to handle changes of the Bookmark2 combo. |
|
222 |
|
223 @param txt text of the combo (string) |
|
224 """ |
|
225 self.__updateOK() |
|
226 |
|
227 def __getRevision(self, no): |
|
228 """ |
|
229 Private method to generate the revision. |
|
230 |
|
231 @param no revision number to generate (1 or 2) |
|
232 @return revision (string) |
|
233 """ |
|
234 if no == 1: |
|
235 numberButton = self.number1Button |
|
236 numberSpinBox = self.number1SpinBox |
|
237 idButton = self.id1Button |
|
238 idEdit = self.id1Edit |
|
239 tagButton = self.tag1Button |
|
240 tagCombo = self.tag1Combo |
|
241 branchButton = self.branch1Button |
|
242 branchCombo = self.branch1Combo |
|
243 bookmarkButton = self.bookmark1Button |
|
244 bookmarkCombo = self.bookmark1Combo |
|
245 tipButton = None |
|
246 else: |
|
247 numberButton = self.number2Button |
|
248 numberSpinBox = self.number2SpinBox |
|
249 idButton = self.id2Button |
|
250 idEdit = self.id2Edit |
|
251 tagButton = self.tag2Button |
|
252 tagCombo = self.tag2Combo |
|
253 branchButton = self.branch2Button |
|
254 branchCombo = self.branch2Combo |
|
255 bookmarkButton = self.bookmark2Button |
|
256 bookmarkCombo = self.bookmark2Combo |
|
257 tipButton = self.tip2Button |
|
258 |
|
259 if numberButton.isChecked(): |
|
260 return "rev({0})".format(numberSpinBox.value()) |
|
261 elif idButton.isChecked(): |
|
262 return "id({0})".format(idEdit.text()) |
|
263 elif tagButton.isChecked(): |
|
264 return tagCombo.currentText() |
|
265 elif branchButton.isChecked(): |
|
266 return branchCombo.currentText() |
|
267 elif bookmarkButton.isChecked(): |
|
268 return bookmarkCombo.currentText() |
|
269 elif tipButton and tipButton.isChecked(): |
|
270 return "" |
|
271 |
|
272 return "" |
|
273 |
|
274 def getData(self): |
|
275 """ |
|
276 Public method to retrieve the data for the rebase session. |
|
277 |
|
278 @return tuple with a source indicator of "S" or "B", the source |
|
279 revision, the destination revision, a flag indicating to collapse, |
|
280 a flag indicating to keep the original changesets, a flag |
|
281 indicating to keep the original branch name, a flag indicating |
|
282 to detach the source, a flag indicating to perform a dry-run only |
|
283 and a flag indicating to perform a dry-run first, than ask for |
|
284 confirmation |
|
285 @rtype tuple of (str, str, str, bool, bool, bool, bool, bool, bool) |
|
286 """ |
|
287 if self.sourceButton.isChecked(): |
|
288 indicator = "S" |
|
289 elif self.baseButton.isChecked(): |
|
290 indicator = "B" |
|
291 else: |
|
292 indicator = "" |
|
293 rev1 = self.__getRevision(1) if indicator else "" |
|
294 |
|
295 return ( |
|
296 indicator, |
|
297 rev1, |
|
298 self.__getRevision(2), |
|
299 self.collapseCheckBox.isChecked(), |
|
300 self.keepChangesetsCheckBox.isChecked(), |
|
301 self.keepBranchCheckBox.isChecked(), |
|
302 self.detachCheckBox.isChecked(), |
|
303 self.dryRunOnlyButton.isChecked(), |
|
304 self.dryRunConfirmButton.isChecked(), |
|
305 ) |