RefactoringRope/InlineDialog.py

Thu, 10 Jan 2019 14:21:07 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 10 Jan 2019 14:21:07 +0100
changeset 302
2e853e2f2430
parent 245
75a35a927952
child 326
67bcde9c65b9
permissions
-rw-r--r--

Updated copyright for 2019.

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

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

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

from __future__ import unicode_literals

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton

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, filename, offset, parent=None):
        """
        Constructor
        
        @param refactoring reference to the main refactoring object
        @type RefactoringServer
        @param title title of the dialog
        @type str
        @param filename file name to be worked on
        @type str
        @param offset offset within file
        @type int or None
        @param parent reference to the parent widget
        @type QWidget
        """
        RefactoringDialogBase.__init__(self, refactoring, title, parent)
        self.setupUi(self)
        
        self._changeGroupName = "Inline"
        
        self.__filename = filename
        self.__offset = offset
        
        self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
        self.__previewButton = self.buttonBox.addButton(
            self.tr("Preview"), QDialogButtonBox.ActionRole)
        self.__previewButton.setDefault(True)
        
        self.__inlinerKind = ""
        
        self._refactoring.sendJson("RequestInlineType", {
            "ChangeGroup": self._changeGroupName,
            "Title": self._title,
            "FileName": self.__filename,
            "Offset": self.__offset,
        })
    
    def __processInlineType(self, data):
        """
        Private method to process the inline type data sent by the refactoring
        client in order to polish the dialog.
        
        @param data dictionary containing the inline type data
        @type dict
        """
        self.__inlinerKind = data["Kind"]
        
        if data["Kind"] == "parameter":
            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.tr("Inlining occurrences of <b>{0}</b> (type '<i>{1}</i>').")
                .format(data["Name"], data["Kind"]))
        
        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
        @type QAbstractButton
        """
        if button == self.__previewButton:
            self.requestPreview()
        elif button == self.__okButton:
            self.applyChanges()
    
    def _calculateChanges(self):
        """
        Protected method to initiate the calculation of the changes.
        """
        self._refactoring.sendJson("CalculateInlineChanges", {
            "ChangeGroup": self._changeGroupName,
            "Title": self._title,
            "FileName": self.__filename,
            "Offset": self.__offset,
            "Kind": self.__inlinerKind,
            "Hierarchy": self.hierarchyCheckBox.isChecked(),
            "Remove": self.removeCheckBox.isChecked(),
            "OnlyCurrent": self.currentCheckBox.isChecked(),
        })
    
    def processChangeData(self, data):
        """
        Public method to process the change data sent by the refactoring
        client.
        
        @param data dictionary containing the change data
        @type dict
        """
        subcommand = data["Subcommand"]
        if subcommand == "InlineType":
            self.__processInlineType(data)
        else:
            # pass on to base class
            RefactoringDialogBase.processChangeData(self, data)

eric ide

mercurial