More work on handlers
This commit is contained in:
@@ -5,10 +5,6 @@
|
||||
#include "MCPFetcher.h"
|
||||
#include "MCPUtils.h"
|
||||
#include "EdGraph/EdGraphNode.h"
|
||||
#include "K2Node_Event.h"
|
||||
#include "K2Node_CustomEvent.h"
|
||||
#include "K2Node_FunctionEntry.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "GraphNode_Delete.generated.h"
|
||||
|
||||
|
||||
@@ -27,8 +23,8 @@ public:
|
||||
|
||||
virtual FString GetDescription() const override
|
||||
{
|
||||
return TEXT("Delete a node from a Blueprint graph. "
|
||||
"Cannot delete entry nodes (FunctionEntry, Event, CustomEvent).");
|
||||
return TEXT("Delete a node from a graph. "
|
||||
"Cannot delete undeletable nodes (entry points, root nodes, etc).");
|
||||
}
|
||||
|
||||
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) override
|
||||
@@ -38,42 +34,21 @@ public:
|
||||
if (!FoundNode) return;
|
||||
|
||||
UEdGraph* Graph = FoundNode->GetGraph();
|
||||
UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForNodeChecked(FoundNode);
|
||||
|
||||
// Protect root/entry nodes — deleting these leaves the graph in an invalid
|
||||
// state with no root node, causing compiler errors that can't be fixed
|
||||
// without recreating the entire function/event.
|
||||
MCPErrorCallback Error(Result);
|
||||
FString NodeTitle = MCPUtils::FormatName(FoundNode);
|
||||
FString GraphName = MCPUtils::FormatName(Graph);
|
||||
|
||||
if (Cast<UK2Node_FunctionEntry>(FoundNode))
|
||||
if (!FoundNode->CanUserDeleteNode())
|
||||
{
|
||||
MCPErrorCallback Error(Result);
|
||||
return Error.SetError(FString::Printf(
|
||||
TEXT("Cannot delete FunctionEntry node '%s' in graph '%s'. ")
|
||||
TEXT("This is the root node of the function — removing it would leave an empty, uncompilable graph. ")
|
||||
TEXT("To remove the entire function, delete it from the Blueprint editor."),
|
||||
*NodeTitle, *GraphName));
|
||||
}
|
||||
if (Cast<UK2Node_Event>(FoundNode))
|
||||
{
|
||||
return Error.SetError(FString::Printf(
|
||||
TEXT("Cannot delete event entry node '%s' in graph '%s'. ")
|
||||
TEXT("This is the root node of the event handler — removing it would leave an empty, uncompilable graph."),
|
||||
*NodeTitle, *GraphName));
|
||||
}
|
||||
if (Cast<UK2Node_CustomEvent>(FoundNode))
|
||||
{
|
||||
return Error.SetError(FString::Printf(
|
||||
TEXT("Cannot delete CustomEvent entry node '%s' in graph '%s'. ")
|
||||
TEXT("This is the root node of the custom event — removing it would leave an empty, uncompilable graph."),
|
||||
TEXT("Cannot delete node '%s' in graph '%s' — it is not deletable."),
|
||||
*NodeTitle, *GraphName));
|
||||
}
|
||||
|
||||
F.PreEdit();
|
||||
FoundNode->BreakAllNodeLinks();
|
||||
Graph->RemoveNode(FoundNode);
|
||||
|
||||
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(BP);
|
||||
F.PostEdit();
|
||||
|
||||
Result.Appendf(TEXT("Deleted node '%s' from graph '%s'.\n"), *NodeTitle, *GraphName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user