Sat, 29 Jan 2011 15:10:40 +0100
Added the 'rename' refactorings.
# -*- coding: utf-8 -*- # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the Refactoring dialog base class. """ from PyQt4.QtCore import Qt from PyQt4.QtGui import QDialog, QApplication from E5Gui.E5Application import e5App from ChangesPreviewDialog import ChangesPreviewDialog from ProgressHandle import ProgressHandle class RefactoringDialogBase(QDialog): """ Class implementing the Refactoring dialog base class. """ def __init__(self, refactoring, title, parent=None): """ Constructor @param refactoring reference to the main refactoring object (Refactoring) @param title title of the dialog (string or QString) @param parent reference to the parent widget (QWidget) """ QDialog.__init__(self, parent) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(title) self._refactoring = refactoring self._title = title self.__handle = None def __createProgressHandle(self, interruptable=True): """ Private method to create a TaskHandle to update a progress dialog. @param interruptable flag indicating, that the task may be interrupted (boolean) """ self.__handle = ProgressHandle(self._title, interruptable, self) self.__handle.show() QApplication.processEvents() 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) """ raise NotImplementedError("_calculateChanges must be overridden.") def __getChanges(self): """ Private method to build the Changes object. @return reference to the Changes object (rope.base.change.ChangeSet) """ self.__createProgressHandle() changes = self._calculateChanges(self.__handle) self.__handle.reset() self.__handle = None return changes def previewChanges(self): """ Public method to preview the changes. """ changes = self.__getChanges() if changes is not None: dlg = ChangesPreviewDialog(changes, self) if dlg.exec_() == QDialog.Accepted: self.applyChanges(changes) def applyChanges(self, changes = None): """ Public method to apply the changes. @param reference to the Changes object (rope.base.change.ChangeSet) """ if changes is None: changes = self.__getChanges() if changes is not None: self.__createProgressHandle(False) try: self._refactoring.getProject().do(changes, self.__handle) except Exception as err: self._refactoring.handleRopeError( err, self._title, self.__handle) self.__handle.reset() self.__handle = None self._refactoring.refreshEditors(changes) p = e5App().getObject("Project") if p.isDirty(): p.saveProject() self.accept()