232 self.refactoringMoveMethodAct.setWhatsThis(self.tr( |
232 self.refactoringMoveMethodAct.setWhatsThis(self.tr( |
233 """<b>Move method</b>""" |
233 """<b>Move method</b>""" |
234 """<p>Move the highlighted method to another class.</p>""" |
234 """<p>Move the highlighted method to another class.</p>""" |
235 )) |
235 )) |
236 self.refactoringMoveMethodAct.triggered.connect( |
236 self.refactoringMoveMethodAct.triggered.connect( |
237 self.__moveMethod) |
237 lambda: self.__move("move_method")) |
238 self.actions.append(self.refactoringMoveMethodAct) |
238 self.actions.append(self.refactoringMoveMethodAct) |
239 |
239 |
240 self.refactoringMoveModuleAct = E5Action( |
240 self.refactoringMoveModuleAct = E5Action( |
241 self.tr('Move current module'), |
241 self.tr('Move current module'), |
242 self.tr('Move Current Module'), |
242 self.tr('Move Current Module'), |
1085 |
1085 |
1086 ##################################################### |
1086 ##################################################### |
1087 ## Move refactorings |
1087 ## Move refactorings |
1088 ##################################################### |
1088 ##################################################### |
1089 |
1089 |
1090 # TODO: continue from here |
1090 def __move(self, moveKind): |
1091 def __moveMethod(self): |
|
1092 """ |
1091 """ |
1093 Private slot to handle the Move Method action. |
1092 Private slot to handle the Move Method action. |
|
1093 |
|
1094 @param moveKind kind of move to be performed |
|
1095 @type str (one of 'move_method' or 'move_module') |
1094 """ |
1096 """ |
1095 aw = e5App().getObject("ViewManager").activeWindow() |
1097 aw = e5App().getObject("ViewManager").activeWindow() |
1096 |
1098 |
1097 if aw is None: |
1099 if aw is None: |
1098 return |
1100 return |
1099 |
1101 |
1100 title = self.tr("Move Method") |
1102 if moveKind == "move_method": |
1101 if not aw.hasSelectedText(): |
1103 title = self.tr("Move Method") |
1102 # no selection available |
1104 if not aw.hasSelectedText(): |
1103 E5MessageBox.warning( |
1105 # no selection available |
1104 self.__ui, title, |
1106 E5MessageBox.warning( |
1105 self.tr("Highlight the method to move" |
1107 self.__ui, title, |
1106 " and try again.")) |
1108 self.tr("Highlight the method to move" |
1107 return |
1109 " and try again.")) |
|
1110 return |
|
1111 else: |
|
1112 title = self.tr("Move Current Module") |
1108 |
1113 |
1109 if not self.confirmAllBuffersSaved(): |
1114 if not self.confirmAllBuffersSaved(): |
1110 return |
1115 return |
1111 |
1116 |
1112 filename = aw.getFileName() |
1117 filename = aw.getFileName() |
1113 line, index, line1, index1 = aw.getSelection() |
1118 if moveKind == "move_method": |
1114 offset = self.__getOffset(aw, line, index) |
1119 line, index, line1, index1 = aw.getSelection() |
1115 |
1120 offset = self.__getOffset(aw, line, index) |
1116 import rope.refactor.move |
|
1117 resource = rope.base.libutils.path_to_resource( |
|
1118 self.__project, filename) |
|
1119 try: |
|
1120 mover = rope.refactor.move.create_move( |
|
1121 self.__project, resource, offset) |
|
1122 except Exception as err: |
|
1123 self.handleRopeError(err, title) |
|
1124 return |
|
1125 |
|
1126 if isinstance(mover, rope.refactor.move.MoveGlobal): |
|
1127 from MoveGlobalMethodDialog import MoveGlobalMethodDialog |
|
1128 self.dlg = MoveGlobalMethodDialog( |
|
1129 self, title, mover, self.__project, parent=self.__ui) |
|
1130 else: |
1121 else: |
1131 from MoveMethodDialog import MoveMethodDialog |
1122 offset = None |
1132 self.dlg = MoveMethodDialog(self, title, mover, parent=self.__ui) |
1123 |
1133 self.dlg.show() |
1124 from MoveDialog import MoveDialog |
1134 |
1125 dlg = MoveDialog(self, title, filename, offset, parent=self.__ui) |
1135 def __moveModule(self): |
1126 changeGroup = dlg.getChangeGroupName() |
1136 """ |
1127 self.__refactoringDialogs[changeGroup] = dlg |
1137 Private slot to handle the Move Current Module action. |
1128 dlg.finished.connect( |
1138 """ |
1129 lambda: self.__refactoringDialogClosed(changeGroup)) |
1139 aw = e5App().getObject("ViewManager").activeWindow() |
1130 dlg.show() |
1140 |
|
1141 if aw is None: |
|
1142 return |
|
1143 |
|
1144 title = self.tr("Move Current Module") |
|
1145 |
|
1146 if not self.confirmAllBuffersSaved(): |
|
1147 return |
|
1148 |
|
1149 filename = aw.getFileName() |
|
1150 offset = None |
|
1151 |
|
1152 import rope.refactor.move |
|
1153 resource = rope.base.libutils.path_to_resource( |
|
1154 self.__project, filename) |
|
1155 try: |
|
1156 mover = rope.refactor.move.create_move( |
|
1157 self.__project, resource, offset) |
|
1158 except Exception as err: |
|
1159 self.handleRopeError(err, title) |
|
1160 return |
|
1161 |
|
1162 from MoveModuleDialog import MoveModuleDialog |
|
1163 self.dlg = MoveModuleDialog(self, title, mover, parent=self.__ui) |
|
1164 self.dlg.show() |
|
1165 |
1131 |
1166 ##################################################### |
1132 ##################################################### |
1167 ## Use function refactoring |
1133 ## Use function refactoring |
1168 ##################################################### |
1134 ##################################################### |
1169 |
1135 |
|
1136 # TODO: continue from here |
1170 def __useFunction(self): |
1137 def __useFunction(self): |
1171 """ |
1138 """ |
1172 Private slot to use a function wherever possible. |
1139 Private slot to use a function wherever possible. |
1173 """ |
1140 """ |
1174 aw = e5App().getObject("ViewManager").activeWindow() |
1141 aw = e5App().getObject("ViewManager").activeWindow() |