5 |
5 |
6 """ |
6 """ |
7 Module implementing the History dialog. |
7 Module implementing the History dialog. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import pyqtSlot, Qt, QItemSelectionModel |
10 from PyQt6.QtCore import pyqtSlot, Qt, QItemSelectionModel |
11 from PyQt5.QtGui import QBrush, QColor, QTextCursor |
11 from PyQt6.QtGui import QBrush, QTextCursor |
12 from PyQt5.QtWidgets import ( |
12 from PyQt6.QtWidgets import ( |
13 QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton |
13 QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton |
14 ) |
14 ) |
15 |
15 |
16 from E5Gui.E5Application import e5App |
16 from EricWidgets.EricApplication import ericApp |
17 from E5Gui import E5MessageBox |
17 from EricWidgets import EricMessageBox |
18 |
18 |
19 from .Ui_HistoryDialog import Ui_HistoryDialog |
19 from .Ui_HistoryDialog import Ui_HistoryDialog |
20 |
20 |
21 import Globals |
21 import Globals |
22 import Utilities |
22 import Utilities |
|
23 import Preferences |
23 |
24 |
24 |
25 |
25 class HistoryDialog(QDialog, Ui_HistoryDialog): |
26 class HistoryDialog(QDialog, Ui_HistoryDialog): |
26 """ |
27 """ |
27 Class implementing the History dialog. |
28 Class implementing the History dialog. |
28 """ |
29 """ |
29 ChangeIDRole = Qt.UserRole |
30 ChangeIDRole = Qt.ItemDataRole.UserRole |
30 |
31 |
31 def __init__(self, refactoring, filename="", parent=None): |
32 def __init__(self, refactoring, filename="", parent=None): |
32 """ |
33 """ |
33 Constructor |
34 Constructor |
34 |
35 |
39 @param parent reference to the parent widget |
40 @param parent reference to the parent widget |
40 @type QWidget |
41 @type QWidget |
41 """ |
42 """ |
42 QDialog.__init__(self, parent) |
43 QDialog.__init__(self, parent) |
43 self.setupUi(self) |
44 self.setupUi(self) |
44 self.setWindowFlags(Qt.Window) |
45 self.setWindowFlags(Qt.WindowType.Window) |
45 |
46 |
46 if Globals.isWindowsPlatform(): |
47 if Globals.isWindowsPlatform(): |
47 self.previewEdit.setFontFamily("Lucida Console") |
48 self.previewEdit.setFontFamily("Lucida Console") |
48 else: |
49 else: |
49 self.previewEdit.setFontFamily("Monospace") |
50 self.previewEdit.setFontFamily("Monospace") |
50 |
51 |
51 self.formats = {} |
52 self.formats = {} |
52 self.formats[' '] = self.previewEdit.currentCharFormat() |
53 self.formats[' '] = self.previewEdit.currentCharFormat() |
53 charFormat = self.previewEdit.currentCharFormat() |
54 |
54 charFormat.setBackground(QBrush(QColor(190, 237, 190))) |
55 charFormat = self.previewEdit.currentCharFormat() |
|
56 charFormat.setBackground( |
|
57 QBrush(Preferences.getDiffColour("AddedColor"))) |
55 self.formats['+'] = charFormat |
58 self.formats['+'] = charFormat |
56 charFormat = self.previewEdit.currentCharFormat() |
59 |
57 charFormat.setBackground(QBrush(QColor(237, 190, 190))) |
60 charFormat = self.previewEdit.currentCharFormat() |
|
61 charFormat.setBackground( |
|
62 QBrush(Preferences.getDiffColour("RemovedColor"))) |
58 self.formats['-'] = charFormat |
63 self.formats['-'] = charFormat |
59 charFormat = self.previewEdit.currentCharFormat() |
64 |
60 charFormat.setBackground(QBrush(QColor(190, 190, 237))) |
65 charFormat = self.previewEdit.currentCharFormat() |
|
66 charFormat.setBackground( |
|
67 QBrush(Preferences.getDiffColour("ReplacedColor"))) |
61 self.formats['@'] = charFormat |
68 self.formats['@'] = charFormat |
62 charFormat = self.previewEdit.currentCharFormat() |
69 |
63 charFormat.setBackground(QBrush(QColor(124, 124, 124))) |
70 charFormat = self.previewEdit.currentCharFormat() |
|
71 charFormat.setBackground( |
|
72 QBrush(Preferences.getDiffColour("ContextColor"))) |
64 self.formats['?'] = charFormat |
73 self.formats['?'] = charFormat |
65 charFormat = self.previewEdit.currentCharFormat() |
74 |
66 charFormat.setBackground(QBrush(QColor(190, 190, 190))) |
75 charFormat = self.previewEdit.currentCharFormat() |
|
76 charFormat.setBackground( |
|
77 QBrush(Preferences.getDiffColour("HeaderColor"))) |
67 self.formats['='] = charFormat |
78 self.formats['='] = charFormat |
68 |
79 |
69 self.__refactoring = refactoring |
80 self.__refactoring = refactoring |
70 self.__filename = filename |
81 self.__filename = filename |
71 |
82 |
74 else: |
85 else: |
75 self.header.setText(self.tr("<b>File History: {0}</b>").format( |
86 self.header.setText(self.tr("<b>File History: {0}</b>").format( |
76 filename)) |
87 filename)) |
77 |
88 |
78 self.__undoButton = self.buttonBox.addButton( |
89 self.__undoButton = self.buttonBox.addButton( |
79 self.tr("&Undo"), QDialogButtonBox.ActionRole) |
90 self.tr("&Undo"), QDialogButtonBox.ButtonRole.ActionRole) |
80 self.__redoButton = self.buttonBox.addButton( |
91 self.__redoButton = self.buttonBox.addButton( |
81 self.tr("&Redo"), QDialogButtonBox.ActionRole) |
92 self.tr("&Redo"), QDialogButtonBox.ButtonRole.ActionRole) |
82 self.__refreshButton = self.buttonBox.addButton( |
93 self.__refreshButton = self.buttonBox.addButton( |
83 self.tr("Re&fresh"), QDialogButtonBox.ActionRole) |
94 self.tr("Re&fresh"), QDialogButtonBox.ButtonRole.ActionRole) |
84 self.__clearButton = self.buttonBox.addButton( |
95 self.__clearButton = self.buttonBox.addButton( |
85 self.tr("&Clear History"), QDialogButtonBox.ActionRole) |
96 self.tr("&Clear History"), QDialogButtonBox.ButtonRole.ActionRole) |
86 |
97 |
87 # populate the list |
98 # populate the list |
88 self.__refreshHistories() |
99 self.__refreshHistories() |
89 |
100 |
90 def __appendText(self, txt, charFormat): |
101 def __appendText(self, txt, charFormat): |
95 @type str |
106 @type str |
96 @param charFormat text format to be used |
107 @param charFormat text format to be used |
97 @type QTextCharFormat |
108 @type QTextCharFormat |
98 """ |
109 """ |
99 tc = self.previewEdit.textCursor() |
110 tc = self.previewEdit.textCursor() |
100 tc.movePosition(QTextCursor.End) |
111 tc.movePosition(QTextCursor.MoveOperation.End) |
101 self.previewEdit.setTextCursor(tc) |
112 self.previewEdit.setTextCursor(tc) |
102 self.previewEdit.setCurrentCharFormat(charFormat) |
113 self.previewEdit.setCurrentCharFormat(charFormat) |
103 self.previewEdit.insertPlainText(txt) |
114 self.previewEdit.insertPlainText(txt) |
104 |
115 |
105 @pyqtSlot(QAbstractButton) |
116 @pyqtSlot(QAbstractButton) |
189 Private method to undo the selected set of changes. |
200 Private method to undo the selected set of changes. |
190 """ |
201 """ |
191 currentUndoItem = self.undoChangesList.currentItem() |
202 currentUndoItem = self.undoChangesList.currentItem() |
192 change = currentUndoItem.text() |
203 change = currentUndoItem.text() |
193 changeId = currentUndoItem.data(HistoryDialog.ChangeIDRole) |
204 changeId = currentUndoItem.data(HistoryDialog.ChangeIDRole) |
194 res = E5MessageBox.yesNo( |
205 res = EricMessageBox.yesNo( |
195 None, |
206 None, |
196 self.tr("Undo refactorings"), |
207 self.tr("Undo Refactorings"), |
197 self.tr("""Shall all refactorings up to <b>{0}</b>""" |
208 self.tr("""Shall all refactorings up to <b>{0}</b>""" |
198 """ be undone?""") |
209 """ be undone?""") |
199 .format(Utilities.html_encode(change))) |
210 .format(Utilities.html_encode(change))) |
200 if res: |
211 if res: |
201 if not self.__refactoring.confirmAllBuffersSaved(): |
212 if not self.__refactoring.confirmAllBuffersSaved(): |
211 Private method to redo the selected set of changes. |
222 Private method to redo the selected set of changes. |
212 """ |
223 """ |
213 currentRedoItem = self.redoChangesList.currentItem() |
224 currentRedoItem = self.redoChangesList.currentItem() |
214 change = currentRedoItem.text() |
225 change = currentRedoItem.text() |
215 changeId = currentRedoItem.data(HistoryDialog.ChangeIDRole) |
226 changeId = currentRedoItem.data(HistoryDialog.ChangeIDRole) |
216 res = E5MessageBox.yesNo( |
227 res = EricMessageBox.yesNo( |
217 None, |
228 None, |
218 self.tr("Redo refactorings"), |
229 self.tr("Redo Refactorings"), |
219 self.tr("""Shall all refactorings up to <b>{0}</b>""" |
230 self.tr("""Shall all refactorings up to <b>{0}</b>""" |
220 """ be redone?""") |
231 """ be redone?""") |
221 .format(Utilities.html_encode(change))) |
232 .format(Utilities.html_encode(change))) |
222 if res: |
233 if res: |
223 if not self.__refactoring.confirmAllBuffersSaved(): |
234 if not self.__refactoring.confirmAllBuffersSaved(): |
248 |
259 |
249 def __clearHistory(self): |
260 def __clearHistory(self): |
250 """ |
261 """ |
251 Private method to clear the refactoring history. |
262 Private method to clear the refactoring history. |
252 """ |
263 """ |
253 res = E5MessageBox.yesNo( |
264 res = EricMessageBox.yesNo( |
254 None, |
265 None, |
255 self.tr("Clear History"), |
266 self.tr("Clear History"), |
256 self.tr("Do you really want to clear the refactoring history?")) |
267 self.tr("Do you really want to clear the refactoring history?")) |
257 if res: |
268 if res: |
258 self.sendJson("History", { |
269 self.sendJson("History", { |
284 itm = QListWidgetItem(change, self.redoChangesList) |
295 itm = QListWidgetItem(change, self.redoChangesList) |
285 itm.setData(HistoryDialog.ChangeIDRole, changeId) |
296 itm.setData(HistoryDialog.ChangeIDRole, changeId) |
286 if self.undoChangesList.count() > 0: |
297 if self.undoChangesList.count() > 0: |
287 self.undoChangesList.setCurrentItem( |
298 self.undoChangesList.setCurrentItem( |
288 self.undoChangesList.item(0), |
299 self.undoChangesList.item(0), |
289 QItemSelectionModel.Select) |
300 QItemSelectionModel.SelectionFlag.Select) |
290 elif self.redoChangesList.count() > 0: |
301 elif self.redoChangesList.count() > 0: |
291 self.redoChangesList.setCurrentItem( |
302 self.redoChangesList.setCurrentItem( |
292 self.redoChangesList.item(0), |
303 self.redoChangesList.item(0), |
293 QItemSelectionModel.Select) |
304 QItemSelectionModel.SelectionFlag.Select) |
294 |
305 |
295 self.__refreshButton.setEnabled(True) |
306 self.__refreshButton.setEnabled(True) |
296 if ( |
307 if ( |
297 self.undoChangesList.count() > 0 or |
308 self.undoChangesList.count() > 0 or |
298 self.redoChangesList.count() > 0 |
309 self.redoChangesList.count() > 0 |
307 charFormat = self.formats[' '] |
318 charFormat = self.formats[' '] |
308 self.__appendText(line, charFormat) |
319 self.__appendText(line, charFormat) |
309 |
320 |
310 elif subcommand in ["Undo", "Redo"]: |
321 elif subcommand in ["Undo", "Redo"]: |
311 self.__refactoring.refreshEditors(data["ChangedFiles"]) |
322 self.__refactoring.refreshEditors(data["ChangedFiles"]) |
312 p = e5App().getObject("Project") |
323 p = ericApp().getObject("Project") |
313 if p.isDirty(): |
324 if p.isDirty(): |
314 p.saveProject() |
325 p.saveProject() |
315 |
326 |
316 self.raise_() |
327 self.raise_() |
317 self.__refreshHistories() |
328 self.__refreshHistories() |