From 4082cc1332c395535278fc3c9c285d09d5a5a985 Mon Sep 17 00:00:00 2001 From: Shrief Gabr Date: Tue, 6 Aug 2024 14:24:49 +0300 Subject: [PATCH] QmlDesigner: Allow importing/exporting a component from Navigator Fixes: QDS-13200 Change-Id: I771e962cca210d82a2434ff6c328e7bbe93e6b0a Reviewed-by: Mahmoud Badri --- .../componentcore/componentcore_constants.h | 10 +++++++++- .../componentcore/designeractionmanager.cpp | 20 +++++++++++++++++++ .../modelnodecontextmenu_helper.h | 7 +++++++ .../componentcore/modelnodeoperations.cpp | 11 ++++++++++ .../componentcore/modelnodeoperations.h | 2 ++ .../components/edit3d/edit3dwidget.cpp | 4 ++-- 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h index 85b6253aa0d..644a7227498 100644 --- a/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h +++ b/src/plugins/qmldesigner/components/componentcore/componentcore_constants.h @@ -68,6 +68,8 @@ inline constexpr char jumpToCodeCommandId[] = "JumpToCode"; inline constexpr char mergeTemplateCommandId[] = "MergeTemplate"; inline constexpr char goToImplementationCommandId[] = "GoToImplementation"; inline constexpr char makeComponentCommandId[] = "MakeComponent"; +inline constexpr char importComponentCommandId[] = "ImportComponent"; +inline constexpr char exportComponentCommandId[] = "ExportComponent"; inline constexpr char editMaterialCommandId[] = "EditMaterial"; inline constexpr char addToContentLibraryCommandId[] = "AddToContentLibrary"; inline constexpr char addItemToStackedContainerCommandId[] = "AddItemToStackedContainer"; @@ -161,6 +163,10 @@ inline constexpr char editMaterialDisplayName[] = QT_TRANSLATE_NOOP("QmlDesigner "Edit Material"); inline constexpr char addToContentLibraryDisplayName[] = QT_TRANSLATE_NOOP( "QmlDesignerContextMenu", "Add to Content Library"); +inline constexpr char importComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", + "Import Component"); +inline constexpr char exportComponentDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", + "Export Component"); inline constexpr char editAnnotationsDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", "Edit Annotations"); inline constexpr char addMouseAreaFillDisplayName[] = QT_TRANSLATE_NOOP("QmlDesignerContextMenu", @@ -325,7 +331,9 @@ enum PrioritiesEnum : int { Last, /******** Section *****************************/ AddingAssetsSection = 7000, - Add3DToContentLib + Add3DToContentLib, + ImportComponent, + ExportComponent, }; }; diff --git a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp index ff46eef5a1b..c39c9b9e68f 100644 --- a/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp +++ b/src/plugins/qmldesigner/components/componentcore/designeractionmanager.cpp @@ -1978,6 +1978,26 @@ void DesignerActionManager::createDefaultDesignerActions() &singleSelection, &singleSelection)); + addDesignerAction(new ModelNodeContextMenuAction( + importComponentCommandId, + importComponentDisplayName, + contextIcon(DesignerIcons::CreateIcon), // TODO: placeholder icon + rootCategory, + QKeySequence(), + Priorities::ImportComponent, + &importComponent)); + + addDesignerAction(new ModelNodeContextMenuAction( + exportComponentCommandId, + exportComponentDisplayName, + contextIcon(DesignerIcons::CreateIcon), // TODO: placeholder icon + rootCategory, + QKeySequence(), + Priorities::ExportComponent, + &exportComponent, + &is3DNode, + &is3DNode)); + addDesignerAction(new ModelNodeContextMenuAction( editMaterialCommandId, editMaterialDisplayName, diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h index 9216933d2b0..98ea60f7690 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodecontextmenu_helper.h @@ -80,6 +80,13 @@ inline bool enableAddToContentLib(const SelectionContext &selectionState) return isNode3D && !isInBundle; } +inline bool is3DNode(const SelectionContext &selectionState) +{ + ModelNode modelNode = selectionState.currentSingleSelectedNode(); + + return modelNode.metaInfo().isQtQuick3DNode(); +} + inline bool hasEditableMaterial(const SelectionContext &selectionState) { ModelNode node = selectionState.currentSingleSelectedNode(); diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index 32aadd7fba3..d114d2dc151 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -803,6 +803,17 @@ void add3DAssetToContentLibrary(const SelectionContext &selectionContext) selectionContext.view()->emitCustomNotification("add_3d_to_content_lib", {node}); } +void importComponent(const SelectionContext &selectionContext) +{ + selectionContext.view()->emitCustomNotification("import_bundle_to_project"); +} + +void exportComponent(const SelectionContext &selectionContext) +{ + ModelNode node = selectionContext.currentSingleSelectedNode(); + selectionContext.view()->emitCustomNotification("export_item_as_bundle", {node}); +} + void goImplementation(const SelectionContext &selectionState) { addSignalHandlerOrGotoImplementation(selectionState, false); diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h index 9e649371c98..fb8ff5826d5 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h @@ -97,6 +97,8 @@ void removeLayout(const SelectionContext &selectionContext); void removePositioner(const SelectionContext &selectionContext); void moveToComponent(const SelectionContext &selectionContext); void add3DAssetToContentLibrary(const SelectionContext &selectionContext); +void importComponent(const SelectionContext &selectionContext); +void exportComponent(const SelectionContext &selectionContext); PropertyName getIndexPropertyName(const ModelNode &modelNode); void addItemToStackedContainer(const SelectionContext &selectionContext); void increaseIndexOfStackedContainer(const SelectionContext &selectionContext); diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dwidget.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dwidget.cpp index 82602fe79b6..ad9b8d6b125 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dwidget.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dwidget.cpp @@ -368,13 +368,13 @@ void Edit3DWidget::createContextMenu() m_importBundleAction = m_contextMenu->addAction( contextIcon(DesignerIcons::CreateIcon), // TODO: placeholder icon - tr("Import Components"), [&] { + tr("Import Component"), [&] { view()->emitCustomNotification("import_bundle_to_project"); // To ContentLibrary }); m_exportBundleAction = m_contextMenu->addAction( contextIcon(DesignerIcons::CreateIcon), // TODO: placeholder icon - tr("Export Components"), [&] { + tr("Export Component"), [&] { view()->emitCustomNotification("export_item_as_bundle", {m_contextMenuTarget}); // To ContentLibrary });