src/eric7/CodeFormatting/BlackFormattingDialog.py

branch
eric7
changeset 9220
e9e7eca7efee
parent 9214
bd28e56047d7
child 9221
bf71ee032bb4
--- a/src/eric7/CodeFormatting/BlackFormattingDialog.py	Tue Jul 12 17:31:17 2022 +0200
+++ b/src/eric7/CodeFormatting/BlackFormattingDialog.py	Wed Jul 13 11:16:20 2022 +0200
@@ -40,6 +40,9 @@
     DataTypeRole = Qt.ItemDataRole.UserRole
     DataRole = Qt.ItemDataRole.UserRole + 1
     
+    StatusColumn = 0
+    FileNameColumn = 1
+    
     def __init__(self, configuration, filesList, project=None,
                  action=BlackFormattingAction.Format, parent=None):
         """
@@ -64,6 +67,8 @@
         
         self.resultsList.header().setSortIndicator(1, Qt.SortOrder.AscendingOrder)
         
+        self.statisticsGroup.setVisible(False)
+        
         self.__report = BlackReport(self)
         self.__report.check = action is BlackFormattingAction.Check
         self.__report.diff = action is BlackFormattingAction.Diff
@@ -75,6 +80,8 @@
         self.__cancelled = False
         self.__diffDialog = None
         
+        self.__allFilter = self.tr("<all>")
+        
         self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
         self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False)
         self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True)
@@ -131,6 +138,21 @@
             QHeaderView.ResizeMode.ResizeToContents)
         self.resultsList.header().setStretchLastSection(True)
     
+    def __populateStatusFilterCombo(self):
+        """
+        Private method to populate the status filter combo box with allowed selections.
+        """
+        allowedSelections = set()
+        for row in range(self.resultsList.topLevelItemCount()):
+            allowedSelections.add(
+                self.resultsList.topLevelItem(row).text(
+                    BlackFormattingDialog.StatusColumn
+                )
+            )
+        
+        self.statusFilterComboBox.addItem(self.__allFilter)
+        self.statusFilterComboBox.addItems(sorted(allowedSelections))
+    
     def __finish(self):
         """
         Private method to perform some actions after the run was performed or canceled.
@@ -145,10 +167,12 @@
         self.progressBar.setVisible(False)
         
         self.__updateStatistics()
+        self.__populateStatusFilterCombo()
     
     def __updateStatistics(self):
         """
-        Private method to update the statistics about the recent formatting run.
+        Private method to update the statistics about the recent formatting run and
+        make them visible.
         """
         self.reformattedLabel.setText(
             self.tr("reformatted")
@@ -165,6 +189,8 @@
         self.processedCountLabel.setText("{0:n}".format(processed))
         self.reformattedCountLabel.setText("{0:n}".format(self.__report.change_count))
         self.unchangedCountLabel.setText("{0:n}".format(self.__report.same_count))
+        
+        self.statisticsGroup.setVisible(True)
     
     @pyqtSlot(QAbstractButton)
     def on_buttonBox_clicked(self, button):
@@ -323,6 +349,21 @@
         if self.__diffDialog is not None:
             self.__diffDialog.close()
         evt.accept()
+    
+    @pyqtSlot(str)
+    def on_statusFilterComboBox_currentTextChanged(self, status):
+        """
+        Private slot handling the selection of a status for items to be shown.
+        
+        @param status selected status
+        @type str
+        """
+        for row in range(self.resultsList.topLevelItemCount()):
+            itm = self.resultsList.topLevelItem(row)
+            itm.setHidden(
+                status != self.__allFilter
+                and itm.text(BlackFormattingDialog.StatusColumn) != status
+            )
 
 
 class BlackReport(black.Report):

eric ide

mercurial