RefactoringRope/InlineDialog.py

branch
server_client_variant
changeset 176
117d86025a5c
parent 147
3f8a995f6e49
child 177
963fc1b0ba6e
equal deleted inserted replaced
175:72a1d9030d67 176:117d86025a5c
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt5.QtCore import pyqtSlot 12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton 13 from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton
14 14
15 import rope.refactor.inline
16
17 from Ui_InlineDialog import Ui_InlineDialog 15 from Ui_InlineDialog import Ui_InlineDialog
18 from RefactoringDialogBase import RefactoringDialogBase 16 from RefactoringDialogBase import RefactoringDialogBase
19 17
20 18
21 class InlineDialog(RefactoringDialogBase, Ui_InlineDialog): 19 class InlineDialog(RefactoringDialogBase, Ui_InlineDialog):
22 """ 20 """
23 Class implementing the Inline dialog. 21 Class implementing the Inline dialog.
24 """ 22 """
25 def __init__(self, refactoring, title, inliner, parent=None): 23 def __init__(self, refactoring, title, filename, offset, parent=None):
26 """ 24 """
27 Constructor 25 Constructor
28 26
29 @param refactoring reference to the main refactoring object 27 @param refactoring reference to the main refactoring object
30 (Refactoring) 28 @type Refactoring
31 @param title title of the dialog (string) 29 @param title title of the dialog
32 @param inliner reference to the inliner object 30 @type str
33 (rope.refactor.inline.InlineMethod, 31 @param filename file name to be worked on
34 rope.refactor.inline.InlineVariable 32 @type str
35 or rope.refactor.inline.InlineParameter) 33 @param offset offset within file
36 @param parent reference to the parent widget (QWidget) 34 @type int or None
35 @param parent reference to the parent widget
36 @type QWidget
37 """ 37 """
38 RefactoringDialogBase.__init__(self, refactoring, title, parent) 38 RefactoringDialogBase.__init__(self, refactoring, title, parent)
39 self.setupUi(self) 39 self.setupUi(self)
40 40
41 self.__inliner = inliner 41 self._changeGroupName = "Inline"
42 42
43 # polish up the dialog 43 self.__filename = filename
44 if isinstance(self.__inliner, rope.refactor.inline.InlineParameter): 44 self.__offset = offset
45
46 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
47 self.__previewButton = self.buttonBox.addButton(
48 self.tr("Preview"), QDialogButtonBox.ActionRole)
49 self.__previewButton.setDefault(True)
50
51 self.__inlinerKind = ""
52
53 self._refactoring.sendJson("RequestInlineType", {
54 "ChangeGroup": self._changeGroupName,
55 "Title": self._title,
56 "FileName": self.__filename,
57 "Offset": self.__offset,
58 })
59
60 def __processInlineType(self, data):
61 """
62 Private method to process the inline type data sent by the refactoring
63 client in order to polish the dialog.
64
65 @param data dictionary containing the change data
66 @type dict
67 """
68 self.__inlinerKind = data["Kind"]
69
70 if data["Kind"] == "parameter":
45 self.removeCheckBox.setVisible(False) 71 self.removeCheckBox.setVisible(False)
46 self.currentCheckBox.setVisible(False) 72 self.currentCheckBox.setVisible(False)
47 self.hierarchyCheckBox.setVisible(True) 73 self.hierarchyCheckBox.setVisible(True)
48 else: 74 else:
49 self.removeCheckBox.setVisible(True) 75 self.removeCheckBox.setVisible(True)
50 self.currentCheckBox.setVisible(True) 76 self.currentCheckBox.setVisible(True)
51 self.hierarchyCheckBox.setVisible(False) 77 self.hierarchyCheckBox.setVisible(False)
52 self.resize(500, 20) 78 self.resize(500, 20)
53 79
54 self.description.setText( 80 self.description.setText(
55 self.tr("Inlining occurrences of <b>{0}</b> (type {1}).") 81 self.tr("Inlining occurrences of <b>{0}</b> (type '<i>{1}</i>').")
56 .format(self.__inliner.name, self.__inliner.get_kind())) 82 .format(data["Name"], data["Kind"]))
57
58 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
59 self.__previewButton = self.buttonBox.addButton(
60 self.tr("Preview"), QDialogButtonBox.ActionRole)
61 self.__previewButton.setDefault(True)
62 83
63 msh = self.minimumSizeHint() 84 msh = self.minimumSizeHint()
64 self.resize(max(self.width(), msh.width()), msh.height()) 85 self.resize(max(self.width(), msh.width()), msh.height())
65 86
66 @pyqtSlot(QAbstractButton) 87 @pyqtSlot(QAbstractButton)
67 def on_buttonBox_clicked(self, button): 88 def on_buttonBox_clicked(self, button):
68 """ 89 """
69 Private slot to act on the button pressed. 90 Private slot to act on the button pressed.
70 91
71 @param button reference to the button pressed (QAbstractButton) 92 @param button reference to the button pressed
93 @type QAbstractButton
72 """ 94 """
73 if button == self.__previewButton: 95 if button == self.__previewButton:
74 self.previewChanges() 96 self.requestPreview()
75 elif button == self.__okButton: 97 elif button == self.__okButton:
76 self.applyChanges() 98 self.applyChanges()
77 99
78 def _calculateChanges(self, handle): 100 def _calculateChanges(self):
79 """ 101 """
80 Protected method to calculate the changes. 102 Protected method to initiate the calculation of the changes.
103 """
104 self._refactoring.sendJson("CalculateInlineChanges", {
105 "ChangeGroup": self._changeGroupName,
106 "Title": self._title,
107 "FileName": self.__filename,
108 "Offset": self.__offset,
109 "Kind": self.__inlinerKind,
110 "Hierarchy": self.hierarchyCheckBox.isChecked(),
111 "Remove": self.removeCheckBox.isChecked(),
112 "OnlyCurrent": self.currentCheckBox.isChecked(),
113 })
114
115 def processChangeData(self, data):
116 """
117 Public method to process the change data sent by the refactoring
118 client.
81 119
82 @param handle reference to the task handle 120 @param data dictionary containing the change data
83 (rope.base.taskhandle.TaskHandle) 121 @type dict
84 @return reference to the Changes object (rope.base.change.ChangeSet)
85 """ 122 """
86 try: 123 subcommand = data["Subcommand"]
87 if isinstance(self.__inliner, 124 if subcommand == "InlineType":
88 rope.refactor.inline.InlineParameter): 125 self.__processInlineType(data)
89 opts = { 126 else:
90 "in_hierarchy": self.hierarchyCheckBox.isChecked(), 127 # pass on to base class
91 } 128 RefactoringDialogBase.processChangeData(self, data)
92 else:
93 opts = {
94 "remove": self.removeCheckBox.isChecked(),
95 "only_current": self.currentCheckBox.isChecked(),
96 }
97 changes = self.__inliner.get_changes(task_handle=handle, **opts)
98 return changes
99 except Exception as err:
100 self._refactoring.handleRopeError(err, self._title, handle)
101 return None

eric ide

mercurial