|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the bookmark dialog. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_HgBookmarkDialog import Ui_HgBookmarkDialog |
|
14 |
|
15 |
|
16 class HgBookmarkDialog(QDialog, Ui_HgBookmarkDialog): |
|
17 """ |
|
18 Class mplementing the bookmark dialog. |
|
19 """ |
|
20 DEFINE_MODE = 0 |
|
21 MOVE_MODE = 1 |
|
22 |
|
23 def __init__(self, mode, tagsList, branchesList, bookmarksList, |
|
24 parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param mode of the dialog (integer) |
|
29 @param tagsList list of tags (list of strings) |
|
30 @param branchesList list of branches (list of strings) |
|
31 @param bookmarksList list of bookmarks (list of strings) |
|
32 @param parent reference to the 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.__mode = mode |
|
41 if mode == self.MOVE_MODE: |
|
42 self.nameEdit.hide() |
|
43 self.nameCombo.addItems([""] + sorted(bookmarksList)) |
|
44 self.setWindowTitle(self.tr("Move Bookmark")) |
|
45 else: |
|
46 self.nameCombo.hide() |
|
47 self.setWindowTitle(self.tr("Define Bookmark")) |
|
48 |
|
49 self.__bookmarksList = bookmarksList[:] |
|
50 |
|
51 self.tagCombo.addItems(sorted(tagsList)) |
|
52 self.branchCombo.addItems(["default"] + sorted(branchesList)) |
|
53 self.bookmarkCombo.addItems(sorted(bookmarksList)) |
|
54 |
|
55 msh = self.minimumSizeHint() |
|
56 self.resize(max(self.width(), msh.width()), msh.height()) |
|
57 |
|
58 def __updateOK(self): |
|
59 """ |
|
60 Private slot to update the OK button. |
|
61 """ |
|
62 enabled = ( |
|
63 self.nameCombo.currentText() != "" |
|
64 if self.__mode == self.MOVE_MODE else |
|
65 self.nameEdit.text() != "" |
|
66 ) |
|
67 if self.idButton.isChecked(): |
|
68 enabled = enabled and self.idEdit.text() != "" |
|
69 elif self.tagButton.isChecked(): |
|
70 enabled = enabled and self.tagCombo.currentText() != "" |
|
71 elif self.branchButton.isChecked(): |
|
72 enabled = enabled and self.branchCombo.currentText() != "" |
|
73 elif self.bookmarkButton.isChecked(): |
|
74 enabled = enabled and self.bookmarkCombo.currentText() != "" |
|
75 |
|
76 self.buttonBox.button( |
|
77 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) |
|
78 |
|
79 def __updateBookmarksCombo(self): |
|
80 """ |
|
81 Private slot to update the bookmarks combo. |
|
82 """ |
|
83 if self.__mode == self.MOVE_MODE: |
|
84 bookmark = self.nameCombo.currentText() |
|
85 selectedBookmark = self.bookmarkCombo.currentText() |
|
86 self.bookmarkCombo.clearEditText() |
|
87 self.bookmarkCombo.clear() |
|
88 self.bookmarkCombo.addItems(sorted(self.__bookmarksList)) |
|
89 index = self.bookmarkCombo.findText(bookmark) |
|
90 if index > -1: |
|
91 self.bookmarkCombo.removeItem(index) |
|
92 if selectedBookmark: |
|
93 index = self.bookmarkCombo.findText(selectedBookmark) |
|
94 if index > -1: |
|
95 self.bookmarkCombo.setCurrentIndex(index) |
|
96 |
|
97 @pyqtSlot(int) |
|
98 def on_nameCombo_activated(self, index): |
|
99 """ |
|
100 Private slot to handle changes of the selected bookmark name. |
|
101 |
|
102 @param index index of the selected entry |
|
103 @type int |
|
104 """ |
|
105 self.__updateOK() |
|
106 self.__updateBookmarksCombo() |
|
107 |
|
108 @pyqtSlot(str) |
|
109 def on_nameEdit_textChanged(self, txt): |
|
110 """ |
|
111 Private slot to handle changes of the bookmark name. |
|
112 |
|
113 @param txt text of the edit (string) |
|
114 """ |
|
115 self.__updateOK() |
|
116 |
|
117 @pyqtSlot(bool) |
|
118 def on_idButton_toggled(self, checked): |
|
119 """ |
|
120 Private slot to handle changes of the ID select button. |
|
121 |
|
122 @param checked state of the button (boolean) |
|
123 """ |
|
124 self.__updateOK() |
|
125 |
|
126 @pyqtSlot(bool) |
|
127 def on_tagButton_toggled(self, checked): |
|
128 """ |
|
129 Private slot to handle changes of the Tag select button. |
|
130 |
|
131 @param checked state of the button (boolean) |
|
132 """ |
|
133 self.__updateOK() |
|
134 |
|
135 @pyqtSlot(bool) |
|
136 def on_branchButton_toggled(self, checked): |
|
137 """ |
|
138 Private slot to handle changes of the Branch select button. |
|
139 |
|
140 @param checked state of the button (boolean) |
|
141 """ |
|
142 self.__updateOK() |
|
143 |
|
144 @pyqtSlot(bool) |
|
145 def on_bookmarkButton_toggled(self, checked): |
|
146 """ |
|
147 Private slot to handle changes of the Bookmark select button. |
|
148 |
|
149 @param checked state of the button (boolean) |
|
150 """ |
|
151 self.__updateOK() |
|
152 |
|
153 @pyqtSlot(str) |
|
154 def on_idEdit_textChanged(self, txt): |
|
155 """ |
|
156 Private slot to handle changes of the ID edit. |
|
157 |
|
158 @param txt text of the edit (string) |
|
159 """ |
|
160 self.__updateOK() |
|
161 |
|
162 @pyqtSlot(str) |
|
163 def on_tagCombo_editTextChanged(self, txt): |
|
164 """ |
|
165 Private slot to handle changes of the Tag combo. |
|
166 |
|
167 @param txt text of the combo (string) |
|
168 """ |
|
169 self.__updateOK() |
|
170 |
|
171 @pyqtSlot(str) |
|
172 def on_branchCombo_editTextChanged(self, txt): |
|
173 """ |
|
174 Private slot to handle changes of the Branch combo. |
|
175 |
|
176 @param txt text of the combo (string) |
|
177 """ |
|
178 self.__updateOK() |
|
179 |
|
180 @pyqtSlot(str) |
|
181 def on_bookmarkCombo_editTextChanged(self, txt): |
|
182 """ |
|
183 Private slot to handle changes of the Bookmark combo. |
|
184 |
|
185 @param txt text of the combo (string) |
|
186 """ |
|
187 self.__updateOK() |
|
188 |
|
189 def getData(self): |
|
190 """ |
|
191 Public method to retrieve the entered data. |
|
192 |
|
193 @return tuple naming the revision and the bookmark name |
|
194 (string, string) |
|
195 """ |
|
196 if self.numberButton.isChecked(): |
|
197 rev = "rev({0})".format(self.numberSpinBox.value()) |
|
198 elif self.idButton.isChecked(): |
|
199 rev = "id({0})".format(self.idEdit.text()) |
|
200 elif self.tagButton.isChecked(): |
|
201 rev = self.tagCombo.currentText() |
|
202 elif self.branchButton.isChecked(): |
|
203 rev = self.branchCombo.currentText() |
|
204 elif self.bookmarkButton.isChecked(): |
|
205 rev = self.bookmarkCombo.currentText() |
|
206 else: |
|
207 rev = "" |
|
208 |
|
209 name = ( |
|
210 self.nameCombo.currentText().replace(" ", "_") |
|
211 if self.__mode == self.MOVE_MODE else |
|
212 self.nameEdit.text().replace(" ", "_") |
|
213 ) |
|
214 |
|
215 return rev, name |