RefactoringRope/RefactoringDialogBase.py

branch
eric7
changeset 389
4f53795beff0
parent 374
958f34e97952
child 396
933b8fcd854f
equal deleted inserted replaced
388:cb044ec27c24 389:4f53795beff0
15 15
16 class RefactoringDialogBase(QDialog): 16 class RefactoringDialogBase(QDialog):
17 """ 17 """
18 Class implementing the Refactoring dialog base class. 18 Class implementing the Refactoring dialog base class.
19 """ 19 """
20
20 def __init__(self, refactoring, title, parent=None): 21 def __init__(self, refactoring, title, parent=None):
21 """ 22 """
22 Constructor 23 Constructor
23 24
24 @param refactoring reference to the main refactoring object 25 @param refactoring reference to the main refactoring object
25 @type RefactoringServer 26 @type RefactoringServer
26 @param title title of the dialog 27 @param title title of the dialog
27 @type str 28 @type str
28 @param parent reference to the parent widget 29 @param parent reference to the parent widget
29 @type QWidget 30 @type QWidget
30 """ 31 """
31 QDialog.__init__(self, parent) 32 QDialog.__init__(self, parent)
32 self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose) 33 self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
33 self.setWindowTitle(title) 34 self.setWindowTitle(title)
34 35
35 self._ui = parent 36 self._ui = parent
36 self._refactoring = refactoring 37 self._refactoring = refactoring
37 self._title = title 38 self._title = title
38 39
39 self._changesCalculated = False 40 self._changesCalculated = False
40 41
41 self.__queue = [] 42 self.__queue = []
42 43
43 def getChangeGroupName(self): 44 def getChangeGroupName(self):
44 """ 45 """
45 Public method to get the name of the change group. 46 Public method to get the name of the change group.
46 47
47 @return name of the associated change group 48 @return name of the associated change group
48 @rtype str 49 @rtype str
49 """ 50 """
50 return self._changeGroupName 51 return self._changeGroupName
51 52
52 def _calculateChanges(self): 53 def _calculateChanges(self):
53 """ 54 """
54 Protected method to initiate the calculation of changes. 55 Protected method to initiate the calculation of changes.
55 56
56 @exception NotImplementedError raised to indicate that this method must 57 @exception NotImplementedError raised to indicate that this method must
57 be overridden by subclasses 58 be overridden by subclasses
58 """ 59 """
59 raise NotImplementedError("_calculateChanges must be overridden.") 60 raise NotImplementedError("_calculateChanges must be overridden.")
60 61
61 def requestPreview(self): 62 def requestPreview(self):
62 """ 63 """
63 Public method to request a preview of the calculated changes. 64 Public method to request a preview of the calculated changes.
64 """ 65 """
65 self.__queue.append(("PreviewChanges", { 66 self.__queue.append(
66 "ChangeGroup": self._changeGroupName, 67 (
67 })) 68 "PreviewChanges",
68 69 {
70 "ChangeGroup": self._changeGroupName,
71 },
72 )
73 )
74
69 self._calculateChanges() 75 self._calculateChanges()
70 76
71 def previewChanges(self, data): 77 def previewChanges(self, data):
72 """ 78 """
73 Public method to preview the changes. 79 Public method to preview the changes.
74 80
75 @param data dictionary containing the change data 81 @param data dictionary containing the change data
76 @type dict 82 @type dict
77 """ 83 """
78 from .ChangesPreviewDialog import ChangesPreviewDialog 84 from .ChangesPreviewDialog import ChangesPreviewDialog
79 dlg = ChangesPreviewDialog( 85
80 data["Description"], data["Changes"], self) 86 dlg = ChangesPreviewDialog(data["Description"], data["Changes"], self)
81 if dlg.exec() == QDialog.DialogCode.Accepted: 87 if dlg.exec() == QDialog.DialogCode.Accepted:
82 self.applyChanges() 88 self.applyChanges()
83 89
84 def applyChanges(self): 90 def applyChanges(self):
85 """ 91 """
86 Public method to apply the changes. 92 Public method to apply the changes.
87 """ 93 """
88 if not self._changesCalculated: 94 if not self._changesCalculated:
89 self.__queue.append(("ApplyChanges", { 95 self.__queue.append(
90 "ChangeGroup": self._changeGroupName, 96 (
91 "Title": self._title, 97 "ApplyChanges",
92 })) 98 {
99 "ChangeGroup": self._changeGroupName,
100 "Title": self._title,
101 },
102 )
103 )
93 self._calculateChanges() 104 self._calculateChanges()
94 else: 105 else:
95 self._refactoring.sendJson("ApplyChanges", { 106 self._refactoring.sendJson(
96 "ChangeGroup": self._changeGroupName, 107 "ApplyChanges",
97 "Title": self._title, 108 {
98 }) 109 "ChangeGroup": self._changeGroupName,
99 110 "Title": self._title,
111 },
112 )
113
100 def processChangeData(self, data): 114 def processChangeData(self, data):
101 """ 115 """
102 Public method to process the change data sent by the refactoring 116 Public method to process the change data sent by the refactoring
103 client. 117 client.
104 118
105 @param data dictionary containing the change data 119 @param data dictionary containing the change data
106 @type dict 120 @type dict
107 """ 121 """
108 subcommand = data["Subcommand"] 122 subcommand = data["Subcommand"]
109 if subcommand == "PreviewChanges": 123 if subcommand == "PreviewChanges":
119 if self._refactoring.handleRopeError(data): 133 if self._refactoring.handleRopeError(data):
120 self._refactoring.refreshEditors(data["ChangedFiles"]) 134 self._refactoring.refreshEditors(data["ChangedFiles"])
121 p = ericApp().getObject("Project") 135 p = ericApp().getObject("Project")
122 if p.isDirty(): 136 if p.isDirty():
123 p.saveProject() 137 p.saveProject()
124 138
125 self.accept() 139 self.accept()
126 140
127 def closeEvent(self, evt): 141 def closeEvent(self, evt):
128 """ 142 """
129 Protected method handling close events. 143 Protected method handling close events.
130 144
131 @param evt reference to the close event object 145 @param evt reference to the close event object
132 @type QCloseEvent 146 @type QCloseEvent
133 """ 147 """
134 self._refactoring.sendJson("ClearChanges", { 148 self._refactoring.sendJson(
135 "ChangeGroup": self._changeGroupName, 149 "ClearChanges",
136 }) 150 {
137 151 "ChangeGroup": self._changeGroupName,
152 },
153 )
154
138 evt.accept() 155 evt.accept()

eric ide

mercurial