--- a/Plugins/VcsPlugins/vcsMercurial/HgBookmarksListDialog.py Tue Nov 15 19:02:50 2016 +0100 +++ b/Plugins/VcsPlugins/vcsMercurial/HgBookmarksListDialog.py Tue Nov 15 19:03:24 2016 +0100 @@ -15,19 +15,19 @@ import os -from PyQt5.QtCore import pyqtSlot, QProcess, Qt, QTimer, QCoreApplication +from PyQt5.QtCore import pyqtSlot, QProcess, Qt, QTimer, QCoreApplication, \ + QPoint from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, \ - QTreeWidgetItem, QLineEdit + QTreeWidgetItem, QLineEdit, QMenu +from E5Gui.E5Application import e5App from E5Gui import E5MessageBox from .Ui_HgBookmarksListDialog import Ui_HgBookmarksListDialog +import UI.PixmapCache -# TODO: Add context menu with these actions -# - Delete Bookmark -# - Rename Bookmark -# - Push Bookmark + class HgBookmarksListDialog(QDialog, Ui_HgBookmarksListDialog): """ Class implementing a dialog to show a list of bookmarks. @@ -54,9 +54,10 @@ self.process = QProcess() self.vcs = vcs self.__bookmarksList = None - self.__path = None + self.__repoDir = None self.__hgClient = vcs.getClient() self.__bookmarksDefined = False + self.__currentRevision = "" self.bookmarksList.headerItem().setText( self.bookmarksList.columnCount(), "") @@ -105,7 +106,6 @@ self.__bookmarksList = bookmarksList del self.__bookmarksList[:] # clear the list - self.__path = path dname, fname = self.vcs.splitPath(path) @@ -115,6 +115,7 @@ repodir = os.path.dirname(repodir) if os.path.splitdrive(repodir)[1] == os.sep: return + self.__repoDir = repodir args = self.vcs.initCommand("bookmarks") @@ -188,6 +189,15 @@ self.__resizeColumns() self.__resort() + + # restore current item + if self.__currentRevision: + items = self.bookmarksList.findItems( + self.__currentRevision, Qt.MatchExactly, 0) + if items: + self.bookmarksList.setCurrentItem(items[0]) + self.__currentRevision = "" + self.bookmarksList.setFocus(Qt.OtherFocusReason) def on_buttonBox_clicked(self, button): """ @@ -365,4 +375,55 @@ """ Private slot to refresh the status display. """ - self.start(self.__path, self.__bookmarksList) + # save the current items commit ID + itm = self.bookmarksList.currentItem() + if itm is not None: + self.__currentRevision = itm.text(0) + else: + self.__currentRevision = "" + + self.start(self.__repoDir, self.__bookmarksList) + + @pyqtSlot(QPoint) + def on_bookmarksList_customContextMenuRequested(self, pos): + """ + Private slot to handle the context menu request. + + @param pos position the context menu was requetsed at + @type QPoint + """ + itm = self.bookmarksList.itemAt(pos) + if itm is not None: + menu = QMenu(self.bookmarksList) + menu.addAction( + UI.PixmapCache.getIcon("vcsSwitch.png"), + self.tr("Switch to"), self.__switchTo) + menu.addSeparator() + menu.popup(self.bookmarksList.mapToGlobal(pos)) + + def __switchTo(self): + """ + Private slot to switch the working directory to the selected revision. + """ + itm = self.bookmarksList.currentItem() + bookmark = itm.text(3).strip() + if bookmark: + shouldReopen = self.vcs.vcsUpdate( + self.__repoDir, revision=bookmark) + if shouldReopen: + res = E5MessageBox.yesNo( + None, + self.tr("Switch"), + self.tr( + """The project should be reread. Do this now?"""), + yesDefault=True) + if res: + e5App().getObject("Project").reopenProject() + return + + self.on_refreshButton_clicked() +# TODO: Add context menu with these actions +# - Delete Bookmark +# - Rename Bookmark +# - Pull Bookmark +# - Push Bookmark