-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAYA-106722 Maya check callback to see if there are any unsaved edits #934
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b574c69
MAYA-106722 Maya check callback to see if there are any unsaved USD e…
fowlertADSK 897701b
MAYA-106780 added some required includes
fowlertADSK 46ccf94
MAYA-106780 Changed the wording based on new info from design
fowlertADSK b3286b8
MAYA-106780 remove unused variable, adding a break
fowlertADSK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// | ||
// Copyright 2020 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#include "sceneResetCheck.h" | ||
|
||
#include "ProxyShape.h" | ||
|
||
#include <pxr/pxr.h> | ||
#include <pxr/usd/usd/common.h> | ||
#include <pxr/usd/usd/stage.h> | ||
|
||
#include <maya/MFnDependencyNode.h> | ||
#include <maya/MGlobal.h> | ||
#include <maya/MItDependencyNodes.h> | ||
#include <maya/MMessage.h> | ||
#include <maya/MSceneMessage.h> | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace { | ||
MCallbackId _beforeNewCheckCallbackId = 0; | ||
MCallbackId _beforeOpenCheckCallbackId = 0; | ||
|
||
const char* ignoreDirtyLayersConfirmScript = R"( | ||
global proc string MayaUsdIgnoreDirtyLayersConfirm() | ||
{ | ||
return `confirmDialog -title "Discard USD Edits" | ||
-message "Are you sure you want to exit this session?\n\nAll edits on your USD layer(s) will be discarded." | ||
-button "Yes" -button "No" -defaultButton "No" -icon "warning" | ||
-cancelButton "No" -dismissString "No"`; | ||
|
||
} | ||
MayaUsdIgnoreDirtyLayersConfirm(); | ||
)"; | ||
|
||
static void _OnMayaNewOrOpenSceneCheckCallback(bool* retCode, void*) | ||
{ | ||
*retCode = true; | ||
|
||
bool atLeastOneDirty = false; | ||
|
||
MFnDependencyNode fn; | ||
MItDependencyNodes iter(MFn::kPluginDependNode); | ||
|
||
for (; !iter.isDone() && !atLeastOneDirty; iter.next()) { | ||
MObject mobj = iter.item(); | ||
fn.setObject(mobj); | ||
if (MayaUsd::ProxyShape::typeId == fn.typeId()) { | ||
MayaUsdProxyShapeBase* pShape = static_cast<MayaUsdProxyShapeBase*>(fn.userNode()); | ||
UsdStageRefPtr stage = pShape ? pShape->getUsdStage() : nullptr; | ||
if (!stage) { | ||
continue; | ||
} | ||
|
||
SdfLayerHandleVector allLayers = stage->GetLayerStack(true); | ||
for (auto layer : allLayers) { | ||
if (layer->IsDirty()) { | ||
atLeastOneDirty = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (atLeastOneDirty) { | ||
MString allowExit = MGlobal::executeCommandStringResult(ignoreDirtyLayersConfirmScript); | ||
if (MString("No") == allowExit) { | ||
*retCode = false; | ||
} | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
void SceneResetCheck::registerSceneResetCheckCallback() | ||
{ | ||
if (_beforeNewCheckCallbackId == 0) { | ||
_beforeNewCheckCallbackId = MSceneMessage::addCheckCallback( | ||
MSceneMessage::kBeforeNewCheck, _OnMayaNewOrOpenSceneCheckCallback); | ||
} | ||
|
||
if (_beforeOpenCheckCallbackId == 0) { | ||
_beforeOpenCheckCallbackId = MSceneMessage::addCheckCallback( | ||
MSceneMessage::kBeforeOpenCheck, _OnMayaNewOrOpenSceneCheckCallback); | ||
} | ||
} | ||
|
||
void SceneResetCheck::deregisterSceneResetCheckCallback() | ||
{ | ||
if (_beforeNewCheckCallbackId != 0) { | ||
MMessage::removeCallback(_beforeNewCheckCallbackId); | ||
_beforeNewCheckCallbackId = 0; | ||
} | ||
|
||
if (_beforeOpenCheckCallbackId != 0) { | ||
MMessage::removeCallback(_beforeOpenCheckCallbackId); | ||
_beforeOpenCheckCallbackId = 0; | ||
} | ||
} | ||
|
||
} // namespace MAYAUSD_NS_DEF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright 2020 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef ADSK_MAYA_SCENE_RESET_CHECK_H | ||
#define ADSK_MAYA_SCENE_RESET_CHECK_H | ||
|
||
#include "base/api.h" | ||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
class SceneResetCheck | ||
{ | ||
public: | ||
MAYAUSD_PLUGIN_PUBLIC | ||
static void registerSceneResetCheckCallback(); | ||
|
||
MAYAUSD_PLUGIN_PUBLIC | ||
static void deregisterSceneResetCheckCallback(); | ||
}; | ||
|
||
} // namespace MAYAUSD_NS_DEF | ||
|
||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not break here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The for loop will exit immediately, it checks atLeastOneDirty. I think I had originally been printing out some information while debugging something and just left it like this (but completely missed the temp variable you pointed out). I could remove the check in the for loop and add an extra line to "break" here if you prefer that style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it won't because you are in a for-loop (allLayers) inside of that other for-loop (that checks atLeastOneDirty).