|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 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 pyqtSignal, Qt, pyqtSlot |
|
13 from PyQt5.QtWidgets import QWidget, QDialogButtonBox |
|
14 |
|
15 from .Ui_SvnCommitDialog import Ui_SvnCommitDialog |
|
16 |
|
17 import Preferences |
|
18 |
|
19 |
|
20 class SvnCommitDialog(QWidget, Ui_SvnCommitDialog): |
|
21 """ |
|
22 Class implementing a dialog to enter the commit message. |
|
23 |
|
24 @signal accepted() emitted, if the dialog was accepted |
|
25 @signal rejected() emitted, if the dialog was rejected |
|
26 """ |
|
27 accepted = pyqtSignal() |
|
28 rejected = pyqtSignal() |
|
29 |
|
30 def __init__(self, vcs, parent=None): |
|
31 """ |
|
32 Constructor |
|
33 |
|
34 @param vcs reference to the vcs object |
|
35 @param parent parent widget (QWidget) |
|
36 """ |
|
37 super(SvnCommitDialog, self).__init__( |
|
38 parent, Qt.WindowFlags(Qt.Window)) |
|
39 self.setupUi(self) |
|
40 |
|
41 if vcs.version < (1, 5, 0): |
|
42 self.changeListsGroup.hide() |
|
43 else: |
|
44 self.changeLists.addItems(sorted(vcs.svnGetChangelists())) |
|
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 self.recentCommitMessages = Preferences.toList( |
|
53 Preferences.Prefs.settings.value('Subversion/Commits')) |
|
54 self.recentComboBox.clear() |
|
55 self.recentComboBox.addItem("") |
|
56 self.recentComboBox.addItems(self.recentCommitMessages) |
|
57 |
|
58 self.logEdit.setFocus(Qt.OtherFocusReason) |
|
59 |
|
60 def logMessage(self): |
|
61 """ |
|
62 Public method to retrieve the log message. |
|
63 |
|
64 @return the log message (string) |
|
65 """ |
|
66 msg = self.logEdit.toPlainText() |
|
67 if msg: |
|
68 if msg in self.recentCommitMessages: |
|
69 self.recentCommitMessages.remove(msg) |
|
70 self.recentCommitMessages.insert(0, msg) |
|
71 no = int(Preferences.Prefs.settings |
|
72 .value('Subversion/CommitMessages', 20)) |
|
73 del self.recentCommitMessages[no:] |
|
74 Preferences.Prefs.settings.setValue( |
|
75 'Subversion/Commits', self.recentCommitMessages) |
|
76 return msg |
|
77 |
|
78 def hasChangelists(self): |
|
79 """ |
|
80 Public method to check, if the user entered some changelists. |
|
81 |
|
82 @return flag indicating availability of changelists (boolean) |
|
83 """ |
|
84 return len(self.changeLists.selectedItems()) > 0 |
|
85 |
|
86 def changelistsData(self): |
|
87 """ |
|
88 Public method to retrieve the changelists data. |
|
89 |
|
90 @return tuple containing the changelists (list of strings) and a flag |
|
91 indicating to keep changelists (boolean) |
|
92 """ |
|
93 slists = [l.text().strip() for l in self.changeLists.selectedItems() |
|
94 if l.text().strip() != ""] |
|
95 |
|
96 if len(slists) == 0: |
|
97 return [], False |
|
98 |
|
99 return slists, self.keepChangeListsCheckBox.isChecked() |
|
100 |
|
101 def on_buttonBox_clicked(self, button): |
|
102 """ |
|
103 Private slot called by a button of the button box clicked. |
|
104 |
|
105 @param button button that was clicked (QAbstractButton) |
|
106 """ |
|
107 if button == self.buttonBox.button(QDialogButtonBox.Cancel): |
|
108 self.logEdit.clear() |
|
109 |
|
110 def on_buttonBox_accepted(self): |
|
111 """ |
|
112 Private slot called by the buttonBox accepted signal. |
|
113 """ |
|
114 self.close() |
|
115 self.accepted.emit() |
|
116 |
|
117 def on_buttonBox_rejected(self): |
|
118 """ |
|
119 Private slot called by the buttonBox rejected signal. |
|
120 """ |
|
121 self.close() |
|
122 self.rejected.emit() |
|
123 |
|
124 @pyqtSlot(str) |
|
125 def on_recentComboBox_activated(self, txt): |
|
126 """ |
|
127 Private slot to select a commit message from recent ones. |
|
128 |
|
129 @param txt text of the combo (string) |
|
130 """ |
|
131 if txt: |
|
132 self.logEdit.setPlainText(txt) |