-
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
Changes from 3 commits
b574c69
897701b
46ccf94
b3286b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
|
||
std::string temp; | ||
SdfLayerHandleVector allLayers = stage->GetLayerStack(true); | ||
for (auto layer : allLayers) { | ||
if (layer->IsDirty()) { | ||
atLeastOneDirty = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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). |
||
} | ||
} | ||
} | ||
} | ||
|
||
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 |
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 |
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.
This variable is unused.