2020-09-24 00:43:27 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "EditorUtilityTask.h"
|
|
|
|
|
#include "EditorUtilitySubsystem.h"
|
|
|
|
|
#include "Editor.h"
|
|
|
|
|
#include "Framework/Notifications/NotificationManager.h"
|
|
|
|
|
#include "Widgets/Notifications/SNotificationList.h"
|
|
|
|
|
#include "EditorUtilityCommon.h"
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "UEditorUtilityTask"
|
|
|
|
|
|
|
|
|
|
UEditorUtilityTask::UEditorUtilityTask()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UEditorUtilityTask::Run()
|
|
|
|
|
{
|
|
|
|
|
UEditorUtilitySubsystem* EditorUtilitySubsystem = GEditor->GetEditorSubsystem<UEditorUtilitySubsystem>();
|
2021-05-12 18:10:03 -04:00
|
|
|
EditorUtilitySubsystem->RegisterAndExecuteTask(this, nullptr);
|
2020-09-24 00:43:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UWorld* UEditorUtilityTask::GetWorld() const
|
|
|
|
|
{
|
|
|
|
|
if (HasAllFlags(RF_ClassDefaultObject))
|
|
|
|
|
{
|
|
|
|
|
// If we are a CDO, we must return nullptr instead of calling Outer->GetWorld() to fool UObject::ImplementsGetWorld.
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GEditor ? GEditor->GetEditorWorldContext(false).World() : nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UEditorUtilityTask::StartExecutingTask()
|
|
|
|
|
{
|
2021-01-21 16:22:06 -04:00
|
|
|
Cached_GIsRunningUnattendedScript = GIsRunningUnattendedScript;
|
|
|
|
|
GIsRunningUnattendedScript = true;
|
|
|
|
|
|
2020-09-24 00:43:27 -04:00
|
|
|
CreateNotification();
|
|
|
|
|
|
|
|
|
|
BeginExecution();
|
|
|
|
|
ReceiveBeginExecution();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UEditorUtilityTask::FinishExecutingTask()
|
|
|
|
|
{
|
2021-05-12 18:10:03 -04:00
|
|
|
SetTaskNotificationText(LOCTEXT("TaskComplete", "Complete"));
|
|
|
|
|
|
2020-09-24 00:43:27 -04:00
|
|
|
if (ensure(MyTaskManager))
|
|
|
|
|
{
|
|
|
|
|
MyTaskManager->RemoveTaskFromActiveList(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TaskNotification.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TaskNotification->SetComplete(true);
|
|
|
|
|
TaskNotification.Reset();
|
|
|
|
|
}
|
2021-01-21 16:22:06 -04:00
|
|
|
|
|
|
|
|
GIsRunningUnattendedScript = Cached_GIsRunningUnattendedScript;
|
2021-05-12 18:10:03 -04:00
|
|
|
|
|
|
|
|
// Notify anyone who needs to know that we're done.
|
|
|
|
|
OnFinished.Broadcast(this);
|
2020-09-24 00:43:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UEditorUtilityTask::CreateNotification()
|
|
|
|
|
{
|
|
|
|
|
FAsyncTaskNotificationConfig NotificationConfig;
|
|
|
|
|
NotificationConfig.TitleText = FText::Format(LOCTEXT("NotificationEditorUtilityTaskTitle", "Task {0}"), GetClass()->GetDisplayNameText());
|
|
|
|
|
NotificationConfig.ProgressText = LOCTEXT("Running", "Running");
|
|
|
|
|
NotificationConfig.bCanCancel = true;
|
|
|
|
|
TaskNotification = MakeUnique<FAsyncTaskNotification>(NotificationConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UEditorUtilityTask::RequestCancel()
|
|
|
|
|
{
|
2021-05-12 18:10:03 -04:00
|
|
|
if (!bCancelRequested)
|
|
|
|
|
{
|
|
|
|
|
bCancelRequested = true;
|
|
|
|
|
|
|
|
|
|
SetTaskNotificationText(LOCTEXT("TaskCanceling", "Canceling"));
|
|
|
|
|
|
|
|
|
|
CancelRequested();
|
|
|
|
|
ReceiveCancelRequested();
|
|
|
|
|
|
|
|
|
|
FinishExecutingTask();
|
|
|
|
|
}
|
2020-09-24 00:43:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UEditorUtilityTask::WasCancelRequested() const
|
|
|
|
|
{
|
|
|
|
|
if (TaskNotification.IsValid())
|
|
|
|
|
{
|
|
|
|
|
if (TaskNotification->GetPromptAction() == EAsyncTaskNotificationPromptAction::Cancel)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bCancelRequested;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UEditorUtilityTask::SetTaskNotificationText(const FText& Text)
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogEditorUtilityBlueprint, Log, TEXT("%s: %s"), *GetPathNameSafe(this), *Text.ToString());
|
|
|
|
|
|
|
|
|
|
if (TaskNotification.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TaskNotification->SetProgressText(Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|