mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 23:23:57 -06:00
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
This commit is contained in:
parent
43615a57b6
commit
71994eaaf9
3 changed files with 31 additions and 9 deletions
|
@ -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"""
|
||||
|
||||
|
|
|
@ -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 { }
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue