RefactoringRope/RefactoringServer.py

branch
eric7
changeset 413
a4cba20ad7ab
parent 412
6fa5892b9097
child 416
45159308166f
equal deleted inserted replaced
412:6fa5892b9097 413:a4cba20ad7ab
51 @param plugin reference to the plugin object 51 @param plugin reference to the plugin object
52 @type RefactoringRopePlugin 52 @type RefactoringRopePlugin
53 @param parent parent 53 @param parent parent
54 @type QObject 54 @type QObject
55 """ 55 """
56 from .FileSystemCommands import EricFileSystemCommands
57
56 super().__init__("RefactoringServer", parent=parent) 58 super().__init__("RefactoringServer", parent=parent)
57 59
58 self.__plugin = plugin 60 self.__plugin = plugin
59 self.__ui = parent 61 self.__ui = parent
60 self.__vm = ericApp().getObject("ViewManager") 62 self.__vm = ericApp().getObject("ViewManager")
70 72
71 self.__progressDialog = None 73 self.__progressDialog = None
72 self.__helpDialog = None 74 self.__helpDialog = None
73 self.__historyDialog = None 75 self.__historyDialog = None
74 self.__refactoringDialogs = {} 76 self.__refactoringDialogs = {}
75
76 from .FileSystemCommands import EricFileSystemCommands
77 77
78 self.__fsCommands = EricFileSystemCommands(self.__ericProject) 78 self.__fsCommands = EricFileSystemCommands(self.__ericProject)
79 79
80 self.__methodMapping = { 80 self.__methodMapping = {
81 "Config": self.__setConfig, 81 "Config": self.__setConfig,
180 self.refactoringRenameAct = EricAction( 180 self.refactoringRenameAct = EricAction(
181 self.tr("Rename"), self.tr("&Rename"), 0, 0, self, "refactoring_rename" 181 self.tr("Rename"), self.tr("&Rename"), 0, 0, self, "refactoring_rename"
182 ) 182 )
183 self.refactoringRenameAct.setStatusTip(self.tr("Rename the highlighted object")) 183 self.refactoringRenameAct.setStatusTip(self.tr("Rename the highlighted object"))
184 self.refactoringRenameAct.setWhatsThis( 184 self.refactoringRenameAct.setWhatsThis(
185 self.tr( 185 self.tr("""<b>Rename</b><p>Rename the highlighted Python object.</p>""")
186 """<b>Rename</b>""" """<p>Rename the highlighted Python object.</p>"""
187 )
188 ) 186 )
189 self.refactoringRenameAct.triggered.connect(self.__rename) 187 self.refactoringRenameAct.triggered.connect(self.__rename)
190 self.actions.append(self.refactoringRenameAct) 188 self.actions.append(self.refactoringRenameAct)
191 189
192 self.refactoringRenameLocalAct = EricAction( 190 self.refactoringRenameLocalAct = EricAction(
761 ) 759 )
762 self.refactoringClearHistoryAct.setStatusTip( 760 self.refactoringClearHistoryAct.setStatusTip(
763 self.tr("Clear the refactoring history") 761 self.tr("Clear the refactoring history")
764 ) 762 )
765 self.refactoringClearHistoryAct.setWhatsThis( 763 self.refactoringClearHistoryAct.setWhatsThis(
766 self.tr( 764 self.tr("""<b>Clear History</b><p>Clears the refactoring history.</p>""")
767 """<b>Clear History</b>""" """<p>Clears the refactoring history.</p>"""
768 )
769 ) 765 )
770 self.refactoringClearHistoryAct.triggered.connect(self.__clearHistory) 766 self.refactoringClearHistoryAct.triggered.connect(self.__clearHistory)
771 self.actions.append(self.refactoringClearHistoryAct) 767 self.actions.append(self.refactoringClearHistoryAct)
772 768
773 ##################################################### 769 #####################################################
1039 @param result dictionary containing the error information 1035 @param result dictionary containing the error information
1040 @type dict 1036 @type dict
1041 @return flag indicating, that the error is to be ignored 1037 @return flag indicating, that the error is to be ignored
1042 @rtype bool 1038 @rtype bool
1043 """ 1039 """
1040 from .ErrorDialog import ErrorDialog
1041
1044 if "Error" not in result: 1042 if "Error" not in result:
1045 return True 1043 return True
1046 1044
1047 title = result.get("Title", self.tr("Rope Error")) 1045 title = result.get("Title", self.tr("Rope Error"))
1048 1046
1061 result["ErrorLine"], 1059 result["ErrorLine"],
1062 ) 1060 )
1063 elif result["Error"] == "InterruptedTaskError": 1061 elif result["Error"] == "InterruptedTaskError":
1064 return True 1062 return True
1065 else: 1063 else:
1066 from .ErrorDialog import ErrorDialog
1067
1068 ErrorDialog( 1064 ErrorDialog(
1069 title, 1065 title,
1070 self.tr("Rope error: {0}").format(result["ErrorString"]), 1066 self.tr("Rope error: {0}").format(result["ErrorString"]),
1071 traceback=result["Traceback"], 1067 traceback=result["Traceback"],
1072 parent=self.__ui, 1068 parent=self.__ui,
1156 the local file 1152 the local file
1157 @type bool 1153 @type bool
1158 @param renameModule flag indicating a module rename refactoring 1154 @param renameModule flag indicating a module rename refactoring
1159 @type bool 1155 @type bool
1160 """ 1156 """
1157 from .RenameDialog import RenameDialog
1158
1161 aw = self.__vm.activeWindow() 1159 aw = self.__vm.activeWindow()
1162 1160
1163 if aw is None: 1161 if aw is None:
1164 return 1162 return
1165 1163
1166 if not renameModule and not aw.hasSelectedText(): 1164 if not renameModule and not aw.hasSelectedText():
1167 # no selection available 1165 # no selection available
1168 EricMessageBox.warning( 1166 EricMessageBox.warning(
1169 self.__ui, 1167 self.__ui,
1170 title, 1168 title,
1171 self.tr( 1169 self.tr("Highlight the declaration you want to rename and try again."),
1172 "Highlight the declaration you want to rename" " and try again."
1173 ),
1174 ) 1170 )
1175 return 1171 return
1176 1172
1177 if isLocal: 1173 if isLocal:
1178 if not self.confirmBufferIsSaved(aw): 1174 if not self.confirmBufferIsSaved(aw):
1192 if line != line1: 1188 if line != line1:
1193 # selection span more than one line 1189 # selection span more than one line
1194 EricMessageBox.warning( 1190 EricMessageBox.warning(
1195 self.__ui, 1191 self.__ui,
1196 title, 1192 title,
1197 self.tr("The selection must not extend beyond" " one line."), 1193 self.tr("The selection must not extend beyond one line."),
1198 ) 1194 )
1199 return 1195 return
1200 index = int(index + (index1 - index) / 2) 1196 index = int(index + (index1 - index) / 2)
1201 # keep it inside the object 1197 # keep it inside the object
1202 offset = self.__getOffset(aw, line, index) 1198 offset = self.__getOffset(aw, line, index)
1203 selectedText = aw.selectedText() 1199 selectedText = aw.selectedText()
1204 1200
1205 from .RenameDialog import RenameDialog
1206
1207 dlg = RenameDialog( 1201 dlg = RenameDialog(
1208 self, 1202 self,
1209 title, 1203 title,
1210 filename, 1204 filename,
1211 offset, 1205 offset,
1220 1214
1221 def __changeOccurrences(self): 1215 def __changeOccurrences(self):
1222 """ 1216 """
1223 Private slot to perform the Change Occurrences refactoring. 1217 Private slot to perform the Change Occurrences refactoring.
1224 """ 1218 """
1219 from .ChangeOccurrencesDialog import ChangeOccurrencesDialog
1220
1225 aw = self.__vm.activeWindow() 1221 aw = self.__vm.activeWindow()
1226 1222
1227 if aw is None: 1223 if aw is None:
1228 return 1224 return
1229 1225
1231 if not aw.hasSelectedText(): 1227 if not aw.hasSelectedText():
1232 # no selection available 1228 # no selection available
1233 EricMessageBox.warning( 1229 EricMessageBox.warning(
1234 self.__ui, 1230 self.__ui,
1235 title, 1231 title,
1236 self.tr("Highlight an occurrence to be changed" " and try again."), 1232 self.tr("Highlight an occurrence to be changed and try again."),
1237 ) 1233 )
1238 return 1234 return
1239 1235
1240 if not self.confirmBufferIsSaved(aw): 1236 if not self.confirmBufferIsSaved(aw):
1241 return 1237 return
1242 1238
1243 filename = aw.getFileName() 1239 filename = aw.getFileName()
1244 line, index, line1, index1 = aw.getSelection() 1240 line, index, line1, index1 = aw.getSelection()
1245 offset = self.__getOffset(aw, line, index) 1241 offset = self.__getOffset(aw, line, index)
1246
1247 from .ChangeOccurrencesDialog import ChangeOccurrencesDialog
1248 1242
1249 dlg = ChangeOccurrencesDialog(self, title, filename, offset, parent=self.__ui) 1243 dlg = ChangeOccurrencesDialog(self, title, filename, offset, parent=self.__ui)
1250 changeGroup = dlg.getChangeGroupName() 1244 changeGroup = dlg.getChangeGroupName()
1251 self.__refactoringDialogs[changeGroup] = dlg 1245 self.__refactoringDialogs[changeGroup] = dlg
1252 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1246 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1275 @param title title of the refactoring 1269 @param title title of the refactoring
1276 @type str 1270 @type str
1277 @param kind kind of extraction to be done 1271 @param kind kind of extraction to be done
1278 @type str ("method" or "variable") 1272 @type str ("method" or "variable")
1279 """ 1273 """
1274 from .ExtractDialog import ExtractDialog
1275
1280 aw = self.__vm.activeWindow() 1276 aw = self.__vm.activeWindow()
1281 1277
1282 if aw is None: 1278 if aw is None:
1283 return 1279 return
1284 1280
1286 # no selection available 1282 # no selection available
1287 EricMessageBox.warning( 1283 EricMessageBox.warning(
1288 self.__ui, 1284 self.__ui,
1289 title, 1285 title,
1290 self.tr( 1286 self.tr(
1291 "Highlight the region of code you want to extract" " and try again." 1287 "Highlight the region of code you want to extract and try again."
1292 ), 1288 ),
1293 ) 1289 )
1294 return 1290 return
1295 1291
1296 if not self.confirmBufferIsSaved(aw): 1292 if not self.confirmBufferIsSaved(aw):
1299 filename = aw.getFileName() 1295 filename = aw.getFileName()
1300 startline, startcolumn, endline, endcolumn = aw.getSelection() 1296 startline, startcolumn, endline, endcolumn = aw.getSelection()
1301 startOffset = self.__getOffset(aw, startline, startcolumn) 1297 startOffset = self.__getOffset(aw, startline, startcolumn)
1302 endOffset = self.__getOffset(aw, endline, endcolumn) 1298 endOffset = self.__getOffset(aw, endline, endcolumn)
1303 1299
1304 from .ExtractDialog import ExtractDialog
1305
1306 dlg = ExtractDialog( 1300 dlg = ExtractDialog(
1307 self, title, filename, startOffset, endOffset, kind, parent=self.__ui 1301 self, title, filename, startOffset, endOffset, kind, parent=self.__ui
1308 ) 1302 )
1309 changeGroup = dlg.getChangeGroupName() 1303 changeGroup = dlg.getChangeGroupName()
1310 self.__refactoringDialogs[changeGroup] = dlg 1304 self.__refactoringDialogs[changeGroup] = dlg
1317 1311
1318 def __inline(self): 1312 def __inline(self):
1319 """ 1313 """
1320 Private slot to handle the Inline Local Variable action. 1314 Private slot to handle the Inline Local Variable action.
1321 """ 1315 """
1316 from .InlineDialog import InlineDialog
1317
1322 aw = self.__vm.activeWindow() 1318 aw = self.__vm.activeWindow()
1323 1319
1324 if aw is None: 1320 if aw is None:
1325 return 1321 return
1326 1322
1342 1338
1343 filename = aw.getFileName() 1339 filename = aw.getFileName()
1344 line, index, line1, index1 = aw.getSelection() 1340 line, index, line1, index1 = aw.getSelection()
1345 offset = self.__getOffset(aw, line, index) 1341 offset = self.__getOffset(aw, line, index)
1346 1342
1347 from .InlineDialog import InlineDialog
1348
1349 dlg = InlineDialog(self, title, filename, offset, parent=self.__ui) 1343 dlg = InlineDialog(self, title, filename, offset, parent=self.__ui)
1350 changeGroup = dlg.getChangeGroupName() 1344 changeGroup = dlg.getChangeGroupName()
1351 self.__refactoringDialogs[changeGroup] = dlg 1345 self.__refactoringDialogs[changeGroup] = dlg
1352 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1346 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1353 dlg.show() 1347 dlg.show()
1361 Private slot to handle the Move Method action. 1355 Private slot to handle the Move Method action.
1362 1356
1363 @param moveKind kind of move to be performed 1357 @param moveKind kind of move to be performed
1364 @type str (one of 'move_method' or 'move_module') 1358 @type str (one of 'move_method' or 'move_module')
1365 """ 1359 """
1360 from .MoveDialog import MoveDialog
1361
1366 aw = self.__vm.activeWindow() 1362 aw = self.__vm.activeWindow()
1367 1363
1368 if aw is None: 1364 if aw is None:
1369 return 1365 return
1370 1366
1373 if not aw.hasSelectedText(): 1369 if not aw.hasSelectedText():
1374 # no selection available 1370 # no selection available
1375 EricMessageBox.warning( 1371 EricMessageBox.warning(
1376 self.__ui, 1372 self.__ui,
1377 title, 1373 title,
1378 self.tr("Highlight the method to move" " and try again."), 1374 self.tr("Highlight the method to move and try again."),
1379 ) 1375 )
1380 return 1376 return
1381 else: 1377 else:
1382 title = self.tr("Move Current Module") 1378 title = self.tr("Move Current Module")
1383 1379
1389 line, index, line1, index1 = aw.getSelection() 1385 line, index, line1, index1 = aw.getSelection()
1390 offset = self.__getOffset(aw, line, index) 1386 offset = self.__getOffset(aw, line, index)
1391 else: 1387 else:
1392 offset = None 1388 offset = None
1393 1389
1394 from .MoveDialog import MoveDialog
1395
1396 dlg = MoveDialog(self, title, filename, offset, parent=self.__ui) 1390 dlg = MoveDialog(self, title, filename, offset, parent=self.__ui)
1397 changeGroup = dlg.getChangeGroupName() 1391 changeGroup = dlg.getChangeGroupName()
1398 self.__refactoringDialogs[changeGroup] = dlg 1392 self.__refactoringDialogs[changeGroup] = dlg
1399 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1393 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1400 dlg.show() 1394 dlg.show()
1405 1399
1406 def __useFunction(self): 1400 def __useFunction(self):
1407 """ 1401 """
1408 Private slot to use a function wherever possible. 1402 Private slot to use a function wherever possible.
1409 """ 1403 """
1404 from .UseFunctionDialog import UseFunctionDialog
1405
1410 aw = self.__vm.activeWindow() 1406 aw = self.__vm.activeWindow()
1411 1407
1412 if aw is None: 1408 if aw is None:
1413 return 1409 return
1414 1410
1425 1421
1426 filename = aw.getFileName() 1422 filename = aw.getFileName()
1427 line, index, line1, index1 = aw.getSelection() 1423 line, index, line1, index1 = aw.getSelection()
1428 offset = self.__getOffset(aw, line, index) 1424 offset = self.__getOffset(aw, line, index)
1429 1425
1430 from .UseFunctionDialog import UseFunctionDialog
1431
1432 dlg = UseFunctionDialog(self, title, filename, offset, parent=self.__ui) 1426 dlg = UseFunctionDialog(self, title, filename, offset, parent=self.__ui)
1433 changeGroup = dlg.getChangeGroupName() 1427 changeGroup = dlg.getChangeGroupName()
1434 self.__refactoringDialogs[changeGroup] = dlg 1428 self.__refactoringDialogs[changeGroup] = dlg
1435 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1429 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1436 dlg.show() 1430 dlg.show()
1441 1435
1442 def __introduceFactoryMethod(self): 1436 def __introduceFactoryMethod(self):
1443 """ 1437 """
1444 Private slot to introduce a factory method or global function. 1438 Private slot to introduce a factory method or global function.
1445 """ 1439 """
1440 from .IntroduceFactoryDialog import IntroduceFactoryDialog
1441
1446 aw = self.__vm.activeWindow() 1442 aw = self.__vm.activeWindow()
1447 1443
1448 if aw is None: 1444 if aw is None:
1449 return 1445 return
1450 1446
1466 1462
1467 filename = aw.getFileName() 1463 filename = aw.getFileName()
1468 line, index, line1, index1 = aw.getSelection() 1464 line, index, line1, index1 = aw.getSelection()
1469 offset = self.__getOffset(aw, line, index) 1465 offset = self.__getOffset(aw, line, index)
1470 1466
1471 from .IntroduceFactoryDialog import IntroduceFactoryDialog
1472
1473 dlg = IntroduceFactoryDialog(self, title, filename, offset, parent=self.__ui) 1467 dlg = IntroduceFactoryDialog(self, title, filename, offset, parent=self.__ui)
1474 changeGroup = dlg.getChangeGroupName() 1468 changeGroup = dlg.getChangeGroupName()
1475 self.__refactoringDialogs[changeGroup] = dlg 1469 self.__refactoringDialogs[changeGroup] = dlg
1476 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1470 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1477 dlg.show() 1471 dlg.show()
1478 1472
1479 def __introduceParameter(self): 1473 def __introduceParameter(self):
1480 """ 1474 """
1481 Private slot to introduce a parameter in a function. 1475 Private slot to introduce a parameter in a function.
1482 """ 1476 """
1477 from .IntroduceParameterDialog import IntroduceParameterDialog
1478
1483 aw = self.__vm.activeWindow() 1479 aw = self.__vm.activeWindow()
1484 1480
1485 if aw is None: 1481 if aw is None:
1486 return 1482 return
1487 1483
1489 if not aw.hasSelectedText(): 1485 if not aw.hasSelectedText():
1490 # no selection available 1486 # no selection available
1491 EricMessageBox.warning( 1487 EricMessageBox.warning(
1492 self.__ui, 1488 self.__ui,
1493 title, 1489 title,
1494 self.tr("Highlight the code for the new parameter" " and try again."), 1490 self.tr("Highlight the code for the new parameter and try again."),
1495 ) 1491 )
1496 return 1492 return
1497 1493
1498 if not self.confirmAllBuffersSaved(): 1494 if not self.confirmAllBuffersSaved():
1499 return 1495 return
1500 1496
1501 filename = aw.getFileName() 1497 filename = aw.getFileName()
1502 line, index, line1, index1 = aw.getSelection() 1498 line, index, line1, index1 = aw.getSelection()
1503 offset = self.__getOffset(aw, line, index) 1499 offset = self.__getOffset(aw, line, index)
1504
1505 from .IntroduceParameterDialog import IntroduceParameterDialog
1506 1500
1507 dlg = IntroduceParameterDialog(self, title, filename, offset, parent=self.__ui) 1501 dlg = IntroduceParameterDialog(self, title, filename, offset, parent=self.__ui)
1508 changeGroup = dlg.getChangeGroupName() 1502 changeGroup = dlg.getChangeGroupName()
1509 self.__refactoringDialogs[changeGroup] = dlg 1503 self.__refactoringDialogs[changeGroup] = dlg
1510 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1504 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1551 @param title title to be used for the import refactoring 1545 @param title title to be used for the import refactoring
1552 @type str 1546 @type str
1553 @param methodName name of the method performing the import refactoring 1547 @param methodName name of the method performing the import refactoring
1554 @type str 1548 @type str
1555 """ 1549 """
1550 from .ConfirmationDialog import ConfirmationDialog
1551
1556 aw = self.__vm.activeWindow() 1552 aw = self.__vm.activeWindow()
1557 1553
1558 if aw is None: 1554 if aw is None:
1559 return 1555 return
1560 1556
1565 if aw.hasSelectedText(): 1561 if aw.hasSelectedText():
1566 line, index, line1, index1 = aw.getSelection() 1562 line, index, line1, index1 = aw.getSelection()
1567 offset = self.__getOffset(aw, line, index) 1563 offset = self.__getOffset(aw, line, index)
1568 else: 1564 else:
1569 offset = None 1565 offset = None
1570
1571 from .ConfirmationDialog import ConfirmationDialog
1572 1566
1573 dlg = ConfirmationDialog( 1567 dlg = ConfirmationDialog(
1574 self, 1568 self,
1575 title, 1569 title,
1576 "Imports", 1570 "Imports",
1606 1600
1607 def __changeSignature(self): 1601 def __changeSignature(self):
1608 """ 1602 """
1609 Private slot to change the signature of a method or function. 1603 Private slot to change the signature of a method or function.
1610 """ 1604 """
1605 from .ChangeSignatureDialog import ChangeSignatureDialog
1606
1611 aw = self.__vm.activeWindow() 1607 aw = self.__vm.activeWindow()
1612 1608
1613 if aw is None: 1609 if aw is None:
1614 return 1610 return
1615 1611
1617 if not aw.hasSelectedText(): 1613 if not aw.hasSelectedText():
1618 # no selection available 1614 # no selection available
1619 EricMessageBox.warning( 1615 EricMessageBox.warning(
1620 self.__ui, 1616 self.__ui,
1621 title, 1617 title,
1622 self.tr("Highlight the method or function to change" " and try again."), 1618 self.tr("Highlight the method or function to change and try again."),
1623 ) 1619 )
1624 return 1620 return
1625 1621
1626 if not self.confirmAllBuffersSaved(): 1622 if not self.confirmAllBuffersSaved():
1627 return 1623 return
1628 1624
1629 filename = aw.getFileName() 1625 filename = aw.getFileName()
1630 line, index, line1, index1 = aw.getSelection() 1626 line, index, line1, index1 = aw.getSelection()
1631 offset = self.__getOffset(aw, line, index) 1627 offset = self.__getOffset(aw, line, index)
1632
1633 from .ChangeSignatureDialog import ChangeSignatureDialog
1634 1628
1635 dlg = ChangeSignatureDialog(self, title, filename, offset, parent=self.__ui) 1629 dlg = ChangeSignatureDialog(self, title, filename, offset, parent=self.__ui)
1636 changeGroup = dlg.getChangeGroupName() 1630 changeGroup = dlg.getChangeGroupName()
1637 self.__refactoringDialogs[changeGroup] = dlg 1631 self.__refactoringDialogs[changeGroup] = dlg
1638 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1632 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1641 def __inlineArgumentDefault(self): 1635 def __inlineArgumentDefault(self):
1642 """ 1636 """
1643 Private slot to inline the default value of a parameter of a 1637 Private slot to inline the default value of a parameter of a
1644 method or function. 1638 method or function.
1645 """ 1639 """
1640 from .InlineArgumentDefaultDialog import InlineArgumentDefaultDialog
1641
1646 aw = self.__vm.activeWindow() 1642 aw = self.__vm.activeWindow()
1647 1643
1648 if aw is None: 1644 if aw is None:
1649 return 1645 return
1650 1646
1666 1662
1667 filename = aw.getFileName() 1663 filename = aw.getFileName()
1668 line, index, line1, index1 = aw.getSelection() 1664 line, index, line1, index1 = aw.getSelection()
1669 offset = self.__getOffset(aw, line, index) 1665 offset = self.__getOffset(aw, line, index)
1670 1666
1671 from .InlineArgumentDefaultDialog import InlineArgumentDefaultDialog
1672
1673 dlg = InlineArgumentDefaultDialog( 1667 dlg = InlineArgumentDefaultDialog(
1674 self, title, filename, offset, parent=self.__ui 1668 self, title, filename, offset, parent=self.__ui
1675 ) 1669 )
1676 changeGroup = dlg.getChangeGroupName() 1670 changeGroup = dlg.getChangeGroupName()
1677 self.__refactoringDialogs[changeGroup] = dlg 1671 self.__refactoringDialogs[changeGroup] = dlg
1680 1674
1681 def __transformModuleToPackage(self): 1675 def __transformModuleToPackage(self):
1682 """ 1676 """
1683 Private slot to transform a module to a package. 1677 Private slot to transform a module to a package.
1684 """ 1678 """
1679 from .ConfirmationDialog import ConfirmationDialog
1680
1685 aw = self.__vm.activeWindow() 1681 aw = self.__vm.activeWindow()
1686 1682
1687 if aw is None: 1683 if aw is None:
1688 return 1684 return
1689 1685
1691 1687
1692 if not self.confirmAllBuffersSaved(): 1688 if not self.confirmAllBuffersSaved():
1693 return 1689 return
1694 1690
1695 filename = aw.getFileName() 1691 filename = aw.getFileName()
1696
1697 from .ConfirmationDialog import ConfirmationDialog
1698 1692
1699 dlg = ConfirmationDialog( 1693 dlg = ConfirmationDialog(
1700 self, 1694 self,
1701 title, 1695 title,
1702 "ModuleToPackage", 1696 "ModuleToPackage",
1713 1707
1714 def __encapsulateAttribute(self): 1708 def __encapsulateAttribute(self):
1715 """ 1709 """
1716 Private slot to encapsulate an attribute. 1710 Private slot to encapsulate an attribute.
1717 """ 1711 """
1712 from .GetterSetterDialog import GetterSetterDialog
1713
1718 aw = self.__vm.activeWindow() 1714 aw = self.__vm.activeWindow()
1719 1715
1720 if aw is None: 1716 if aw is None:
1721 return 1717 return
1722 1718
1724 if not aw.hasSelectedText(): 1720 if not aw.hasSelectedText():
1725 # no selection available 1721 # no selection available
1726 EricMessageBox.warning( 1722 EricMessageBox.warning(
1727 self.__ui, 1723 self.__ui,
1728 title, 1724 title,
1729 self.tr("Highlight the attribute to encapsulate" " and try again."), 1725 self.tr("Highlight the attribute to encapsulate and try again."),
1730 ) 1726 )
1731 return 1727 return
1732 1728
1733 if not self.confirmAllBuffersSaved(): 1729 if not self.confirmAllBuffersSaved():
1734 return 1730 return
1735 1731
1736 filename = aw.getFileName() 1732 filename = aw.getFileName()
1737 line, index, line1, index1 = aw.getSelection() 1733 line, index, line1, index1 = aw.getSelection()
1738 offset = self.__getOffset(aw, line, index) 1734 offset = self.__getOffset(aw, line, index)
1739
1740 from .GetterSetterDialog import GetterSetterDialog
1741 1735
1742 dlg = GetterSetterDialog(self, title, filename, offset, parent=self.__ui) 1736 dlg = GetterSetterDialog(self, title, filename, offset, parent=self.__ui)
1743 changeGroup = dlg.getChangeGroupName() 1737 changeGroup = dlg.getChangeGroupName()
1744 self.__refactoringDialogs[changeGroup] = dlg 1738 self.__refactoringDialogs[changeGroup] = dlg
1745 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup)) 1739 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1747 1741
1748 def __convertLocalToAttribute(self): 1742 def __convertLocalToAttribute(self):
1749 """ 1743 """
1750 Private slot to convert a local variable to an attribute. 1744 Private slot to convert a local variable to an attribute.
1751 """ 1745 """
1746 from .ConfirmationDialog import ConfirmationDialog
1747
1752 aw = self.__vm.activeWindow() 1748 aw = self.__vm.activeWindow()
1753 1749
1754 if aw is None: 1750 if aw is None:
1755 return 1751 return
1756 1752
1772 1768
1773 filename = aw.getFileName() 1769 filename = aw.getFileName()
1774 line, index, line1, index1 = aw.getSelection() 1770 line, index, line1, index1 = aw.getSelection()
1775 offset = self.__getOffset(aw, line, index) 1771 offset = self.__getOffset(aw, line, index)
1776 1772
1777 from .ConfirmationDialog import ConfirmationDialog
1778
1779 dlg = ConfirmationDialog( 1773 dlg = ConfirmationDialog(
1780 self, 1774 self,
1781 title, 1775 title,
1782 "LocalToAttribute", 1776 "LocalToAttribute",
1783 "CalculateLocalToAttributeChanges", 1777 "CalculateLocalToAttributeChanges",
1794 1788
1795 def __methodToMethodObject(self): 1789 def __methodToMethodObject(self):
1796 """ 1790 """
1797 Private slot to change the signature of a method or function. 1791 Private slot to change the signature of a method or function.
1798 """ 1792 """
1793 from .MethodToMethodObjectDialog import MethodToMethodObjectDialog
1794
1799 aw = self.__vm.activeWindow() 1795 aw = self.__vm.activeWindow()
1800 1796
1801 if aw is None: 1797 if aw is None:
1802 return 1798 return
1803 1799
1805 if not aw.hasSelectedText(): 1801 if not aw.hasSelectedText():
1806 # no selection available 1802 # no selection available
1807 EricMessageBox.warning( 1803 EricMessageBox.warning(
1808 self.__ui, 1804 self.__ui,
1809 title, 1805 title,
1810 self.tr( 1806 self.tr("Highlight the method or function to convert and try again."),
1811 "Highlight the method or function to convert" " and try again."
1812 ),
1813 ) 1807 )
1814 return 1808 return
1815 1809
1816 if not self.confirmAllBuffersSaved(): 1810 if not self.confirmAllBuffersSaved():
1817 return 1811 return
1818 1812
1819 filename = aw.getFileName() 1813 filename = aw.getFileName()
1820 line, index, line1, index1 = aw.getSelection() 1814 line, index, line1, index1 = aw.getSelection()
1821 offset = self.__getOffset(aw, line, index) 1815 offset = self.__getOffset(aw, line, index)
1822
1823 from .MethodToMethodObjectDialog import MethodToMethodObjectDialog
1824 1816
1825 dlg = MethodToMethodObjectDialog( 1817 dlg = MethodToMethodObjectDialog(
1826 self, title, filename, offset, parent=self.__ui 1818 self, title, filename, offset, parent=self.__ui
1827 ) 1819 )
1828 changeGroup = dlg.getChangeGroupName() 1820 changeGroup = dlg.getChangeGroupName()
1836 1828
1837 def __showProjectHistory(self): 1829 def __showProjectHistory(self):
1838 """ 1830 """
1839 Private method to show the project refactoring history. 1831 Private method to show the project refactoring history.
1840 """ 1832 """
1833 from .HistoryDialog import HistoryDialog
1834
1841 if self.__historyDialog is not None: 1835 if self.__historyDialog is not None:
1842 self.__historyDialog.close() 1836 self.__historyDialog.close()
1843
1844 from .HistoryDialog import HistoryDialog
1845 1837
1846 self.__historyDialog = HistoryDialog(self, parent=self.__ui) 1838 self.__historyDialog = HistoryDialog(self, parent=self.__ui)
1847 self.__historyDialog.finished.connect(self.__historyDialogClosed) 1839 self.__historyDialog.finished.connect(self.__historyDialogClosed)
1848 self.__historyDialog.show() 1840 self.__historyDialog.show()
1849 1841
1850 def __showFileHistory(self): 1842 def __showFileHistory(self):
1851 """ 1843 """
1852 Private method to show the refactoring history of the current file. 1844 Private method to show the refactoring history of the current file.
1853 """ 1845 """
1846 from .HistoryDialog import HistoryDialog
1847
1854 aw = self.__vm.activeWindow() 1848 aw = self.__vm.activeWindow()
1855 1849
1856 if aw is None: 1850 if aw is None:
1857 return 1851 return
1858 1852
1859 if self.__historyDialog is not None: 1853 if self.__historyDialog is not None:
1860 self.__historyDialog.close() 1854 self.__historyDialog.close()
1861
1862 from .HistoryDialog import HistoryDialog
1863 1855
1864 filename = aw.getFileName() 1856 filename = aw.getFileName()
1865 if filename: 1857 if filename:
1866 self.__historyDialog = HistoryDialog( 1858 self.__historyDialog = HistoryDialog(
1867 self, filename=filename, parent=self.__ui 1859 self, filename=filename, parent=self.__ui
1942 the client. 1934 the client.
1943 1935
1944 @param result dictionary containing the result data 1936 @param result dictionary containing the result data
1945 @type dict 1937 @type dict
1946 """ 1938 """
1939 from .MatchesDialog import MatchesDialog
1940
1947 if self.handleRopeError(result): 1941 if self.handleRopeError(result):
1948 title = result["Title"] 1942 title = result["Title"]
1949 if result["EntriesCount"] > 0: 1943 if result["EntriesCount"] > 0:
1950 from .MatchesDialog import MatchesDialog
1951
1952 self.dlg = MatchesDialog(self.__ui, True) 1944 self.dlg = MatchesDialog(self.__ui, True)
1953 self.dlg.show() 1945 self.dlg.show()
1954 for occurrence in result["Entries"]: 1946 for occurrence in result["Entries"]:
1955 self.dlg.addEntry( 1947 self.dlg.addEntry(
1956 # file name, lineno, unsure 1948 # file name, lineno, unsure
1997 the client. 1989 the client.
1998 1990
1999 @param result dictionary containing the result data 1991 @param result dictionary containing the result data
2000 @type dict 1992 @type dict
2001 """ 1993 """
1994 from .MatchesDialog import MatchesDialog
1995
2002 if self.handleRopeError(result): 1996 if self.handleRopeError(result):
2003 title = result["Title"] 1997 title = result["Title"]
2004 if "Location" in result: 1998 if "Location" in result:
2005 location = result["Location"] 1999 location = result["Location"]
2006
2007 from .MatchesDialog import MatchesDialog
2008 2000
2009 self.dlg = MatchesDialog(self.__ui, False) 2001 self.dlg = MatchesDialog(self.__ui, False)
2010 self.dlg.show() 2002 self.dlg.show()
2011 self.dlg.addEntry(location[0], location[1]) 2003 self.dlg.addEntry(location[0], location[1])
2012 # file name, lineno 2004 # file name, lineno
2048 the client. 2040 the client.
2049 2041
2050 @param result dictionary containing the result data 2042 @param result dictionary containing the result data
2051 @type dict 2043 @type dict
2052 """ 2044 """
2045 from .MatchesDialog import MatchesDialog
2046
2053 if self.handleRopeError(result): 2047 if self.handleRopeError(result):
2054 title = result["Title"] 2048 title = result["Title"]
2055 if result["EntriesCount"] > 0: 2049 if result["EntriesCount"] > 0:
2056 from .MatchesDialog import MatchesDialog
2057
2058 self.dlg = MatchesDialog(self.__ui, True) 2050 self.dlg = MatchesDialog(self.__ui, True)
2059 self.dlg.show() 2051 self.dlg.show()
2060 for occurrence in result["Entries"]: 2052 for occurrence in result["Entries"]:
2061 self.dlg.addEntry( 2053 self.dlg.addEntry(
2062 # file name, lineno, unsure 2054 # file name, lineno, unsure
2075 2067
2076 def __editConfig(self): 2068 def __editConfig(self):
2077 """ 2069 """
2078 Private slot to open the rope configuration file in an editor. 2070 Private slot to open the rope configuration file in an editor.
2079 """ 2071 """
2072 from eric7.QScintilla.MiniEditor import MiniEditor
2073
2080 ropedir = self.__ropeConfig["RopeFolderName"] 2074 ropedir = self.__ropeConfig["RopeFolderName"]
2081 configfile = "" 2075 configfile = ""
2082 if ropedir and os.path.exists(ropedir): 2076 if ropedir and os.path.exists(ropedir):
2083 configfile = os.path.join(ropedir, "config.py") 2077 configfile = os.path.join(ropedir, "config.py")
2084 if os.path.exists(configfile): 2078 if os.path.exists(configfile):
2085 from eric7.QScintilla.MiniEditor import MiniEditor
2086
2087 self.__editor = MiniEditor(configfile) 2079 self.__editor = MiniEditor(configfile)
2088 self.__editor.show() 2080 self.__editor.show()
2089 self.__editor.editorSaved.connect(self.__configChanged) 2081 self.__editor.editorSaved.connect(self.__configChanged)
2090 else: 2082 else:
2091 EricMessageBox.critical( 2083 EricMessageBox.critical(
2092 self.__ui, 2084 self.__ui,
2093 self.tr("Configure Rope"), 2085 self.tr("Configure Rope"),
2094 self.tr( 2086 self.tr(
2095 """The Rope configuration file '{0}' does""" """ not exist.""" 2087 """The Rope configuration file '{0}' does not exist."""
2096 ).format(configfile), 2088 ).format(configfile),
2097 ) 2089 )
2098 else: 2090 else:
2099 EricMessageBox.critical( 2091 EricMessageBox.critical(
2100 self.__ui, 2092 self.__ui,
2135 2127
2136 def __showRopeHelp(self): 2128 def __showRopeHelp(self):
2137 """ 2129 """
2138 Private slot to show help about the refactorings offered by Rope. 2130 Private slot to show help about the refactorings offered by Rope.
2139 """ 2131 """
2132 from .HelpDialog import HelpDialog
2133
2140 if self.__helpDialog is None: 2134 if self.__helpDialog is None:
2141 from .HelpDialog import HelpDialog
2142
2143 self.__helpDialog = HelpDialog( 2135 self.__helpDialog = HelpDialog(
2144 self.tr("Help about rope refactorings"), 2136 self.tr("Help about rope refactorings"),
2145 self.__ropeConfig["RopeHelpFile"], 2137 self.__ropeConfig["RopeHelpFile"],
2146 ) 2138 )
2147 self.__helpDialog.show() 2139 self.__helpDialog.show()
2158 """This action might take some time. """ 2150 """This action might take some time. """
2159 """Do you really want to perform SOA?""" 2151 """Do you really want to perform SOA?"""
2160 ), 2152 ),
2161 ) 2153 )
2162 if res: 2154 if res:
2163
2164 self.sendJson( 2155 self.sendJson(
2165 "PerformSoa", 2156 "PerformSoa",
2166 { 2157 {
2167 "Title": title, 2158 "Title": title,
2168 }, 2159 },

eric ide

mercurial