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