Plugins/VcsPlugins/vcsMercurial/HgTagDialog.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3408
b6e6a7062d12
child 3656
441956d8fce5
--- a/Plugins/VcsPlugins/vcsMercurial/HgTagDialog.py	Sun Mar 30 22:00:14 2014 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/HgTagDialog.py	Thu Apr 03 23:05:31 2014 +0200
@@ -14,21 +14,25 @@
 
 from .Ui_HgTagDialog import Ui_HgTagDialog
 
+import UI.PixmapCache
+
 
 class HgTagDialog(QDialog, Ui_HgTagDialog):
     """
     Class implementing a dialog to enter the data for a tagging operation.
     """
-    CreateRegularTag = 1
+    CreateGlobalTag = 1
     CreateLocalTag = 2
-    DeleteTag = 3
-    CreateBranch = 4
+    DeleteGlobalTag = 3
+    DeleteLocalTag = 4
     
-    def __init__(self, taglist, parent=None):
+    def __init__(self, taglist, revision=None, tagName=None, parent=None):
         """
         Constructor
         
         @param taglist list of previously entered tags (list of strings)
+        @param revision revision to set tag for (string)
+        @param tagName name of the tag (string)
         @param parent parent widget (QWidget)
         """
         super(HgTagDialog, self).__init__(parent)
@@ -38,7 +42,28 @@
         self.okButton.setEnabled(False)
         
         self.tagCombo.clear()
-        self.tagCombo.addItems(sorted(taglist))
+        self.tagCombo.addItem("", False)
+        for tag, isLocal in sorted(taglist):
+            if isLocal:
+                icon = UI.PixmapCache.getIcon("vcsTagLocal.png")
+            else:
+                icon = UI.PixmapCache.getIcon("vcsTagGlobal.png")
+            self.tagCombo.addItem(icon, tag, isLocal)
+        
+        if revision:
+            self.revisionEdit.setText(revision)
+        
+        if tagName:
+            index = self.tagCombo.findText(tagName)
+            if index > -1:
+                self.tagCombo.setCurrentIndex(index)
+                # suggest the most relevant tag action
+                self.deleteTagButton.setChecked(True)
+            else:
+                self.tagCombo.setEditText(tagName)
+        
+        msh = self.minimumSizeHint()
+        self.resize(max(self.width(), msh.width()), msh.height())
     
     @pyqtSlot(str)
     def on_tagCombo_editTextChanged(self, text):
@@ -49,18 +74,35 @@
         """
         self.okButton.setDisabled(text == "")
     
+    @pyqtSlot(int)
+    def on_tagCombo_currentIndexChanged(self, index):
+        """
+        Private slot setting the local status of the selected entry.
+        
+        @param index index of the selected entrie (integer)
+        """
+        isLocal = self.tagCombo.itemData(index)
+        if isLocal:
+            self.localTagButton.setChecked(True)
+        else:
+            self.globalTagButton.setChecked(True)
+    
     def getParameters(self):
         """
         Public method to retrieve the tag data.
         
-        @return tuple of string and int (tag, tag operation)
+        @return tuple of two strings and int (tag, revision, tag operation)
         """
-        tag = self.tagCombo.currentText()
+        tag = self.tagCombo.currentText().replace(" ", "_")
         tagOp = 0
-        if self.createRegularButton.isChecked():
-            tagOp = HgTagDialog.CreateRegularTag
-        elif self.createLocalButton.isChecked():
-            tagOp = HgTagDialog.CreateLocalTag
-        elif self.deleteButton.isChecked():
-            tagOp = HgTagDialog.DeleteTag
-        return (tag, tagOp)
+        if self.createTagButton.isChecked():
+            if self.globalTagButton.isChecked():
+                tagOp = HgTagDialog.CreateGlobalTag
+            else:
+                tagOp = HgTagDialog.CreateLocalTag
+        else:
+            if self.globalTagButton.isChecked():
+                tagOp = HgTagDialog.DeleteGlobalTag
+            else:
+                tagOp = HgTagDialog.DeleteLocalTag
+        return (tag, self.revisionEdit.text(), tagOp)

eric ide

mercurial