RefactoringRope/ChangesPreviewDialog.py

branch
eric7
changeset 389
4f53795beff0
parent 374
958f34e97952
child 411
8cccb49bba7b
equal deleted inserted replaced
388:cb044ec27c24 389:4f53795beff0
15 15
16 class ChangesPreviewDialog(PreviewDialogBase): 16 class ChangesPreviewDialog(PreviewDialogBase):
17 """ 17 """
18 Class implementing the Changes preview dialog. 18 Class implementing the Changes preview dialog.
19 """ 19 """
20
20 ChangeRole = Qt.ItemDataRole.UserRole 21 ChangeRole = Qt.ItemDataRole.UserRole
21 22
22 def __init__(self, description, changes, parent): 23 def __init__(self, description, changes, parent):
23 """ 24 """
24 Constructor 25 Constructor
25 26
26 @param description description of the changes 27 @param description description of the changes
27 @type str 28 @type str
28 @param changes list of lists containing the change data 29 @param changes list of lists containing the change data
29 @type list of list of (str, str) 30 @type list of list of (str, str)
30 @param parent reference to the parent widget 31 @param parent reference to the parent widget
31 @type QWidget 32 @type QWidget
32 """ 33 """
33 PreviewDialogBase.__init__(self, parent) 34 PreviewDialogBase.__init__(self, parent)
34 35
35 self.buttonBox.addButton( 36 self.buttonBox.addButton(
36 self.tr("&Apply Changes"), QDialogButtonBox.ButtonRole.AcceptRole) 37 self.tr("&Apply Changes"), QDialogButtonBox.ButtonRole.AcceptRole
38 )
37 self.buttonBox.addButton(QDialogButtonBox.StandardButton.Cancel) 39 self.buttonBox.addButton(QDialogButtonBox.StandardButton.Cancel)
38 40
39 self.description.setText(description) 41 self.description.setText(description)
40 for changeTitle, changeText in changes: 42 for changeTitle, changeText in changes:
41 itm = QListWidgetItem(changeTitle, self.changesList) 43 itm = QListWidgetItem(changeTitle, self.changesList)
42 if changeText is None: 44 if changeText is None:
43 changeText = self.tr("No changes available.") 45 changeText = self.tr("No changes available.")
44 itm.setData(ChangesPreviewDialog.ChangeRole, changeText) 46 itm.setData(ChangesPreviewDialog.ChangeRole, changeText)
45 if self.changesList.count(): 47 if self.changesList.count():
46 self.changesList.item(0).setSelected(True) 48 self.changesList.item(0).setSelected(True)
47 self.on_changesList_currentItemChanged( 49 self.on_changesList_currentItemChanged(self.changesList.item(0), None)
48 self.changesList.item(0), None) 50
49
50 @pyqtSlot(QListWidgetItem, QListWidgetItem) 51 @pyqtSlot(QListWidgetItem, QListWidgetItem)
51 def on_changesList_currentItemChanged(self, current, previous): 52 def on_changesList_currentItemChanged(self, current, previous):
52 """ 53 """
53 Private slot called when a change is selected. 54 Private slot called when a change is selected.
54 55
55 @param current reference to the new current item 56 @param current reference to the new current item
56 @type QListWidgetItem 57 @type QListWidgetItem
57 @param previous reference to the old current item 58 @param previous reference to the old current item
58 @type QListWidgetItem 59 @type QListWidgetItem
59 """ 60 """
60 if current is None: 61 if current is None:
61 return 62 return
62 63
63 self.previewEdit.clear() 64 self.previewEdit.clear()
64 for line in ( 65 for line in current.data(ChangesPreviewDialog.ChangeRole).splitlines(True):
65 current.data(ChangesPreviewDialog.ChangeRole).splitlines(True)
66 ):
67 try: 66 try:
68 charFormat = self.formats[line[0]] 67 charFormat = self.formats[line[0]]
69 except (IndexError, KeyError): 68 except (IndexError, KeyError):
70 charFormat = self.formats[' '] 69 charFormat = self.formats[" "]
71 self._appendText(line, charFormat) 70 self._appendText(line, charFormat)

eric ide

mercurial