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