RefactoringRope/Refactoring.py

branch
server_client_variant
changeset 175
72a1d9030d67
parent 174
04583cac110f
child 176
117d86025a5c
equal deleted inserted replaced
174:04583cac110f 175:72a1d9030d67
1003 """ 1003 """
1004 Private slot to handle the Extract Local Variable action. 1004 Private slot to handle the Extract Local Variable action.
1005 """ 1005 """
1006 self.__doExtract(self.tr("Extract Local Variable"), "variable") 1006 self.__doExtract(self.tr("Extract Local Variable"), "variable")
1007 1007
1008 # TODO: continue from here
1009 def __doExtract(self, title, kind): 1008 def __doExtract(self, title, kind):
1010 """ 1009 """
1011 Private method to perform the extract refactoring. 1010 Private method to perform the extract refactoring.
1012 1011
1013 @param title title of the refactoring (string) 1012 @param title title of the refactoring
1014 @param kind kind of extraction to be done (string, 1013 @type str
1015 "method" or "variable") 1014 @param kind kind of extraction to be done
1016 @exception Exception raised to indicate a wrong extraction method 1015 @type str ("method" or "variable")
1017 """ 1016 """
1017 assert kind in ["variable", "method"]
1018
1018 aw = e5App().getObject("ViewManager").activeWindow() 1019 aw = e5App().getObject("ViewManager").activeWindow()
1019 1020
1020 if aw is None: 1021 if aw is None:
1021 return 1022 return
1022 1023
1034 filename = aw.getFileName() 1035 filename = aw.getFileName()
1035 startline, startcolumn, endline, endcolumn = aw.getSelection() 1036 startline, startcolumn, endline, endcolumn = aw.getSelection()
1036 startOffset = self.__getOffset(aw, startline, startcolumn) 1037 startOffset = self.__getOffset(aw, startline, startcolumn)
1037 endOffset = self.__getOffset(aw, endline, endcolumn) 1038 endOffset = self.__getOffset(aw, endline, endcolumn)
1038 1039
1039 import rope.refactor.extract
1040 resource = rope.base.libutils.path_to_resource(
1041 self.__project, filename)
1042 try:
1043 if kind == "variable":
1044 extractor = rope.refactor.extract.ExtractVariable(
1045 self.__project, resource, startOffset, endOffset)
1046 elif kind == "method":
1047 extractor = rope.refactor.extract.ExtractMethod(
1048 self.__project, resource, startOffset, endOffset)
1049 else:
1050 raise Exception("Invalid extraction kind <{0}>.".format(kind))
1051 except Exception as err:
1052 self.handleRopeError(err, title)
1053 return
1054
1055 from ExtractDialog import ExtractDialog 1040 from ExtractDialog import ExtractDialog
1056 self.dlg = ExtractDialog(self, title, extractor, parent=self.__ui) 1041 dlg = ExtractDialog(self, title, filename, startOffset, endOffset,
1057 self.dlg.show() 1042 kind, parent=self.__ui)
1043 changeGroup = dlg.getChangeGroupName()
1044 self.__refactoringDialogs[changeGroup] = dlg
1045 dlg.finished.connect(
1046 lambda: self.__refactoringDialogClosed(changeGroup))
1047 dlg.show()
1058 1048
1059 ##################################################### 1049 #####################################################
1060 ## Inline refactorings 1050 ## Inline refactorings
1061 ##################################################### 1051 #####################################################
1062 1052
1053 # TODO: continue from here
1063 def __inline(self): 1054 def __inline(self):
1064 """ 1055 """
1065 Private slot to handle the Inline Local Variable action. 1056 Private slot to handle the Inline Local Variable action.
1066 """ 1057 """
1067 aw = e5App().getObject("ViewManager").activeWindow() 1058 aw = e5App().getObject("ViewManager").activeWindow()

eric ide

mercurial