Plugins/VcsPlugins/vcsMercurial/HgBookmarksListDialog.py

changeset 5325
d0b6adb1721f
parent 5322
c2cabdca0734
child 5328
9c11e9285a46
equal deleted inserted replaced
5324:337c27027c66 5325:d0b6adb1721f
13 except NameError: 13 except NameError:
14 pass 14 pass
15 15
16 import os 16 import os
17 17
18 from PyQt5.QtCore import pyqtSlot, QProcess, Qt, QTimer, QCoreApplication 18 from PyQt5.QtCore import pyqtSlot, QProcess, Qt, QTimer, QCoreApplication, \
19 QPoint
19 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, \ 20 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, \
20 QTreeWidgetItem, QLineEdit 21 QTreeWidgetItem, QLineEdit, QMenu
21 22
23 from E5Gui.E5Application import e5App
22 from E5Gui import E5MessageBox 24 from E5Gui import E5MessageBox
23 25
24 from .Ui_HgBookmarksListDialog import Ui_HgBookmarksListDialog 26 from .Ui_HgBookmarksListDialog import Ui_HgBookmarksListDialog
25 27
26 28 import UI.PixmapCache
27 # TODO: Add context menu with these actions 29
28 # - Delete Bookmark 30
29 # - Rename Bookmark
30 # - Push Bookmark
31 class HgBookmarksListDialog(QDialog, Ui_HgBookmarksListDialog): 31 class HgBookmarksListDialog(QDialog, Ui_HgBookmarksListDialog):
32 """ 32 """
33 Class implementing a dialog to show a list of bookmarks. 33 Class implementing a dialog to show a list of bookmarks.
34 """ 34 """
35 def __init__(self, vcs, parent=None): 35 def __init__(self, vcs, parent=None):
52 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 52 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
53 53
54 self.process = QProcess() 54 self.process = QProcess()
55 self.vcs = vcs 55 self.vcs = vcs
56 self.__bookmarksList = None 56 self.__bookmarksList = None
57 self.__path = None 57 self.__repoDir = None
58 self.__hgClient = vcs.getClient() 58 self.__hgClient = vcs.getClient()
59 self.__bookmarksDefined = False 59 self.__bookmarksDefined = False
60 self.__currentRevision = ""
60 61
61 self.bookmarksList.headerItem().setText( 62 self.bookmarksList.headerItem().setText(
62 self.bookmarksList.columnCount(), "") 63 self.bookmarksList.columnCount(), "")
63 self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder) 64 self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder)
64 65
103 self.intercept = False 104 self.intercept = False
104 self.activateWindow() 105 self.activateWindow()
105 106
106 self.__bookmarksList = bookmarksList 107 self.__bookmarksList = bookmarksList
107 del self.__bookmarksList[:] # clear the list 108 del self.__bookmarksList[:] # clear the list
108 self.__path = path
109 109
110 dname, fname = self.vcs.splitPath(path) 110 dname, fname = self.vcs.splitPath(path)
111 111
112 # find the root of the repo 112 # find the root of the repo
113 repodir = dname 113 repodir = dname
114 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): 114 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
115 repodir = os.path.dirname(repodir) 115 repodir = os.path.dirname(repodir)
116 if os.path.splitdrive(repodir)[1] == os.sep: 116 if os.path.splitdrive(repodir)[1] == os.sep:
117 return 117 return
118 self.__repoDir = repodir
118 119
119 args = self.vcs.initCommand("bookmarks") 120 args = self.vcs.initCommand("bookmarks")
120 121
121 if self.__hgClient: 122 if self.__hgClient:
122 self.inputGroup.setEnabled(False) 123 self.inputGroup.setEnabled(False)
186 else: 187 else:
187 self.__bookmarksDefined = True 188 self.__bookmarksDefined = True
188 189
189 self.__resizeColumns() 190 self.__resizeColumns()
190 self.__resort() 191 self.__resort()
192
193 # restore current item
194 if self.__currentRevision:
195 items = self.bookmarksList.findItems(
196 self.__currentRevision, Qt.MatchExactly, 0)
197 if items:
198 self.bookmarksList.setCurrentItem(items[0])
199 self.__currentRevision = ""
200 self.bookmarksList.setFocus(Qt.OtherFocusReason)
191 201
192 def on_buttonBox_clicked(self, button): 202 def on_buttonBox_clicked(self, button):
193 """ 203 """
194 Private slot called by a button of the button box clicked. 204 Private slot called by a button of the button box clicked.
195 205
363 @pyqtSlot() 373 @pyqtSlot()
364 def on_refreshButton_clicked(self): 374 def on_refreshButton_clicked(self):
365 """ 375 """
366 Private slot to refresh the status display. 376 Private slot to refresh the status display.
367 """ 377 """
368 self.start(self.__path, self.__bookmarksList) 378 # save the current items commit ID
379 itm = self.bookmarksList.currentItem()
380 if itm is not None:
381 self.__currentRevision = itm.text(0)
382 else:
383 self.__currentRevision = ""
384
385 self.start(self.__repoDir, self.__bookmarksList)
386
387 @pyqtSlot(QPoint)
388 def on_bookmarksList_customContextMenuRequested(self, pos):
389 """
390 Private slot to handle the context menu request.
391
392 @param pos position the context menu was requetsed at
393 @type QPoint
394 """
395 itm = self.bookmarksList.itemAt(pos)
396 if itm is not None:
397 menu = QMenu(self.bookmarksList)
398 menu.addAction(
399 UI.PixmapCache.getIcon("vcsSwitch.png"),
400 self.tr("Switch to"), self.__switchTo)
401 menu.addSeparator()
402 menu.popup(self.bookmarksList.mapToGlobal(pos))
403
404 def __switchTo(self):
405 """
406 Private slot to switch the working directory to the selected revision.
407 """
408 itm = self.bookmarksList.currentItem()
409 bookmark = itm.text(3).strip()
410 if bookmark:
411 shouldReopen = self.vcs.vcsUpdate(
412 self.__repoDir, revision=bookmark)
413 if shouldReopen:
414 res = E5MessageBox.yesNo(
415 None,
416 self.tr("Switch"),
417 self.tr(
418 """The project should be reread. Do this now?"""),
419 yesDefault=True)
420 if res:
421 e5App().getObject("Project").reopenProject()
422 return
423
424 self.on_refreshButton_clicked()
425 # TODO: Add context menu with these actions
426 # - Delete Bookmark
427 # - Rename Bookmark
428 # - Pull Bookmark
429 # - Push Bookmark

eric ide

mercurial