diff --git a/QgisModelBaker/qgismodelbaker.py b/QgisModelBaker/qgismodelbaker.py index 976b74d7b..4766fc16c 100644 --- a/QgisModelBaker/qgismodelbaker.py +++ b/QgisModelBaker/qgismodelbaker.py @@ -563,29 +563,18 @@ def eventFilter(self, obj, event): When files are dropped, then ask to use it in the model baker. """ if event.type() == QEvent.Drop: - dropped_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidExtenstions - ] - additional_xml_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] in ["xml", "XML"] - ] - additional_ini_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidIniExtensions - ] + ( + dropped_files, + dropped_xml_files, + dropped_ini_files, + ) = FileDropListView.extractDroppedFiles(event.mimeData().urls()) + + # Outside wizard, accept drops only for "real" interlis files, as xml and ini are too generic to assume must be handled by MB if dropped_files: - if self._is_handling_requested( - dropped_files + additional_xml_files + additional_ini_files - ): + dropped_files.extend(dropped_xml_files) + if self._is_handling_requested(dropped_files + dropped_ini_files): if self.parent.handle_dropped_files( - dropped_files + additional_xml_files, additional_ini_files + dropped_files, dropped_ini_files ): return True return False diff --git a/QgisModelBaker/utils/gui_utils.py b/QgisModelBaker/utils/gui_utils.py index 6edbd60f8..eceb48a37 100644 --- a/QgisModelBaker/utils/gui_utils.py +++ b/QgisModelBaker/utils/gui_utils.py @@ -256,7 +256,8 @@ class FileDropListView(QListView): List view allowing to drop ili and transfer files. """ - ValidExtenstions = ["xtf", "XTF", "itf", "ITF", "ili", "XML", "xml"] + ValidExtenstions = ["xtf", "XTF", "itf", "ITF", "ili"] + ValidXmlExtensions = ["XML", "xml"] ValidIniExtensions = ["ini", "INI", "toml", "TOML"] files_dropped = pyqtSignal(list, list) @@ -277,21 +278,35 @@ def dragEnterEvent(self, event): break def dropEvent(self, event): - dropped_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidExtenstions - ] - dropped_ini_files = [ - url.toLocalFile() - for url in event.mimeData().urls() - if pathlib.Path(url.toLocalFile()).suffix[1:] - in FileDropListView.ValidIniExtensions - ] + dropped_files, dropped_xml_files, dropped_ini_files = self.extractDroppedFiles( + event.mimeData().urls() + ) + + dropped_files.extend(dropped_xml_files) self.files_dropped.emit(dropped_files, dropped_ini_files) event.acceptProposedAction() + @staticmethod + def extractDroppedFiles(url_list): + dropped_interlis_files = [] + dropped_xml_files = [] + dropped_ini_files = [] + for url in url_list: + local_file = url.toLocalFile() + suffix = pathlib.Path(local_file).suffix[1:] + if suffix in FileDropListView.ValidExtenstions: + dropped_interlis_files.append(local_file) + continue + + if suffix in FileDropListView.ValidXmlExtensions: + dropped_xml_files.append(local_file) + continue + + if suffix in FileDropListView.ValidIniExtensions: + dropped_ini_files.append(local_file) + + return dropped_interlis_files, dropped_xml_files, dropped_ini_files + class SourceModel(QStandardItemModel): """