Files
UnrealEngineUWP/Engine/Source/Editor/UnrealEd/Private/ScopedTransaction.cpp
Francis Hurteau b0b7099b27 Do not capture objects to transaction when they are marked with any async flags
Do not allow new transaction to be created while in the midst of loading packages or post loading objects
Temporarily shelve an opened transaction while ticking async loading in the main thread and consider this scope as "loading packages"

#rb Jamie.Dale

[CL 15397637 by Francis Hurteau in ue5-main branch]
2021-02-12 10:56:07 -04:00

58 lines
1.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "ScopedTransaction.h"
#include "Framework/Application/SlateApplication.h"
#include "Editor.h"
FScopedTransaction::FScopedTransaction(const FText& SessionName, const bool bShouldActuallyTransact )
{
Construct( TEXT(""), SessionName, NULL, bShouldActuallyTransact);
}
FScopedTransaction::FScopedTransaction(const TCHAR* TransactionContext, const FText& SessionName, UObject* PrimaryObject, const bool bShouldActuallyTransact)
{
Construct( TransactionContext, SessionName, PrimaryObject, bShouldActuallyTransact);
}
void FScopedTransaction::Construct (const TCHAR* TransactionContext, const FText& SessionName, UObject* PrimaryObject, const bool bShouldActuallyTransact)
{
if( bShouldActuallyTransact && GEditor && GEditor->CanTransact() && ensure(!GIsTransacting))
{
Index = GEditor->BeginTransaction( TransactionContext, SessionName, PrimaryObject );
check( IsOutstanding() );
}
else
{
Index = -1;
}
}
FScopedTransaction::~FScopedTransaction()
{
if ( IsOutstanding() )
{
GEditor->EndTransaction();
}
}
/**
* Cancels the transaction. Reentrant.
*/
void FScopedTransaction::Cancel()
{
if ( IsOutstanding() )
{
GEditor->CancelTransaction( Index );
Index = -1;
}
}
/**
* @return true if the transaction is still outstanding (that is, has not been cancelled).
*/
bool FScopedTransaction::IsOutstanding() const
{
return Index >= 0;
}