16 from RefactoringDialogBase import RefactoringDialogBase |
16 from RefactoringDialogBase import RefactoringDialogBase |
17 |
17 |
18 |
18 |
19 class UseFunctionDialog(RefactoringDialogBase, Ui_UseFunctionDialog): |
19 class UseFunctionDialog(RefactoringDialogBase, Ui_UseFunctionDialog): |
20 """ |
20 """ |
21 Class implementing the Inline dialog. |
21 Class implementing the Use Function dialog. |
22 """ |
22 """ |
23 def __init__(self, refactoring, title, user, parent=None): |
23 def __init__(self, refactoring, title, filename, offset, parent=None): |
24 """ |
24 """ |
25 Constructor |
25 Constructor |
26 |
26 |
27 @param refactoring reference to the main refactoring object |
27 @param refactoring reference to the main refactoring object |
28 (Refactoring) |
28 @type Refactoring |
29 @param title title of the dialog (string) |
29 @param title title of the dialog |
30 @param user reference to the usefunction object |
30 @type str |
31 (rope.refactor.usefunction.UseFunction) |
31 @param filename file name to be worked on |
32 @param parent reference to the parent widget (QWidget) |
32 @type str |
|
33 @param offset offset within file |
|
34 @type int or None |
|
35 @param parent reference to the parent widget |
|
36 @type QWidget |
33 """ |
37 """ |
34 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
38 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
35 self.setupUi(self) |
39 self.setupUi(self) |
36 |
40 |
37 self.__user = user |
41 self._changeGroupName = "UseFunction" |
38 |
42 |
39 self.description.setText( |
43 self.__filename = filename |
40 self.tr("Using Function <b>{0}</b>.") |
44 self.__offset = offset |
41 .format(self.__user.get_function_name())) |
|
42 |
45 |
43 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
46 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
44 self.__previewButton = self.buttonBox.addButton( |
47 self.__previewButton = self.buttonBox.addButton( |
45 self.tr("Preview"), QDialogButtonBox.ActionRole) |
48 self.tr("Preview"), QDialogButtonBox.ActionRole) |
46 self.__previewButton.setDefault(True) |
49 self.__previewButton.setDefault(True) |
|
50 |
|
51 self._refactoring.sendJson("RequestUseFunction", { |
|
52 "ChangeGroup": self._changeGroupName, |
|
53 "Title": self._title, |
|
54 "FileName": self.__filename, |
|
55 "Offset": self.__offset, |
|
56 }) |
|
57 |
|
58 def __processUseFunctionName(self, data): |
|
59 """ |
|
60 Private method to process the function name data sent by the |
|
61 refactoring client in order to polish the dialog. |
|
62 |
|
63 @param data dictionary containing the inline type data |
|
64 @type dict |
|
65 """ |
|
66 self.description.setText( |
|
67 self.tr("Using Function <b>{0}</b>.") |
|
68 .format(data["FunctionName"])) |
|
69 |
|
70 if not data["FunctionName"]: |
|
71 self.__okButton.setEnabled(False) |
|
72 self.__previewButton.setEnabled(False) |
47 |
73 |
48 msh = self.minimumSizeHint() |
74 msh = self.minimumSizeHint() |
49 self.resize(max(self.width(), msh.width()), msh.height()) |
75 self.resize(max(self.width(), msh.width()), msh.height()) |
50 |
76 |
51 @pyqtSlot(QAbstractButton) |
77 @pyqtSlot(QAbstractButton) |
52 def on_buttonBox_clicked(self, button): |
78 def on_buttonBox_clicked(self, button): |
53 """ |
79 """ |
54 Private slot to act on the button pressed. |
80 Private slot to act on the button pressed. |
55 |
81 |
56 @param button reference to the button pressed (QAbstractButton) |
82 @param button reference to the button pressed |
|
83 @type QAbstractButton |
57 """ |
84 """ |
58 if button == self.__previewButton: |
85 if button == self.__previewButton: |
59 self.previewChanges() |
86 self.requestPreview() |
60 elif button == self.__okButton: |
87 elif button == self.__okButton: |
61 self.applyChanges() |
88 self.applyChanges() |
62 |
89 |
63 def _calculateChanges(self, handle): |
90 def _calculateChanges(self): |
64 """ |
91 """ |
65 Protected method to calculate the changes. |
92 Protected method to initiate the calculation of the changes. |
|
93 """ |
|
94 self._refactoring.sendJson("CalculateUseFunctionChanges", { |
|
95 "ChangeGroup": self._changeGroupName, |
|
96 "Title": self._title, |
|
97 "FileName": self.__filename, |
|
98 "Offset": self.__offset, |
|
99 }) |
|
100 |
|
101 def processChangeData(self, data): |
|
102 """ |
|
103 Public method to process the change data sent by the refactoring |
|
104 client. |
66 |
105 |
67 @param handle reference to the task handle |
106 @param data dictionary containing the change data |
68 (rope.base.taskhandle.TaskHandle) |
107 @type dict |
69 @return reference to the Changes object (rope.base.change.ChangeSet) |
|
70 """ |
108 """ |
71 try: |
109 subcommand = data["Subcommand"] |
72 changes = self.__user.get_changes(task_handle=handle) |
110 if subcommand == "UseFunctionName": |
73 return changes |
111 self.__processUseFunctionName(data) |
74 except Exception as err: |
112 else: |
75 self._refactoring.handleRopeError(err, self._title, handle) |
113 # pass on to base class |
76 return None |
114 RefactoringDialogBase.processChangeData(self, data) |