RefactoringRope/InlineDialog.py

Wed, 01 Jan 2014 14:47:56 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2014 14:47:56 +0100
changeset 62
1077db8d0589
parent 55
d501156be247
child 74
0973b175e2ad
permissions
-rw-r--r--

Updated copyright for 2014.

# -*- coding: utf-8 -*-

# Copyright (c) 2010 - 2014 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)
        @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

eric ide

mercurial