Plugins/VcsPlugins/vcsGit/GitMergeDialog.py

changeset 6020
baf6da1ae288
child 6048
82ad8ec9548c
equal deleted inserted replaced
6019:58ecdaf0b789 6020:baf6da1ae288
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the merge data.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
14
15 from .Ui_GitMergeDialog import Ui_GitMergeDialog
16
17
18 class GitMergeDialog(QDialog, Ui_GitMergeDialog):
19 """
20 Class implementing a dialog to enter the merge data.
21 """
22 def __init__(self, tagsList, branchesList, currentBranch,
23 remoteBranchesList, parent=None):
24 """
25 Constructor
26
27 @param tagsList list of tags (list of strings)
28 @param branchesList list of branches (list of strings)
29 @param currentBranch name of the current branch (string)
30 @param remoteBranchesList list of remote branches (list of strings)
31 @param parent reference to the parent widget (QWidget)
32 """
33 super(GitMergeDialog, self).__init__(parent)
34 self.setupUi(self)
35
36 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
37
38 self.__currentBranch = currentBranch
39
40 self.tagCombo.addItems(sorted(tagsList))
41 if currentBranch in branchesList:
42 branchesList.remove(currentBranch)
43 self.branchCombo.addItems(sorted(branchesList))
44 self.remoteBranchCombo.addItems(sorted(remoteBranchesList))
45
46 msh = self.minimumSizeHint()
47 self.resize(max(self.width(), msh.width()), msh.height())
48
49 def __updateOK(self):
50 """
51 Private slot to update the OK button.
52 """
53 enabled = True
54 if self.idButton.isChecked():
55 enabled = self.idEdit.text() != ""
56 elif self.tagButton.isChecked():
57 enabled = self.tagCombo.currentText() != ""
58 elif self.branchButton.isChecked():
59 enabled = self.branchCombo.currentText() != ""
60 elif self.remoteBranchButton.isChecked():
61 enabled = self.remoteBranchCombo.currentText() != ""
62
63 enabled &= (self.commitGroupBox.isChecked() and
64 self.commitMessageEdit.toPlainText() != "")
65
66 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enabled)
67
68 def __generateDefaultCommitMessage(self):
69 """
70 Private slot to generate a default commit message based on the
71 data entered.
72 """
73 if self.commitGroupBox.isChecked():
74 if self.idButton.isChecked():
75 msg = "Merged commit {0} into {1}.".format(
76 self.idEdit.text(), self.__currentBranch)
77 elif self.tagButton.isChecked():
78 msg = "Merged tag {0} into {1}.".format(
79 self.tagCombo.currentText(), self.__currentBranch)
80 elif self.branchButton.isChecked():
81 msg = "Merged branch {0} into {1}.".format(
82 self.branchCombo.currentText(), self.__currentBranch)
83 elif self.remoteBranchButton.isChecked():
84 msg = "Merged remote branch {0} into {1}.".format(
85 self.remoteBranchCombo.currentText(), self.__currentBranch)
86 else:
87 msg = "Merged into {0}.".format(self.__currentBranch)
88 self.commitMessageEdit.setPlainText(msg)
89 else:
90 self.commitMessageEdit.clear()
91
92 @pyqtSlot(bool)
93 def on_idButton_toggled(self, checked):
94 """
95 Private slot to handle changes of the ID select button.
96
97 @param checked state of the button (boolean)
98 """
99 self.__generateDefaultCommitMessage()
100 self.__updateOK()
101
102 @pyqtSlot(bool)
103 def on_tagButton_toggled(self, checked):
104 """
105 Private slot to handle changes of the Tag select button.
106
107 @param checked state of the button (boolean)
108 """
109 self.__generateDefaultCommitMessage()
110 self.__updateOK()
111
112 @pyqtSlot(bool)
113 def on_branchButton_toggled(self, checked):
114 """
115 Private slot to handle changes of the Branch select button.
116
117 @param checked state of the button (boolean)
118 """
119 self.__generateDefaultCommitMessage()
120 self.__updateOK()
121
122 @pyqtSlot(bool)
123 def on_remoteBranchButton_toggled(self, checked):
124 """
125 Private slot to handle changes of the Remote Branch select button.
126
127 @param checked state of the button (boolean)
128 """
129 self.__generateDefaultCommitMessage()
130 self.__updateOK()
131
132 @pyqtSlot(bool)
133 def on_noneButton_toggled(self, checked):
134 """
135 Private slot to handle changes of the None select button.
136
137 @param checked state of the button (boolean)
138 """
139 self.__generateDefaultCommitMessage()
140
141 @pyqtSlot(str)
142 def on_idEdit_textChanged(self, txt):
143 """
144 Private slot to handle changes of the Commit edit.
145
146 @param txt text of the edit (string)
147 """
148 self.__generateDefaultCommitMessage()
149 self.__updateOK()
150
151 @pyqtSlot(str)
152 def on_tagCombo_editTextChanged(self, txt):
153 """
154 Private slot to handle changes of the Tag combo.
155
156 @param txt text of the combo (string)
157 """
158 self.__generateDefaultCommitMessage()
159 self.__updateOK()
160
161 @pyqtSlot(str)
162 def on_branchCombo_editTextChanged(self, txt):
163 """
164 Private slot to handle changes of the Branch combo.
165
166 @param txt text of the combo (string)
167 """
168 self.__generateDefaultCommitMessage()
169 self.__updateOK()
170
171 @pyqtSlot(str)
172 def on_remoteBranchCombo_editTextChanged(self, txt):
173 """
174 Private slot to handle changes of the Remote Branch combo.
175
176 @param txt text of the combo (string)
177 """
178 self.__generateDefaultCommitMessage()
179 self.__updateOK()
180
181 @pyqtSlot(bool)
182 def on_commitGroupBox_toggled(self, checked):
183 """
184 Private slot to handle changes of the Commit select group.
185
186 @param checked state of the group (boolean)
187 """
188 self.__generateDefaultCommitMessage()
189 self.__updateOK()
190
191 @pyqtSlot()
192 def on_commitMessageEdit_textChanged(self):
193 """
194 Private slot to handle changes of the commit message edit.
195 """
196 self.__updateOK()
197
198 def getParameters(self):
199 """
200 Public method to retrieve the merge data.
201
202 @return tuple naming the revision, a flag indicating that the merge
203 shall be committed, the commit message, a flag indicating that a
204 log summary shall be appended and a flag indicating to show diff
205 statistics at the end of the merge (string, boolean, string,
206 boolean, boolean)
207 """
208 if self.idButton.isChecked():
209 rev = self.idEdit.text()
210 elif self.tagButton.isChecked():
211 rev = self.tagCombo.currentText()
212 elif self.branchButton.isChecked():
213 rev = self.branchCombo.currentText()
214 elif self.remoteBranchButton.isChecked():
215 rev = self.remoteBranchCombo.currentText()
216 else:
217 rev = ""
218
219 return (
220 rev,
221 self.commitGroupBox.isChecked(),
222 self.commitMessageEdit.toPlainText(),
223 self.addLogCheckBox.isChecked(),
224 self.diffstatCheckBox.isChecked(),
225 )

eric ide

mercurial