23 import rope.refactor.move |
23 import rope.refactor.move |
24 import rope.refactor.change_signature |
24 import rope.refactor.change_signature |
25 import rope.refactor.introduce_factory |
25 import rope.refactor.introduce_factory |
26 import rope.refactor.introduce_parameter |
26 import rope.refactor.introduce_parameter |
27 ##import rope.refactor.method_object |
27 ##import rope.refactor.method_object |
28 ##import rope.refactor.encapsulate_field |
28 import rope.refactor.encapsulate_field |
29 ##import rope.refactor.localtofield |
29 import rope.refactor.localtofield |
30 ##import rope.refactor.topackage |
30 import rope.refactor.topackage |
31 from rope.refactor.importutils import ImportOrganizer |
31 from rope.refactor.importutils import ImportOrganizer |
32 |
32 |
33 import rope.contrib.findit |
33 import rope.contrib.findit |
34 ##import rope.contrib.finderrors |
34 ##import rope.contrib.finderrors |
35 |
35 |
437 """<p>Inline a parameters default value.</p>""" |
438 """<p>Inline a parameters default value.</p>""" |
438 )) |
439 )) |
439 self.refactoringInlineArgumentDefaultAct.triggered[()].connect( |
440 self.refactoringInlineArgumentDefaultAct.triggered[()].connect( |
440 self.__inlineArgumentDefault) |
441 self.__inlineArgumentDefault) |
441 self.actions.append(self.refactoringInlineArgumentDefaultAct) |
442 self.actions.append(self.refactoringInlineArgumentDefaultAct) |
|
443 |
|
444 self.refactoringTransformModuleAct = E5Action( |
|
445 self.trUtf8('Transform Module to Package'), |
|
446 self.trUtf8('Transform Module to Package'), |
|
447 0, 0, |
|
448 self,'refactoring_transform_module_to_package') |
|
449 self.refactoringTransformModuleAct.setStatusTip(self.trUtf8( |
|
450 'Transform the current module to a package')) |
|
451 self.refactoringTransformModuleAct.setWhatsThis(self.trUtf8( |
|
452 """<b>Transform Module to Package</b>""" |
|
453 """<p>Transform the current module to a package.</p>""" |
|
454 )) |
|
455 self.refactoringTransformModuleAct.triggered[()].connect( |
|
456 self.__transformModuleToPackage) |
|
457 self.actions.append(self.refactoringTransformModuleAct) |
|
458 |
|
459 self.refactoringEncapsulateAttributeAct = E5Action( |
|
460 self.trUtf8('Encapsulate Attribute'), |
|
461 self.trUtf8('Encap&sulate Attribute'), |
|
462 0, 0, |
|
463 self,'refactoring_encapsulate_attribute') |
|
464 self.refactoringEncapsulateAttributeAct.setStatusTip(self.trUtf8( |
|
465 'Generate a getter/setter for an attribute')) |
|
466 self.refactoringEncapsulateAttributeAct.setWhatsThis(self.trUtf8( |
|
467 """<b>Encapsulate Attribute</b>""" |
|
468 """<p>Generate a getter/setter for an attribute and changes""" |
|
469 """ its occurrences to use them.</p>""" |
|
470 )) |
|
471 self.refactoringEncapsulateAttributeAct.triggered[()].connect( |
|
472 self.__encapsulateAttribute) |
|
473 self.actions.append(self.refactoringEncapsulateAttributeAct) |
|
474 |
|
475 self.refactoringLocalVariableToAttributeAct = E5Action( |
|
476 self.trUtf8('Local Variable to Attribute'), |
|
477 self.trUtf8('Local Varia&ble to Attribute'), |
|
478 0, 0, |
|
479 self,'refactoring_local_variable_to_attribute') |
|
480 self.refactoringLocalVariableToAttributeAct.setStatusTip(self.trUtf8( |
|
481 'Change a local variable to an attribute')) |
|
482 self.refactoringLocalVariableToAttributeAct.setWhatsThis(self.trUtf8( |
|
483 """<b>Local Variable to Attribute</b>""" |
|
484 """<p>Change a local variable to an attribute.</p>""" |
|
485 )) |
|
486 self.refactoringLocalVariableToAttributeAct.triggered[()].connect( |
|
487 self.__convertLocalToAttribute) |
|
488 self.actions.append(self.refactoringLocalVariableToAttributeAct) |
442 |
489 |
443 ##################################################### |
490 ##################################################### |
444 ## Undo/Redo actions |
491 ## Undo/Redo actions |
445 ##################################################### |
492 ##################################################### |
446 |
493 |
677 smenu.addSeparator() |
724 smenu.addSeparator() |
678 smenu.addAction(self.refactoringIntroduceFactoryAct) |
725 smenu.addAction(self.refactoringIntroduceFactoryAct) |
679 smenu.addAction(self.refactoringIntroduceParameterAct) |
726 smenu.addAction(self.refactoringIntroduceParameterAct) |
680 ## smenu.addAction(self.refactoringMethodToMethodObjectAct) |
727 ## smenu.addAction(self.refactoringMethodToMethodObjectAct) |
681 smenu.addSeparator() |
728 smenu.addSeparator() |
682 ## smenu.addAction(self.refactoringEncapsulateAttributeAct) |
729 smenu.addAction(self.refactoringEncapsulateAttributeAct) |
683 ## smenu.addAction(self.refactoringLocalVariableToAttributeAct) |
730 smenu.addAction(self.refactoringLocalVariableToAttributeAct) |
684 smenu.addSeparator() |
731 smenu.addSeparator() |
685 smenu.addAction(self.refactoringRenameModuleAct) |
732 smenu.addAction(self.refactoringRenameModuleAct) |
686 smenu.addAction(self.refactoringMoveModuleAct) |
733 smenu.addAction(self.refactoringMoveModuleAct) |
687 ## smenu.addAction(self.refactoringTransformModuleAct) |
734 smenu.addAction(self.refactoringTransformModuleAct) |
688 smenu.addSeparator() |
735 smenu.addSeparator() |
689 |
736 |
690 imenu = smenu.addMenu(self.trUtf8("Im&ports")) |
737 imenu = smenu.addMenu(self.trUtf8("Im&ports")) |
691 imenu.addAction(self.refactoringImportsOrganizeAct) |
738 imenu.addAction(self.refactoringImportsOrganizeAct) |
692 imenu.addAction(self.refactoringImportsStarExpandAct) |
739 imenu.addAction(self.refactoringImportsStarExpandAct) |
1420 return |
1467 return |
1421 |
1468 |
1422 self.dlg = InlineArgumentDefaultDialog(self, title, changer, |
1469 self.dlg = InlineArgumentDefaultDialog(self, title, changer, |
1423 parent=self.__ui) |
1470 parent=self.__ui) |
1424 self.dlg.show() |
1471 self.dlg.show() |
|
1472 |
|
1473 def __transformModuleToPackage(self): |
|
1474 """ |
|
1475 Private slot to transform a module to a package. |
|
1476 """ |
|
1477 aw = e5App().getObject("ViewManager").activeWindow() |
|
1478 |
|
1479 if aw is None: |
|
1480 return |
|
1481 |
|
1482 title = self.trUtf8("Transform Module to Package") |
|
1483 |
|
1484 if not self.confirmAllBuffersSaved(): |
|
1485 return |
|
1486 |
|
1487 filename = aw.getFileName() |
|
1488 |
|
1489 resource = rope.base.libutils.path_to_resource( |
|
1490 self.__project, filename) |
|
1491 try: |
|
1492 changes = rope.refactor.topackage.ModuleToPackage( |
|
1493 self.__project, resource).get_changes() |
|
1494 self.__project.do(changes) |
|
1495 if self.__e5project.isDirty(): |
|
1496 self.__e5project.saveProject() |
|
1497 except Exception as err: |
|
1498 self.handleRopeError(err, title) |
|
1499 return |
|
1500 |
|
1501 def __encapsulateAttribute(self): |
|
1502 """ |
|
1503 Private slot to encapsulate an attribute. |
|
1504 """ |
|
1505 aw = e5App().getObject("ViewManager").activeWindow() |
|
1506 |
|
1507 if aw is None: |
|
1508 return |
|
1509 |
|
1510 title = self.trUtf8("Encapsulate Attribute") |
|
1511 if not aw.hasSelectedText(): |
|
1512 # no selection available |
|
1513 E5MessageBox.warning(self.__ui, title, |
|
1514 self.trUtf8("Highlight the attribute to encapsulate" |
|
1515 " and try again.")) |
|
1516 return |
|
1517 |
|
1518 if not self.confirmAllBuffersSaved(): |
|
1519 return |
|
1520 |
|
1521 filename = aw.getFileName() |
|
1522 line, index, line1, index1 = aw.getSelection() |
|
1523 offset = aw.positionFromLineIndex(line, index) |
|
1524 |
|
1525 resource = rope.base.libutils.path_to_resource( |
|
1526 self.__project, filename) |
|
1527 |
|
1528 try: |
|
1529 encapsulateField = \ |
|
1530 rope.refactor.encapsulate_field.EncapsulateField( |
|
1531 self.__project, resource, offset) |
|
1532 except Exception as err: |
|
1533 self.handleRopeError(err, title) |
|
1534 return |
|
1535 |
|
1536 dlg = GetterSetterDialog(encapsulateField.get_field_name()) |
|
1537 if dlg.exec_() == QDialog.Accepted: |
|
1538 getter, setter = dlg.getData() |
|
1539 handle = ProgressHandle(title, False, self.__ui) |
|
1540 handle.show() |
|
1541 QApplication.processEvents() |
|
1542 try: |
|
1543 changes = encapsulateField.get_changes( |
|
1544 getter=getter, setter=setter, task_handle=handle) |
|
1545 handle.reset() |
|
1546 dlg = ConfirmationDialog(changes, self.__ui) |
|
1547 if dlg.exec_() == QDialog.Accepted: |
|
1548 self.__project.do(changes) |
|
1549 self.refreshEditors(changes) |
|
1550 if self.__e5project.isDirty(): |
|
1551 self.__e5project.saveProject() |
|
1552 except Exception as err: |
|
1553 self.handleRopeError(err, title, handle) |
|
1554 |
|
1555 def __convertLocalToAttribute(self): |
|
1556 """ |
|
1557 Private slot to convert a local variable to an attribute. |
|
1558 """ |
|
1559 aw = e5App().getObject("ViewManager").activeWindow() |
|
1560 |
|
1561 if aw is None: |
|
1562 return |
|
1563 |
|
1564 title = self.trUtf8("Local Variable to Attribute") |
|
1565 if not aw.hasSelectedText(): |
|
1566 # no selection available |
|
1567 E5MessageBox.warning(self.__ui, title, |
|
1568 self.trUtf8("Highlight the local variable to make an attribute" |
|
1569 " and try again.")) |
|
1570 return |
|
1571 |
|
1572 if not self.confirmAllBuffersSaved(): |
|
1573 return |
|
1574 |
|
1575 filename = aw.getFileName() |
|
1576 line, index, line1, index1 = aw.getSelection() |
|
1577 offset = aw.positionFromLineIndex(line, index) |
|
1578 |
|
1579 resource = rope.base.libutils.path_to_resource( |
|
1580 self.__project, filename) |
|
1581 try: |
|
1582 changes = rope.refactor.localtofield.LocalToField( |
|
1583 self.__project, resource, offset).get_changes() |
|
1584 dlg = ConfirmationDialog(changes, self.__ui) |
|
1585 if dlg.exec_() == QDialog.Accepted: |
|
1586 self.__project.do(changes) |
|
1587 self.refreshEditors(changes) |
|
1588 if self.__e5project.isDirty(): |
|
1589 self.__e5project.saveProject() |
|
1590 except Exception as err: |
|
1591 self.handleRopeError(err, title) |
1425 |
1592 |
1426 ##################################################### |
1593 ##################################################### |
1427 ## Undo/Redo refactorings |
1594 ## Undo/Redo refactorings |
1428 ##################################################### |
1595 ##################################################### |
1429 |
1596 |