src/eric7/Plugins/VcsPlugins/vcsGit/GitMergeDialog.py

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

eric ide

mercurial