Plugins/VcsPlugins/vcsGit/GitCommitDialog.py

changeset 6020
baf6da1ae288
child 6048
82ad8ec9548c
equal deleted inserted replaced
6019:58ecdaf0b789 6020:baf6da1ae288
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2017 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
13 from PyQt5.QtWidgets import QWidget, QDialogButtonBox
14
15 from .Ui_GitCommitDialog import Ui_GitCommitDialog
16
17
18 class GitCommitDialog(QWidget, Ui_GitCommitDialog):
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, amend, commitAll, parent=None):
29 """
30 Constructor
31
32 @param vcs reference to the vcs object
33 @param msg initial message (string)
34 @param amend flag indicating to amend the HEAD commit (boolean)
35 @param commitAll flag indicating to commit all local changes (boolean)
36 @param parent parent widget (QWidget)
37 """
38 super(GitCommitDialog, self).__init__(
39 parent, Qt.WindowFlags(Qt.Window))
40 self.setupUi(self)
41
42 self.__vcs = vcs
43
44 self.logEdit.setPlainText(msg)
45 self.amendCheckBox.setChecked(amend)
46 self.stagedCheckBox.setChecked(not commitAll)
47
48 def showEvent(self, evt):
49 """
50 Protected method called when the dialog is about to be shown.
51
52 @param evt the event (QShowEvent)
53 """
54 commitMessages = self.__vcs.getPlugin().getPreferences('Commits')
55 self.recentComboBox.clear()
56 self.recentComboBox.addItem("")
57 for message in commitMessages:
58 abbrMsg = message[:60]
59 if len(message) > 60:
60 abbrMsg += "..."
61 self.recentComboBox.addItem(abbrMsg, message)
62
63 self.logEdit.setFocus(Qt.OtherFocusReason)
64
65 def logMessage(self):
66 """
67 Public method to retrieve the log message.
68
69 @return the log message (string)
70 """
71 msg = self.logEdit.toPlainText()
72 if msg:
73 commitMessages = self.__vcs.getPlugin().getPreferences('Commits')
74 if msg in commitMessages:
75 commitMessages.remove(msg)
76 commitMessages.insert(0, msg)
77 no = self.__vcs.getPlugin().getPreferences("CommitMessages")
78 del commitMessages[no:]
79 self.__vcs.getPlugin().setPreferences(
80 'Commits', commitMessages)
81
82 return msg
83
84 def stagedOnly(self):
85 """
86 Public method to retrieve the state of the staged only flag.
87
88 @return state of the staged only flag (boolean)
89 """
90 return self.stagedCheckBox.isChecked()
91
92 def amend(self):
93 """
94 Public method to retrieve the state of the amend flag.
95
96 @return state of the amend flag (boolean)
97 """
98 return self.amendCheckBox.isChecked()
99
100 def resetAuthor(self):
101 """
102 Public method to retrieve the state of the reset author flag.
103
104 @return state of the reset author flag (boolean)
105 """
106 return self.resetAuthorCheckBox.isChecked()
107
108 def on_buttonBox_clicked(self, button):
109 """
110 Private slot called by a button of the button box clicked.
111
112 @param button button that was clicked (QAbstractButton)
113 """
114 if button == self.buttonBox.button(QDialogButtonBox.Cancel):
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(str)
132 def on_recentComboBox_activated(self, txt):
133 """
134 Private slot to select a commit message from recent ones.
135
136 @param txt text of the selected entry (string)
137 """
138 if txt:
139 self.logEdit.setPlainText(self.recentComboBox.currentData())

eric ide

mercurial