|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the commit message. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QDateTime |
|
13 from PyQt5.QtWidgets import QWidget, QDialogButtonBox |
|
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, 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 parent parent widget (QWidget) |
|
36 """ |
|
37 super(HgCommitDialog, self).__init__(parent, Qt.WindowFlags(Qt.Window)) |
|
38 self.setupUi(self) |
|
39 |
|
40 self.__vcs = vcs |
|
41 |
|
42 self.logEdit.setPlainText(msg) |
|
43 |
|
44 if mq: |
|
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.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(QDialogButtonBox.Cancel): |
|
81 self.logEdit.clear() |
|
82 |
|
83 def on_buttonBox_accepted(self): |
|
84 """ |
|
85 Private slot called by the buttonBox accepted signal. |
|
86 """ |
|
87 self.close() |
|
88 self.accepted.emit() |
|
89 |
|
90 def on_buttonBox_rejected(self): |
|
91 """ |
|
92 Private slot called by the buttonBox rejected signal. |
|
93 """ |
|
94 self.close() |
|
95 self.rejected.emit() |
|
96 |
|
97 @pyqtSlot(str) |
|
98 def on_recentComboBox_activated(self, txt): |
|
99 """ |
|
100 Private slot to select a commit message from recent ones. |
|
101 |
|
102 @param txt text of the selected entry (string) |
|
103 """ |
|
104 if txt: |
|
105 self.logEdit.setPlainText(self.recentComboBox.currentData()) |
|
106 |
|
107 def getCommitData(self): |
|
108 """ |
|
109 Public method to retrieve the entered data for the commit. |
|
110 |
|
111 @return tuple containing the log message, a flag indicating to amend |
|
112 the last commit, a flag indicating to commit subrepositories as |
|
113 well, name of the author and date/time of the commit |
|
114 @rtype tuple of str, bool, bool, str, str |
|
115 """ |
|
116 msg = self.logEdit.toPlainText() |
|
117 if msg: |
|
118 commitMessages = self.__vcs.getPlugin().getPreferences('Commits') |
|
119 if msg in commitMessages: |
|
120 commitMessages.remove(msg) |
|
121 commitMessages.insert(0, msg) |
|
122 no = self.__vcs.getPlugin().getPreferences("CommitMessages") |
|
123 del commitMessages[no:] |
|
124 self.__vcs.getPlugin().setPreferences( |
|
125 'Commits', commitMessages) |
|
126 |
|
127 author = self.authorComboBox.currentText() |
|
128 if author: |
|
129 commitAuthors = \ |
|
130 self.__vcs.getPlugin().getPreferences('CommitAuthors') |
|
131 if author in commitAuthors: |
|
132 commitAuthors.remove(author) |
|
133 commitAuthors.insert(0, author) |
|
134 no = self.__vcs.getPlugin().getPreferences("CommitAuthorsLimit") |
|
135 del commitAuthors[no:] |
|
136 self.__vcs.getPlugin().setPreferences( |
|
137 'CommitAuthors', commitAuthors) |
|
138 |
|
139 if self.dateTimeGroup.isChecked(): |
|
140 dateTime = \ |
|
141 self.dateTimeEdit.dateTime().toString("yyyy-MM-dd hh:mm") |
|
142 else: |
|
143 dateTime = "" |
|
144 |
|
145 return ( |
|
146 msg, |
|
147 self.amendCheckBox.isChecked(), |
|
148 self.subrepoCheckBox.isChecked(), |
|
149 author, |
|
150 dateTime, |
|
151 ) |