16 class FiletypeAssociationDialog(QDialog, Ui_FiletypeAssociationDialog): |
16 class FiletypeAssociationDialog(QDialog, Ui_FiletypeAssociationDialog): |
17 """ |
17 """ |
18 Class implementing a dialog to enter filetype associations for the project. |
18 Class implementing a dialog to enter filetype associations for the project. |
19 """ |
19 """ |
20 |
20 |
21 def __init__(self, project, parent=None): |
21 def __init__(self, project, fileTypesDict, parent=None): |
22 """ |
22 """ |
23 Constructor |
23 Constructor |
24 |
24 |
25 @param project reference to the project object |
25 @param project reference to the project object |
26 @param parent reference to the parent widget (QWidget) |
26 @type Project |
|
27 @param fileTypesDict dictionary containing the file type associations |
|
28 @type dict |
|
29 @param parent reference to the parent widget (defaults to None) |
|
30 @type QWidget (optional) |
27 """ |
31 """ |
28 super().__init__(parent) |
32 super().__init__(parent) |
29 self.setupUi(self) |
33 self.setupUi(self) |
30 |
34 |
31 self.filetypeAssociationList.headerItem().setText( |
35 self.filetypeAssociationList.headerItem().setText( |
33 ) |
37 ) |
34 self.filetypeAssociationList.header().setSortIndicator( |
38 self.filetypeAssociationList.header().setSortIndicator( |
35 0, Qt.SortOrder.AscendingOrder |
39 0, Qt.SortOrder.AscendingOrder |
36 ) |
40 ) |
37 |
41 |
38 self.__project = project |
|
39 |
|
40 self.filetypeCombo.addItem("", "") |
42 self.filetypeCombo.addItem("", "") |
41 for fileCategory in sorted(self.__project.getFileCategories()): |
43 for fileCategory in sorted(project.getFileCategories()): |
42 self.filetypeCombo.addItem( |
44 self.filetypeCombo.addItem( |
43 self.__project.getFileCategoryType(fileCategory), fileCategory |
45 project.getFileCategoryType(fileCategory), fileCategory |
44 ) |
46 ) |
45 self.filetypeCombo.addItem(self.tr("Ignore"), "__IGNORE__") |
47 self.filetypeCombo.addItem(self.tr("Ignore"), "__IGNORE__") |
46 |
48 |
47 for pattern, filetype in self.__project.getProjectData( |
49 for pattern, filetype in fileTypesDict.items(): |
48 dataKey="FILETYPES" |
|
49 ).items(): |
|
50 try: |
50 try: |
51 self.__createItem( |
51 self.__createItem( |
52 pattern, self.__project.getFileCategoryType(filetype), filetype |
52 pattern, project.getFileCategoryType(filetype), filetype |
53 ) |
53 ) |
54 except KeyError: |
54 except KeyError: |
55 # skip entries with unknown file type |
55 # skip entries with unknown file type |
56 if filetype == "__IGNORE__": |
56 if filetype == "__IGNORE__": |
57 self.__createItem(pattern, self.tr("Ignore"), "__IGNORE__") |
57 self.__createItem(pattern, self.tr("Ignore"), "__IGNORE__") |
92 """ |
92 """ |
93 itm = QTreeWidgetItem(self.filetypeAssociationList, [pattern, filetypeStr]) |
93 itm = QTreeWidgetItem(self.filetypeAssociationList, [pattern, filetypeStr]) |
94 itm.setData(1, Qt.ItemDataRole.UserRole, fileCategory) |
94 itm.setData(1, Qt.ItemDataRole.UserRole, fileCategory) |
95 return itm |
95 return itm |
96 |
96 |
97 def on_filetypeAssociationList_currentItemChanged(self, itm, prevItm): |
97 |
98 """ |
98 @pyqtSlot() |
99 Private slot to handle the currentItemChanged signal of the |
99 def on_filetypeAssociationList_itemSelectionChanged(self): |
100 association list. |
100 """ |
101 |
101 Private slot to handle a change of the selected item. |
102 @param itm reference to the new current item (QTreeWidgetItem) |
102 """ |
103 @param prevItm reference to the previous current item (QTreeWidgetItem) |
103 selectedItems = self.filetypeAssociationList.selectedItems() |
104 """ |
104 if bool(selectedItems): |
105 if itm is None: |
105 self.filePatternEdit.setText(selectedItems[0].text(0)) |
|
106 self.filetypeCombo.setCurrentText(selectedItems[0].text(1)) |
|
107 self.deleteAssociationButton.setEnabled(True) |
|
108 else: |
106 self.filePatternEdit.clear() |
109 self.filePatternEdit.clear() |
107 self.filetypeCombo.setCurrentIndex(0) |
110 self.filetypeCombo.setCurrentIndex(0) |
108 self.deleteAssociationButton.setEnabled(False) |
111 self.deleteAssociationButton.setEnabled(False) |
109 else: |
|
110 self.filePatternEdit.setText(itm.text(0)) |
|
111 self.filetypeCombo.setCurrentText(itm.text(1)) |
|
112 self.deleteAssociationButton.setEnabled(True) |
|
113 |
112 |
114 @pyqtSlot() |
113 @pyqtSlot() |
115 def on_addAssociationButton_clicked(self): |
114 def on_addAssociationButton_clicked(self): |
116 """ |
115 """ |
117 Private slot to add the association displayed to the list. |
116 Private slot to add the association displayed to the list. |
184 """ |
183 """ |
185 self.addAssociationButton.setEnabled( |
184 self.addAssociationButton.setEnabled( |
186 bool(self.filePatternEdit.text()) and bool(self.filetypeCombo.currentText()) |
185 bool(self.filePatternEdit.text()) and bool(self.filetypeCombo.currentText()) |
187 ) |
186 ) |
188 |
187 |
189 def transferData(self): |
188 def getData(self): |
190 """ |
189 """ |
191 Public slot to transfer the associations into the projects data |
190 Public method to get the entered associations into. |
192 structure. |
191 |
|
192 @return dictionary containing the defined file type associations |
|
193 @rtype dict |
193 """ |
194 """ |
194 fileTypes = {} |
195 fileTypes = {} |
195 for index in range(self.filetypeAssociationList.topLevelItemCount()): |
196 for index in range(self.filetypeAssociationList.topLevelItemCount()): |
196 itm = self.filetypeAssociationList.topLevelItem(index) |
197 itm = self.filetypeAssociationList.topLevelItem(index) |
197 fileTypes[itm.text(0)] = itm.data(1, Qt.ItemDataRole.UserRole) |
198 fileTypes[itm.text(0)] = itm.data(1, Qt.ItemDataRole.UserRole) |
198 self.__project.setProjectData(fileTypes, dataKey="FILETYPES") |
199 |
|
200 return fileTypes |