src/eric7/Plugins/VcsPlugins/vcsMercurial/HgCommitDialog.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) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the commit message.
8 """
9
10 from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt, QDateTime
11 from PyQt6.QtWidgets import QWidget, QDialogButtonBox
12
13 from EricWidgets.EricApplication import ericApp
14
15 from .Ui_HgCommitDialog import Ui_HgCommitDialog
16
17
18 class HgCommitDialog(QWidget, Ui_HgCommitDialog):
19 """
20 Class implementing a dialog to enter the commit message.
21
22 @signal accepted() emitted, if the dialog was accepted
23 @signal rejected() emitted, if the dialog was rejected
24 """
25 accepted = pyqtSignal()
26 rejected = pyqtSignal()
27
28 def __init__(self, vcs, msg, mq, merge, parent=None):
29 """
30 Constructor
31
32 @param vcs reference to the vcs object
33 @param msg initial message (string)
34 @param mq flag indicating a queue commit (boolean)
35 @param merge flag indicating a merge commit (boolean)
36 @param parent parent widget (QWidget)
37 """
38 super().__init__(parent, Qt.WindowType.Window)
39 self.setupUi(self)
40
41 self.__vcs = vcs
42
43 project = ericApp().getObject("Project")
44 pwl, pel = project.getProjectDictionaries()
45 language = project.getProjectSpellLanguage()
46 self.logEdit.setLanguageWithPWL(language, pwl or None, pel or None)
47 self.logEdit.setPlainText(msg)
48
49 if mq or merge:
50 self.amendCheckBox.setVisible(False)
51 self.subrepoCheckBox.setVisible(False)
52 else:
53 self.subrepoCheckBox.setVisible(vcs.hasSubrepositories())
54
55 def showEvent(self, evt):
56 """
57 Protected method called when the dialog is about to be shown.
58
59 @param evt the event (QShowEvent)
60 """
61 commitMessages = self.__vcs.vcsCommitMessages()
62 self.recentComboBox.clear()
63 self.recentComboBox.addItem("")
64 for message in commitMessages:
65 abbrMsg = message[:60]
66 if len(message) > 60:
67 abbrMsg += "..."
68 self.recentComboBox.addItem(abbrMsg, message)
69
70 commitAuthors = self.__vcs.getPlugin().getPreferences('CommitAuthors')
71 self.authorComboBox.clear()
72 self.authorComboBox.addItem("")
73 self.authorComboBox.addItems(commitAuthors)
74
75 self.dateTimeEdit.setDateTime(QDateTime.currentDateTime())
76
77 self.logEdit.setFocus(Qt.FocusReason.OtherFocusReason)
78
79 def on_buttonBox_clicked(self, button):
80 """
81 Private slot called by a button of the button box clicked.
82
83 @param button button that was clicked (QAbstractButton)
84 """
85 if button == self.buttonBox.button(
86 QDialogButtonBox.StandardButton.Cancel
87 ):
88 self.logEdit.clear()
89
90 def on_buttonBox_accepted(self):
91 """
92 Private slot called by the buttonBox accepted signal.
93 """
94 self.close()
95 self.accepted.emit()
96
97 def on_buttonBox_rejected(self):
98 """
99 Private slot called by the buttonBox rejected signal.
100 """
101 self.close()
102 self.rejected.emit()
103
104 @pyqtSlot(int)
105 def on_recentComboBox_activated(self, index):
106 """
107 Private slot to select a commit message from recent ones.
108
109 @param index index of the selected entry
110 @type int
111 """
112 txt = self.recentComboBox.itemText(index)
113 if txt:
114 self.logEdit.setPlainText(self.recentComboBox.currentData())
115
116 def getCommitData(self):
117 """
118 Public method to retrieve the entered data for the commit.
119
120 @return tuple containing the log message, a flag indicating to amend
121 the last commit, a flag indicating to commit subrepositories as
122 well, name of the author and date/time of the commit
123 @rtype tuple of str, bool, bool, str, str
124 """
125 msg = self.logEdit.toPlainText()
126 if msg:
127 self.__vcs.vcsAddCommitMessage(msg)
128
129 author = self.authorComboBox.currentText()
130 if author:
131 commitAuthors = self.__vcs.getPlugin().getPreferences(
132 'CommitAuthors')
133 if author in commitAuthors:
134 commitAuthors.remove(author)
135 commitAuthors.insert(0, author)
136 no = self.__vcs.getPlugin().getPreferences("CommitAuthorsLimit")
137 del commitAuthors[no:]
138 self.__vcs.getPlugin().setPreferences(
139 'CommitAuthors', commitAuthors)
140
141 dateTime = (
142 self.dateTimeEdit.dateTime().toString("yyyy-MM-dd hh:mm")
143 if self.dateTimeGroup.isChecked() else
144 ""
145 )
146
147 return (
148 msg,
149 self.amendCheckBox.isChecked(),
150 self.subrepoCheckBox.isChecked(),
151 author,
152 dateTime,
153 )

eric ide

mercurial