RefactoringRope/InlineDialog.py

changeset 6
07dabc6bb157
child 9
8cee612bcc28
equal deleted inserted replaced
5:49a4abfc1f89 6:07dabc6bb157
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Inline dialog.
8 """
9
10 from PyQt4.QtCore import pyqtSlot
11 from PyQt4.QtGui import QDialogButtonBox, QAbstractButton
12
13 import rope.refactor.inline
14
15 from Ui_InlineDialog import Ui_InlineDialog
16 from RefactoringDialogBase import RefactoringDialogBase
17
18
19 class InlineDialog(RefactoringDialogBase, Ui_InlineDialog):
20 """
21 Class implementing the Inline dialog.
22 """
23 def __init__(self, refactoring, title, inliner, parent = None):
24 """
25 Constructor
26
27 @param refactoring reference to the main refactoring object
28 (Refactoring)
29 @param title title of the dialog (string or QString)
30 @param inliner reference to the inliner object
31 (rope.refactor.inline.InlineMethod,
32 rope.refactor.inline.InlineVariable
33 or rope.refactor.inline.InlineParameter)
34 @param parent reference to the parent widget (QWidget)
35 """
36 RefactoringDialogBase.__init__(self, refactoring, title, parent)
37 self.setupUi(self)
38
39 self.__inliner = inliner
40
41 # polish up the dialog
42 if isinstance(self.__inliner, rope.refactor.inline.InlineParameter):
43 self.removeCheckBox.setVisible(False)
44 self.currentCheckBox.setVisible(False)
45 self.hierarchyCheckBox.setVisible(True)
46 else:
47 self.removeCheckBox.setVisible(True)
48 self.currentCheckBox.setVisible(True)
49 self.hierarchyCheckBox.setVisible(False)
50 self.resize(500, 20)
51
52 self.description.setText(
53 self.trUtf8("Inlining occurrences of <b>{0}</b> (type {1}).")\
54 .format(self.__inliner.name, self.__inliner.get_kind()))
55
56 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
57 self.__previewButton = self.buttonBox.addButton(
58 self.trUtf8("Preview"), QDialogButtonBox.ActionRole)
59 self.__previewButton.setDefault(True)
60
61 @pyqtSlot(QAbstractButton)
62 def on_buttonBox_clicked(self, button):
63 """
64 Private slot to act on the button pressed.
65
66 @param button reference to the button pressed (QAbstractButton)
67 """
68 if button == self.__previewButton:
69 self.previewChanges()
70 elif button == self.__okButton:
71 self.applyChanges()
72
73 def _calculateChanges(self, handle):
74 """
75 Protected method to calculate the changes.
76
77 @param handle reference to the task handle
78 (rope.base.taskhandle.TaskHandle)
79 @return reference to the Changes object (rope.base.change.ChangeSet)
80 """
81 try:
82 if isinstance(self.__inliner,
83 rope.refactor.inline.InlineParameter):
84 opts = {
85 "in_hierarchy" : self.hierarchyCheckBox.isChecked(),
86 }
87 else:
88 opts = {
89 "remove" : self.removeCheckBox.isChecked(),
90 "only_current" : self.currentCheckBox.isChecked(),
91 }
92 changes = self.__inliner.get_changes(task_handle=handle, **opts)
93 return changes
94 except Exception as err:
95 self._refactoring.handleRopeError(err, self._title, handle)
96 return None

eric ide

mercurial