From 71994eaaf90ca6302cbbc860ebb1366bf710b8fe Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Wed, 23 Dec 2020 17:13:14 +0100 Subject: [PATCH] Change the Open File(s) option according to the file providers count When there is only one file provider (i.e. the local file provider), the Open File(s) will be a simple item in the File menu. When there are more than one file providers, the Open File(s) will become a submenu in the File menu, which will contain all the file providers as submenu items. CURA-7868 --- cura/CuraApplication.py | 11 +++++++++++ resources/qml/Menus/FileMenu.qml | 18 +++++++++++++++--- resources/qml/Menus/OpenFilesMenu.qml | 11 +++++------ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f0c69d5a61..ee347e7a4d 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -30,6 +30,7 @@ from UM.Operations.SetTransformOperation import SetTransformOperation from UM.Platform import Platform from UM.PluginError import PluginNotFoundError from UM.Preferences import Preferences +from UM.Qt.Bindings.FileProviderModel import FileProviderModel from UM.Qt.QtApplication import QtApplication # The class we're inheriting from. from UM.Resources import Resources from UM.Scene.Camera import Camera @@ -822,6 +823,9 @@ class CuraApplication(QtApplication): self._add_printer_pages_model_without_cancel.initialize(cancellable = False) self._whats_new_pages_model.initialize() + # Initialize the FileProviderModel + self._file_provider_model.initialize(self._onFileProviderEnabledChanged) + # Detect in which mode to run and execute that mode if self._is_headless: self.runWithoutGUI() @@ -1051,6 +1055,13 @@ class CuraApplication(QtApplication): self._simple_mode_settings_manager = SimpleModeSettingsManager() return self._simple_mode_settings_manager + @pyqtSlot(result = QObject) + def getFileProviderModel(self) -> FileProviderModel: + return self._file_provider_model + + def _onFileProviderEnabledChanged(self): + self._file_provider_model.update() + def event(self, event): """Handle Qt events""" diff --git a/resources/qml/Menus/FileMenu.qml b/resources/qml/Menus/FileMenu.qml index 24c081502a..a1bd246763 100644 --- a/resources/qml/Menus/FileMenu.qml +++ b/resources/qml/Menus/FileMenu.qml @@ -22,11 +22,23 @@ Menu { id: openMenu action: Cura.Actions.open - visible: CuraApplication.fileProviders.length > 0 // DEBUG: It's > 0 so that both options are visible for debugging purposes + visible: (CuraApplication.getFileProviderModel().count == 1) } - OpenFilesMenu { - visible: CuraApplication.fileProviders.length > 0 // DEBUG: It's > 0 so that both options are visible for debugging purposes + OpenFilesMenu + { + id: openFilesMenu + visible: (CuraApplication.getFileProviderModel().count > 1) + } + + Connections + { + target: CuraApplication.getFileProviderModel() + onItemsChanged: + { + openMenu.visible = (CuraApplication.getFileProviderModel().count == 1) // 1 because the open local files menu should always exist in the model + openFilesMenu.visible = (CuraApplication.getFileProviderModel().count > 1) + } } RecentFilesMenu { } diff --git a/resources/qml/Menus/OpenFilesMenu.qml b/resources/qml/Menus/OpenFilesMenu.qml index a3afa9a598..226ea70680 100644 --- a/resources/qml/Menus/OpenFilesMenu.qml +++ b/resources/qml/Menus/OpenFilesMenu.qml @@ -11,15 +11,14 @@ import "../Dialogs" Menu { - id: menu + id: openFilesMenu title: catalog.i18nc("@title:menu menubar:file", "Open File(s)...") iconName: "document-open-recent"; - Instantiator { id: fileProviders - model: UM.FileProviderModel { } + model: CuraApplication.getFileProviderModel() MenuItem { text: @@ -34,12 +33,12 @@ Menu } else { - fileProviders.model.trigger(model.name); + CuraApplication.getFileProviderModel().trigger(model.name); } } shortcut: model.shortcut } - onObjectAdded: menu.insertItem(index, object) - onObjectRemoved: menu.removeItem(object) + onObjectAdded: openFilesMenu.insertItem(index, object) + onObjectRemoved: openFilesMenu.removeItem(object) } }