Plugins/VcsPlugins/vcsMercurial/HgBookmarkRenameDialog.py

changeset 3562
ef3f13a2c599
parent 3484
645c12de6b0c
child 3656
441956d8fce5
diff -r 8938a2a66dee -r ef3f13a2c599 Plugins/VcsPlugins/vcsMercurial/HgBookmarkRenameDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/VcsPlugins/vcsMercurial/HgBookmarkRenameDialog.py	Mon May 12 18:19:22 2014 +0200
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to get the data to rename a bookmark.
+"""
+
+from __future__ import unicode_literals
+
+from PyQt4.QtCore import pyqtSlot
+from PyQt4.QtGui import QDialog, QDialogButtonBox
+
+from .Ui_HgBookmarkRenameDialog import Ui_HgBookmarkRenameDialog
+
+
+class HgBookmarkRenameDialog(QDialog, Ui_HgBookmarkRenameDialog):
+    """
+    Class implementing a dialog to get the data to rename a bookmark.
+    """
+    def __init__(self, bookmarksList, parent=None):
+        """
+        Constructor
+        
+        @param bookmarksList list of bookmarks (list of strings)
+        @param parent reference to the parent widget (QWidget)
+        """
+        super(HgBookmarkRenameDialog, self).__init__(parent)
+        self.setupUi(self)
+        
+        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
+       
+        self.bookmarkCombo.addItems(sorted(bookmarksList))
+        
+        msh = self.minimumSizeHint()
+        self.resize(max(self.width(), msh.width()), msh.height())
+    
+    def __updateUI(self):
+        """
+        Private slot to update the UI.
+        """
+        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
+            self.nameEdit.text() != "" and
+            self.bookmarkCombo.currentText() != ""
+        )
+    
+    @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.__updateUI()
+    
+    @pyqtSlot(str)
+    def on_bookmarkCombo_editTextChanged(self, txt):
+        """
+        Private slot to handle changes of the selected bookmark.
+        
+        @param txt name of the selected bookmark (string)
+        """
+        self.__updateUI()
+    
+    def getData(self):
+        """
+        Public method to retrieve the entered data.
+        
+        @return tuple naming the new and old bookmark names
+            (string, string)
+        """
+        return (
+            self.nameEdit.text().replace(" ", "_"),
+            self.bookmarkCombo.currentText().replace(" ", "_")
+        )

eric ide

mercurial