|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the commit message. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, Qt, SIGNAL |
|
11 from PyQt4.QtGui import QWidget, QDialogButtonBox |
|
12 |
|
13 from .Ui_HgCommitDialog import Ui_HgCommitDialog |
|
14 |
|
15 import Preferences |
|
16 |
|
17 class HgCommitDialog(QWidget, Ui_HgCommitDialog): |
|
18 """ |
|
19 Class implementing a dialog to enter the commit message. |
|
20 |
|
21 @signal accepted() emitted, if the dialog was accepted |
|
22 @signal rejected() emitted, if the dialog was rejected |
|
23 """ |
|
24 def __init__(self, vcs, parent = None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param vcs reference to the vcs object |
|
29 @param parent parent widget (QWidget) |
|
30 """ |
|
31 QWidget.__init__(self, parent, Qt.WindowFlags(Qt.Window)) |
|
32 self.setupUi(self) |
|
33 |
|
34 def showEvent(self, evt): |
|
35 """ |
|
36 Public method called when the dialog is about to be shown. |
|
37 |
|
38 @param evt the event (QShowEvent) |
|
39 """ |
|
40 self.recentCommitMessages = Preferences.toList( |
|
41 Preferences.Prefs.settings.value('Mercurial/Commits')) |
|
42 self.recentComboBox.clear() |
|
43 self.recentComboBox.addItem("") |
|
44 self.recentComboBox.addItems(self.recentCommitMessages) |
|
45 |
|
46 def logMessage(self): |
|
47 """ |
|
48 Public method to retrieve the log message. |
|
49 |
|
50 @return the log message (string) |
|
51 """ |
|
52 msg = self.logEdit.toPlainText() |
|
53 if msg: |
|
54 if msg in self.recentCommitMessages: |
|
55 self.recentCommitMessages.remove(msg) |
|
56 self.recentCommitMessages.insert(0, msg) |
|
57 no = int(Preferences.Prefs.settings\ |
|
58 .value('Mercurial/CommitMessages', 20)) |
|
59 del self.recentCommitMessages[no:] |
|
60 Preferences.Prefs.settings.setValue('Mercurial/Commits', |
|
61 self.recentCommitMessages) |
|
62 return msg |
|
63 |
|
64 def on_buttonBox_clicked(self, button): |
|
65 """ |
|
66 Private slot called by a button of the button box clicked. |
|
67 |
|
68 @param button button that was clicked (QAbstractButton) |
|
69 """ |
|
70 if button == self.buttonBox.button(QDialogButtonBox.Cancel): |
|
71 self.logEdit.clear() |
|
72 |
|
73 def on_buttonBox_accepted(self): |
|
74 """ |
|
75 Private slot called by the buttonBox accepted signal. |
|
76 """ |
|
77 self.close() |
|
78 self.emit(SIGNAL("accepted()")) |
|
79 |
|
80 def on_buttonBox_rejected(self): |
|
81 """ |
|
82 Private slot called by the buttonBox rejected signal. |
|
83 """ |
|
84 self.close() |
|
85 self.emit(SIGNAL("rejected()")) |
|
86 |
|
87 @pyqtSlot(str) |
|
88 def on_recentComboBox_activated(self, txt): |
|
89 """ |
|
90 Private slot to select a commit message from recent ones. |
|
91 """ |
|
92 if txt: |
|
93 self.logEdit.setPlainText(txt) |