12 from PyQt4.QtCore import pyqtSlot |
12 from PyQt4.QtCore import pyqtSlot |
13 from PyQt4.QtGui import QDialog, QDialogButtonBox |
13 from PyQt4.QtGui import QDialog, QDialogButtonBox |
14 |
14 |
15 from .Ui_HgTagDialog import Ui_HgTagDialog |
15 from .Ui_HgTagDialog import Ui_HgTagDialog |
16 |
16 |
|
17 import UI.PixmapCache |
|
18 |
17 |
19 |
18 class HgTagDialog(QDialog, Ui_HgTagDialog): |
20 class HgTagDialog(QDialog, Ui_HgTagDialog): |
19 """ |
21 """ |
20 Class implementing a dialog to enter the data for a tagging operation. |
22 Class implementing a dialog to enter the data for a tagging operation. |
21 """ |
23 """ |
22 CreateRegularTag = 1 |
24 CreateGlobalTag = 1 |
23 CreateLocalTag = 2 |
25 CreateLocalTag = 2 |
24 DeleteTag = 3 |
26 DeleteGlobalTag = 3 |
25 CreateBranch = 4 |
27 DeleteLocalTag = 4 |
26 |
28 |
27 def __init__(self, taglist, parent=None): |
29 def __init__(self, taglist, revision=None, tagName=None, parent=None): |
28 """ |
30 """ |
29 Constructor |
31 Constructor |
30 |
32 |
31 @param taglist list of previously entered tags (list of strings) |
33 @param taglist list of previously entered tags (list of strings) |
|
34 @param revision revision to set tag for (string) |
|
35 @param tagName name of the tag (string) |
32 @param parent parent widget (QWidget) |
36 @param parent parent widget (QWidget) |
33 """ |
37 """ |
34 super(HgTagDialog, self).__init__(parent) |
38 super(HgTagDialog, self).__init__(parent) |
35 self.setupUi(self) |
39 self.setupUi(self) |
36 |
40 |
37 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
41 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
38 self.okButton.setEnabled(False) |
42 self.okButton.setEnabled(False) |
39 |
43 |
40 self.tagCombo.clear() |
44 self.tagCombo.clear() |
41 self.tagCombo.addItems(sorted(taglist)) |
45 self.tagCombo.addItem("", False) |
|
46 for tag, isLocal in sorted(taglist): |
|
47 if isLocal: |
|
48 icon = UI.PixmapCache.getIcon("vcsTagLocal.png") |
|
49 else: |
|
50 icon = UI.PixmapCache.getIcon("vcsTagGlobal.png") |
|
51 self.tagCombo.addItem(icon, tag, isLocal) |
|
52 |
|
53 if revision: |
|
54 self.revisionEdit.setText(revision) |
|
55 |
|
56 if tagName: |
|
57 index = self.tagCombo.findText(tagName) |
|
58 if index > -1: |
|
59 self.tagCombo.setCurrentIndex(index) |
|
60 # suggest the most relevant tag action |
|
61 self.deleteTagButton.setChecked(True) |
|
62 else: |
|
63 self.tagCombo.setEditText(tagName) |
|
64 |
|
65 msh = self.minimumSizeHint() |
|
66 self.resize(max(self.width(), msh.width()), msh.height()) |
42 |
67 |
43 @pyqtSlot(str) |
68 @pyqtSlot(str) |
44 def on_tagCombo_editTextChanged(self, text): |
69 def on_tagCombo_editTextChanged(self, text): |
45 """ |
70 """ |
46 Private method used to enable/disable the OK-button. |
71 Private method used to enable/disable the OK-button. |
47 |
72 |
48 @param text tag name entered in the combo (string) |
73 @param text tag name entered in the combo (string) |
49 """ |
74 """ |
50 self.okButton.setDisabled(text == "") |
75 self.okButton.setDisabled(text == "") |
51 |
76 |
|
77 @pyqtSlot(int) |
|
78 def on_tagCombo_currentIndexChanged(self, index): |
|
79 """ |
|
80 Private slot setting the local status of the selected entry. |
|
81 |
|
82 @param index index of the selected entrie (integer) |
|
83 """ |
|
84 isLocal = self.tagCombo.itemData(index) |
|
85 if isLocal: |
|
86 self.localTagButton.setChecked(True) |
|
87 else: |
|
88 self.globalTagButton.setChecked(True) |
|
89 |
52 def getParameters(self): |
90 def getParameters(self): |
53 """ |
91 """ |
54 Public method to retrieve the tag data. |
92 Public method to retrieve the tag data. |
55 |
93 |
56 @return tuple of string and int (tag, tag operation) |
94 @return tuple of two strings and int (tag, revision, tag operation) |
57 """ |
95 """ |
58 tag = self.tagCombo.currentText() |
96 tag = self.tagCombo.currentText().replace(" ", "_") |
59 tagOp = 0 |
97 tagOp = 0 |
60 if self.createRegularButton.isChecked(): |
98 if self.createTagButton.isChecked(): |
61 tagOp = HgTagDialog.CreateRegularTag |
99 if self.globalTagButton.isChecked(): |
62 elif self.createLocalButton.isChecked(): |
100 tagOp = HgTagDialog.CreateGlobalTag |
63 tagOp = HgTagDialog.CreateLocalTag |
101 else: |
64 elif self.deleteButton.isChecked(): |
102 tagOp = HgTagDialog.CreateLocalTag |
65 tagOp = HgTagDialog.DeleteTag |
103 else: |
66 return (tag, tagOp) |
104 if self.globalTagButton.isChecked(): |
|
105 tagOp = HgTagDialog.DeleteGlobalTag |
|
106 else: |
|
107 tagOp = HgTagDialog.DeleteLocalTag |
|
108 return (tag, self.revisionEdit.text(), tagOp) |