eric7/Plugins/VcsPlugins/vcsGit/GitCommitDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 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
11 from PyQt5.QtWidgets import QWidget, QDialogButtonBox
12
13 from .Ui_GitCommitDialog import Ui_GitCommitDialog
14
15
16 class GitCommitDialog(QWidget, Ui_GitCommitDialog):
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, amend, commitAll, parent=None):
27 """
28 Constructor
29
30 @param vcs reference to the vcs object
31 @param msg initial message (string)
32 @param amend flag indicating to amend the HEAD commit (boolean)
33 @param commitAll flag indicating to commit all local changes (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 self.amendCheckBox.setChecked(amend)
44 self.stagedCheckBox.setChecked(not commitAll)
45
46 def showEvent(self, evt):
47 """
48 Protected method called when the dialog is about to be shown.
49
50 @param evt the event (QShowEvent)
51 """
52 commitMessages = self.__vcs.getPlugin().getPreferences('Commits')
53 self.recentComboBox.clear()
54 self.recentComboBox.addItem("")
55 for message in commitMessages:
56 abbrMsg = message[:60]
57 if len(message) > 60:
58 abbrMsg += "..."
59 self.recentComboBox.addItem(abbrMsg, message)
60
61 self.logEdit.setFocus(Qt.FocusReason.OtherFocusReason)
62
63 def logMessage(self):
64 """
65 Public method to retrieve the log message.
66
67 @return the log message (string)
68 """
69 msg = self.logEdit.toPlainText()
70 if msg:
71 commitMessages = self.__vcs.getPlugin().getPreferences('Commits')
72 if msg in commitMessages:
73 commitMessages.remove(msg)
74 commitMessages.insert(0, msg)
75 no = self.__vcs.getPlugin().getPreferences("CommitMessages")
76 del commitMessages[no:]
77 self.__vcs.getPlugin().setPreferences(
78 'Commits', commitMessages)
79
80 return msg
81
82 def stagedOnly(self):
83 """
84 Public method to retrieve the state of the staged only flag.
85
86 @return state of the staged only flag (boolean)
87 """
88 return self.stagedCheckBox.isChecked()
89
90 def amend(self):
91 """
92 Public method to retrieve the state of the amend flag.
93
94 @return state of the amend flag (boolean)
95 """
96 return self.amendCheckBox.isChecked()
97
98 def resetAuthor(self):
99 """
100 Public method to retrieve the state of the reset author flag.
101
102 @return state of the reset author flag (boolean)
103 """
104 return self.resetAuthorCheckBox.isChecked()
105
106 def on_buttonBox_clicked(self, button):
107 """
108 Private slot called by a button of the button box clicked.
109
110 @param button button that was clicked (QAbstractButton)
111 """
112 if button == self.buttonBox.button(
113 QDialogButtonBox.StandardButton.Cancel
114 ):
115 self.logEdit.clear()
116
117 def on_buttonBox_accepted(self):
118 """
119 Private slot called by the buttonBox accepted signal.
120 """
121 self.close()
122 self.accepted.emit()
123
124 def on_buttonBox_rejected(self):
125 """
126 Private slot called by the buttonBox rejected signal.
127 """
128 self.close()
129 self.rejected.emit()
130
131 @pyqtSlot(int)
132 def on_recentComboBox_activated(self, index):
133 """
134 Private slot to select a commit message from recent ones.
135
136 @param index index of the selected entry
137 @type int
138 """
139 txt = self.recentComboBox.itemText(index)
140 if txt:
141 self.logEdit.setPlainText(self.recentComboBox.currentData())

eric ide

mercurial