RefactoringRope/ChangesPreviewDialog.py

changeset 3
3be1b4662b48
child 20
83b71483e198
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RefactoringRope/ChangesPreviewDialog.py	Sat Jan 29 15:10:40 2011 +0100
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the Changes preview dialog.
+"""
+
+from PyQt4.QtCore import Qt, pyqtSlot
+from PyQt4.QtGui import QDialogButtonBox, QListWidgetItem
+
+from PreviewDialogBase import PreviewDialogBase
+
+class ChangesPreviewDialog(PreviewDialogBase):
+    """
+    Class implementing the Changes preview dialog.
+    """
+    ChangeRole = Qt.UserRole
+    
+    def __init__(self, changes, parent):
+        """
+        Constructor
+        
+        @param changes reference to the Changes object
+            (rope.base.change.ChangeSet)
+        @param parent reference to the parent widget (QWidget)
+        """
+        PreviewDialogBase.__init__(self, parent)
+        
+        self.buttonBox.addButton(self.trUtf8("&Apply Changes"), 
+            QDialogButtonBox.AcceptRole)
+        self.buttonBox.addButton(QDialogButtonBox.Cancel)
+        
+        self.description.setText(changes.description)
+        for change in changes.changes:
+            itm = QListWidgetItem(str(change), self.changesList)
+            try:
+                changeDescription = change.get_description()
+            except AttributeError:
+                changeDescription = self.trUtf8("No changes available.")
+            itm.setData(ChangesPreviewDialog.ChangeRole, 
+                        changeDescription)
+        if self.changesList.count():
+            self.changesList.item(0).setSelected(True)
+    
+    @pyqtSlot(QListWidgetItem, QListWidgetItem)
+    def on_changesList_currentItemChanged(self, current, previous):
+        """
+        Private slot called when a change is selected.
+        
+        @param current reference to the new current item (QListWidgetItem)
+        @param previous reference to the old current item (QListWidgetItem)
+        """
+        if current is None:
+            return
+        
+        self.previewEdit.clear()
+        for line in current.data(ChangesPreviewDialog.ChangeRole)\
+                    .splitlines(True):
+            try:
+                format = self.formats[line[0]]
+            except (IndexError, KeyError):
+                format = self.formats[' ']
+            self._appendText(line, format)

eric ide

mercurial