23 |
28 |
24 class HgBookmarksListDialog(QDialog, Ui_HgBookmarksListDialog): |
29 class HgBookmarksListDialog(QDialog, Ui_HgBookmarksListDialog): |
25 """ |
30 """ |
26 Class implementing a dialog to show a list of bookmarks. |
31 Class implementing a dialog to show a list of bookmarks. |
27 """ |
32 """ |
|
33 |
28 def __init__(self, vcs, parent=None): |
34 def __init__(self, vcs, parent=None): |
29 """ |
35 """ |
30 Constructor |
36 Constructor |
31 |
37 |
32 @param vcs reference to the vcs object |
38 @param vcs reference to the vcs object |
33 @param parent parent widget (QWidget) |
39 @param parent parent widget (QWidget) |
34 """ |
40 """ |
35 super().__init__(parent) |
41 super().__init__(parent) |
36 self.setupUi(self) |
42 self.setupUi(self) |
37 self.setWindowFlags(Qt.WindowType.Window) |
43 self.setWindowFlags(Qt.WindowType.Window) |
38 |
44 |
39 self.refreshButton = self.buttonBox.addButton( |
45 self.refreshButton = self.buttonBox.addButton( |
40 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole) |
46 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole |
41 self.refreshButton.setToolTip( |
47 ) |
42 self.tr("Press to refresh the bookmarks display")) |
48 self.refreshButton.setToolTip(self.tr("Press to refresh the bookmarks display")) |
43 self.refreshButton.setEnabled(False) |
49 self.refreshButton.setEnabled(False) |
44 self.buttonBox.button( |
50 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
45 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
51 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
46 self.buttonBox.button( |
52 |
47 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
48 |
|
49 self.vcs = vcs |
53 self.vcs = vcs |
50 self.__bookmarksList = None |
54 self.__bookmarksList = None |
51 self.__hgClient = vcs.getClient() |
55 self.__hgClient = vcs.getClient() |
52 self.__bookmarksDefined = False |
56 self.__bookmarksDefined = False |
53 self.__currentRevision = "" |
57 self.__currentRevision = "" |
54 |
58 |
55 self.bookmarksList.headerItem().setText( |
59 self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "") |
56 self.bookmarksList.columnCount(), "") |
60 self.bookmarksList.header().setSortIndicator(3, Qt.SortOrder.AscendingOrder) |
57 self.bookmarksList.header().setSortIndicator( |
61 |
58 3, Qt.SortOrder.AscendingOrder) |
|
59 |
|
60 self.show() |
62 self.show() |
61 QCoreApplication.processEvents() |
63 QCoreApplication.processEvents() |
62 |
64 |
63 def closeEvent(self, e): |
65 def closeEvent(self, e): |
64 """ |
66 """ |
65 Protected slot implementing a close event handler. |
67 Protected slot implementing a close event handler. |
66 |
68 |
67 @param e close event (QCloseEvent) |
69 @param e close event (QCloseEvent) |
68 """ |
70 """ |
69 if self.__hgClient.isExecuting(): |
71 if self.__hgClient.isExecuting(): |
70 self.__hgClient.cancel() |
72 self.__hgClient.cancel() |
71 |
73 |
72 e.accept() |
74 e.accept() |
73 |
75 |
74 def start(self, bookmarksList): |
76 def start(self, bookmarksList): |
75 """ |
77 """ |
76 Public slot to start the bookmarks command. |
78 Public slot to start the bookmarks command. |
77 |
79 |
78 @param bookmarksList reference to string list receiving the bookmarks |
80 @param bookmarksList reference to string list receiving the bookmarks |
79 (list of strings) |
81 (list of strings) |
80 """ |
82 """ |
81 self.bookmarksList.clear() |
83 self.bookmarksList.clear() |
82 self.__bookmarksDefined = False |
84 self.__bookmarksDefined = False |
83 |
85 |
84 self.errorGroup.hide() |
86 self.errorGroup.hide() |
85 |
87 |
86 self.intercept = False |
88 self.intercept = False |
87 self.activateWindow() |
89 self.activateWindow() |
88 |
90 |
89 self.__bookmarksList = bookmarksList |
91 self.__bookmarksList = bookmarksList |
90 del self.__bookmarksList[:] # clear the list |
92 del self.__bookmarksList[:] # clear the list |
91 |
93 |
92 args = self.vcs.initCommand("bookmarks") |
94 args = self.vcs.initCommand("bookmarks") |
93 |
95 |
94 self.refreshButton.setEnabled(False) |
96 self.refreshButton.setEnabled(False) |
95 |
97 |
96 out, err = self.__hgClient.runcommand(args) |
98 out, err = self.__hgClient.runcommand(args) |
97 if err: |
99 if err: |
98 self.__showError(err) |
100 self.__showError(err) |
99 if out: |
101 if out: |
100 for line in out.splitlines(): |
102 for line in out.splitlines(): |
101 self.__processOutputLine(line) |
103 self.__processOutputLine(line) |
102 if self.__hgClient.wasCanceled(): |
104 if self.__hgClient.wasCanceled(): |
103 break |
105 break |
104 self.__finish() |
106 self.__finish() |
105 |
107 |
106 def __finish(self): |
108 def __finish(self): |
107 """ |
109 """ |
108 Private slot called when the process finished or the user pressed |
110 Private slot called when the process finished or the user pressed |
109 the button. |
111 the button. |
110 """ |
112 """ |
111 self.refreshButton.setEnabled(True) |
113 self.refreshButton.setEnabled(True) |
112 |
114 |
113 self.buttonBox.button( |
115 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) |
114 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
116 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
115 self.buttonBox.button( |
117 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
116 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
118 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus( |
117 self.buttonBox.button( |
119 Qt.FocusReason.OtherFocusReason |
118 QDialogButtonBox.StandardButton.Close).setDefault(True) |
120 ) |
119 self.buttonBox.button( |
121 |
120 QDialogButtonBox.StandardButton.Close).setFocus( |
|
121 Qt.FocusReason.OtherFocusReason) |
|
122 |
|
123 if self.bookmarksList.topLevelItemCount() == 0: |
122 if self.bookmarksList.topLevelItemCount() == 0: |
124 # no bookmarks defined |
123 # no bookmarks defined |
125 self.__generateItem( |
124 self.__generateItem(self.tr("no bookmarks defined"), "", "", "") |
126 self.tr("no bookmarks defined"), "", "", "") |
|
127 self.__bookmarksDefined = False |
125 self.__bookmarksDefined = False |
128 else: |
126 else: |
129 self.__bookmarksDefined = True |
127 self.__bookmarksDefined = True |
130 |
128 |
131 self.__resizeColumns() |
129 self.__resizeColumns() |
132 self.__resort() |
130 self.__resort() |
133 |
131 |
134 # restore current item |
132 # restore current item |
135 if self.__currentRevision: |
133 if self.__currentRevision: |
136 items = self.bookmarksList.findItems( |
134 items = self.bookmarksList.findItems( |
137 self.__currentRevision, Qt.MatchFlag.MatchExactly, 0) |
135 self.__currentRevision, Qt.MatchFlag.MatchExactly, 0 |
|
136 ) |
138 if items: |
137 if items: |
139 self.bookmarksList.setCurrentItem(items[0]) |
138 self.bookmarksList.setCurrentItem(items[0]) |
140 self.__currentRevision = "" |
139 self.__currentRevision = "" |
141 self.bookmarksList.setFocus(Qt.FocusReason.OtherFocusReason) |
140 self.bookmarksList.setFocus(Qt.FocusReason.OtherFocusReason) |
142 |
141 |
143 def on_buttonBox_clicked(self, button): |
142 def on_buttonBox_clicked(self, button): |
144 """ |
143 """ |
145 Private slot called by a button of the button box clicked. |
144 Private slot called by a button of the button box clicked. |
146 |
145 |
147 @param button button that was clicked (QAbstractButton) |
146 @param button button that was clicked (QAbstractButton) |
148 """ |
147 """ |
149 if button == self.buttonBox.button( |
148 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
150 QDialogButtonBox.StandardButton.Close |
|
151 ): |
|
152 self.close() |
149 self.close() |
153 elif button == self.buttonBox.button( |
150 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): |
154 QDialogButtonBox.StandardButton.Cancel |
|
155 ): |
|
156 if self.__hgClient: |
151 if self.__hgClient: |
157 self.__hgClient.cancel() |
152 self.__hgClient.cancel() |
158 else: |
153 else: |
159 self.__finish() |
154 self.__finish() |
160 elif button == self.refreshButton: |
155 elif button == self.refreshButton: |
161 self.on_refreshButton_clicked() |
156 self.on_refreshButton_clicked() |
162 |
157 |
163 def __resort(self): |
158 def __resort(self): |
164 """ |
159 """ |
165 Private method to resort the tree. |
160 Private method to resort the tree. |
166 """ |
161 """ |
167 self.bookmarksList.sortItems( |
162 self.bookmarksList.sortItems( |
168 self.bookmarksList.sortColumn(), |
163 self.bookmarksList.sortColumn(), |
169 self.bookmarksList.header().sortIndicatorOrder()) |
164 self.bookmarksList.header().sortIndicatorOrder(), |
170 |
165 ) |
|
166 |
171 def __resizeColumns(self): |
167 def __resizeColumns(self): |
172 """ |
168 """ |
173 Private method to resize the list columns. |
169 Private method to resize the list columns. |
174 """ |
170 """ |
175 self.bookmarksList.header().resizeSections( |
171 self.bookmarksList.header().resizeSections( |
176 QHeaderView.ResizeMode.ResizeToContents) |
172 QHeaderView.ResizeMode.ResizeToContents |
|
173 ) |
177 self.bookmarksList.header().setStretchLastSection(True) |
174 self.bookmarksList.header().setStretchLastSection(True) |
178 |
175 |
179 def __generateItem(self, revision, changeset, status, name): |
176 def __generateItem(self, revision, changeset, status, name): |
180 """ |
177 """ |
181 Private method to generate a bookmark item in the bookmarks list. |
178 Private method to generate a bookmark item in the bookmarks list. |
182 |
179 |
183 @param revision revision of the bookmark (string) |
180 @param revision revision of the bookmark (string) |
184 @param changeset changeset of the bookmark (string) |
181 @param changeset changeset of the bookmark (string) |
185 @param status of the bookmark (string) |
182 @param status of the bookmark (string) |
186 @param name name of the bookmark (string) |
183 @param name name of the bookmark (string) |
187 """ |
184 """ |
239 itm = self.bookmarksList.currentItem() |
236 itm = self.bookmarksList.currentItem() |
240 if itm is not None: |
237 if itm is not None: |
241 self.__currentRevision = itm.text(0) |
238 self.__currentRevision = itm.text(0) |
242 else: |
239 else: |
243 self.__currentRevision = "" |
240 self.__currentRevision = "" |
244 |
241 |
245 self.start(self.__bookmarksList) |
242 self.start(self.__bookmarksList) |
246 |
243 |
247 @pyqtSlot(QPoint) |
244 @pyqtSlot(QPoint) |
248 def on_bookmarksList_customContextMenuRequested(self, pos): |
245 def on_bookmarksList_customContextMenuRequested(self, pos): |
249 """ |
246 """ |
250 Private slot to handle the context menu request. |
247 Private slot to handle the context menu request. |
251 |
248 |
252 @param pos position the context menu was requetsed at |
249 @param pos position the context menu was requetsed at |
253 @type QPoint |
250 @type QPoint |
254 """ |
251 """ |
255 itm = self.bookmarksList.itemAt(pos) |
252 itm = self.bookmarksList.itemAt(pos) |
256 if itm is not None and self.__bookmarksDefined: |
253 if itm is not None and self.__bookmarksDefined: |
257 menu = QMenu(self.bookmarksList) |
254 menu = QMenu(self.bookmarksList) |
258 menu.addAction( |
255 menu.addAction( |
259 UI.PixmapCache.getIcon("vcsSwitch"), |
256 UI.PixmapCache.getIcon("vcsSwitch"), |
260 self.tr("Switch to"), self.__switchTo) |
257 self.tr("Switch to"), |
|
258 self.__switchTo, |
|
259 ) |
261 menu.addSeparator() |
260 menu.addSeparator() |
262 menu.addAction( |
261 menu.addAction( |
263 UI.PixmapCache.getIcon("deleteBookmark"), |
262 UI.PixmapCache.getIcon("deleteBookmark"), |
264 self.tr("Delete"), self.__deleteBookmark) |
263 self.tr("Delete"), |
|
264 self.__deleteBookmark, |
|
265 ) |
265 menu.addAction( |
266 menu.addAction( |
266 UI.PixmapCache.getIcon("renameBookmark"), |
267 UI.PixmapCache.getIcon("renameBookmark"), |
267 self.tr("Rename"), self.__renameBookmark) |
268 self.tr("Rename"), |
|
269 self.__renameBookmark, |
|
270 ) |
268 menu.addSeparator() |
271 menu.addSeparator() |
269 act = menu.addAction( |
272 act = menu.addAction( |
270 UI.PixmapCache.getIcon("pullBookmark"), |
273 UI.PixmapCache.getIcon("pullBookmark"), |
271 self.tr("Pull"), self.__pullBookmark) |
274 self.tr("Pull"), |
|
275 self.__pullBookmark, |
|
276 ) |
272 act.setEnabled(self.vcs.canPull()) |
277 act.setEnabled(self.vcs.canPull()) |
273 act = menu.addAction( |
278 act = menu.addAction( |
274 UI.PixmapCache.getIcon("pushBookmark"), |
279 UI.PixmapCache.getIcon("pushBookmark"), |
275 self.tr("Push"), self.__pushBookmark) |
280 self.tr("Push"), |
|
281 self.__pushBookmark, |
|
282 ) |
276 act.setEnabled(self.vcs.canPush()) |
283 act.setEnabled(self.vcs.canPush()) |
277 menu.addSeparator() |
284 menu.addSeparator() |
278 act = menu.addAction( |
285 act = menu.addAction( |
279 UI.PixmapCache.getIcon("pushBookmark"), |
286 UI.PixmapCache.getIcon("pushBookmark"), |
280 self.tr("Push Current"), self.__pushCurrentBookmark) |
287 self.tr("Push Current"), |
|
288 self.__pushCurrentBookmark, |
|
289 ) |
281 act.setEnabled(self.vcs.canPush()) |
290 act.setEnabled(self.vcs.canPush()) |
282 if self.vcs.version >= (5, 7): |
291 if self.vcs.version >= (5, 7): |
283 act = menu.addAction( |
292 act = menu.addAction( |
284 UI.PixmapCache.getIcon("pushBookmark"), |
293 UI.PixmapCache.getIcon("pushBookmark"), |
285 self.tr("Push All"), self.__pushAllBookmarks) |
294 self.tr("Push All"), |
|
295 self.__pushAllBookmarks, |
|
296 ) |
286 act.setEnabled(self.vcs.canPush()) |
297 act.setEnabled(self.vcs.canPush()) |
287 |
298 |
288 menu.popup(self.bookmarksList.mapToGlobal(pos)) |
299 menu.popup(self.bookmarksList.mapToGlobal(pos)) |
289 |
300 |
290 def __switchTo(self): |
301 def __switchTo(self): |
291 """ |
302 """ |
292 Private slot to switch the working directory to the selected revision. |
303 Private slot to switch the working directory to the selected revision. |
293 """ |
304 """ |
294 itm = self.bookmarksList.currentItem() |
305 itm = self.bookmarksList.currentItem() |
297 shouldReopen = self.vcs.vcsUpdate(revision=bookmark) |
308 shouldReopen = self.vcs.vcsUpdate(revision=bookmark) |
298 if shouldReopen: |
309 if shouldReopen: |
299 res = EricMessageBox.yesNo( |
310 res = EricMessageBox.yesNo( |
300 None, |
311 None, |
301 self.tr("Switch"), |
312 self.tr("Switch"), |
302 self.tr( |
313 self.tr("""The project should be reread. Do this now?"""), |
303 """The project should be reread. Do this now?"""), |
314 yesDefault=True, |
304 yesDefault=True) |
315 ) |
305 if res: |
316 if res: |
306 ericApp().getObject("Project").reopenProject() |
317 ericApp().getObject("Project").reopenProject() |
307 return |
318 return |
308 |
319 |
309 self.on_refreshButton_clicked() |
320 self.on_refreshButton_clicked() |
310 |
321 |
311 def __deleteBookmark(self): |
322 def __deleteBookmark(self): |
312 """ |
323 """ |
313 Private slot to delete the selected bookmark. |
324 Private slot to delete the selected bookmark. |
314 """ |
325 """ |
315 itm = self.bookmarksList.currentItem() |
326 itm = self.bookmarksList.currentItem() |
316 bookmark = itm.text(3).strip() |
327 bookmark = itm.text(3).strip() |
317 if bookmark: |
328 if bookmark: |
318 yes = EricMessageBox.yesNo( |
329 yes = EricMessageBox.yesNo( |
319 self, |
330 self, |
320 self.tr("Delete Bookmark"), |
331 self.tr("Delete Bookmark"), |
321 self.tr("""<p>Shall the bookmark <b>{0}</b> really be""" |
332 self.tr( |
322 """ deleted?</p>""").format(bookmark)) |
333 """<p>Shall the bookmark <b>{0}</b> really be""" """ deleted?</p>""" |
|
334 ).format(bookmark), |
|
335 ) |
323 if yes: |
336 if yes: |
324 self.vcs.hgBookmarkDelete(bookmark=bookmark) |
337 self.vcs.hgBookmarkDelete(bookmark=bookmark) |
325 self.on_refreshButton_clicked() |
338 self.on_refreshButton_clicked() |
326 |
339 |
327 def __renameBookmark(self): |
340 def __renameBookmark(self): |
328 """ |
341 """ |
329 Private slot to rename the selected bookmark. |
342 Private slot to rename the selected bookmark. |
330 """ |
343 """ |
331 itm = self.bookmarksList.currentItem() |
344 itm = self.bookmarksList.currentItem() |
332 bookmark = itm.text(3).strip() |
345 bookmark = itm.text(3).strip() |
333 if bookmark: |
346 if bookmark: |
334 newName, ok = QInputDialog.getText( |
347 newName, ok = QInputDialog.getText( |
335 self, |
348 self, |
336 self.tr("Rename Bookmark"), |
349 self.tr("Rename Bookmark"), |
337 self.tr("<p>Enter the new name for bookmark <b>{0}</b>:</p>") |
350 self.tr("<p>Enter the new name for bookmark <b>{0}</b>:</p>").format( |
338 .format(bookmark), |
351 bookmark |
339 QLineEdit.EchoMode.Normal) |
352 ), |
|
353 QLineEdit.EchoMode.Normal, |
|
354 ) |
340 if ok and bool(newName): |
355 if ok and bool(newName): |
341 self.vcs.hgBookmarkRename((bookmark, newName)) |
356 self.vcs.hgBookmarkRename((bookmark, newName)) |
342 self.on_refreshButton_clicked() |
357 self.on_refreshButton_clicked() |
343 |
358 |
344 def __pullBookmark(self): |
359 def __pullBookmark(self): |
345 """ |
360 """ |
346 Private slot to pull the selected bookmark. |
361 Private slot to pull the selected bookmark. |
347 """ |
362 """ |
348 itm = self.bookmarksList.currentItem() |
363 itm = self.bookmarksList.currentItem() |
349 bookmark = itm.text(3).strip() |
364 bookmark = itm.text(3).strip() |
350 if bookmark: |
365 if bookmark: |
351 self.vcs.hgBookmarkPull(bookmark=bookmark) |
366 self.vcs.hgBookmarkPull(bookmark=bookmark) |
352 self.on_refreshButton_clicked() |
367 self.on_refreshButton_clicked() |
353 |
368 |
354 def __pushBookmark(self): |
369 def __pushBookmark(self): |
355 """ |
370 """ |
356 Private slot to push the selected bookmark. |
371 Private slot to push the selected bookmark. |
357 """ |
372 """ |
358 itm = self.bookmarksList.currentItem() |
373 itm = self.bookmarksList.currentItem() |
359 bookmark = itm.text(3).strip() |
374 bookmark = itm.text(3).strip() |
360 if bookmark: |
375 if bookmark: |
361 self.vcs.hgBookmarkPush(bookmark=bookmark) |
376 self.vcs.hgBookmarkPush(bookmark=bookmark) |
362 self.on_refreshButton_clicked() |
377 self.on_refreshButton_clicked() |
363 |
378 |
364 def __pushCurrentBookmark(self): |
379 def __pushCurrentBookmark(self): |
365 """ |
380 """ |
366 Private slot to push the current bookmark. |
381 Private slot to push the current bookmark. |
367 """ |
382 """ |
368 self.vcs.hgBookmarkPush(current=True) |
383 self.vcs.hgBookmarkPush(current=True) |
369 self.on_refreshButton_clicked() |
384 self.on_refreshButton_clicked() |
370 |
385 |
371 def __pushAllBookmarks(self): |
386 def __pushAllBookmarks(self): |
372 """ |
387 """ |
373 Private slot to push all bookmarks. |
388 Private slot to push all bookmarks. |
374 """ |
389 """ |
375 self.vcs.hgBookmarkPush(allBookmarks=True) |
390 self.vcs.hgBookmarkPush(allBookmarks=True) |