4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show a list of bookmarks. |
7 Module implementing a dialog to show a list of bookmarks. |
8 """ |
8 """ |
9 |
|
10 import os |
|
11 |
9 |
12 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QPoint |
10 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QPoint |
13 from PyQt5.QtWidgets import ( |
11 from PyQt5.QtWidgets import ( |
14 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QLineEdit, QMenu, |
12 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QLineEdit, QMenu, |
15 QInputDialog |
13 QInputDialog |
46 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
44 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
47 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
45 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
48 |
46 |
49 self.vcs = vcs |
47 self.vcs = vcs |
50 self.__bookmarksList = None |
48 self.__bookmarksList = None |
51 self.__repoDir = None |
|
52 self.__hgClient = vcs.getClient() |
49 self.__hgClient = vcs.getClient() |
53 self.__bookmarksDefined = False |
50 self.__bookmarksDefined = False |
54 self.__currentRevision = "" |
51 self.__currentRevision = "" |
55 |
52 |
56 self.bookmarksList.headerItem().setText( |
53 self.bookmarksList.headerItem().setText( |
69 if self.__hgClient.isExecuting(): |
66 if self.__hgClient.isExecuting(): |
70 self.__hgClient.cancel() |
67 self.__hgClient.cancel() |
71 |
68 |
72 e.accept() |
69 e.accept() |
73 |
70 |
74 def start(self, path, bookmarksList): |
71 def start(self, bookmarksList): |
75 """ |
72 """ |
76 Public slot to start the bookmarks command. |
73 Public slot to start the bookmarks command. |
77 |
74 |
78 @param path name of directory to be listed (string) |
|
79 @param bookmarksList reference to string list receiving the bookmarks |
75 @param bookmarksList reference to string list receiving the bookmarks |
80 (list of strings) |
76 (list of strings) |
81 """ |
77 """ |
82 self.bookmarksList.clear() |
78 self.bookmarksList.clear() |
83 self.__bookmarksDefined = False |
79 self.__bookmarksDefined = False |
87 self.intercept = False |
83 self.intercept = False |
88 self.activateWindow() |
84 self.activateWindow() |
89 |
85 |
90 self.__bookmarksList = bookmarksList |
86 self.__bookmarksList = bookmarksList |
91 del self.__bookmarksList[:] # clear the list |
87 del self.__bookmarksList[:] # clear the list |
92 |
|
93 dname, fname = self.vcs.splitPath(path) |
|
94 |
|
95 # find the root of the repo |
|
96 repodir = dname |
|
97 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
98 repodir = os.path.dirname(repodir) |
|
99 if os.path.splitdrive(repodir)[1] == os.sep: |
|
100 return |
|
101 self.__repoDir = repodir |
|
102 |
88 |
103 args = self.vcs.initCommand("bookmarks") |
89 args = self.vcs.initCommand("bookmarks") |
104 |
90 |
105 self.refreshButton.setEnabled(False) |
91 self.refreshButton.setEnabled(False) |
106 |
92 |
243 if itm is not None: |
229 if itm is not None: |
244 self.__currentRevision = itm.text(0) |
230 self.__currentRevision = itm.text(0) |
245 else: |
231 else: |
246 self.__currentRevision = "" |
232 self.__currentRevision = "" |
247 |
233 |
248 self.start(self.__repoDir, self.__bookmarksList) |
234 self.start(self.__bookmarksList) |
249 |
235 |
250 @pyqtSlot(QPoint) |
236 @pyqtSlot(QPoint) |
251 def on_bookmarksList_customContextMenuRequested(self, pos): |
237 def on_bookmarksList_customContextMenuRequested(self, pos): |
252 """ |
238 """ |
253 Private slot to handle the context menu request. |
239 Private slot to handle the context menu request. |
284 Private slot to switch the working directory to the selected revision. |
270 Private slot to switch the working directory to the selected revision. |
285 """ |
271 """ |
286 itm = self.bookmarksList.currentItem() |
272 itm = self.bookmarksList.currentItem() |
287 bookmark = itm.text(3).strip() |
273 bookmark = itm.text(3).strip() |
288 if bookmark: |
274 if bookmark: |
289 shouldReopen = self.vcs.vcsUpdate( |
275 shouldReopen = self.vcs.vcsUpdate(revision=bookmark) |
290 self.__repoDir, revision=bookmark) |
|
291 if shouldReopen: |
276 if shouldReopen: |
292 res = E5MessageBox.yesNo( |
277 res = E5MessageBox.yesNo( |
293 None, |
278 None, |
294 self.tr("Switch"), |
279 self.tr("Switch"), |
295 self.tr( |
280 self.tr( |
312 self, |
297 self, |
313 self.tr("Delete Bookmark"), |
298 self.tr("Delete Bookmark"), |
314 self.tr("""<p>Shall the bookmark <b>{0}</b> really be""" |
299 self.tr("""<p>Shall the bookmark <b>{0}</b> really be""" |
315 """ deleted?</p>""").format(bookmark)) |
300 """ deleted?</p>""").format(bookmark)) |
316 if yes: |
301 if yes: |
317 self.vcs.hgBookmarkDelete(self.__repoDir, bookmark=bookmark) |
302 self.vcs.hgBookmarkDelete(bookmark=bookmark) |
318 self.on_refreshButton_clicked() |
303 self.on_refreshButton_clicked() |
319 |
304 |
320 def __renameBookmark(self): |
305 def __renameBookmark(self): |
321 """ |
306 """ |
322 Private slot to rename the selected bookmark. |
307 Private slot to rename the selected bookmark. |
329 self.tr("Rename Bookmark"), |
314 self.tr("Rename Bookmark"), |
330 self.tr("<p>Enter the new name for bookmark <b>{0}</b>:</p>") |
315 self.tr("<p>Enter the new name for bookmark <b>{0}</b>:</p>") |
331 .format(bookmark), |
316 .format(bookmark), |
332 QLineEdit.Normal) |
317 QLineEdit.Normal) |
333 if ok and bool(newName): |
318 if ok and bool(newName): |
334 self.vcs.hgBookmarkRename(self.__repoDir, (bookmark, newName)) |
319 self.vcs.hgBookmarkRename((bookmark, newName)) |
335 self.on_refreshButton_clicked() |
320 self.on_refreshButton_clicked() |
336 |
321 |
337 def __pullBookmark(self): |
322 def __pullBookmark(self): |
338 """ |
323 """ |
339 Private slot to pull the selected bookmark. |
324 Private slot to pull the selected bookmark. |
340 """ |
325 """ |
341 itm = self.bookmarksList.currentItem() |
326 itm = self.bookmarksList.currentItem() |
342 bookmark = itm.text(3).strip() |
327 bookmark = itm.text(3).strip() |
343 if bookmark: |
328 if bookmark: |
344 self.vcs.hgBookmarkPull(self.__repoDir, bookmark=bookmark) |
329 self.vcs.hgBookmarkPull(bookmark=bookmark) |
345 self.on_refreshButton_clicked() |
330 self.on_refreshButton_clicked() |
346 |
331 |
347 def __pushBookmark(self): |
332 def __pushBookmark(self): |
348 """ |
333 """ |
349 Private slot to push the selected bookmark. |
334 Private slot to push the selected bookmark. |
350 """ |
335 """ |
351 itm = self.bookmarksList.currentItem() |
336 itm = self.bookmarksList.currentItem() |
352 bookmark = itm.text(3).strip() |
337 bookmark = itm.text(3).strip() |
353 if bookmark: |
338 if bookmark: |
354 self.vcs.hgBookmarkPush(self.__repoDir, bookmark=bookmark) |
339 self.vcs.hgBookmarkPush(bookmark=bookmark) |
355 self.on_refreshButton_clicked() |
340 self.on_refreshButton_clicked() |