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