--- a/RefactoringRope/RefactoringServer.py Sat Dec 23 15:48:55 2023 +0100 +++ b/RefactoringRope/RefactoringServer.py Sat Dec 23 17:58:35 2023 +0100 @@ -53,6 +53,8 @@ @param parent parent @type QObject """ + from .FileSystemCommands import EricFileSystemCommands + super().__init__("RefactoringServer", parent=parent) self.__plugin = plugin @@ -73,8 +75,6 @@ self.__historyDialog = None self.__refactoringDialogs = {} - from .FileSystemCommands import EricFileSystemCommands - self.__fsCommands = EricFileSystemCommands(self.__ericProject) self.__methodMapping = { @@ -182,9 +182,7 @@ ) self.refactoringRenameAct.setStatusTip(self.tr("Rename the highlighted object")) self.refactoringRenameAct.setWhatsThis( - self.tr( - """<b>Rename</b>""" """<p>Rename the highlighted Python object.</p>""" - ) + self.tr("""<b>Rename</b><p>Rename the highlighted Python object.</p>""") ) self.refactoringRenameAct.triggered.connect(self.__rename) self.actions.append(self.refactoringRenameAct) @@ -763,9 +761,7 @@ self.tr("Clear the refactoring history") ) self.refactoringClearHistoryAct.setWhatsThis( - self.tr( - """<b>Clear History</b>""" """<p>Clears the refactoring history.</p>""" - ) + self.tr("""<b>Clear History</b><p>Clears the refactoring history.</p>""") ) self.refactoringClearHistoryAct.triggered.connect(self.__clearHistory) self.actions.append(self.refactoringClearHistoryAct) @@ -1041,6 +1037,8 @@ @return flag indicating, that the error is to be ignored @rtype bool """ + from .ErrorDialog import ErrorDialog + if "Error" not in result: return True @@ -1063,8 +1061,6 @@ elif result["Error"] == "InterruptedTaskError": return True else: - from .ErrorDialog import ErrorDialog - ErrorDialog( title, self.tr("Rope error: {0}").format(result["ErrorString"]), @@ -1158,6 +1154,8 @@ @param renameModule flag indicating a module rename refactoring @type bool """ + from .RenameDialog import RenameDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1168,9 +1166,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr( - "Highlight the declaration you want to rename" " and try again." - ), + self.tr("Highlight the declaration you want to rename and try again."), ) return @@ -1194,7 +1190,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr("The selection must not extend beyond" " one line."), + self.tr("The selection must not extend beyond one line."), ) return index = int(index + (index1 - index) / 2) @@ -1202,8 +1198,6 @@ offset = self.__getOffset(aw, line, index) selectedText = aw.selectedText() - from .RenameDialog import RenameDialog - dlg = RenameDialog( self, title, @@ -1222,6 +1216,8 @@ """ Private slot to perform the Change Occurrences refactoring. """ + from .ChangeOccurrencesDialog import ChangeOccurrencesDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1233,7 +1229,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr("Highlight an occurrence to be changed" " and try again."), + self.tr("Highlight an occurrence to be changed and try again."), ) return @@ -1244,8 +1240,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .ChangeOccurrencesDialog import ChangeOccurrencesDialog - dlg = ChangeOccurrencesDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1277,6 +1271,8 @@ @param kind kind of extraction to be done @type str ("method" or "variable") """ + from .ExtractDialog import ExtractDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1288,7 +1284,7 @@ self.__ui, title, self.tr( - "Highlight the region of code you want to extract" " and try again." + "Highlight the region of code you want to extract and try again." ), ) return @@ -1301,8 +1297,6 @@ startOffset = self.__getOffset(aw, startline, startcolumn) endOffset = self.__getOffset(aw, endline, endcolumn) - from .ExtractDialog import ExtractDialog - dlg = ExtractDialog( self, title, filename, startOffset, endOffset, kind, parent=self.__ui ) @@ -1319,6 +1313,8 @@ """ Private slot to handle the Inline Local Variable action. """ + from .InlineDialog import InlineDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1344,8 +1340,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .InlineDialog import InlineDialog - dlg = InlineDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1363,6 +1357,8 @@ @param moveKind kind of move to be performed @type str (one of 'move_method' or 'move_module') """ + from .MoveDialog import MoveDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1375,7 +1371,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr("Highlight the method to move" " and try again."), + self.tr("Highlight the method to move and try again."), ) return else: @@ -1391,8 +1387,6 @@ else: offset = None - from .MoveDialog import MoveDialog - dlg = MoveDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1407,6 +1401,8 @@ """ Private slot to use a function wherever possible. """ + from .UseFunctionDialog import UseFunctionDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1427,8 +1423,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .UseFunctionDialog import UseFunctionDialog - dlg = UseFunctionDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1443,6 +1437,8 @@ """ Private slot to introduce a factory method or global function. """ + from .IntroduceFactoryDialog import IntroduceFactoryDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1468,8 +1464,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .IntroduceFactoryDialog import IntroduceFactoryDialog - dlg = IntroduceFactoryDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1480,6 +1474,8 @@ """ Private slot to introduce a parameter in a function. """ + from .IntroduceParameterDialog import IntroduceParameterDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1491,7 +1487,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr("Highlight the code for the new parameter" " and try again."), + self.tr("Highlight the code for the new parameter and try again."), ) return @@ -1502,8 +1498,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .IntroduceParameterDialog import IntroduceParameterDialog - dlg = IntroduceParameterDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1553,6 +1547,8 @@ @param methodName name of the method performing the import refactoring @type str """ + from .ConfirmationDialog import ConfirmationDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1568,8 +1564,6 @@ else: offset = None - from .ConfirmationDialog import ConfirmationDialog - dlg = ConfirmationDialog( self, title, @@ -1608,6 +1602,8 @@ """ Private slot to change the signature of a method or function. """ + from .ChangeSignatureDialog import ChangeSignatureDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1619,7 +1615,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr("Highlight the method or function to change" " and try again."), + self.tr("Highlight the method or function to change and try again."), ) return @@ -1630,8 +1626,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .ChangeSignatureDialog import ChangeSignatureDialog - dlg = ChangeSignatureDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1643,6 +1637,8 @@ Private slot to inline the default value of a parameter of a method or function. """ + from .InlineArgumentDefaultDialog import InlineArgumentDefaultDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1668,8 +1664,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .InlineArgumentDefaultDialog import InlineArgumentDefaultDialog - dlg = InlineArgumentDefaultDialog( self, title, filename, offset, parent=self.__ui ) @@ -1682,6 +1676,8 @@ """ Private slot to transform a module to a package. """ + from .ConfirmationDialog import ConfirmationDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1694,8 +1690,6 @@ filename = aw.getFileName() - from .ConfirmationDialog import ConfirmationDialog - dlg = ConfirmationDialog( self, title, @@ -1715,6 +1709,8 @@ """ Private slot to encapsulate an attribute. """ + from .GetterSetterDialog import GetterSetterDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1726,7 +1722,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr("Highlight the attribute to encapsulate" " and try again."), + self.tr("Highlight the attribute to encapsulate and try again."), ) return @@ -1737,8 +1733,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .GetterSetterDialog import GetterSetterDialog - dlg = GetterSetterDialog(self, title, filename, offset, parent=self.__ui) changeGroup = dlg.getChangeGroupName() self.__refactoringDialogs[changeGroup] = dlg @@ -1749,6 +1743,8 @@ """ Private slot to convert a local variable to an attribute. """ + from .ConfirmationDialog import ConfirmationDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1774,8 +1770,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .ConfirmationDialog import ConfirmationDialog - dlg = ConfirmationDialog( self, title, @@ -1796,6 +1790,8 @@ """ Private slot to change the signature of a method or function. """ + from .MethodToMethodObjectDialog import MethodToMethodObjectDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1807,9 +1803,7 @@ EricMessageBox.warning( self.__ui, title, - self.tr( - "Highlight the method or function to convert" " and try again." - ), + self.tr("Highlight the method or function to convert and try again."), ) return @@ -1820,8 +1814,6 @@ line, index, line1, index1 = aw.getSelection() offset = self.__getOffset(aw, line, index) - from .MethodToMethodObjectDialog import MethodToMethodObjectDialog - dlg = MethodToMethodObjectDialog( self, title, filename, offset, parent=self.__ui ) @@ -1838,11 +1830,11 @@ """ Private method to show the project refactoring history. """ + from .HistoryDialog import HistoryDialog + if self.__historyDialog is not None: self.__historyDialog.close() - from .HistoryDialog import HistoryDialog - self.__historyDialog = HistoryDialog(self, parent=self.__ui) self.__historyDialog.finished.connect(self.__historyDialogClosed) self.__historyDialog.show() @@ -1851,6 +1843,8 @@ """ Private method to show the refactoring history of the current file. """ + from .HistoryDialog import HistoryDialog + aw = self.__vm.activeWindow() if aw is None: @@ -1859,8 +1853,6 @@ if self.__historyDialog is not None: self.__historyDialog.close() - from .HistoryDialog import HistoryDialog - filename = aw.getFileName() if filename: self.__historyDialog = HistoryDialog( @@ -1944,11 +1936,11 @@ @param result dictionary containing the result data @type dict """ + from .MatchesDialog import MatchesDialog + if self.handleRopeError(result): title = result["Title"] if result["EntriesCount"] > 0: - from .MatchesDialog import MatchesDialog - self.dlg = MatchesDialog(self.__ui, True) self.dlg.show() for occurrence in result["Entries"]: @@ -1999,13 +1991,13 @@ @param result dictionary containing the result data @type dict """ + from .MatchesDialog import MatchesDialog + if self.handleRopeError(result): title = result["Title"] if "Location" in result: location = result["Location"] - from .MatchesDialog import MatchesDialog - self.dlg = MatchesDialog(self.__ui, False) self.dlg.show() self.dlg.addEntry(location[0], location[1]) @@ -2050,11 +2042,11 @@ @param result dictionary containing the result data @type dict """ + from .MatchesDialog import MatchesDialog + if self.handleRopeError(result): title = result["Title"] if result["EntriesCount"] > 0: - from .MatchesDialog import MatchesDialog - self.dlg = MatchesDialog(self.__ui, True) self.dlg.show() for occurrence in result["Entries"]: @@ -2077,13 +2069,13 @@ """ Private slot to open the rope configuration file in an editor. """ + from eric7.QScintilla.MiniEditor import MiniEditor + ropedir = self.__ropeConfig["RopeFolderName"] configfile = "" if ropedir and os.path.exists(ropedir): configfile = os.path.join(ropedir, "config.py") if os.path.exists(configfile): - from eric7.QScintilla.MiniEditor import MiniEditor - self.__editor = MiniEditor(configfile) self.__editor.show() self.__editor.editorSaved.connect(self.__configChanged) @@ -2092,7 +2084,7 @@ self.__ui, self.tr("Configure Rope"), self.tr( - """The Rope configuration file '{0}' does""" """ not exist.""" + """The Rope configuration file '{0}' does not exist.""" ).format(configfile), ) else: @@ -2137,9 +2129,9 @@ """ Private slot to show help about the refactorings offered by Rope. """ + from .HelpDialog import HelpDialog + if self.__helpDialog is None: - from .HelpDialog import HelpDialog - self.__helpDialog = HelpDialog( self.tr("Help about rope refactorings"), self.__ropeConfig["RopeHelpFile"], @@ -2160,7 +2152,6 @@ ), ) if res: - self.sendJson( "PerformSoa", {