|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2022 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 PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.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 # connect various radio buttons and input fields |
|
54 self.id1Button.toggled.connect(self.__updateOK) |
|
55 self.tag1Button.toggled.connect(self.__updateOK) |
|
56 self.branch1Button.toggled.connect(self.__updateOK) |
|
57 self.bookmark1Button.toggled.connect(self.__updateOK) |
|
58 self.expression1Button.toggled.connect(self.__updateOK) |
|
59 self.id2Button.toggled.connect(self.__updateOK) |
|
60 self.tag2Button.toggled.connect(self.__updateOK) |
|
61 self.branch2Button.toggled.connect(self.__updateOK) |
|
62 self.bookmark2Button.toggled.connect(self.__updateOK) |
|
63 self.expression2Button.toggled.connect(self.__updateOK) |
|
64 |
|
65 self.id1Edit.textChanged.connect(self.__updateOK) |
|
66 self.expression1Edit.textChanged.connect(self.__updateOK) |
|
67 self.id2Edit.textChanged.connect(self.__updateOK) |
|
68 self.expression2Edit.textChanged.connect(self.__updateOK) |
|
69 |
|
70 self.tag1Combo.editTextChanged.connect(self.__updateOK) |
|
71 self.branch1Combo.editTextChanged.connect(self.__updateOK) |
|
72 self.bookmark1Combo.editTextChanged.connect(self.__updateOK) |
|
73 self.tag2Combo.editTextChanged.connect(self.__updateOK) |
|
74 self.branch2Combo.editTextChanged.connect(self.__updateOK) |
|
75 self.bookmark2Combo.editTextChanged.connect(self.__updateOK) |
|
76 |
|
77 msh = self.minimumSizeHint() |
|
78 self.resize(max(self.width(), msh.width()), msh.height()) |
|
79 |
|
80 @pyqtSlot() |
|
81 def __updateOK(self): |
|
82 """ |
|
83 Private slot to update the OK button. |
|
84 """ |
|
85 enabled = True |
|
86 if not self.parentButton.isChecked(): |
|
87 if self.id1Button.isChecked(): |
|
88 enabled = enabled and bool(self.id1Edit.text()) |
|
89 elif self.tag1Button.isChecked(): |
|
90 enabled = enabled and bool(self.tag1Combo.currentText()) |
|
91 elif self.branch1Button.isChecked(): |
|
92 enabled = enabled and bool(self.branch1Combo.currentText()) |
|
93 elif self.bookmark1Button.isChecked(): |
|
94 enabled = enabled and bool(self.bookmark1Combo.currentText()) |
|
95 elif self.expression1Button.isChecked(): |
|
96 enabled = enabled and bool(self.expression1Edit.text()) |
|
97 |
|
98 if self.id2Button.isChecked(): |
|
99 enabled = enabled and bool(self.id2Edit.text()) |
|
100 elif self.tag2Button.isChecked(): |
|
101 enabled = enabled and bool(self.tag2Combo.currentText()) |
|
102 elif self.branch2Button.isChecked(): |
|
103 enabled = enabled and bool(self.branch2Combo.currentText()) |
|
104 elif self.bookmark2Button.isChecked(): |
|
105 enabled = enabled and bool(self.bookmark2Combo.currentText()) |
|
106 elif self.expression2Button.isChecked(): |
|
107 enabled = enabled and bool(self.expression2Edit.text()) |
|
108 |
|
109 self.buttonBox.button( |
|
110 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) |
|
111 |
|
112 def __getRevision(self, no): |
|
113 """ |
|
114 Private method to generate the revision. |
|
115 |
|
116 @param no revision number to generate (1 or 2) |
|
117 @type int |
|
118 @return revision |
|
119 @rtype str |
|
120 """ |
|
121 if no == 1: |
|
122 numberButton = self.number1Button |
|
123 numberSpinBox = self.number1SpinBox |
|
124 idButton = self.id1Button |
|
125 idEdit = self.id1Edit |
|
126 tagButton = self.tag1Button |
|
127 tagCombo = self.tag1Combo |
|
128 branchButton = self.branch1Button |
|
129 branchCombo = self.branch1Combo |
|
130 bookmarkButton = self.bookmark1Button |
|
131 bookmarkCombo = self.bookmark1Combo |
|
132 expressionButton = self.expression1Button |
|
133 expressionEdit = self.expression1Edit |
|
134 tipButton = None |
|
135 else: |
|
136 numberButton = self.number2Button |
|
137 numberSpinBox = self.number2SpinBox |
|
138 idButton = self.id2Button |
|
139 idEdit = self.id2Edit |
|
140 tagButton = self.tag2Button |
|
141 tagCombo = self.tag2Combo |
|
142 branchButton = self.branch2Button |
|
143 branchCombo = self.branch2Combo |
|
144 bookmarkButton = self.bookmark2Button |
|
145 bookmarkCombo = self.bookmark2Combo |
|
146 expressionButton = self.expression2Button |
|
147 expressionEdit = self.expression2Edit |
|
148 tipButton = self.tip2Button |
|
149 |
|
150 if numberButton.isChecked(): |
|
151 return "rev({0})".format(numberSpinBox.value()) |
|
152 elif idButton.isChecked(): |
|
153 return "id({0})".format(idEdit.text()) |
|
154 elif tagButton.isChecked(): |
|
155 return tagCombo.currentText() |
|
156 elif branchButton.isChecked(): |
|
157 return branchCombo.currentText() |
|
158 elif bookmarkButton.isChecked(): |
|
159 return bookmarkCombo.currentText() |
|
160 elif expressionButton.isChecked(): |
|
161 return expressionEdit.text() |
|
162 elif tipButton and tipButton.isChecked(): |
|
163 return "" |
|
164 |
|
165 return "" |
|
166 |
|
167 def getData(self): |
|
168 """ |
|
169 Public method to retrieve the data for the rebase session. |
|
170 |
|
171 @return tuple with a source indicator of "S" or "B", the source |
|
172 revision, the destination revision, a flag indicating to collapse, |
|
173 a flag indicating to keep the original changesets, a flag |
|
174 indicating to keep the original branch name, a flag indicating |
|
175 to detach the source, a flag indicating to perform a dry-run only |
|
176 and a flag indicating to perform a dry-run first, than ask for |
|
177 confirmation |
|
178 @rtype tuple of (str, str, str, bool, bool, bool, bool, bool, bool) |
|
179 """ |
|
180 if self.sourceButton.isChecked(): |
|
181 indicator = "S" |
|
182 elif self.baseButton.isChecked(): |
|
183 indicator = "B" |
|
184 else: |
|
185 indicator = "" |
|
186 rev1 = self.__getRevision(1) if indicator else "" |
|
187 |
|
188 return ( |
|
189 indicator, |
|
190 rev1, |
|
191 self.__getRevision(2), |
|
192 self.collapseCheckBox.isChecked(), |
|
193 self.keepChangesetsCheckBox.isChecked(), |
|
194 self.keepBranchCheckBox.isChecked(), |
|
195 self.detachCheckBox.isChecked(), |
|
196 self.dryRunOnlyButton.isChecked(), |
|
197 self.dryRunConfirmButton.isChecked(), |
|
198 ) |