RefactoringRope/ExtractDialog.py

Tue, 10 Dec 2024 15:49:01 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 10 Dec 2024 15:49:01 +0100
branch
eric7
changeset 426
7592a1c052e8
parent 412
6fa5892b9097
permissions
-rw-r--r--

Updated copyright for 2025.

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

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

"""
Module implementing the Extract dialog.
"""

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

from .RefactoringDialogBase import RefactoringDialogBase
from .Ui_ExtractDialog import Ui_ExtractDialog


class ExtractDialog(RefactoringDialogBase, Ui_ExtractDialog):
    """
    Class implementing the Extract dialog.
    """

    def __init__(
        self,
        refactoring,
        title,
        filename,
        startOffset,
        endOffset,
        extractionType,
        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 startOffset offset within file to start extraction
        @type int
        @param endOffset offset within file to end extraction
        @type int
        @param extractionType type of extraction to be performed
        @type str
        @param parent reference to the parent widget
        @type QWidget
        """
        RefactoringDialogBase.__init__(self, refactoring, title, parent)
        self.setupUi(self)

        self._changeGroupName = "Extract"

        self.__filename = filename
        self.__startOffset = startOffset
        self.__endOffset = endOffset
        self.__extractionType = extractionType

        self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
        self.__okButton.setEnabled(False)
        self.__previewButton = self.buttonBox.addButton(
            self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole
        )
        self.__previewButton.setDefault(True)
        self.__previewButton.setEnabled(False)

        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())

    @pyqtSlot(str)
    def on_newNameEdit_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 != "")
        self.__previewButton.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 calculate the changes.
        """
        self._refactoring.sendJson(
            "CalculateExtractChanges",
            {
                "ChangeGroup": self._changeGroupName,
                "Title": self._title,
                "FileName": self.__filename,
                "StartOffset": self.__startOffset,
                "EndOffset": self.__endOffset,
                "Kind": self.__extractionType,
                "NewName": self.newNameEdit.text(),
                "Similar": self.similarCheckBox.isChecked(),
                "Global": self.globalCheckBox.isChecked(),
            },
        )

eric ide

mercurial