src/eric7/Plugins/VcsPlugins/vcsMercurial/CloseheadExtension/HgCloseHeadSelectionDialog.py

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

eric ide

mercurial