|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2025 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the uncommit data. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import QDateTime, Qt, pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog |
|
12 |
|
13 from eric7.EricWidgets.EricApplication import ericApp |
|
14 |
|
15 from .Ui_HgUncommitDialog import Ui_HgUncommitDialog |
|
16 |
|
17 |
|
18 class HgUncommitDialog(QDialog, Ui_HgUncommitDialog): |
|
19 """ |
|
20 Class implementing a dialog to enter the uncommit data. |
|
21 """ |
|
22 |
|
23 def __init__(self, vcs, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param vcs reference to the version control object |
|
28 @type Hg |
|
29 @param parent reference to the parent widget (defaults to None) |
|
30 @type QWidget (optional) |
|
31 """ |
|
32 super().__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.__vcs = vcs |
|
36 |
|
37 project = ericApp().getObject("Project") |
|
38 pwl, pel = project.getProjectDictionaries() |
|
39 language = project.getProjectSpellLanguage() |
|
40 self.logEdit.setLanguageWithPWL(language, pwl or None, pel or None) |
|
41 |
|
42 commitMessages = self.__vcs.vcsCommitMessages() |
|
43 self.recentComboBox.clear() |
|
44 self.recentComboBox.addItem("") |
|
45 for message in commitMessages: |
|
46 abbrMsg = message[:60] |
|
47 if len(message) > 60: |
|
48 abbrMsg += "..." |
|
49 self.recentComboBox.addItem(abbrMsg, message) |
|
50 |
|
51 commitAuthors = self.__vcs.getPlugin().getPreferences("CommitAuthors") |
|
52 self.authorComboBox.clear() |
|
53 self.authorComboBox.addItem("") |
|
54 self.authorComboBox.addItems(commitAuthors) |
|
55 |
|
56 self.dateTimeEdit.setDateTime(QDateTime.currentDateTime()) |
|
57 |
|
58 self.logEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
|
59 |
|
60 @pyqtSlot(int) |
|
61 def on_recentComboBox_activated(self, index): |
|
62 """ |
|
63 Private slot to select a commit message from recent ones. |
|
64 |
|
65 @param index index of the selected entry |
|
66 @type int |
|
67 """ |
|
68 txt = self.recentComboBox.itemText(index) |
|
69 if txt: |
|
70 self.logEdit.setPlainText(self.recentComboBox.currentData()) |
|
71 |
|
72 def getUncommitData(self): |
|
73 """ |
|
74 Public method to retrieve the entered uncommit data. |
|
75 |
|
76 @return tuple containing the commit message, a flag indicating to |
|
77 allow an empty commit, a flag indicating to allow an uncommit |
|
78 with outstanding changes, name of the author and date/time of |
|
79 the commit |
|
80 @rtype tuple of (str, bool, bool, str, str) |
|
81 """ |
|
82 msg = self.logEdit.toPlainText() |
|
83 if msg: |
|
84 self.__vcs.vcsAddCommitMessage(msg) |
|
85 |
|
86 author = self.authorComboBox.currentText() |
|
87 if author: |
|
88 commitAuthors = self.__vcs.getPlugin().getPreferences("CommitAuthors") |
|
89 if author in commitAuthors: |
|
90 commitAuthors.remove(author) |
|
91 commitAuthors.insert(0, author) |
|
92 no = self.__vcs.getPlugin().getPreferences("CommitAuthorsLimit") |
|
93 del commitAuthors[no:] |
|
94 self.__vcs.getPlugin().setPreferences("CommitAuthors", commitAuthors) |
|
95 |
|
96 dateTime = ( |
|
97 self.dateTimeEdit.dateTime().toString("yyyy-MM-dd hh:mm") |
|
98 if self.dateTimeGroup.isChecked() |
|
99 else "" |
|
100 ) |
|
101 |
|
102 return ( |
|
103 msg, |
|
104 self.keepCheckBox.isChecked(), |
|
105 self.allowDirtyCheckBox.isChecked(), |
|
106 author, |
|
107 dateTime, |
|
108 ) |