85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "WingServer.h"
|
|
#include "WingHandler.h"
|
|
#include "WingFetcher.h"
|
|
#include "WingUtils.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "EdGraph/EdGraph.h"
|
|
#include "Kismet2/BlueprintEditorUtils.h"
|
|
#include "BlueprintGraph_Rename.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UWing_BlueprintGraph_Rename : public UObject, public IWingHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Path to the graph, e.g. /Game/Foo,graph:MyFunction"))
|
|
FString Graph;
|
|
|
|
UPROPERTY(meta=(Description="New name for the graph"))
|
|
FString NewName;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Rename a function or macro graph in a Blueprint. Cannot rename EventGraph pages.");
|
|
}
|
|
|
|
virtual void Handle() override
|
|
{
|
|
WingFetcher F;
|
|
UEdGraph* TargetGraph = F.Walk(Graph).Cast<UEdGraph>();
|
|
if (!TargetGraph) return;
|
|
|
|
UBlueprint* BP = Cast<UBlueprint>(TargetGraph->GetOuter());
|
|
if (!BP)
|
|
{
|
|
UWingServer::Printf(TEXT("Error: Graph '%s' is not owned by a Blueprint.\n"), *Graph);
|
|
return;
|
|
}
|
|
|
|
// Check if it's an UbergraphPage -- disallow rename
|
|
if (BP->UbergraphPages.Contains(TargetGraph))
|
|
{
|
|
UWingServer::Printf(TEXT("Error: Cannot rename UbergraphPage '%s'. EventGraph pages cannot be renamed.\n"),
|
|
*WingUtils::FormatName(TargetGraph));
|
|
return;
|
|
}
|
|
|
|
// Verify it's a function or macro graph
|
|
bool bIsFunction = BP->FunctionGraphs.Contains(TargetGraph);
|
|
bool bIsMacro = BP->MacroGraphs.Contains(TargetGraph);
|
|
if (!bIsFunction && !bIsMacro)
|
|
{
|
|
UWingServer::Printf(TEXT("Error: Graph '%s' is not a function or macro graph.\n"),
|
|
*WingUtils::FormatName(TargetGraph));
|
|
return;
|
|
}
|
|
|
|
// Check for name collision
|
|
for (UEdGraph* Existing : WingUtils::AllGraphsNamed(BP, NewName))
|
|
{
|
|
if (Existing != TargetGraph)
|
|
{
|
|
UWingServer::Printf(TEXT("Error: A graph named '%s' already exists in '%s'.\n"),
|
|
*NewName, *WingUtils::FormatName(BP));
|
|
return;
|
|
}
|
|
}
|
|
|
|
FBlueprintEditorUtils::RenameGraph(TargetGraph, NewName);
|
|
WingUtils::SaveBlueprintPackage(BP);
|
|
|
|
UWingServer::Printf(TEXT("Renamed to %s %s\n"),
|
|
bIsFunction ? TEXT("function") : TEXT("macro"),
|
|
*WingUtils::FormatName(TargetGraph));
|
|
}
|
|
};
|