|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to select a revision. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_GitRevisionSelectionDialog import Ui_GitRevisionSelectionDialog |
|
14 |
|
15 |
|
16 class GitRevisionSelectionDialog(QDialog, Ui_GitRevisionSelectionDialog): |
|
17 """ |
|
18 Class implementing a dialog to select a revision. |
|
19 """ |
|
20 def __init__(self, tagsList, branchesList, trackingBranchesList=None, |
|
21 noneLabel="", showBranches=True, showHead=True, parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param tagsList list of tags (list of strings) |
|
26 @param branchesList list of branches (list of strings) |
|
27 @param trackingBranchesList list of remote branches (list of strings) |
|
28 @param noneLabel label text for "no revision selected" (string) |
|
29 @param showBranches flag indicating to show the branch selection |
|
30 (boolean) |
|
31 @param showHead flag indicating to show the head selection (boolean) |
|
32 @param parent parent widget (QWidget) |
|
33 """ |
|
34 super().__init__(parent) |
|
35 self.setupUi(self) |
|
36 |
|
37 self.buttonBox.button( |
|
38 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
39 |
|
40 self.tagCombo.addItems(sorted(tagsList)) |
|
41 self.branchCombo.addItems(["master"] + sorted(branchesList)) |
|
42 |
|
43 self.tipButton.setVisible(showHead) |
|
44 self.branchButton.setVisible(showBranches) |
|
45 self.branchCombo.setVisible(showBranches) |
|
46 |
|
47 if noneLabel: |
|
48 self.noneButton.setText(noneLabel) |
|
49 |
|
50 if trackingBranchesList is not None: |
|
51 self.remoteBranchCombo.addItems(sorted(trackingBranchesList)) |
|
52 else: |
|
53 self.remoteBranchButton.setVisible(False) |
|
54 self.remoteBranchCombo.setVisible(False) |
|
55 |
|
56 msh = self.minimumSizeHint() |
|
57 self.resize(max(self.width(), msh.width()), msh.height()) |
|
58 |
|
59 def __updateOK(self): |
|
60 """ |
|
61 Private slot to update the OK button. |
|
62 """ |
|
63 enabled = True |
|
64 if self.revButton.isChecked(): |
|
65 enabled = self.revEdit.text() != "" |
|
66 elif self.tagButton.isChecked(): |
|
67 enabled = self.tagCombo.currentText() != "" |
|
68 elif self.branchButton.isChecked(): |
|
69 enabled = self.branchCombo.currentText() != "" |
|
70 elif self.remoteBranchButton.isChecked(): |
|
71 enabled = self.remoteBranchCombo.currentText() != "" |
|
72 |
|
73 self.buttonBox.button( |
|
74 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) |
|
75 |
|
76 @pyqtSlot(bool) |
|
77 def on_revButton_toggled(self, checked): |
|
78 """ |
|
79 Private slot to handle changes of the rev select button. |
|
80 |
|
81 @param checked state of the button (boolean) |
|
82 """ |
|
83 self.__updateOK() |
|
84 |
|
85 @pyqtSlot(bool) |
|
86 def on_tagButton_toggled(self, checked): |
|
87 """ |
|
88 Private slot to handle changes of the Tag select button. |
|
89 |
|
90 @param checked state of the button (boolean) |
|
91 """ |
|
92 self.__updateOK() |
|
93 |
|
94 @pyqtSlot(bool) |
|
95 def on_branchButton_toggled(self, checked): |
|
96 """ |
|
97 Private slot to handle changes of the Branch select button. |
|
98 |
|
99 @param checked state of the button (boolean) |
|
100 """ |
|
101 self.__updateOK() |
|
102 |
|
103 @pyqtSlot(bool) |
|
104 def on_remoteBranchButton_toggled(self, checked): |
|
105 """ |
|
106 Private slot to handle changes of the Remote Branch select button. |
|
107 |
|
108 @param checked state of the button (boolean) |
|
109 """ |
|
110 self.__updateOK() |
|
111 |
|
112 @pyqtSlot(str) |
|
113 def on_revEdit_textChanged(self, txt): |
|
114 """ |
|
115 Private slot to handle changes of the rev edit. |
|
116 |
|
117 @param txt text of the edit (string) |
|
118 """ |
|
119 self.__updateOK() |
|
120 |
|
121 @pyqtSlot(str) |
|
122 def on_tagCombo_editTextChanged(self, txt): |
|
123 """ |
|
124 Private slot to handle changes of the Tag combo. |
|
125 |
|
126 @param txt text of the combo (string) |
|
127 """ |
|
128 self.__updateOK() |
|
129 |
|
130 @pyqtSlot(str) |
|
131 def on_branchCombo_editTextChanged(self, txt): |
|
132 """ |
|
133 Private slot to handle changes of the Branch combo. |
|
134 |
|
135 @param txt text of the combo (string) |
|
136 """ |
|
137 self.__updateOK() |
|
138 |
|
139 @pyqtSlot(str) |
|
140 def on_remoteBranchCombo_editTextChanged(self, txt): |
|
141 """ |
|
142 Private slot to handle changes of the Remote Branch combo. |
|
143 |
|
144 @param txt text of the combo (string) |
|
145 """ |
|
146 self.__updateOK() |
|
147 |
|
148 def getRevision(self): |
|
149 """ |
|
150 Public method to retrieve the selected revision. |
|
151 |
|
152 @return selected revision (string) |
|
153 """ |
|
154 if self.revButton.isChecked(): |
|
155 rev = self.revEdit.text() |
|
156 elif self.tagButton.isChecked(): |
|
157 rev = self.tagCombo.currentText() |
|
158 elif self.branchButton.isChecked(): |
|
159 rev = self.branchCombo.currentText() |
|
160 elif self.remoteBranchButton.isChecked(): |
|
161 rev = self.remoteBranchCombo.currentText() |
|
162 elif self.tipButton.isChecked(): |
|
163 rev = "HEAD" |
|
164 else: |
|
165 rev = "" |
|
166 |
|
167 return rev |