|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2019 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to select the heads to be closed. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem |
|
12 |
|
13 from .Ui_HgCloseHeadSelectionDialog import Ui_HgCloseHeadSelectionDialog |
|
14 |
|
15 |
|
16 class HgCloseHeadSelectionDialog(QDialog, Ui_HgCloseHeadSelectionDialog): |
|
17 """ |
|
18 Class implementing a dialog to select the heads to be closed. |
|
19 """ |
|
20 def __init__(self, vcs, parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param vcs reference to the VCS object |
|
25 @type Hg |
|
26 @param parent reference to the parent widget |
|
27 @type QWidget |
|
28 """ |
|
29 super().__init__(parent) |
|
30 self.setupUi(self) |
|
31 |
|
32 self.buttonBox.button( |
|
33 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
34 self.buttonBox.button( |
|
35 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
36 |
|
37 heads = self.__getHeads(vcs) |
|
38 for revision, branch in heads: |
|
39 QTreeWidgetItem(self.headsList, [revision, branch]) |
|
40 |
|
41 def __getHeads(self, vcs): |
|
42 """ |
|
43 Private method to get the open heads. |
|
44 |
|
45 @param vcs reference to the VCS object |
|
46 @type Hg |
|
47 @return list of tuples containing the revision and the corresponding |
|
48 branch name |
|
49 @rtype list of tuples of (str, str) |
|
50 """ |
|
51 args = vcs.initCommand("heads") |
|
52 args.append('--template') |
|
53 args.append('{node|short}@@@{branches}\n') |
|
54 |
|
55 output = "" |
|
56 client = vcs.getClient() |
|
57 output, error = client.runcommand(args) |
|
58 |
|
59 heads = [] |
|
60 if output: |
|
61 for line in output.splitlines(): |
|
62 line = line.strip() |
|
63 if line: |
|
64 revision, branch = line.split("@@@") |
|
65 heads.append((revision, branch)) |
|
66 |
|
67 return heads |
|
68 |
|
69 @pyqtSlot() |
|
70 def on_headsList_itemSelectionChanged(self): |
|
71 """ |
|
72 Private slot handling changes of the selection. |
|
73 """ |
|
74 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
75 len(self.headsList.selectedItems()) > 0 |
|
76 ) |
|
77 |
|
78 def getData(self): |
|
79 """ |
|
80 Public method to retrieve the entered data. |
|
81 |
|
82 @return tuple containing a list of selected revisions and the commit |
|
83 message |
|
84 @rtype tuple of (list of str, str) |
|
85 """ |
|
86 revisions = [itm.text(0) for itm in self.headsList.selectedItems()] |
|
87 message = self.logEdit.toPlainText().strip() |
|
88 |
|
89 return revisions, message |