1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to select revisions. |
|
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_HgMultiRevisionSelectionDialog import \ |
|
16 Ui_HgMultiRevisionSelectionDialog |
|
17 |
|
18 |
|
19 class HgMultiRevisionSelectionDialog( |
|
20 QDialog, Ui_HgMultiRevisionSelectionDialog): |
|
21 """ |
|
22 Class implementing a dialog to select revisions. |
|
23 """ |
|
24 def __init__(self, tagsList, branchesList, bookmarksList=None, |
|
25 emptyRevsOk=False, showLimit=False, limitDefault=100, |
|
26 parent=None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param tagsList list of tags (list of strings) |
|
31 @param branchesList list of branches (list of strings) |
|
32 @param bookmarksList list of bookmarks (list of strings) |
|
33 @param emptyRevsOk flag indicating that it is ok to not enter |
|
34 revisions (boolean) |
|
35 @param showLimit flag indicating to show the limit entry (boolean) |
|
36 @param limitDefault default value for the limit (integer) |
|
37 @param parent parent widget (QWidget) |
|
38 """ |
|
39 super(HgMultiRevisionSelectionDialog, self).__init__(parent) |
|
40 self.setupUi(self) |
|
41 |
|
42 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
43 |
|
44 self.__emptyRevsOk = emptyRevsOk |
|
45 |
|
46 self.tagCombo.addItems(sorted(tagsList)) |
|
47 self.branchCombo.addItems(["default"] + sorted(branchesList)) |
|
48 if bookmarksList is not None: |
|
49 self.bookmarkCombo.addItems(sorted(bookmarksList)) |
|
50 else: |
|
51 self.bookmarkButton.setHidden(True) |
|
52 self.bookmarkCombo.setHidden(True) |
|
53 |
|
54 self.limitSpinBox.setValue(limitDefault) |
|
55 self.limitGroup.setVisible(showLimit) |
|
56 |
|
57 def __updateOK(self): |
|
58 """ |
|
59 Private slot to update the OK button. |
|
60 """ |
|
61 enabled = True |
|
62 if self.changesetsButton.isChecked(): |
|
63 enabled = self.changesetsEdit.toPlainText() != "" |
|
64 elif self.tagButton.isChecked(): |
|
65 enabled = self.tagCombo.currentText() != "" |
|
66 elif self.branchButton.isChecked(): |
|
67 enabled = self.branchCombo.currentText() != "" |
|
68 elif self.bookmarkButton.isChecked(): |
|
69 enabled = self.bookmarkCombo.currentText() != "" |
|
70 if not enabled and self.__emptyRevsOk: |
|
71 enabled = self.limitGroup.isChecked() |
|
72 |
|
73 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled) |
|
74 |
|
75 @pyqtSlot(bool) |
|
76 def on_changesetsButton_toggled(self, checked): |
|
77 """ |
|
78 Private slot to handle changes of the Changesets select button. |
|
79 |
|
80 @param checked state of the button (boolean) |
|
81 """ |
|
82 self.__updateOK() |
|
83 |
|
84 @pyqtSlot(bool) |
|
85 def on_tagButton_toggled(self, checked): |
|
86 """ |
|
87 Private slot to handle changes of the Tag select button. |
|
88 |
|
89 @param checked state of the button (boolean) |
|
90 """ |
|
91 self.__updateOK() |
|
92 |
|
93 @pyqtSlot(bool) |
|
94 def on_branchButton_toggled(self, checked): |
|
95 """ |
|
96 Private slot to handle changes of the Branch select button. |
|
97 |
|
98 @param checked state of the button (boolean) |
|
99 """ |
|
100 self.__updateOK() |
|
101 |
|
102 @pyqtSlot(bool) |
|
103 def on_bookmarkButton_toggled(self, checked): |
|
104 """ |
|
105 Private slot to handle changes of the Bookmark select button. |
|
106 |
|
107 @param checked state of the button (boolean) |
|
108 """ |
|
109 self.__updateOK() |
|
110 |
|
111 @pyqtSlot() |
|
112 def on_changesetsEdit_textChanged(self): |
|
113 """ |
|
114 Private slot to handle changes of the Changesets edit. |
|
115 """ |
|
116 self.__updateOK() |
|
117 |
|
118 @pyqtSlot(str) |
|
119 def on_tagCombo_editTextChanged(self, txt): |
|
120 """ |
|
121 Private slot to handle changes of the Tag combo. |
|
122 |
|
123 @param txt text of the combo (string) |
|
124 """ |
|
125 self.__updateOK() |
|
126 |
|
127 @pyqtSlot(str) |
|
128 def on_branchCombo_editTextChanged(self, txt): |
|
129 """ |
|
130 Private slot to handle changes of the Branch combo. |
|
131 |
|
132 @param txt text of the combo (string) |
|
133 """ |
|
134 self.__updateOK() |
|
135 |
|
136 @pyqtSlot(str) |
|
137 def on_bookmarkCombo_editTextChanged(self, txt): |
|
138 """ |
|
139 Private slot to handle changes of the Bookmark combo. |
|
140 |
|
141 @param txt text of the combo (string) |
|
142 """ |
|
143 self.__updateOK() |
|
144 |
|
145 @pyqtSlot(bool) |
|
146 def on_limitGroup_toggled(self, checked): |
|
147 """ |
|
148 Private slot to handle changes of the Limit Results group status. |
|
149 |
|
150 @param checked state of the group (boolean) |
|
151 """ |
|
152 self.__updateOK() |
|
153 |
|
154 def getRevisions(self): |
|
155 """ |
|
156 Public method to retrieve the selected revisions. |
|
157 |
|
158 @return tuple of selected revisions (list of strings) and number |
|
159 of entries to be shown (integer) |
|
160 """ |
|
161 if self.changesetsButton.isChecked(): |
|
162 revs = self.changesetsEdit.toPlainText().strip().splitlines() |
|
163 elif self.tagButton.isChecked(): |
|
164 revs = [self.tagCombo.currentText()] |
|
165 elif self.branchButton.isChecked(): |
|
166 revs = [self.branchCombo.currentText()] |
|
167 elif self.bookmarkButton.isChecked(): |
|
168 revs = [self.bookmarkCombo.currentText()] |
|
169 else: |
|
170 revs = [] |
|
171 |
|
172 if self.limitGroup.isChecked(): |
|
173 limit = self.limitSpinBox.value() |
|
174 else: |
|
175 limit = 0 |
|
176 |
|
177 return revs, limit |
|