RefactoringRope/ChangeOccurrencesDialog.py

Tue, 19 Sep 2017 19:40:18 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 19 Sep 2017 19:40:18 +0200
branch
server_client_variant
changeset 174
04583cac110f
parent 147
3f8a995f6e49
child 177
963fc1b0ba6e
permissions
-rw-r--r--

Implemented the distributed "Change Occurrences" method.

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

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

"""
Module implementing the Change Occurrences dialog.
"""

from __future__ import unicode_literals

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

from Ui_ChangeOccurrencesDialog import Ui_ChangeOccurrencesDialog
from RefactoringDialogBase import RefactoringDialogBase


class ChangeOccurrencesDialog(RefactoringDialogBase,
                              Ui_ChangeOccurrencesDialog):
    """
    Class implementing the Change Occurrences dialog.
    """
    def __init__(self, refactoring, title, filename, offset, parent=None):
        """
        Constructor
        
        @param refactoring reference to the main refactoring object
        @type Refactoring
        @param title title of the dialog
        @str str
        @param filename file name to be worked on
        @type str
        @param offset offset within file
        @type int
        @param parent reference to the parent widget
        @type QWidget
        """
        RefactoringDialogBase.__init__(self, refactoring, title, parent)
        self.setupUi(self)
        
        self._changeGroupName = "ChangeOccurrences"
        
        self.__filename = filename
        self.__offset = offset
        
        self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
        self.__okButton.setEnabled(False)
        self.__previewButton = self.buttonBox.addButton(
            self.tr("Preview"), QDialogButtonBox.ActionRole)
        self.__previewButton.setDefault(True)
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    @pyqtSlot(str)
    def on_replaceEdit_textChanged(self, text):
        """
        Private slot to react to changes of the new name.
        
        @param text text entered into the edit
        @type str
        """
        self.__okButton.setEnabled(text != "")
    
    @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("CalculateChangeOccurrencesChanges", {
            "ChangeGroup": self._changeGroupName,
            "Title": self._title,
            "FileName": self.__filename,
            "Offset": self.__offset,
            "NewName": self.replaceEdit.text(),
            "OnlyCalls": self.onlyCallsCheckBox.isChecked(),
            "Reads": self.readsCheckBox.isChecked(),
            "Writes": self.writesCheckBox.isChecked(),
        })

eric ide

mercurial