eric7/Plugins/VcsPlugins/vcsMercurial/HgBookmarkDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8259
2bbec88047dd
child 8318
962bce857696
diff -r 4e8b98454baa -r 800c432b34c8 eric7/Plugins/VcsPlugins/vcsMercurial/HgBookmarkDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric7/Plugins/VcsPlugins/vcsMercurial/HgBookmarkDialog.py	Sat May 15 18:45:04 2021 +0200
@@ -0,0 +1,215 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the bookmark dialog.
+"""
+
+from PyQt5.QtCore import pyqtSlot
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox
+
+from .Ui_HgBookmarkDialog import Ui_HgBookmarkDialog
+
+
+class HgBookmarkDialog(QDialog, Ui_HgBookmarkDialog):
+    """
+    Class mplementing the bookmark dialog.
+    """
+    DEFINE_MODE = 0
+    MOVE_MODE = 1
+    
+    def __init__(self, mode, tagsList, branchesList, bookmarksList,
+                 parent=None):
+        """
+        Constructor
+        
+        @param mode of the dialog (integer)
+        @param tagsList list of tags (list of strings)
+        @param branchesList list of branches (list of strings)
+        @param bookmarksList list of bookmarks (list of strings)
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Ok).setEnabled(False)
+        
+        self.__mode = mode
+        if mode == self.MOVE_MODE:
+            self.nameEdit.hide()
+            self.nameCombo.addItems([""] + sorted(bookmarksList))
+            self.setWindowTitle(self.tr("Move Bookmark"))
+        else:
+            self.nameCombo.hide()
+            self.setWindowTitle(self.tr("Define Bookmark"))
+        
+        self.__bookmarksList = bookmarksList[:]
+        
+        self.tagCombo.addItems(sorted(tagsList))
+        self.branchCombo.addItems(["default"] + sorted(branchesList))
+        self.bookmarkCombo.addItems(sorted(bookmarksList))
+        
+        msh = self.minimumSizeHint()
+        self.resize(max(self.width(), msh.width()), msh.height())
+    
+    def __updateOK(self):
+        """
+        Private slot to update the OK button.
+        """
+        enabled = (
+            self.nameCombo.currentText() != ""
+            if self.__mode == self.MOVE_MODE else
+            self.nameEdit.text() != ""
+        )
+        if self.idButton.isChecked():
+            enabled = enabled and self.idEdit.text() != ""
+        elif self.tagButton.isChecked():
+            enabled = enabled and self.tagCombo.currentText() != ""
+        elif self.branchButton.isChecked():
+            enabled = enabled and self.branchCombo.currentText() != ""
+        elif self.bookmarkButton.isChecked():
+            enabled = enabled and self.bookmarkCombo.currentText() != ""
+        
+        self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Ok).setEnabled(enabled)
+    
+    def __updateBookmarksCombo(self):
+        """
+        Private slot to update the bookmarks combo.
+        """
+        if self.__mode == self.MOVE_MODE:
+            bookmark = self.nameCombo.currentText()
+            selectedBookmark = self.bookmarkCombo.currentText()
+            self.bookmarkCombo.clearEditText()
+            self.bookmarkCombo.clear()
+            self.bookmarkCombo.addItems(sorted(self.__bookmarksList))
+            index = self.bookmarkCombo.findText(bookmark)
+            if index > -1:
+                self.bookmarkCombo.removeItem(index)
+            if selectedBookmark:
+                index = self.bookmarkCombo.findText(selectedBookmark)
+                if index > -1:
+                    self.bookmarkCombo.setCurrentIndex(index)
+    
+    @pyqtSlot(int)
+    def on_nameCombo_activated(self, index):
+        """
+        Private slot to handle changes of the selected bookmark name.
+        
+        @param index index of the selected entry
+        @type int
+        """
+        self.__updateOK()
+        self.__updateBookmarksCombo()
+    
+    @pyqtSlot(str)
+    def on_nameEdit_textChanged(self, txt):
+        """
+        Private slot to handle changes of the bookmark name.
+        
+        @param txt text of the edit (string)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(bool)
+    def on_idButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the ID select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(bool)
+    def on_tagButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the Tag select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(bool)
+    def on_branchButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the Branch select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(bool)
+    def on_bookmarkButton_toggled(self, checked):
+        """
+        Private slot to handle changes of the Bookmark select button.
+        
+        @param checked state of the button (boolean)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(str)
+    def on_idEdit_textChanged(self, txt):
+        """
+        Private slot to handle changes of the ID edit.
+        
+        @param txt text of the edit (string)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(str)
+    def on_tagCombo_editTextChanged(self, txt):
+        """
+        Private slot to handle changes of the Tag combo.
+        
+        @param txt text of the combo (string)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(str)
+    def on_branchCombo_editTextChanged(self, txt):
+        """
+        Private slot to handle changes of the Branch combo.
+        
+        @param txt text of the combo (string)
+        """
+        self.__updateOK()
+    
+    @pyqtSlot(str)
+    def on_bookmarkCombo_editTextChanged(self, txt):
+        """
+        Private slot to handle changes of the Bookmark combo.
+        
+        @param txt text of the combo (string)
+        """
+        self.__updateOK()
+    
+    def getData(self):
+        """
+        Public method to retrieve the entered data.
+        
+        @return tuple naming the revision and the bookmark name
+            (string, string)
+        """
+        if self.numberButton.isChecked():
+            rev = "rev({0})".format(self.numberSpinBox.value())
+        elif self.idButton.isChecked():
+            rev = "id({0})".format(self.idEdit.text())
+        elif self.tagButton.isChecked():
+            rev = self.tagCombo.currentText()
+        elif self.branchButton.isChecked():
+            rev = self.branchCombo.currentText()
+        elif self.bookmarkButton.isChecked():
+            rev = self.bookmarkCombo.currentText()
+        else:
+            rev = ""
+        
+        name = (
+            self.nameCombo.currentText().replace(" ", "_")
+            if self.__mode == self.MOVE_MODE else
+            self.nameEdit.text().replace(" ", "_")
+        )
+        
+        return rev, name

eric ide

mercurial