RefactoringRope/HistoryDialog.py

branch
eric7
changeset 389
4f53795beff0
parent 374
958f34e97952
child 396
933b8fcd854f
--- a/RefactoringRope/HistoryDialog.py	Sat Jun 25 18:06:56 2022 +0200
+++ b/RefactoringRope/HistoryDialog.py	Wed Sep 21 15:30:34 2022 +0200
@@ -9,9 +9,7 @@
 
 from PyQt6.QtCore import pyqtSlot, Qt, QItemSelectionModel
 from PyQt6.QtGui import QBrush, QTextCursor
-from PyQt6.QtWidgets import (
-    QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton
-)
+from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton
 
 from EricWidgets.EricApplication import ericApp
 from EricWidgets import EricMessageBox
@@ -27,12 +25,13 @@
     """
     Class implementing the History dialog.
     """
+
     ChangeIDRole = Qt.ItemDataRole.UserRole
-    
+
     def __init__(self, refactoring, filename="", parent=None):
         """
         Constructor
-        
+
         @param refactoring reference to the main refactoring object
         @type RefactoringServer
         @param filename name of the file to show the history for
@@ -43,65 +42,63 @@
         QDialog.__init__(self, parent)
         self.setupUi(self)
         self.setWindowFlags(Qt.WindowType.Window)
-        
+
         if Globals.isWindowsPlatform():
             self.previewEdit.setFontFamily("Lucida Console")
         else:
             self.previewEdit.setFontFamily("Monospace")
-        
+
         self.formats = {}
-        self.formats[' '] = self.previewEdit.currentCharFormat()
-        
+        self.formats[" "] = self.previewEdit.currentCharFormat()
+
         charFormat = self.previewEdit.currentCharFormat()
-        charFormat.setBackground(
-            QBrush(Preferences.getDiffColour("AddedColor")))
-        self.formats['+'] = charFormat
-        
-        charFormat = self.previewEdit.currentCharFormat()
-        charFormat.setBackground(
-            QBrush(Preferences.getDiffColour("RemovedColor")))
-        self.formats['-'] = charFormat
-        
+        charFormat.setBackground(QBrush(Preferences.getDiffColour("AddedColor")))
+        self.formats["+"] = charFormat
+
         charFormat = self.previewEdit.currentCharFormat()
-        charFormat.setBackground(
-            QBrush(Preferences.getDiffColour("ReplacedColor")))
-        self.formats['@'] = charFormat
-        
+        charFormat.setBackground(QBrush(Preferences.getDiffColour("RemovedColor")))
+        self.formats["-"] = charFormat
+
+        charFormat = self.previewEdit.currentCharFormat()
+        charFormat.setBackground(QBrush(Preferences.getDiffColour("ReplacedColor")))
+        self.formats["@"] = charFormat
+
         charFormat = self.previewEdit.currentCharFormat()
-        charFormat.setBackground(
-            QBrush(Preferences.getDiffColour("ContextColor")))
-        self.formats['?'] = charFormat
-        
+        charFormat.setBackground(QBrush(Preferences.getDiffColour("ContextColor")))
+        self.formats["?"] = charFormat
+
         charFormat = self.previewEdit.currentCharFormat()
-        charFormat.setBackground(
-            QBrush(Preferences.getDiffColour("HeaderColor")))
-        self.formats['='] = charFormat
-        
+        charFormat.setBackground(QBrush(Preferences.getDiffColour("HeaderColor")))
+        self.formats["="] = charFormat
+
         self.__refactoring = refactoring
         self.__filename = filename
-        
+
         if not filename:
             self.header.setText(self.tr("<b>Project History</b>"))
         else:
-            self.header.setText(self.tr("<b>File History: {0}</b>").format(
-                filename))
-        
+            self.header.setText(self.tr("<b>File History: {0}</b>").format(filename))
+
         self.__undoButton = self.buttonBox.addButton(
-            self.tr("&Undo"), QDialogButtonBox.ButtonRole.ActionRole)
+            self.tr("&Undo"), QDialogButtonBox.ButtonRole.ActionRole
+        )
         self.__redoButton = self.buttonBox.addButton(
-            self.tr("&Redo"), QDialogButtonBox.ButtonRole.ActionRole)
+            self.tr("&Redo"), QDialogButtonBox.ButtonRole.ActionRole
+        )
         self.__refreshButton = self.buttonBox.addButton(
-            self.tr("Re&fresh"), QDialogButtonBox.ButtonRole.ActionRole)
+            self.tr("Re&fresh"), QDialogButtonBox.ButtonRole.ActionRole
+        )
         self.__clearButton = self.buttonBox.addButton(
-            self.tr("&Clear History"), QDialogButtonBox.ButtonRole.ActionRole)
-        
+            self.tr("&Clear History"), QDialogButtonBox.ButtonRole.ActionRole
+        )
+
         # populate the list
         self.__refreshHistories()
-    
+
     def __appendText(self, txt, charFormat):
         """
         Private method to append text to the end of the preview pane.
-        
+
         @param txt text to insert
         @type str
         @param charFormat text format to be used
@@ -112,12 +109,12 @@
         self.previewEdit.setTextCursor(tc)
         self.previewEdit.setCurrentCharFormat(charFormat)
         self.previewEdit.insertPlainText(txt)
-    
+
     @pyqtSlot(QAbstractButton)
     def on_buttonBox_clicked(self, button):
         """
         Private slot handling the selection of a dialog button.
-        
+
         @param button reference to the button clicked
         @type QAbstractButton
         """
@@ -131,29 +128,32 @@
             self.__refreshHistories()
         elif button == self.__clearButton:
             self.__clearHistory()
-    
+
     def __currentItemChanged(self, current):
         """
         Private method to request change data of an item.
-        
+
         @param current reference to the item to get change data for
         @type QListWidgetItem
         """
         if current is None:
             return
-        
+
         self.previewEdit.clear()
         changeId = current.data(HistoryDialog.ChangeIDRole)
-        self.__refactoring.sendJson("History", {
-            "Subcommand": "GetChange",
-            "Id": changeId,
-        })
-    
+        self.__refactoring.sendJson(
+            "History",
+            {
+                "Subcommand": "GetChange",
+                "Id": changeId,
+            },
+        )
+
     @pyqtSlot(QListWidgetItem, QListWidgetItem)
     def on_redoChangesList_currentItemChanged(self, current, previous):
         """
         Private slot handling a change of the current redo change.
-        
+
         @param current reference to the new current redo item
         @type QListWidgetItem
         @param previous reference to the previous current redo item
@@ -161,22 +161,22 @@
         """
         self.__redoButton.setEnabled(current is not None)
         self.__currentItemChanged(current)
-    
+
     @pyqtSlot(QListWidgetItem)
     def on_redoChangesList_itemClicked(self, item):
         """
         Private slot handling a click on a redo entry.
-        
+
         @param item reference to the clicked item
         @type QListWidgetItem
         """
         self.__currentItemChanged(item)
-    
+
     @pyqtSlot(QListWidgetItem, QListWidgetItem)
     def on_undoChangesList_currentItemChanged(self, current, previous):
         """
         Private slot handling a change of the current undo change.
-        
+
         @param current reference to the new current undo item
         @type QListWidgetItem
         @param previous reference to the previous current undo item
@@ -184,17 +184,17 @@
         """
         self.__undoButton.setEnabled(current is not None)
         self.__currentItemChanged(current)
-    
+
     @pyqtSlot(QListWidgetItem)
     def on_undoChangesList_itemClicked(self, item):
         """
         Private slot handling a click on an undo entry.
-        
+
         @param item reference to the clicked item
         @type QListWidgetItem
         """
         self.__currentItemChanged(item)
-    
+
     def __undoChanges(self):
         """
         Private method to undo the selected set of changes.
@@ -205,18 +205,22 @@
         res = EricMessageBox.yesNo(
             None,
             self.tr("Undo Refactorings"),
-            self.tr("""Shall all refactorings up to <b>{0}</b>"""
-                    """ be undone?""")
-            .format(Utilities.html_encode(change)))
+            self.tr(
+                """Shall all refactorings up to <b>{0}</b>""" """ be undone?"""
+            ).format(Utilities.html_encode(change)),
+        )
         if res:
             if not self.__refactoring.confirmAllBuffersSaved():
                 return
-            
-            self.__refactoring.sendJson("History", {
-                "Subcommand": "Undo",
-                "Id": changeId,
-            })
-    
+
+            self.__refactoring.sendJson(
+                "History",
+                {
+                    "Subcommand": "Undo",
+                    "Id": changeId,
+                },
+            )
+
     def __redoChanges(self):
         """
         Private method to redo the selected set of changes.
@@ -227,18 +231,22 @@
         res = EricMessageBox.yesNo(
             None,
             self.tr("Redo Refactorings"),
-            self.tr("""Shall all refactorings up to <b>{0}</b>"""
-                    """ be redone?""")
-            .format(Utilities.html_encode(change)))
+            self.tr(
+                """Shall all refactorings up to <b>{0}</b>""" """ be redone?"""
+            ).format(Utilities.html_encode(change)),
+        )
         if res:
             if not self.__refactoring.confirmAllBuffersSaved():
                 return
-            
-            self.__refactoring.sendJson("History", {
-                "Subcommand": "Redo",
-                "Id": changeId,
-            })
-    
+
+            self.__refactoring.sendJson(
+                "History",
+                {
+                    "Subcommand": "Redo",
+                    "Id": changeId,
+                },
+            )
+
     def __refreshHistories(self):
         """
         Private method to refresh the undo and redo history lists.
@@ -247,16 +255,15 @@
         self.__redoButton.setEnabled(False)
         self.__refreshButton.setEnabled(False)
         self.__clearButton.setEnabled(False)
-        
+
         self.undoChangesList.clear()
         self.redoChangesList.clear()
         self.previewEdit.clear()
-        
-        self.__refactoring.sendJson("History", {
-            "Subcommand": "Get",
-            "Filename": self.__filename
-        })
-    
+
+        self.__refactoring.sendJson(
+            "History", {"Subcommand": "Get", "Filename": self.__filename}
+        )
+
     def __clearHistory(self):
         """
         Private method to clear the refactoring history.
@@ -264,25 +271,29 @@
         res = EricMessageBox.yesNo(
             None,
             self.tr("Clear History"),
-            self.tr("Do you really want to clear the refactoring history?"))
+            self.tr("Do you really want to clear the refactoring history?"),
+        )
         if res:
-            self.sendJson("History", {
-                "Subcommand": "Clear",
-            })
-            
+            self.sendJson(
+                "History",
+                {
+                    "Subcommand": "Clear",
+                },
+            )
+
             self.historyCleared()
-    
+
     def historyCleared(self):
         """
         Public method to indicate, that the refactoring history was cleared
         through the menu.
         """
         self.__refreshHistories()
-    
+
     def processHistoryCommand(self, data):
         """
         Public method to process the data sent by the refactoring client.
-        
+
         @param data dictionary containing the history data
         @type dict
         """
@@ -297,45 +308,47 @@
             if self.undoChangesList.count() > 0:
                 self.undoChangesList.setCurrentItem(
                     self.undoChangesList.item(0),
-                    QItemSelectionModel.SelectionFlag.Select)
+                    QItemSelectionModel.SelectionFlag.Select,
+                )
             elif self.redoChangesList.count() > 0:
                 self.redoChangesList.setCurrentItem(
                     self.redoChangesList.item(0),
-                    QItemSelectionModel.SelectionFlag.Select)
-            
+                    QItemSelectionModel.SelectionFlag.Select,
+                )
+
             self.__refreshButton.setEnabled(True)
-            if (
-                self.undoChangesList.count() > 0 or
-                self.redoChangesList.count() > 0
-            ):
+            if self.undoChangesList.count() > 0 or self.redoChangesList.count() > 0:
                 self.__clearButton.setEnabled(True)
-        
+
         elif subcommand == "ChangeDescription":
             for line in data["Description"].splitlines(True):
                 try:
                     charFormat = self.formats[line[0]]
                 except (IndexError, KeyError):
-                    charFormat = self.formats[' ']
+                    charFormat = self.formats[" "]
                 self.__appendText(line, charFormat)
-        
+
         elif subcommand in ["Undo", "Redo"]:
             self.__refactoring.refreshEditors(data["ChangedFiles"])
             p = ericApp().getObject("Project")
             if p.isDirty():
                 p.saveProject()
-            
+
             self.raise_()
             self.__refreshHistories()
-    
+
     def closeEvent(self, evt):
         """
         Protected method handling close events.
-        
+
         @param evt reference to the close event object
         @type QCloseEvent
         """
-        self.__refactoring.sendJson("History", {
-            "Subcommand": "ClearChanges",
-        })
-        
+        self.__refactoring.sendJson(
+            "History",
+            {
+                "Subcommand": "ClearChanges",
+            },
+        )
+
         evt.accept()

eric ide

mercurial