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