eric7/Plugins/VcsPlugins/vcsGit/GitRevisionsSelectionDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the revisions for the git diff command.
8 """
9
10 from PyQt5.QtCore import pyqtSlot
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
12
13 from .Ui_GitRevisionsSelectionDialog import Ui_GitRevisionsSelectionDialog
14
15
16 class GitRevisionsSelectionDialog(QDialog, Ui_GitRevisionsSelectionDialog):
17 """
18 Class implementing a dialog to enter the revisions for the git diff
19 command.
20 """
21 def __init__(self, tagsList, branchesList, 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 parent parent widget of the dialog (QWidget)
28 """
29 super().__init__(parent)
30 self.setupUi(self)
31
32 self.buttonBox.button(
33 QDialogButtonBox.StandardButton.Ok).setEnabled(False)
34
35 self.tag1Combo.addItems(sorted(tagsList))
36 self.tag2Combo.addItems(sorted(tagsList))
37 self.branch1Combo.addItems(["master"] + sorted(branchesList))
38 self.branch2Combo.addItems(["master"] + sorted(branchesList))
39
40 msh = self.minimumSizeHint()
41 self.resize(max(self.width(), msh.width()), msh.height())
42
43 def __updateOK(self):
44 """
45 Private slot to update the OK button.
46 """
47 enabled = True
48 if self.rev1Button.isChecked():
49 enabled = enabled and self.rev1Edit.text() != ""
50 elif self.tag1Button.isChecked():
51 enabled = enabled and self.tag1Combo.currentText() != ""
52 elif self.branch1Button.isChecked():
53 enabled = enabled and self.branch1Combo.currentText() != ""
54
55 if self.rev2Button.isChecked():
56 enabled = enabled and self.rev2Edit.text() != ""
57 elif self.tag2Button.isChecked():
58 enabled = enabled and self.tag2Combo.currentText() != ""
59 elif self.branch2Button.isChecked():
60 enabled = enabled and self.branch2Combo.currentText() != ""
61
62 self.buttonBox.button(
63 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled)
64
65 @pyqtSlot(bool)
66 def on_rev1Button_toggled(self, checked):
67 """
68 Private slot to handle changes of the rev1 select button.
69
70 @param checked state of the button (boolean)
71 """
72 self.__updateOK()
73
74 @pyqtSlot(bool)
75 def on_rev2Button_toggled(self, checked):
76 """
77 Private slot to handle changes of the rev2 select button.
78
79 @param checked state of the button (boolean)
80 """
81 self.__updateOK()
82
83 @pyqtSlot(bool)
84 def on_tag1Button_toggled(self, checked):
85 """
86 Private slot to handle changes of the Tag1 select button.
87
88 @param checked state of the button (boolean)
89 """
90 self.__updateOK()
91
92 @pyqtSlot(bool)
93 def on_tag2Button_toggled(self, checked):
94 """
95 Private slot to handle changes of the Tag2 select button.
96
97 @param checked state of the button (boolean)
98 """
99 self.__updateOK()
100
101 @pyqtSlot(bool)
102 def on_branch1Button_toggled(self, checked):
103 """
104 Private slot to handle changes of the Branch1 select button.
105
106 @param checked state of the button (boolean)
107 """
108 self.__updateOK()
109
110 @pyqtSlot(bool)
111 def on_branch2Button_toggled(self, checked):
112 """
113 Private slot to handle changes of the Branch2 select button.
114
115 @param checked state of the button (boolean)
116 """
117 self.__updateOK()
118
119 @pyqtSlot(str)
120 def on_rev1Edit_textChanged(self, txt):
121 """
122 Private slot to handle changes of the rev1 edit.
123
124 @param txt text of the edit (string)
125 """
126 self.__updateOK()
127
128 @pyqtSlot(str)
129 def on_rev2Edit_textChanged(self, txt):
130 """
131 Private slot to handle changes of the rev2 edit.
132
133 @param txt text of the edit (string)
134 """
135 self.__updateOK()
136
137 @pyqtSlot(str)
138 def on_tag1Combo_editTextChanged(self, txt):
139 """
140 Private slot to handle changes of the Tag1 combo.
141
142 @param txt text of the combo (string)
143 """
144 self.__updateOK()
145
146 @pyqtSlot(str)
147 def on_tag2Combo_editTextChanged(self, txt):
148 """
149 Private slot to handle changes of the Tag2 combo.
150
151 @param txt text of the combo (string)
152 """
153 self.__updateOK()
154
155 @pyqtSlot(str)
156 def on_branch1Combo_editTextChanged(self, txt):
157 """
158 Private slot to handle changes of the Branch1 combo.
159
160 @param txt text of the combo (string)
161 """
162 self.__updateOK()
163
164 @pyqtSlot(str)
165 def on_branch2Combo_editTextChanged(self, txt):
166 """
167 Private slot to handle changes of the Branch2 combo.
168
169 @param txt text of the combo (string)
170 """
171 self.__updateOK()
172
173 def __getRevision(self, no):
174 """
175 Private method to generate the revision.
176
177 @param no revision number to generate (1 or 2)
178 @return revision (string)
179 """
180 if no == 1:
181 revButton = self.rev1Button
182 revEdit = self.rev1Edit
183 tagButton = self.tag1Button
184 tagCombo = self.tag1Combo
185 branchButton = self.branch1Button
186 branchCombo = self.branch1Combo
187 tipButton = self.tip1Button
188 prevButton = self.prev1Button
189 noneButton = self.none1Button
190 else:
191 revButton = self.rev2Button
192 revEdit = self.rev2Edit
193 tagButton = self.tag2Button
194 tagCombo = self.tag2Combo
195 branchButton = self.branch2Button
196 branchCombo = self.branch2Combo
197 tipButton = self.tip2Button
198 prevButton = self.prev2Button
199 noneButton = self.none2Button
200
201 if revButton.isChecked():
202 return revEdit.text()
203 elif tagButton.isChecked():
204 return tagCombo.currentText()
205 elif branchButton.isChecked():
206 return branchCombo.currentText()
207 elif tipButton.isChecked():
208 return "HEAD"
209 elif prevButton.isChecked():
210 return "HEAD^"
211 elif noneButton.isChecked():
212 return ""
213
214 return ""
215
216 def getRevisions(self):
217 """
218 Public method to get the revisions.
219
220 @return list of two revisions (list of strings)
221 """
222 rev1 = self.__getRevision(1)
223 rev2 = self.__getRevision(2)
224
225 return [rev1, rev2]

eric ide

mercurial