eric6/Plugins/VcsPlugins/vcsMercurial/HgRevisionSelectionDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 6989
8b8cadf8d7e9
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 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_HgRevisionSelectionDialog import Ui_HgRevisionSelectionDialog
16
17
18 class HgRevisionSelectionDialog(QDialog, Ui_HgRevisionSelectionDialog):
19 """
20 Class implementing a dialog to select a revision.
21 """
22 def __init__(self, tagsList, branchesList, bookmarksList=None,
23 noneLabel="", 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 bookmarksList list of bookmarks (list of strings)
30 @param noneLabel labeltext for "no revision selected" (string)
31 @param parent parent widget (QWidget)
32 """
33 super(HgRevisionSelectionDialog, self).__init__(parent)
34 self.setupUi(self)
35
36 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
37
38 self.tagCombo.addItems(sorted(tagsList))
39 self.branchCombo.addItems(["default"] + sorted(branchesList))
40 if bookmarksList is not None:
41 self.bookmarkCombo.addItems(sorted(bookmarksList))
42 else:
43 self.bookmarkButton.setHidden(True)
44 self.bookmarkCombo.setHidden(True)
45
46 if noneLabel:
47 self.noneButton.setText(noneLabel)
48
49 msh = self.minimumSizeHint()
50 self.resize(max(self.width(), msh.width()), msh.height())
51
52 def __updateOK(self):
53 """
54 Private slot to update the OK button.
55 """
56 enabled = True
57 if self.idButton.isChecked():
58 enabled = self.idEdit.text() != ""
59 elif self.tagButton.isChecked():
60 enabled = self.tagCombo.currentText() != ""
61 elif self.branchButton.isChecked():
62 enabled = self.branchCombo.currentText() != ""
63 elif self.bookmarkButton.isChecked():
64 enabled = self.bookmarkCombo.currentText() != ""
65
66 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled)
67
68 @pyqtSlot(bool)
69 def on_idButton_toggled(self, checked):
70 """
71 Private slot to handle changes of the ID select button.
72
73 @param checked state of the button (boolean)
74 """
75 self.__updateOK()
76
77 @pyqtSlot(bool)
78 def on_tagButton_toggled(self, checked):
79 """
80 Private slot to handle changes of the Tag select button.
81
82 @param checked state of the button (boolean)
83 """
84 self.__updateOK()
85
86 @pyqtSlot(bool)
87 def on_branchButton_toggled(self, checked):
88 """
89 Private slot to handle changes of the Branch select button.
90
91 @param checked state of the button (boolean)
92 """
93 self.__updateOK()
94
95 @pyqtSlot(bool)
96 def on_bookmarkButton_toggled(self, checked):
97 """
98 Private slot to handle changes of the Bookmark select button.
99
100 @param checked state of the button (boolean)
101 """
102 self.__updateOK()
103
104 @pyqtSlot(str)
105 def on_idEdit_textChanged(self, txt):
106 """
107 Private slot to handle changes of the ID edit.
108
109 @param txt text of the edit (string)
110 """
111 self.__updateOK()
112
113 @pyqtSlot(str)
114 def on_tagCombo_editTextChanged(self, txt):
115 """
116 Private slot to handle changes of the Tag combo.
117
118 @param txt text of the combo (string)
119 """
120 self.__updateOK()
121
122 @pyqtSlot(str)
123 def on_branchCombo_editTextChanged(self, txt):
124 """
125 Private slot to handle changes of the Branch combo.
126
127 @param txt text of the combo (string)
128 """
129 self.__updateOK()
130
131 @pyqtSlot(str)
132 def on_bookmarkCombo_editTextChanged(self, txt):
133 """
134 Private slot to handle changes of the Bookmark combo.
135
136 @param txt text of the combo (string)
137 """
138 self.__updateOK()
139
140 def getRevision(self, revset=True):
141 """
142 Public method to retrieve the selected revision.
143
144 @param revset flag indicating to get the revision or ID as a
145 revset
146 @type bool
147 @return selected revision
148 @rtype str
149 """
150 if self.numberButton.isChecked():
151 if revset:
152 rev = "rev({0})".format(self.numberSpinBox.value())
153 else:
154 rev = str(self.numberSpinBox.value())
155 elif self.idButton.isChecked():
156 if revset:
157 rev = "id({0})".format(self.idEdit.text())
158 else:
159 rev = self.idEdit.text()
160 elif self.tagButton.isChecked():
161 rev = self.tagCombo.currentText()
162 elif self.branchButton.isChecked():
163 rev = self.branchCombo.currentText()
164 elif self.bookmarkButton.isChecked():
165 rev = self.bookmarkCombo.currentText()
166 elif self.tipButton.isChecked():
167 rev = "tip"
168 else:
169 rev = ""
170
171 return rev

eric ide

mercurial