From aa7d2a2212e0be921c05888ea8fcc942db1c20a6 Mon Sep 17 00:00:00 2001 From: spinell-adsk Date: Thu, 28 Jan 2021 15:31:41 -0500 Subject: [PATCH] MAYA-107607 - As a user, I'd like to not save a layer when a sublayer is anonymous - Avoid saving a layer that contains sub anonymous layer (Add warning dialog box) --- lib/usd/ui/layerEditor/layerTreeItem.cpp | 27 +++++++++++++++++++++++ lib/usd/ui/layerEditor/layerTreeModel.cpp | 10 +++++---- lib/usd/ui/layerEditor/layerTreeModel.h | 8 +++---- lib/usd/ui/layerEditor/stringResources.h | 2 ++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/usd/ui/layerEditor/layerTreeItem.cpp b/lib/usd/ui/layerEditor/layerTreeItem.cpp index 28e9c8efa5..c0f4116555 100644 --- a/lib/usd/ui/layerEditor/layerTreeItem.cpp +++ b/lib/usd/ui/layerEditor/layerTreeItem.cpp @@ -233,6 +233,33 @@ void LayerTreeItem::saveEdits() { bool shouldSaveEdits = true; + // if the current layer contains anonymous layer(s), + // display a warning and abort the saving operation. + LayerItemVector anonymLayerItems = parentModel()->getAllAnonymousLayers(this); + if (!anonymLayerItems.empty()) { + const MString titleFormat + = StringResources::getAsMString(StringResources::kSaveLayerWarnTitle); + const MString msgFormat + = StringResources::getAsMString(StringResources::kSaveLayerSaveNestedAnonymLayer); + + MString title; + title.format(titleFormat, displayName().c_str()); + + MString nbAnonymLayer; + nbAnonymLayer += static_cast(anonymLayerItems.size()); + + MString msg; + msg.format(msgFormat, displayName().c_str(), nbAnonymLayer); + + QStringList anonymLayerNames; + for (auto item : anonymLayerItems) { + anonymLayerNames.append(item->displayName().c_str()); + } + + warningDialog(MQtUtil::toQString(title), MQtUtil::toQString(msg), &anonymLayerNames); + return; + } + // the layer is already saved on disk. // ask the user a confirmation before overwrite it. if (!isAnonymous()) { diff --git a/lib/usd/ui/layerEditor/layerTreeModel.cpp b/lib/usd/ui/layerEditor/layerTreeModel.cpp index 53dc2c3aff..e87a02da8f 100644 --- a/lib/usd/ui/layerEditor/layerTreeModel.cpp +++ b/lib/usd/ui/layerEditor/layerTreeModel.cpp @@ -381,11 +381,12 @@ void layerItemVectorRecurs( } } -LayerItemVector LayerTreeModel::getAllItems(ConditionFunc filter) const +LayerItemVector +LayerTreeModel::getAllItems(ConditionFunc filter, const LayerTreeItem* item /* = nullptr*/) const { LayerItemVector result; - auto root = invisibleRootItem(); + auto root = item ? item : invisibleRootItem(); for (int i = 0, count = root->rowCount(); i < count; i++) { auto child = dynamic_cast(root->child(i)); layerItemVectorRecurs(child, filter, result); @@ -399,11 +400,12 @@ LayerItemVector LayerTreeModel::getAllNeedsSavingLayers() const return getAllItems(filter); } -LayerItemVector LayerTreeModel::getAllAnonymousLayers() const +LayerItemVector +LayerTreeModel::getAllAnonymousLayers(const LayerTreeItem* item /* = nullptr*/) const { auto filter = [](const LayerTreeItem* item) { return item->isAnonymous() && !item->isSessionLayer(); }; - return getAllItems(filter); + return getAllItems(filter, item); } void LayerTreeModel::saveStage(QWidget* in_parent) diff --git a/lib/usd/ui/layerEditor/layerTreeModel.h b/lib/usd/ui/layerEditor/layerTreeModel.h index e53081afb3..5b7e354a97 100644 --- a/lib/usd/ui/layerEditor/layerTreeModel.h +++ b/lib/usd/ui/layerEditor/layerTreeModel.h @@ -63,13 +63,13 @@ class LayerTreeModel LayerTreeItem* layerItemFromIndex(const QModelIndex& index) const; // gets everything recursivly as an array : used to simplify iteration typedef bool (*ConditionFunc)(const LayerTreeItem*); - LayerItemVector getAllItems(ConditionFunc filter = [](const LayerTreeItem*) { - return true; - }) const; + LayerItemVector getAllItems( + ConditionFunc filter = [](const LayerTreeItem*) { return true; }, + const LayerTreeItem* item = nullptr) const; // get all the layers that need saving LayerItemVector getAllNeedsSavingLayers() const; // get all anonymous layers except the session layer - LayerItemVector getAllAnonymousLayers() const; + LayerItemVector getAllAnonymousLayers(const LayerTreeItem* item = nullptr) const; // get an appropriate name for a new anonymous layer std::string findNameForNewAnonymousLayer() const; diff --git a/lib/usd/ui/layerEditor/stringResources.h b/lib/usd/ui/layerEditor/stringResources.h index 997e30d0db..0c29ceb81d 100644 --- a/lib/usd/ui/layerEditor/stringResources.h +++ b/lib/usd/ui/layerEditor/stringResources.h @@ -79,6 +79,8 @@ const auto kSave { create("kSave", "Save") }; const auto kSaveAll { create("kSaveAll", "Save All") }; const auto kSaveAllEditsInLayerStack { create("kSaveAllEditsInLayerStack", "Save all edits in the Layer Stack")}; const auto kSaveLayer { create("kSaveLayer", "Save Layer") }; +const auto kSaveLayerSaveNestedAnonymLayer { create("kSaveLayerSaveNestedAnonymLayer", + "To save ^1s, you must save your ^2s anonymous layer(s) that are nested under it.") }; const auto kSaveLayerWarnTitle { create("kSaveLayerWarnTitle", "Save ^1s") }; const auto kSaveLayerWarnMsg { create("kSaveLayerWarnMsg", "Saving edits to ^1s will overwrite your file.") }; const auto kSaveStage { create("kSaveStage", "Save Stage") };