src/eric7/Project/FiletypeAssociationDialog.py

branch
eric7
changeset 9610
b45bccbdf331
parent 9559
34fc53e6159d
child 9612
93b496cc3c88
diff -r c2f9c10c47cc -r b45bccbdf331 src/eric7/Project/FiletypeAssociationDialog.py
--- a/src/eric7/Project/FiletypeAssociationDialog.py	Sun Dec 11 15:49:39 2022 +0100
+++ b/src/eric7/Project/FiletypeAssociationDialog.py	Sun Dec 11 17:33:46 2022 +0100
@@ -18,12 +18,16 @@
     Class implementing a dialog to enter filetype associations for the project.
     """
 
-    def __init__(self, project, parent=None):
+    def __init__(self, project, fileTypesDict, parent=None):
         """
         Constructor
 
         @param project reference to the project object
-        @param parent reference to the parent widget (QWidget)
+        @type Project
+        @param fileTypesDict dictionary containing the file type associations
+        @type dict
+        @param parent reference to the parent widget (defaults to None)
+        @type QWidget (optional)
         """
         super().__init__(parent)
         self.setupUi(self)
@@ -35,21 +39,17 @@
             0, Qt.SortOrder.AscendingOrder
         )
 
-        self.__project = project
-
         self.filetypeCombo.addItem("", "")
-        for fileCategory in sorted(self.__project.getFileCategories()):
+        for fileCategory in sorted(project.getFileCategories()):
             self.filetypeCombo.addItem(
-                self.__project.getFileCategoryType(fileCategory), fileCategory
+                project.getFileCategoryType(fileCategory), fileCategory
             )
         self.filetypeCombo.addItem(self.tr("Ignore"), "__IGNORE__")
 
-        for pattern, filetype in self.__project.getProjectData(
-            dataKey="FILETYPES"
-        ).items():
+        for pattern, filetype in fileTypesDict.items():
             try:
                 self.__createItem(
-                    pattern, self.__project.getFileCategoryType(filetype), filetype
+                    pattern, project.getFileCategoryType(filetype), filetype
                 )
             except KeyError:
                 # skip entries with unknown file type
@@ -94,22 +94,21 @@
         itm.setData(1, Qt.ItemDataRole.UserRole, fileCategory)
         return itm
 
-    def on_filetypeAssociationList_currentItemChanged(self, itm, prevItm):
+
+    @pyqtSlot()
+    def on_filetypeAssociationList_itemSelectionChanged(self):
+        """
+        Private slot to handle a change of the selected item.
         """
-        Private slot to handle the currentItemChanged signal of the
-        association list.
-
-        @param itm reference to the new current item (QTreeWidgetItem)
-        @param prevItm reference to the previous current item (QTreeWidgetItem)
-        """
-        if itm is None:
+        selectedItems = self.filetypeAssociationList.selectedItems()
+        if bool(selectedItems):
+            self.filePatternEdit.setText(selectedItems[0].text(0))
+            self.filetypeCombo.setCurrentText(selectedItems[0].text(1))
+            self.deleteAssociationButton.setEnabled(True)
+        else:
             self.filePatternEdit.clear()
             self.filetypeCombo.setCurrentIndex(0)
             self.deleteAssociationButton.setEnabled(False)
-        else:
-            self.filePatternEdit.setText(itm.text(0))
-            self.filetypeCombo.setCurrentText(itm.text(1))
-            self.deleteAssociationButton.setEnabled(True)
 
     @pyqtSlot()
     def on_addAssociationButton_clicked(self):
@@ -186,13 +185,16 @@
             bool(self.filePatternEdit.text()) and bool(self.filetypeCombo.currentText())
         )
 
-    def transferData(self):
+    def getData(self):
         """
-        Public slot to transfer the associations into the projects data
-        structure.
+        Public method to get the entered associations into.
+
+        @return dictionary containing the defined file type associations
+        @rtype dict
         """
         fileTypes = {}
         for index in range(self.filetypeAssociationList.topLevelItemCount()):
             itm = self.filetypeAssociationList.topLevelItem(index)
             fileTypes[itm.text(0)] = itm.data(1, Qt.ItemDataRole.UserRole)
-        self.__project.setProjectData(fileTypes, dataKey="FILETYPES")
+
+        return fileTypes

eric ide

mercurial