diff -r 49a4abfc1f89 -r 07dabc6bb157 RefactoringRope/InlineDialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RefactoringRope/InlineDialog.py Sat Jan 29 19:57:25 2011 +0100 @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the Inline dialog. +""" + +from PyQt4.QtCore import pyqtSlot +from PyQt4.QtGui import QDialogButtonBox, QAbstractButton + +import rope.refactor.inline + +from Ui_InlineDialog import Ui_InlineDialog +from RefactoringDialogBase import RefactoringDialogBase + + +class InlineDialog(RefactoringDialogBase, Ui_InlineDialog): + """ + Class implementing the Inline dialog. + """ + def __init__(self, refactoring, title, inliner, parent = None): + """ + Constructor + + @param refactoring reference to the main refactoring object + (Refactoring) + @param title title of the dialog (string or QString) + @param inliner reference to the inliner object + (rope.refactor.inline.InlineMethod, + rope.refactor.inline.InlineVariable + or rope.refactor.inline.InlineParameter) + @param parent reference to the parent widget (QWidget) + """ + RefactoringDialogBase.__init__(self, refactoring, title, parent) + self.setupUi(self) + + self.__inliner = inliner + + # polish up the dialog + if isinstance(self.__inliner, rope.refactor.inline.InlineParameter): + self.removeCheckBox.setVisible(False) + self.currentCheckBox.setVisible(False) + self.hierarchyCheckBox.setVisible(True) + else: + self.removeCheckBox.setVisible(True) + self.currentCheckBox.setVisible(True) + self.hierarchyCheckBox.setVisible(False) + self.resize(500, 20) + + self.description.setText( + self.trUtf8("Inlining occurrences of <b>{0}</b> (type {1}).")\ + .format(self.__inliner.name, self.__inliner.get_kind())) + + self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) + self.__previewButton = self.buttonBox.addButton( + self.trUtf8("Preview"), QDialogButtonBox.ActionRole) + self.__previewButton.setDefault(True) + + @pyqtSlot(QAbstractButton) + def on_buttonBox_clicked(self, button): + """ + Private slot to act on the button pressed. + + @param button reference to the button pressed (QAbstractButton) + """ + if button == self.__previewButton: + self.previewChanges() + elif button == self.__okButton: + self.applyChanges() + + def _calculateChanges(self, handle): + """ + Protected method to calculate the changes. + + @param handle reference to the task handle + (rope.base.taskhandle.TaskHandle) + @return reference to the Changes object (rope.base.change.ChangeSet) + """ + try: + if isinstance(self.__inliner, + rope.refactor.inline.InlineParameter): + opts = { + "in_hierarchy" : self.hierarchyCheckBox.isChecked(), + } + else: + opts = { + "remove" : self.removeCheckBox.isChecked(), + "only_current" : self.currentCheckBox.isChecked(), + } + changes = self.__inliner.get_changes(task_handle=handle, **opts) + return changes + except Exception as err: + self._refactoring.handleRopeError(err, self._title, handle) + return None