RefactoringRope/InlineArgumentDefaultDialog.py

branch
server_client_variant
changeset 185
3336637a673b
parent 147
3f8a995f6e49
child 189
2711fdd91925
equal deleted inserted replaced
184:4a806271f0b9 185:3336637a673b
21 """ 21 """
22 Class implementing the Inline Argument Default dialog. 22 Class implementing the Inline Argument Default dialog.
23 """ 23 """
24 NameRole = Qt.UserRole 24 NameRole = Qt.UserRole
25 25
26 def __init__(self, refactoring, title, changer, parent=None): 26 def __init__(self, refactoring, title, filename, offset, parent=None):
27 """ 27 """
28 Constructor 28 Constructor
29 29
30 @param refactoring reference to the main refactoring object 30 @param refactoring reference to the main refactoring object
31 (Refactoring) 31 @type Refactoring
32 @param title title of the dialog (string) 32 @param title title of the dialog
33 @param changer reference to the signature changer object 33 @type str
34 (rope.refactor.change_signature.ChangeSignature) 34 @param filename file name to be worked on
35 @param parent reference to the parent widget (QWidget) 35 @type str
36 @param offset offset within file
37 @type int or None
38 @param parent reference to the parent widget
39 @type QWidget
36 """ 40 """
37 RefactoringDialogBase.__init__(self, refactoring, title, parent) 41 RefactoringDialogBase.__init__(self, refactoring, title, parent)
38 self.setupUi(self) 42 self.setupUi(self)
39 43
40 self.__signature = changer 44 self._changeGroupName = "ChangeSignature"
41 self.__definition_info = self.__signature.get_args() 45
46 self.__filename = filename
47 self.__offset = offset
48
49 self.__definition_info = []
42 50
43 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) 51 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
44 self.__okButton.setEnabled(False) 52 self.__okButton.setEnabled(False)
45 self.__previewButton = self.buttonBox.addButton( 53 self.__previewButton = self.buttonBox.addButton(
46 self.tr("Preview"), QDialogButtonBox.ActionRole) 54 self.tr("Preview"), QDialogButtonBox.ActionRole)
47 self.__previewButton.setDefault(True) 55 self.__previewButton.setDefault(True)
48 self.__previewButton.setEnabled(False) 56 self.__previewButton.setEnabled(False)
49 57
58 self._refactoring.sendJson("RequestSignature", {
59 "ChangeGroup": self._changeGroupName,
60 "Title": self._title,
61 "FileName": self.__filename,
62 "Offset": self.__offset,
63 })
64
65 def __processSignature(self, data):
66 """
67 Private method to process the inline type data sent by the refactoring
68 client in order to polish the dialog.
69
70 @param data dictionary containing the inline type data
71 @type dict
72 """
73 self.__definition_info = data["DefinitionInfo"]
74
50 # populate the parameters list 75 # populate the parameters list
51 for arg, default in self.__definition_info: 76 for arg, default in self.__definition_info:
52 if default is not None: 77 if default is not None:
53 itm = QListWidgetItem("{0} = {1}".format(arg, default), 78 itm = QListWidgetItem("{0}={1}".format(arg, default),
54 self.parameterList) 79 self.parameterList)
55 itm.setData(InlineArgumentDefaultDialog.NameRole, arg) 80 itm.setData(InlineArgumentDefaultDialog.NameRole, arg)
56 81
57 @pyqtSlot() 82 @pyqtSlot()
58 def on_parameterList_itemSelectionChanged(self): 83 def on_parameterList_itemSelectionChanged(self):
59 """ 84 """
60 Private slot called, when the selection changes. 85 Private slot called, when the selection changes.
61 """ 86 """
62 self.__okButton.setEnabled( 87 enable = len(self.parameterList.selectedItems()) > 0
63 len(self.parameterList.selectedItems()) > 0) 88
64 self.__previewButton.setEnabled( 89 self.__okButton.setEnabled(enable)
65 len(self.parameterList.selectedItems()) > 0) 90 self.__previewButton.setEnabled(enable)
66 91
67 @pyqtSlot(QAbstractButton) 92 @pyqtSlot(QAbstractButton)
68 def on_buttonBox_clicked(self, button): 93 def on_buttonBox_clicked(self, button):
69 """ 94 """
70 Private slot to act on the button pressed. 95 Private slot to act on the button pressed.
71 96
72 @param button reference to the button pressed (QAbstractButton) 97 @param button reference to the button pressed
98 @type QAbstractButton
73 """ 99 """
74 if button == self.__previewButton: 100 if button == self.__previewButton:
75 self.previewChanges() 101 self.requestPreview()
76 elif button == self.__okButton: 102 elif button == self.__okButton:
77 self.applyChanges() 103 self.applyChanges()
78 104
79 def __getParameterIndex(self, definition_info, name): 105 def __getParameterIndex(self, definition_info, name):
80 """ 106 """
81 Private method to calculate the index of the given paramter. 107 Private method to calculate the index of the given paramter.
82 108
83 @param definition_info object containing the method definition 109 @param definition_info list of lists containing the method signature
84 @param name parameter name (string) 110 definition
85 @return index of the parameter (integer) 111 @type list of lists of two str
112 @param name parameter name
113 @type str
114 @return index of the parameter
115 @rtype int
86 """ 116 """
87 for index, pair in enumerate(definition_info): 117 for index, pair in enumerate(definition_info):
88 if pair[0] == name: 118 if pair[0] == name:
89 return index 119 return index
90 120
91 def _calculateChanges(self, handle): 121 def _calculateChanges(self):
92 """ 122 """
93 Protected method to calculate the changes. 123 Protected method to initiate the calculation of the changes.
94
95 @param handle reference to the task handle
96 (rope.base.taskhandle.TaskHandle)
97 @return reference to the Changes object (rope.base.change.ChangeSet)
98 """ 124 """
99 items = self.parameterList.selectedItems() 125 items = self.parameterList.selectedItems()
100 if len(items) > 0: 126 if len(items) > 0:
101 import rope.refactor.change_signature
102
103 itm = items[0] 127 itm = items[0]
104 name = itm.data(InlineArgumentDefaultDialog.NameRole) 128 name = itm.data(InlineArgumentDefaultDialog.NameRole)
105 index = self.__getParameterIndex(self.__definition_info, name) 129 index = self.__getParameterIndex(self.__definition_info, name)
106 try: 130
107 inliner = \ 131 self._refactoring.sendJson(
108 rope.refactor.change_signature.ArgumentDefaultInliner( 132 "CalculateInlineArgumentDefaultChanges", {
109 index) 133 "ChangeGroup": self._changeGroupName,
110 changes = self.__signature.get_changes( 134 "Title": self._title,
111 [inliner], task_handle=handle) 135 "FileName": self.__filename,
112 return changes 136 "Offset": self.__offset,
113 except Exception as err: 137 "Index": index,
114 self._refactoring.handleRopeError(err, self._title, handle) 138 })
115 return None 139
140 def processChangeData(self, data):
141 """
142 Public method to process the change data sent by the refactoring
143 client.
144
145 @param data dictionary containing the change data
146 @type dict
147 """
148 subcommand = data["Subcommand"]
149 if subcommand == "Signature":
150 self.__processSignature(data)
151 else:
152 # pass on to base class
153 RefactoringDialogBase.processChangeData(self, data)

eric ide

mercurial