|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the commit message. |
|
8 """ |
|
9 |
|
10 import pysvn |
|
11 |
|
12 from PyQt6.QtCore import pyqtSignal, Qt, pyqtSlot |
|
13 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
|
14 |
|
15 from EricWidgets.EricApplication import ericApp |
|
16 |
|
17 from .Ui_SvnCommitDialog import Ui_SvnCommitDialog |
|
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().__init__(parent, Qt.WindowType.Window) |
|
38 self.setupUi(self) |
|
39 |
|
40 self.__vcs = vcs |
|
41 |
|
42 project = ericApp().getObject("Project") |
|
43 pwl, pel = project.getProjectDictionaries() |
|
44 language = project.getProjectSpellLanguage() |
|
45 self.logEdit.setLanguageWithPWL(language, pwl or None, pel or None) |
|
46 |
|
47 if pysvn.svn_version < (1, 5, 0) or pysvn.version < (1, 6, 0): |
|
48 self.changeListsGroup.hide() |
|
49 else: |
|
50 self.changeLists.addItems(sorted(vcs.svnGetChangelists())) |
|
51 |
|
52 def showEvent(self, evt): |
|
53 """ |
|
54 Protected method called when the dialog is about to be shown. |
|
55 |
|
56 @param evt the event (QShowEvent) |
|
57 """ |
|
58 commitMessages = self.__vcs.vcsCommitMessages() |
|
59 self.recentComboBox.clear() |
|
60 self.recentComboBox.addItem("") |
|
61 self.recentComboBox.addItems(commitMessages) |
|
62 |
|
63 self.logEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
|
64 |
|
65 def logMessage(self): |
|
66 """ |
|
67 Public method to retrieve the log message. |
|
68 |
|
69 This method has the side effect of saving the 20 most recent |
|
70 commit messages for reuse. |
|
71 |
|
72 @return the log message (string) |
|
73 """ |
|
74 msg = self.logEdit.toPlainText() |
|
75 if msg: |
|
76 self.__vcs.vcsAddCommitMessage(msg) |
|
77 return msg |
|
78 |
|
79 def hasChangelists(self): |
|
80 """ |
|
81 Public method to check, if the user entered some changelists. |
|
82 |
|
83 @return flag indicating availability of changelists (boolean) |
|
84 """ |
|
85 return len(self.changeLists.selectedItems()) > 0 |
|
86 |
|
87 def changelistsData(self): |
|
88 """ |
|
89 Public method to retrieve the changelists data. |
|
90 |
|
91 @return tuple containing the changelists (list of strings) and a flag |
|
92 indicating to keep changelists (boolean) |
|
93 """ |
|
94 slists = [line.text().strip() |
|
95 for line in self.changeLists.selectedItems() |
|
96 if line.text().strip() != ""] |
|
97 |
|
98 if len(slists) == 0: |
|
99 return [], False |
|
100 |
|
101 return slists, self.keepChangeListsCheckBox.isChecked() |
|
102 |
|
103 def on_buttonBox_clicked(self, button): |
|
104 """ |
|
105 Private slot called by a button of the button box clicked. |
|
106 |
|
107 @param button button that was clicked (QAbstractButton) |
|
108 """ |
|
109 if button == self.buttonBox.button( |
|
110 QDialogButtonBox.StandardButton.Cancel |
|
111 ): |
|
112 self.logEdit.clear() |
|
113 |
|
114 def on_buttonBox_accepted(self): |
|
115 """ |
|
116 Private slot called by the buttonBox accepted signal. |
|
117 """ |
|
118 self.close() |
|
119 self.accepted.emit() |
|
120 |
|
121 def on_buttonBox_rejected(self): |
|
122 """ |
|
123 Private slot called by the buttonBox rejected signal. |
|
124 """ |
|
125 self.close() |
|
126 self.rejected.emit() |
|
127 |
|
128 @pyqtSlot(int) |
|
129 def on_recentComboBox_activated(self, index): |
|
130 """ |
|
131 Private slot to select a commit message from recent ones. |
|
132 |
|
133 @param index index of the selected entry |
|
134 @type int |
|
135 """ |
|
136 txt = self.recentComboBox.itemText(index) |
|
137 if txt: |
|
138 self.logEdit.setPlainText(txt) |