eric6/Plugins/VcsPlugins/vcsGit/GitRevisionSelectionDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to select a revision.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
14
15 from .Ui_GitRevisionSelectionDialog import Ui_GitRevisionSelectionDialog
16
17
18 class GitRevisionSelectionDialog(QDialog, Ui_GitRevisionSelectionDialog):
19 """
20 Class implementing a dialog to select a revision.
21 """
22 def __init__(self, tagsList, branchesList, trackingBranchesList=None,
23 noneLabel="", showBranches=True, showHead=True, parent=None):
24 """
25 Constructor
26
27 @param tagsList list of tags (list of strings)
28 @param branchesList list of branches (list of strings)
29 @param trackingBranchesList list of remote branches (list of strings)
30 @param noneLabel label text for "no revision selected" (string)
31 @param showBranches flag indicating to show the branch selection
32 (boolean)
33 @param showHead flag indicating to show the head selection (boolean)
34 @param parent parent widget (QWidget)
35 """
36 super(GitRevisionSelectionDialog, self).__init__(parent)
37 self.setupUi(self)
38
39 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
40
41 self.tagCombo.addItems(sorted(tagsList))
42 self.branchCombo.addItems(["master"] + sorted(branchesList))
43
44 self.tipButton.setVisible(showHead)
45 self.branchButton.setVisible(showBranches)
46 self.branchCombo.setVisible(showBranches)
47
48 if noneLabel:
49 self.noneButton.setText(noneLabel)
50
51 if trackingBranchesList is not None:
52 self.remoteBranchCombo.addItems(sorted(trackingBranchesList))
53 else:
54 self.remoteBranchButton.setVisible(False)
55 self.remoteBranchCombo.setVisible(False)
56
57 msh = self.minimumSizeHint()
58 self.resize(max(self.width(), msh.width()), msh.height())
59
60 def __updateOK(self):
61 """
62 Private slot to update the OK button.
63 """
64 enabled = True
65 if self.revButton.isChecked():
66 enabled = self.revEdit.text() != ""
67 elif self.tagButton.isChecked():
68 enabled = self.tagCombo.currentText() != ""
69 elif self.branchButton.isChecked():
70 enabled = self.branchCombo.currentText() != ""
71 elif self.remoteBranchButton.isChecked():
72 enabled = self.remoteBranchCombo.currentText() != ""
73
74 self.buttonBox.button(QDialogButtonBox.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

eric ide

mercurial