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