32 self.setAttribute(Qt.WA_DeleteOnClose) |
32 self.setAttribute(Qt.WA_DeleteOnClose) |
33 self.setWindowTitle(title) |
33 self.setWindowTitle(title) |
34 |
34 |
35 self._refactoring = refactoring |
35 self._refactoring = refactoring |
36 self._title = title |
36 self._title = title |
37 self.__handle = None |
|
38 |
37 |
39 def __createProgressHandle(self, interruptable=True): |
38 def calculateChanges(self): |
40 """ |
39 """ |
41 Private method to create a TaskHandle to update a progress dialog. |
40 Public method to initiate the calculation of changes. |
42 |
41 |
43 @param interruptable flag indicating, that the task may be |
|
44 interrupted (boolean) |
|
45 """ |
|
46 from ProgressHandle import ProgressHandle |
|
47 self.__handle = ProgressHandle(self._title, interruptable, self) |
|
48 self.__handle.show() |
|
49 QApplication.processEvents() |
|
50 |
|
51 def _calculateChanges(self, handle): |
|
52 """ |
|
53 Protected method to calculate the changes. |
|
54 |
|
55 @param handle reference to the task handle |
|
56 (rope.base.taskhandle.TaskHandle) |
|
57 @ireturn reference to the ChangeSet object (rope.base.change.ChangeSet) |
|
58 @exception NotImplementedError raised to indicate that this method must |
42 @exception NotImplementedError raised to indicate that this method must |
59 be overridden by subclasses |
43 be overridden by subclasses |
60 """ |
44 """ |
61 raise NotImplementedError("_calculateChanges must be overridden.") |
45 raise NotImplementedError("_calculateChanges must be overridden.") |
62 |
46 |
63 def __getChanges(self): |
47 def previewChanges(self, data): |
64 """ |
|
65 Private method to build the Changes object. |
|
66 |
|
67 @return reference to the Changes object (rope.base.change.ChangeSet) |
|
68 """ |
|
69 self.__createProgressHandle() |
|
70 changes = self._calculateChanges(self.__handle) |
|
71 self.__handle.reset() |
|
72 self.__handle = None |
|
73 |
|
74 return changes |
|
75 |
|
76 def previewChanges(self): |
|
77 """ |
48 """ |
78 Public method to preview the changes. |
49 Public method to preview the changes. |
|
50 |
|
51 @param data dictionary containing the change data |
|
52 @type dict |
79 """ |
53 """ |
80 changes = self.__getChanges() |
54 from ChangesPreviewDialog import ChangesPreviewDialog |
81 |
55 dlg = ChangesPreviewDialog( |
82 if changes is not None: |
56 data["Description"], data["Changes"], self) |
83 from ChangesPreviewDialog import ChangesPreviewDialog |
57 if dlg.exec_() == QDialog.Accepted: |
84 dlg = ChangesPreviewDialog(changes, self) |
58 self.applyChanges() |
85 if dlg.exec_() == QDialog.Accepted: |
|
86 self.applyChanges(changes) |
|
87 |
59 |
88 def applyChanges(self, changes=None): |
60 def applyChanges(self): |
89 """ |
61 """ |
90 Public method to apply the changes. |
62 Public method to apply the changes. |
|
63 """ |
|
64 self._refactoring.sendJson("ApplyChanges", { |
|
65 "ChangeGroup": self._changeGroupName, |
|
66 }) |
|
67 ## if changes is not None: |
|
68 ## self.__createProgressHandle(False) |
|
69 ## try: |
|
70 ## self._refactoring.getProject().do(changes, self.__handle) |
|
71 ## except Exception as err: |
|
72 ## self._refactoring.handleRopeError( |
|
73 ## err, self._title, self.__handle) |
|
74 ## self.__handle.reset() |
|
75 ## self.__handle = None |
|
76 |
|
77 def processChangeData(self, data): |
|
78 """ |
|
79 Public method to process the change data sent by the refactoring |
|
80 client. |
91 |
81 |
92 @param changes reference to the ChangeSet object |
82 @param data dictionary containing the change data |
93 (rope.base.change.ChangeSet) |
83 @type dict |
94 """ |
84 """ |
95 if changes is None: |
85 subcommand = data["Subcommand"] |
96 changes = self.__getChanges() |
86 if subcommand == "PreviewChanges": |
97 |
87 self.previewChanges(data) |
98 if changes is not None: |
88 elif subcommand == "ChangesApplied": |
99 self.__createProgressHandle(False) |
89 self._refactoring.refreshEditors(data["ChangedFiles"]) |
100 try: |
|
101 self._refactoring.getProject().do(changes, self.__handle) |
|
102 except Exception as err: |
|
103 self._refactoring.handleRopeError( |
|
104 err, self._title, self.__handle) |
|
105 self.__handle.reset() |
|
106 self.__handle = None |
|
107 |
|
108 self._refactoring.refreshEditors(changes) |
|
109 p = e5App().getObject("Project") |
90 p = e5App().getObject("Project") |
110 if p.isDirty(): |
91 if p.isDirty(): |
111 p.saveProject() |
92 p.saveProject() |
112 |
93 |
113 self.accept() |
94 self.accept() |
|
95 |
|
96 def closeEvent(self, evt): |
|
97 """ |
|
98 Protected method handling close events. |
|
99 |
|
100 @param evt reference to the close event object |
|
101 @type QCloseEvent |
|
102 """ |
|
103 self.__refactoring.sendJson("ClearChanges", { |
|
104 "ChangeGroup": self._changeGroupName, |
|
105 }) |
|
106 |
|
107 evt.accept() |