5 |
5 |
6 """ |
6 """ |
7 Module implementing the queues extension interface. |
7 Module implementing the queues extension interface. |
8 """ |
8 """ |
9 |
9 |
|
10 import enum |
|
11 |
10 from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog |
12 from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog |
11 |
13 |
12 from eric7.EricWidgets import EricMessageBox |
14 from eric7.EricWidgets import EricMessageBox |
13 |
15 |
14 from ..HgDialog import HgDialog |
16 from ..HgDialog import HgDialog |
15 from ..HgExtension import HgExtension |
17 from ..HgExtension import HgExtension |
|
18 |
|
19 |
|
20 class QueuePatchesListType(enum.Enum): |
|
21 """ |
|
22 Class defining the supported queue patch list types. |
|
23 """ |
|
24 |
|
25 APPLIED = 0 |
|
26 UNAPPLIED = 1 |
|
27 SERIES = 2 |
|
28 |
|
29 |
|
30 class QueueOperation(enum.Enum): |
|
31 """ |
|
32 Class defining the supported queue operations. |
|
33 """ |
|
34 |
|
35 POP = 0 |
|
36 PUSH = 1 |
|
37 GOTO = 2 |
|
38 |
|
39 DELETE = 3 |
|
40 PURGE = 4 |
|
41 ACTIVATE = 5 |
16 |
42 |
17 |
43 |
18 class Queues(HgExtension): |
44 class Queues(HgExtension): |
19 """ |
45 """ |
20 Class implementing the queues extension interface. |
46 Class implementing the queues extension interface. |
21 """ |
47 """ |
22 |
|
23 # TODO: change this to an enum |
|
24 APPLIED_LIST = 0 |
|
25 UNAPPLIED_LIST = 1 |
|
26 SERIES_LIST = 2 |
|
27 |
|
28 # TODO: change this to an enum |
|
29 POP = 0 |
|
30 PUSH = 1 |
|
31 GOTO = 2 |
|
32 |
|
33 # TODO: change this to an enum |
|
34 QUEUE_DELETE = 0 |
|
35 QUEUE_PURGE = 1 |
|
36 QUEUE_ACTIVATE = 2 |
|
37 |
48 |
38 def __init__(self, vcs): |
49 def __init__(self, vcs): |
39 """ |
50 """ |
40 Constructor |
51 Constructor |
41 |
52 |
77 def __getPatchesList(self, listType, withSummary=False): |
88 def __getPatchesList(self, listType, withSummary=False): |
78 """ |
89 """ |
79 Private method to get a list of patches of a given type. |
90 Private method to get a list of patches of a given type. |
80 |
91 |
81 @param listType type of patches list to get |
92 @param listType type of patches list to get |
82 (Queues.APPLIED_LIST, Queues.UNAPPLIED_LIST, Queues.SERIES_LIST) |
93 @type QueuePatchesListType |
83 @type int |
|
84 @param withSummary flag indicating to get a summary as well |
94 @param withSummary flag indicating to get a summary as well |
85 @type bool |
95 @type bool |
86 @return list of patches |
96 @return list of patches |
87 @rtype list of str |
97 @rtype list of str |
88 @exception ValueError raised to indicate an invalid patch list type |
98 @exception ValueError raised to indicate an invalid patch list type |
89 """ |
99 """ |
90 patchesList = [] |
100 patchesList = [] |
91 |
101 |
92 if listType not in ( |
102 if not isinstance(listType, QueuePatchesListType): |
93 Queues.APPLIED_LIST, |
|
94 Queues.UNAPPLIED_LIST, |
|
95 Queues.SERIES_LIST, |
|
96 ): |
|
97 raise ValueError("illegal value for listType") |
103 raise ValueError("illegal value for listType") |
98 |
104 |
99 if listType == Queues.APPLIED_LIST: |
105 if listType == QueuePatchesListType.APPLIED: |
100 args = self.vcs.initCommand("qapplied") |
106 args = self.vcs.initCommand("qapplied") |
101 elif listType == Queues.UNAPPLIED_LIST: |
107 elif listType == QueuePatchesListType.UNAPPLIED: |
102 args = self.vcs.initCommand("qunapplied") |
108 args = self.vcs.initCommand("qunapplied") |
103 else: |
109 else: |
104 args = self.vcs.initCommand("qseries") |
110 args = self.vcs.initCommand("qseries") |
105 |
111 |
106 if withSummary: |
112 if withSummary: |
183 |
189 |
184 def hgQueueNewPatch(self): |
190 def hgQueueNewPatch(self): |
185 """ |
191 """ |
186 Public method to create a new named patch. |
192 Public method to create a new named patch. |
187 """ |
193 """ |
188 from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog |
194 from .HgQueuesNewPatchDialog import ( |
189 |
195 HgQueuesNewPatchDialog, |
190 dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialog.NEW_MODE) |
196 HgQueuesNewPatchDialogMode, |
|
197 ) |
|
198 |
|
199 dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialogMode.NEW) |
191 if dlg.exec() == QDialog.DialogCode.Accepted: |
200 if dlg.exec() == QDialog.DialogCode.Accepted: |
192 ( |
201 ( |
193 name, |
202 name, |
194 message, |
203 message, |
195 (userData, currentUser, userName), |
204 (userData, currentUser, userName), |
226 |
235 |
227 @param editMessage flag indicating to edit the current |
236 @param editMessage flag indicating to edit the current |
228 commit message |
237 commit message |
229 @type bool |
238 @type bool |
230 """ |
239 """ |
231 from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog |
240 from .HgQueuesNewPatchDialog import ( |
|
241 HgQueuesNewPatchDialog, |
|
242 HgQueuesNewPatchDialogMode, |
|
243 ) |
232 |
244 |
233 args = self.vcs.initCommand("qrefresh") |
245 args = self.vcs.initCommand("qrefresh") |
234 |
246 |
235 if editMessage: |
247 if editMessage: |
236 currentMessage = self.__getCommitMessage() |
248 currentMessage = self.__getCommitMessage() |
237 dlg = HgQueuesNewPatchDialog( |
249 dlg = HgQueuesNewPatchDialog( |
238 HgQueuesNewPatchDialog.REFRESH_MODE, currentMessage |
250 HgQueuesNewPatchDialogMode.REFRESH, currentMessage |
239 ) |
251 ) |
240 if dlg.exec() == QDialog.DialogCode.Accepted: |
252 if dlg.exec() == QDialog.DialogCode.Accepted: |
241 ( |
253 ( |
242 name, |
254 name, |
243 message, |
255 message, |
296 def hgQueuePushPopPatches(self, operation, doAll=False, named=False, force=False): |
308 def hgQueuePushPopPatches(self, operation, doAll=False, named=False, force=False): |
297 """ |
309 """ |
298 Public method to push patches onto the stack or pop patches off the |
310 Public method to push patches onto the stack or pop patches off the |
299 stack. |
311 stack. |
300 |
312 |
301 @param operation operation type to be performed (Queues.POP, |
313 @param operation operation to be performed (POP, PUSH or GOTO) |
302 Queues.PUSH, Queues.GOTO) |
314 @type QueueOperation |
303 @type int |
|
304 @param doAll flag indicating to push/pop all |
315 @param doAll flag indicating to push/pop all |
305 @type bool |
316 @type bool |
306 @param named flag indicating to push/pop until a named patch |
317 @param named flag indicating to push/pop until a named patch |
307 is at the top of the stack |
318 is at the top of the stack |
308 @type bool |
319 @type bool |
310 @type bool |
321 @type bool |
311 @return flag indicating that the project should be reread |
322 @return flag indicating that the project should be reread |
312 @rtype bool |
323 @rtype bool |
313 @exception ValueError raised to indicate an invalid operation |
324 @exception ValueError raised to indicate an invalid operation |
314 """ |
325 """ |
315 if operation not in (Queues.POP, Queues.PUSH, Queues.GOTO): |
326 if operation not in ( |
|
327 QueueOperation.POP, |
|
328 QueueOperation.PUSH, |
|
329 QueueOperation.GOTO, |
|
330 ): |
316 raise ValueError("illegal value for operation") |
331 raise ValueError("illegal value for operation") |
317 |
332 |
318 if operation == Queues.POP: |
333 if operation == QueueOperation.POP: |
319 args = self.vcs.initCommand("qpop") |
334 args = self.vcs.initCommand("qpop") |
320 title = self.tr("Pop Patches") |
335 title = self.tr("Pop Patches") |
321 listType = Queues.APPLIED_LIST |
336 listType = QueuePatchesListType |
322 elif operation == Queues.PUSH: |
337 elif operation == QueueOperation.PUSH: |
323 args = self.vcs.initCommand("qpush") |
338 args = self.vcs.initCommand("qpush") |
324 title = self.tr("Push Patches") |
339 title = self.tr("Push Patches") |
325 listType = Queues.UNAPPLIED_LIST |
340 listType = QueuePatchesListType.UNAPPLIED |
326 else: |
341 else: |
327 args = self.vcs.initCommand("qgoto") |
342 args = self.vcs.initCommand("qgoto") |
328 title = self.tr("Go to Patch") |
343 title = self.tr("Go to Patch") |
329 listType = Queues.SERIES_LIST |
344 listType = QueuePatchesListType.SERIES |
330 |
345 |
331 args.append("-v") |
346 args.append("-v") |
332 if force: |
347 if force: |
333 args.append("--force") |
348 args.append("--force") |
334 if doAll and operation in (Queues.POP, Queues.PUSH): |
349 if doAll and operation in (QueueOperation.POP, QueueOperation.PUSH): |
335 args.append("--all") |
350 args.append("--all") |
336 elif named or operation == Queues.GOTO: |
351 elif named or operation == QueueOperation.GOTO: |
337 patchnames = self.__getPatchesList(listType) |
352 patchnames = self.__getPatchesList(listType) |
338 if patchnames: |
353 if patchnames: |
339 patch, ok = QInputDialog.getItem( |
354 patch, ok = QInputDialog.getItem( |
340 None, |
355 None, |
341 self.tr("Select Patch"), |
356 self.tr("Select Patch"), |
413 def hgQueueDeletePatch(self): |
428 def hgQueueDeletePatch(self): |
414 """ |
429 """ |
415 Public method to delete a selected unapplied patch. |
430 Public method to delete a selected unapplied patch. |
416 """ |
431 """ |
417 args = self.vcs.initCommand("qdelete") |
432 args = self.vcs.initCommand("qdelete") |
418 patchnames = sorted(self.__getPatchesList(Queues.UNAPPLIED_LIST)) |
433 patchnames = sorted(self.__getPatchesList(QueuePatchesListType.UNAPPLIED)) |
419 if patchnames: |
434 if patchnames: |
420 patch, ok = QInputDialog.getItem( |
435 patch, ok = QInputDialog.getItem( |
421 None, |
436 None, |
422 self.tr("Select Patch"), |
437 self.tr("Select Patch"), |
423 self.tr("Select the patch to be deleted:"), |
438 self.tr("Select the patch to be deleted:"), |
612 Public method to create a new queue or rename the active queue. |
627 Public method to create a new queue or rename the active queue. |
613 |
628 |
614 @param isCreate flag indicating to create a new queue |
629 @param isCreate flag indicating to create a new queue |
615 @type bool |
630 @type bool |
616 """ |
631 """ |
617 from .HgQueuesQueueManagementDialog import HgQueuesQueueManagementDialog |
632 from .HgQueuesQueueManagementDialog import ( |
|
633 HgQueuesQueueManagementDialog, |
|
634 HgQueuesQueueManagementDialogMode, |
|
635 ) |
618 |
636 |
619 title = ( |
637 title = ( |
620 self.tr("Create New Queue") if isCreate else self.tr("Rename Active Queue") |
638 self.tr("Create New Queue") if isCreate else self.tr("Rename Active Queue") |
621 ) |
639 ) |
622 dlg = HgQueuesQueueManagementDialog( |
640 dlg = HgQueuesQueueManagementDialog( |
623 HgQueuesQueueManagementDialog.NAME_INPUT, title, False, self.vcs |
641 HgQueuesQueueManagementDialogMode.NAME_INPUT, title, False, self.vcs |
624 ) |
642 ) |
625 if dlg.exec() == QDialog.DialogCode.Accepted: |
643 if dlg.exec() == QDialog.DialogCode.Accepted: |
626 queueName = dlg.getData() |
644 queueName = dlg.getData() |
627 if queueName: |
645 if queueName: |
628 args = self.vcs.initCommand("qqueue") |
646 args = self.vcs.initCommand("qqueue") |
653 def hgQueueDeletePurgeActivateQueue(self, operation): |
671 def hgQueueDeletePurgeActivateQueue(self, operation): |
654 """ |
672 """ |
655 Public method to delete the reference to a queue and optionally |
673 Public method to delete the reference to a queue and optionally |
656 remove the patch directory or set the active queue. |
674 remove the patch directory or set the active queue. |
657 |
675 |
658 @param operation operation to be performed (Queues.QUEUE_DELETE, |
676 @param operation operation to be performed (PURGE, DELETE or ACTIVATE) |
659 Queues.QUEUE_PURGE, Queues.QUEUE_ACTIVATE) |
677 @type QueueOperation |
660 @type int |
|
661 @exception ValueError raised to indicate an invalid operation |
678 @exception ValueError raised to indicate an invalid operation |
662 """ |
679 """ |
663 from .HgQueuesQueueManagementDialog import HgQueuesQueueManagementDialog |
680 from .HgQueuesQueueManagementDialog import ( |
|
681 HgQueuesQueueManagementDialog, |
|
682 HgQueuesQueueManagementDialogMode, |
|
683 ) |
664 |
684 |
665 if operation not in ( |
685 if operation not in ( |
666 Queues.QUEUE_PURGE, |
686 QueueOperation.PURGE, |
667 Queues.QUEUE_DELETE, |
687 QueueOperation.DELETE, |
668 Queues.QUEUE_ACTIVATE, |
688 QueueOperation.ACTIVATE, |
669 ): |
689 ): |
670 raise ValueError("illegal value for operation") |
690 raise ValueError("illegal value for operation") |
671 |
691 |
672 if operation == Queues.QUEUE_PURGE: |
692 if operation == QueueOperation.PURGE: |
673 title = self.tr("Purge Queue") |
693 title = self.tr("Purge Queue") |
674 elif operation == Queues.QUEUE_DELETE: |
694 elif operation == QueueOperation.DELETE: |
675 title = self.tr("Delete Queue") |
695 title = self.tr("Delete Queue") |
676 else: |
696 else: |
677 title = self.tr("Activate Queue") |
697 title = self.tr("Activate Queue") |
678 |
698 |
679 dlg = HgQueuesQueueManagementDialog( |
699 dlg = HgQueuesQueueManagementDialog( |
680 HgQueuesQueueManagementDialog.QUEUE_INPUT, title, True, self.vcs |
700 HgQueuesQueueManagementDialogMode.QUEUE_INPUT, title, True, self.vcs |
681 ) |
701 ) |
682 if dlg.exec() == QDialog.DialogCode.Accepted: |
702 if dlg.exec() == QDialog.DialogCode.Accepted: |
683 queueName = dlg.getData() |
703 queueName = dlg.getData() |
684 if queueName: |
704 if queueName: |
685 args = self.vcs.initCommand("qqueue") |
705 args = self.vcs.initCommand("qqueue") |
686 if operation == Queues.QUEUE_PURGE: |
706 if operation == QueueOperation.PURGE: |
687 args.append("--purge") |
707 args.append("--purge") |
688 elif operation == Queues.QUEUE_DELETE: |
708 elif operation == QueueOperation.DELETE: |
689 args.append("--delete") |
709 args.append("--delete") |
690 args.append(queueName) |
710 args.append(queueName) |
691 |
711 |
692 client = self.vcs.getClient() |
712 client = self.vcs.getClient() |
693 error = client.runcommand(args)[1] |
713 error = client.runcommand(args)[1] |
694 |
714 |
695 if error: |
715 if error: |
696 if operation == Queues.QUEUE_PURGE: |
716 if operation == QueueOperation.PURGE: |
697 errMsg = self.tr("Error while purging the queue.") |
717 errMsg = self.tr("Error while purging the queue.") |
698 elif operation == Queues.QUEUE_DELETE: |
718 elif operation == QueueOperation.DELETE: |
699 errMsg = self.tr("Error while deleting the queue.") |
719 errMsg = self.tr("Error while deleting the queue.") |
700 elif operation == Queues.QUEUE_ACTIVATE: |
720 elif operation == QueueOperation.ACTIVATE: |
701 errMsg = self.tr("Error while setting the active queue.") |
721 errMsg = self.tr("Error while setting the active queue.") |
702 EricMessageBox.warning( |
722 EricMessageBox.warning( |
703 None, title, """<p>{0}</p><p>{1}</p>""".format(errMsg, error) |
723 None, title, """<p>{0}</p><p>{1}</p>""".format(errMsg, error) |
704 ) |
724 ) |
705 else: |
725 else: |
711 |
731 |
712 def hgQueueListQueues(self): |
732 def hgQueueListQueues(self): |
713 """ |
733 """ |
714 Public method to list available queues. |
734 Public method to list available queues. |
715 """ |
735 """ |
716 from .HgQueuesQueueManagementDialog import HgQueuesQueueManagementDialog |
736 from .HgQueuesQueueManagementDialog import ( |
|
737 HgQueuesQueueManagementDialog, |
|
738 HgQueuesQueueManagementDialogMode, |
|
739 ) |
717 |
740 |
718 self.queuesListQueuesDialog = HgQueuesQueueManagementDialog( |
741 self.queuesListQueuesDialog = HgQueuesQueueManagementDialog( |
719 HgQueuesQueueManagementDialog.NO_INPUT, |
742 HgQueuesQueueManagementDialogMode.NO_INPUT, |
720 self.tr("Available Queues"), |
743 self.tr("Available Queues"), |
721 False, |
744 False, |
722 self.vcs, |
745 self.vcs, |
723 ) |
746 ) |
724 self.queuesListQueuesDialog.show() |
747 self.queuesListQueuesDialog.show() |