RefactoringRope/InlineDialog.py

Fri, 02 May 2014 21:06:07 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Fri, 02 May 2014 21:06:07 +0200
changeset 76
936b2a98fe4e
parent 74
0973b175e2ad
parent 63
c02061242598
child 86
3339c75dc777
permissions
-rw-r--r--

Merge with Py2 comp.

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

# Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the Inline dialog.
"""

from __future__ import unicode_literals

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)
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    @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