21 |
19 |
22 class HgQueuesDefineGuardsDialog(QDialog, Ui_HgQueuesDefineGuardsDialog): |
20 class HgQueuesDefineGuardsDialog(QDialog, Ui_HgQueuesDefineGuardsDialog): |
23 """ |
21 """ |
24 Class implementing a dialog to define guards for patches. |
22 Class implementing a dialog to define guards for patches. |
25 """ |
23 """ |
|
24 |
26 def __init__(self, vcs, extension, patchesList, parent=None): |
25 def __init__(self, vcs, extension, patchesList, parent=None): |
27 """ |
26 """ |
28 Constructor |
27 Constructor |
29 |
28 |
30 @param vcs reference to the vcs object |
29 @param vcs reference to the vcs object |
31 @param extension reference to the extension module (Queues) |
30 @param extension reference to the extension module (Queues) |
32 @param patchesList list of patches (list of strings) |
31 @param patchesList list of patches (list of strings) |
33 @param parent reference to the parent widget (QWidget) |
32 @param parent reference to the parent widget (QWidget) |
34 """ |
33 """ |
35 super().__init__(parent) |
34 super().__init__(parent) |
36 self.setupUi(self) |
35 self.setupUi(self) |
37 self.setWindowFlags(Qt.WindowType.Window) |
36 self.setWindowFlags(Qt.WindowType.Window) |
38 |
37 |
39 self.vcs = vcs |
38 self.vcs = vcs |
40 self.extension = extension |
39 self.extension = extension |
41 self.__hgClient = vcs.getClient() |
40 self.__hgClient = vcs.getClient() |
42 |
41 |
43 self.__patches = patchesList[:] |
42 self.__patches = patchesList[:] |
44 self.patchSelector.addItems([""] + self.__patches) |
43 self.patchSelector.addItems([""] + self.__patches) |
45 |
44 |
46 self.plusButton.setIcon(UI.PixmapCache.getIcon("plus")) |
45 self.plusButton.setIcon(UI.PixmapCache.getIcon("plus")) |
47 self.minusButton.setIcon(UI.PixmapCache.getIcon("minus")) |
46 self.minusButton.setIcon(UI.PixmapCache.getIcon("minus")) |
48 |
47 |
49 self.__dirtyList = False |
48 self.__dirtyList = False |
50 self.__currentPatch = "" |
49 self.__currentPatch = "" |
51 |
50 |
52 self.show() |
51 self.show() |
53 QCoreApplication.processEvents() |
52 QCoreApplication.processEvents() |
54 |
53 |
55 def closeEvent(self, e): |
54 def closeEvent(self, e): |
56 """ |
55 """ |
57 Protected slot implementing a close event handler. |
56 Protected slot implementing a close event handler. |
58 |
57 |
59 @param e close event (QCloseEvent) |
58 @param e close event (QCloseEvent) |
60 """ |
59 """ |
61 if self.__hgClient.isExecuting(): |
60 if self.__hgClient.isExecuting(): |
62 self.__hgClient.cancel() |
61 self.__hgClient.cancel() |
63 |
62 |
64 if self.__dirtyList: |
63 if self.__dirtyList: |
65 res = EricMessageBox.question( |
64 res = EricMessageBox.question( |
66 self, |
65 self, |
67 self.tr("Unsaved Changes"), |
66 self.tr("Unsaved Changes"), |
68 self.tr("""The guards list has been changed.""" |
67 self.tr( |
69 """ Shall the changes be applied?"""), |
68 """The guards list has been changed.""" |
|
69 """ Shall the changes be applied?""" |
|
70 ), |
70 EricMessageBox.Apply | EricMessageBox.Discard, |
71 EricMessageBox.Apply | EricMessageBox.Discard, |
71 EricMessageBox.Apply) |
72 EricMessageBox.Apply, |
|
73 ) |
72 if res == EricMessageBox.Apply: |
74 if res == EricMessageBox.Apply: |
73 self.__applyGuards() |
75 self.__applyGuards() |
74 else: |
76 else: |
75 self.__dirtyList = False |
77 self.__dirtyList = False |
76 |
78 |
77 e.accept() |
79 e.accept() |
78 |
80 |
79 def start(self): |
81 def start(self): |
80 """ |
82 """ |
81 Public slot to start the list command. |
83 Public slot to start the list command. |
82 """ |
84 """ |
83 self.on_patchSelector_activated(0) |
85 self.on_patchSelector_activated(0) |
84 |
86 |
85 @pyqtSlot(int) |
87 @pyqtSlot(int) |
86 def on_patchSelector_activated(self, index): |
88 def on_patchSelector_activated(self, index): |
87 """ |
89 """ |
88 Private slot to get the list of guards defined for the given patch |
90 Private slot to get the list of guards defined for the given patch |
89 name. |
91 name. |
90 |
92 |
91 @param index index of the selected entry |
93 @param index index of the selected entry |
92 @type int |
94 @type int |
93 """ |
95 """ |
94 patch = self.patchSelector.itemText(index) |
96 patch = self.patchSelector.itemText(index) |
95 if self.__dirtyList: |
97 if self.__dirtyList: |
96 res = EricMessageBox.question( |
98 res = EricMessageBox.question( |
97 self, |
99 self, |
98 self.tr("Unsaved Changes"), |
100 self.tr("Unsaved Changes"), |
99 self.tr("""The guards list has been changed.""" |
101 self.tr( |
100 """ Shall the changes be applied?"""), |
102 """The guards list has been changed.""" |
|
103 """ Shall the changes be applied?""" |
|
104 ), |
101 EricMessageBox.Apply | EricMessageBox.Discard, |
105 EricMessageBox.Apply | EricMessageBox.Discard, |
102 EricMessageBox.Apply) |
106 EricMessageBox.Apply, |
|
107 ) |
103 if res == EricMessageBox.Apply: |
108 if res == EricMessageBox.Apply: |
104 self.__applyGuards() |
109 self.__applyGuards() |
105 else: |
110 else: |
106 self.__dirtyList = False |
111 self.__dirtyList = False |
107 |
112 |
108 self.guardsList.clear() |
113 self.guardsList.clear() |
109 self.patchNameLabel.setText("") |
114 self.patchNameLabel.setText("") |
110 |
115 |
111 self.guardCombo.clear() |
116 self.guardCombo.clear() |
112 guardsList = self.extension.getGuardsList() |
117 guardsList = self.extension.getGuardsList() |
113 self.guardCombo.addItems(guardsList) |
118 self.guardCombo.addItems(guardsList) |
114 self.guardCombo.setEditText("") |
119 self.guardCombo.setEditText("") |
115 |
120 |
116 args = self.vcs.initCommand("qguard") |
121 args = self.vcs.initCommand("qguard") |
117 if patch: |
122 if patch: |
118 args.append(patch) |
123 args.append(patch) |
119 |
124 |
120 output = self.__hgClient.runcommand(args)[0] |
125 output = self.__hgClient.runcommand(args)[0] |
121 |
126 |
122 if output: |
127 if output: |
123 patchName, guards = output.split(":", 1) |
128 patchName, guards = output.split(":", 1) |
124 self.patchNameLabel.setText(patchName) |
129 self.patchNameLabel.setText(patchName) |
125 guardsList = guards.strip().split() |
130 guardsList = guards.strip().split() |
126 for guard in guardsList: |
131 for guard in guardsList: |
134 sign = "-" |
139 sign = "-" |
135 else: |
140 else: |
136 continue |
141 continue |
137 itm = QListWidgetItem(icon, guard, self.guardsList) |
142 itm = QListWidgetItem(icon, guard, self.guardsList) |
138 itm.setData(Qt.ItemDataRole.UserRole, sign) |
143 itm.setData(Qt.ItemDataRole.UserRole, sign) |
139 |
144 |
140 self.on_guardsList_itemSelectionChanged() |
145 self.on_guardsList_itemSelectionChanged() |
141 |
146 |
142 @pyqtSlot() |
147 @pyqtSlot() |
143 def on_guardsList_itemSelectionChanged(self): |
148 def on_guardsList_itemSelectionChanged(self): |
144 """ |
149 """ |
145 Private slot to handle changes of the selection of guards. |
150 Private slot to handle changes of the selection of guards. |
146 """ |
151 """ |
147 self.removeButton.setEnabled( |
152 self.removeButton.setEnabled(len(self.guardsList.selectedItems()) > 0) |
148 len(self.guardsList.selectedItems()) > 0) |
153 |
149 |
|
150 def __getGuard(self, guard): |
154 def __getGuard(self, guard): |
151 """ |
155 """ |
152 Private method to get a reference to a named guard. |
156 Private method to get a reference to a named guard. |
153 |
157 |
154 @param guard name of the guard (string) |
158 @param guard name of the guard (string) |
155 @return reference to the guard item (QListWidgetItem) |
159 @return reference to the guard item (QListWidgetItem) |
156 """ |
160 """ |
157 items = self.guardsList.findItems( |
161 items = self.guardsList.findItems(guard, Qt.MatchFlag.MatchCaseSensitive) |
158 guard, Qt.MatchFlag.MatchCaseSensitive) |
|
159 if items: |
162 if items: |
160 return items[0] |
163 return items[0] |
161 else: |
164 else: |
162 return None |
165 return None |
163 |
166 |
164 @pyqtSlot(str) |
167 @pyqtSlot(str) |
165 def on_guardCombo_editTextChanged(self, txt): |
168 def on_guardCombo_editTextChanged(self, txt): |
166 """ |
169 """ |
167 Private slot to handle changes of the text of the guard combo. |
170 Private slot to handle changes of the text of the guard combo. |
168 |
171 |
169 @param txt contents of the guard combo line edit (string) |
172 @param txt contents of the guard combo line edit (string) |
170 """ |
173 """ |
171 self.addButton.setEnabled(txt != "") |
174 self.addButton.setEnabled(txt != "") |
172 |
175 |
173 @pyqtSlot() |
176 @pyqtSlot() |
174 def on_addButton_clicked(self): |
177 def on_addButton_clicked(self): |
175 """ |
178 """ |
176 Private slot to add a guard definition to the list or change it. |
179 Private slot to add a guard definition to the list or change it. |
177 """ |
180 """ |
180 sign = "+" |
183 sign = "+" |
181 icon = UI.PixmapCache.getIcon("plus") |
184 icon = UI.PixmapCache.getIcon("plus") |
182 else: |
185 else: |
183 sign = "-" |
186 sign = "-" |
184 icon = UI.PixmapCache.getIcon("minus") |
187 icon = UI.PixmapCache.getIcon("minus") |
185 |
188 |
186 guardItem = self.__getGuard(guard) |
189 guardItem = self.__getGuard(guard) |
187 if guardItem: |
190 if guardItem: |
188 # guard already exists, remove it first |
191 # guard already exists, remove it first |
189 row = self.guardsList.row(guardItem) |
192 row = self.guardsList.row(guardItem) |
190 itm = self.guardsList.takeItem(row) |
193 itm = self.guardsList.takeItem(row) |
191 del itm |
194 del itm |
192 |
195 |
193 itm = QListWidgetItem(icon, guard, self.guardsList) |
196 itm = QListWidgetItem(icon, guard, self.guardsList) |
194 itm.setData(Qt.ItemDataRole.UserRole, sign) |
197 itm.setData(Qt.ItemDataRole.UserRole, sign) |
195 self.guardsList.sortItems() |
198 self.guardsList.sortItems() |
196 |
199 |
197 self.__dirtyList = True |
200 self.__dirtyList = True |
198 |
201 |
199 @pyqtSlot() |
202 @pyqtSlot() |
200 def on_removeButton_clicked(self): |
203 def on_removeButton_clicked(self): |
201 """ |
204 """ |
202 Private slot to remove guard definitions from the list. |
205 Private slot to remove guard definitions from the list. |
203 """ |
206 """ |
204 res = EricMessageBox.yesNo( |
207 res = EricMessageBox.yesNo( |
205 self, |
208 self, |
206 self.tr("Remove Guards"), |
209 self.tr("Remove Guards"), |
207 self.tr( |
210 self.tr("""Do you really want to remove the selected guards?"""), |
208 """Do you really want to remove the selected guards?""")) |
211 ) |
209 if res: |
212 if res: |
210 for guardItem in self.guardsList.selectedItems(): |
213 for guardItem in self.guardsList.selectedItems(): |
211 row = self.guardsList.row(guardItem) |
214 row = self.guardsList.row(guardItem) |
212 itm = self.guardsList.takeItem(row) # __IGNORE_WARNING__ |
215 itm = self.guardsList.takeItem(row) # __IGNORE_WARNING__ |
213 del itm |
216 del itm |
214 |
217 |
215 self.__dirtyList = True |
218 self.__dirtyList = True |
216 |
219 |
217 @pyqtSlot(QAbstractButton) |
220 @pyqtSlot(QAbstractButton) |
218 def on_buttonBox_clicked(self, button): |
221 def on_buttonBox_clicked(self, button): |
219 """ |
222 """ |
220 Private slot called by a button of the button box clicked. |
223 Private slot called by a button of the button box clicked. |
221 |
224 |
222 @param button button that was clicked (QAbstractButton) |
225 @param button button that was clicked (QAbstractButton) |
223 """ |
226 """ |
224 if button == self.buttonBox.button( |
227 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Apply): |
225 QDialogButtonBox.StandardButton.Apply |
|
226 ): |
|
227 self.__applyGuards() |
228 self.__applyGuards() |
228 elif button == self.buttonBox.button( |
229 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
229 QDialogButtonBox.StandardButton.Close |
|
230 ): |
|
231 self.close() |
230 self.close() |
232 |
231 |
233 @pyqtSlot() |
232 @pyqtSlot() |
234 def __applyGuards(self): |
233 def __applyGuards(self): |
235 """ |
234 """ |
236 Private slot to apply the defined guards to the current patch. |
235 Private slot to apply the defined guards to the current patch. |
237 """ |
236 """ |
239 guardsList = [] |
238 guardsList = [] |
240 for row in range(self.guardsList.count()): |
239 for row in range(self.guardsList.count()): |
241 itm = self.guardsList.item(row) |
240 itm = self.guardsList.item(row) |
242 guard = itm.data(Qt.ItemDataRole.UserRole) + itm.text() |
241 guard = itm.data(Qt.ItemDataRole.UserRole) + itm.text() |
243 guardsList.append(guard) |
242 guardsList.append(guard) |
244 |
243 |
245 args = self.vcs.initCommand("qguard") |
244 args = self.vcs.initCommand("qguard") |
246 args.append(self.patchNameLabel.text()) |
245 args.append(self.patchNameLabel.text()) |
247 if guardsList: |
246 if guardsList: |
248 args.append("--") |
247 args.append("--") |
249 args.extend(guardsList) |
248 args.extend(guardsList) |
250 else: |
249 else: |
251 args.append("--none") |
250 args.append("--none") |
252 |
251 |
253 error = self.__hgClient.runcommand(args)[1] |
252 error = self.__hgClient.runcommand(args)[1] |
254 |
253 |
255 if error: |
254 if error: |
256 EricMessageBox.warning( |
255 EricMessageBox.warning( |
257 self, |
256 self, |
258 self.tr("Apply Guard Definitions"), |
257 self.tr("Apply Guard Definitions"), |
259 self.tr("""<p>The defined guards could not be""" |
258 self.tr( |
260 """ applied.</p><p>Reason: {0}</p>""") |
259 """<p>The defined guards could not be""" |
261 .format(error)) |
260 """ applied.</p><p>Reason: {0}</p>""" |
|
261 ).format(error), |
|
262 ) |
262 else: |
263 else: |
263 self.__dirtyList = False |
264 self.__dirtyList = False |
264 index = self.patchSelector.findText(self.patchNameLabel.text()) |
265 index = self.patchSelector.findText(self.patchNameLabel.text()) |
265 if index == -1: |
266 if index == -1: |
266 index = 0 |
267 index = 0 |