11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt |
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt |
13 from PyQt5.QtWidgets import QWidget, QDialogButtonBox |
13 from PyQt5.QtWidgets import QWidget, QDialogButtonBox |
14 |
14 |
15 from .Ui_HgCommitDialog import Ui_HgCommitDialog |
15 from .Ui_HgCommitDialog import Ui_HgCommitDialog |
16 |
|
17 import Preferences |
|
18 |
16 |
19 |
17 |
20 # TODO: add capability to set the author |
18 # TODO: add capability to set the author |
21 # TODO: add capability to set date and time, |
19 # TODO: add capability to set date and time, |
22 class HgCommitDialog(QWidget, Ui_HgCommitDialog): |
20 class HgCommitDialog(QWidget, Ui_HgCommitDialog): |
39 @param parent parent widget (QWidget) |
37 @param parent parent widget (QWidget) |
40 """ |
38 """ |
41 super(HgCommitDialog, self).__init__(parent, Qt.WindowFlags(Qt.Window)) |
39 super(HgCommitDialog, self).__init__(parent, Qt.WindowFlags(Qt.Window)) |
42 self.setupUi(self) |
40 self.setupUi(self) |
43 |
41 |
|
42 self.__vcs = vcs |
|
43 |
44 self.logEdit.setPlainText(msg) |
44 self.logEdit.setPlainText(msg) |
45 |
45 |
46 if mq: |
46 if mq: |
47 self.amendCheckBox.setVisible(False) |
47 self.amendCheckBox.setVisible(False) |
48 self.subrepoCheckBox.setVisible(False) |
48 self.subrepoCheckBox.setVisible(False) |
53 """ |
53 """ |
54 Protected method called when the dialog is about to be shown. |
54 Protected method called when the dialog is about to be shown. |
55 |
55 |
56 @param evt the event (QShowEvent) |
56 @param evt the event (QShowEvent) |
57 """ |
57 """ |
58 self.recentCommitMessages = Preferences.toList( |
58 commitMessages = self.__vcs.getPlugin().getPreferences('Commits') |
59 Preferences.Prefs.settings.value('Mercurial/Commits')) |
|
60 self.recentComboBox.clear() |
59 self.recentComboBox.clear() |
61 self.recentComboBox.addItem("") |
60 self.recentComboBox.addItem("") |
62 self.recentComboBox.addItems(self.recentCommitMessages) |
61 for message in commitMessages: |
63 |
62 abbrMsg = message[:60] |
64 def logMessage(self): |
63 if len(message) > 60: |
65 """ |
64 abbrMsg += "..." |
66 Public method to retrieve the log message. |
65 self.recentComboBox.addItem(abbrMsg, message) |
67 |
|
68 @return the log message (string) |
|
69 """ |
|
70 msg = self.logEdit.toPlainText() |
|
71 if msg: |
|
72 if msg in self.recentCommitMessages: |
|
73 self.recentCommitMessages.remove(msg) |
|
74 self.recentCommitMessages.insert(0, msg) |
|
75 no = int(Preferences.Prefs.settings.value( |
|
76 'Mercurial/CommitMessages', 20)) |
|
77 del self.recentCommitMessages[no:] |
|
78 Preferences.Prefs.settings.setValue( |
|
79 'Mercurial/Commits', self.recentCommitMessages) |
|
80 return msg |
|
81 |
|
82 def amend(self): |
|
83 """ |
|
84 Public method to retrieve the state of the amend flag. |
|
85 |
|
86 @return state of the amend flag (boolean) |
|
87 """ |
|
88 return self.amendCheckBox.isChecked() |
|
89 |
|
90 def commitSubrepositories(self): |
|
91 """ |
|
92 Public method to retrieve the state of the commit sub-repositories |
|
93 flag. |
|
94 |
|
95 @return state of the sub-repositories flag (boolean) |
|
96 """ |
|
97 return self.subrepoCheckBox.isChecked() |
|
98 |
66 |
99 def on_buttonBox_clicked(self, button): |
67 def on_buttonBox_clicked(self, button): |
100 """ |
68 """ |
101 Private slot called by a button of the button box clicked. |
69 Private slot called by a button of the button box clicked. |
102 |
70 |
125 Private slot to select a commit message from recent ones. |
93 Private slot to select a commit message from recent ones. |
126 |
94 |
127 @param txt text of the selected entry (string) |
95 @param txt text of the selected entry (string) |
128 """ |
96 """ |
129 if txt: |
97 if txt: |
130 self.logEdit.setPlainText(txt) |
98 self.logEdit.setPlainText(self.recentComboBox.currentData()) |
|
99 |
|
100 def getCommitData(self): |
|
101 """ |
|
102 Public method to retrieve the entered data for the commit. |
|
103 |
|
104 @return tuple containing the log message, a flag indicating to amend |
|
105 the last commit and a flag indicating to commit subrepositories |
|
106 as well |
|
107 @rtype tuple of str, bool, bool |
|
108 """ |
|
109 msg = self.logEdit.toPlainText() |
|
110 if msg: |
|
111 commitMessages = self.__vcs.getPlugin().getPreferences('Commits') |
|
112 if msg in commitMessages: |
|
113 commitMessages.remove(msg) |
|
114 commitMessages.insert(0, msg) |
|
115 no = self.__vcs.getPlugin().getPreferences("CommitMessages") |
|
116 del commitMessages[no:] |
|
117 self.__vcs.getPlugin().setPreferences( |
|
118 'Commits', commitMessages) |
|
119 |
|
120 return ( |
|
121 msg, |
|
122 self.amendCheckBox.isChecked(), |
|
123 self.subrepoCheckBox.isChecked() |
|
124 ) |