Don't store the editor in the WingFetcher.
This commit is contained in:
@@ -53,8 +53,13 @@ public:
|
|||||||
{
|
{
|
||||||
// Use the material editor's DeleteNodes to properly remove
|
// Use the material editor's DeleteNodes to properly remove
|
||||||
// both the graph node and the underlying material expression.
|
// both the graph node and the underlying material expression.
|
||||||
IMaterialEditor* MatEditor = F.CastEditor<UMaterial, IMaterialEditor>();
|
UMaterial* Material = F.CastAsset<UMaterial>();
|
||||||
if (!MatEditor) return;
|
if (!Material) return;
|
||||||
|
|
||||||
|
IAssetEditorInstance* Editor = WingUtils::CheckOpenEditorForAsset(Material, WingOut::Stdout);
|
||||||
|
if (!Editor) return;
|
||||||
|
|
||||||
|
IMaterialEditor* MatEditor = static_cast<IMaterialEditor*>(Editor);
|
||||||
MatEditor->DeleteNodes({FoundNode});
|
MatEditor->DeleteNodes({FoundNode});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include "WidgetBlueprint.h"
|
#include "WidgetBlueprint.h"
|
||||||
#include "Blueprint/WidgetTree.h"
|
#include "Blueprint/WidgetTree.h"
|
||||||
#include "Components/Widget.h"
|
#include "Components/Widget.h"
|
||||||
#include "Subsystems/AssetEditorSubsystem.h"
|
|
||||||
#include "WingServer.h"
|
#include "WingServer.h"
|
||||||
#include "WingManual.h"
|
#include "WingManual.h"
|
||||||
|
|
||||||
@@ -54,7 +53,6 @@ WingFetcher& WingFetcher::SetError()
|
|||||||
Obj.Reset();
|
Obj.Reset();
|
||||||
ResultPin = nullptr;
|
ResultPin = nullptr;
|
||||||
OriginalAsset.Reset();
|
OriginalAsset.Reset();
|
||||||
Editor = nullptr;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,26 +154,20 @@ WingFetcher& WingFetcher::Asset(const FString& PackagePath)
|
|||||||
|
|
||||||
OriginalAsset.Reset(Obj.Get());
|
OriginalAsset.Reset(Obj.Get());
|
||||||
|
|
||||||
// Open the editor for this asset (or bring it to front if already open).
|
// If this is a material, open the editor and get the transient copy.
|
||||||
UAssetEditorSubsystem* Sub = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
|
// If it's not a material, try to open the editor, but it's okay if we can't.
|
||||||
if (!Sub || !Sub->OpenEditorForAsset(Obj.Get()))
|
|
||||||
{
|
|
||||||
Errors.Printf(TEXT("ERROR: Could not open editor for '%s'\n"), *PackagePath);
|
|
||||||
return SetError();
|
|
||||||
}
|
|
||||||
Editor = Sub->FindEditorForAsset(OriginalAsset.Get(), false);
|
|
||||||
if (!Editor)
|
|
||||||
{
|
|
||||||
Errors.Printf(TEXT("ERROR: Could not find editor instance for '%s'\n"), *PackagePath);
|
|
||||||
return SetError();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this is a material, use the editor's transient copy.
|
|
||||||
if (UMaterial* Mat = ::Cast<UMaterial>(Obj.Get()))
|
if (UMaterial* Mat = ::Cast<UMaterial>(Obj.Get()))
|
||||||
{
|
{
|
||||||
|
IAssetEditorInstance* Editor = WingUtils::CheckOpenEditorForAsset(OriginalAsset.Get(), Errors);
|
||||||
|
if (!Editor) return SetError();
|
||||||
IMaterialEditor *MatEditor = static_cast<IMaterialEditor*>(Editor);
|
IMaterialEditor *MatEditor = static_cast<IMaterialEditor*>(Editor);
|
||||||
SetObj(MatEditor->GetMaterialInterface()->GetBaseMaterial());
|
SetObj(MatEditor->GetMaterialInterface()->GetBaseMaterial());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WingUtils::CheckOpenEditorForAsset(OriginalAsset.Get(), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -490,6 +490,30 @@ UObject *WingUtils::GetGeneratedCDO(UBlueprint *BP)
|
|||||||
return BP->GeneratedClass->GetDefaultObject();
|
return BP->GeneratedClass->GetDefaultObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Editor helpers
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
IAssetEditorInstance* WingUtils::CheckOpenEditorForAsset(UObject* Asset, WingOut Errors)
|
||||||
|
{
|
||||||
|
const FString AssetPath = Asset ? Asset->GetPathName() : TEXT("null");
|
||||||
|
UAssetEditorSubsystem* Sub = GEditor ? GEditor->GetEditorSubsystem<UAssetEditorSubsystem>() : nullptr;
|
||||||
|
if (!Sub || !Sub->OpenEditorForAsset(Asset))
|
||||||
|
{
|
||||||
|
Errors.Printf(TEXT("ERROR: Could not open editor for '%s'\n"), *AssetPath);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
IAssetEditorInstance* Editor = Sub->FindEditorForAsset(Asset, false);
|
||||||
|
if (!Editor)
|
||||||
|
{
|
||||||
|
Errors.Printf(TEXT("ERROR: Could not find editor instance for '%s'\n"), *AssetPath);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Editor;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Material helpers
|
// Material helpers
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|||||||
@@ -96,18 +96,6 @@ public:
|
|||||||
return ::Cast<T>(OriginalAsset.Get());
|
return ::Cast<T>(OriginalAsset.Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// When an asset is loaded, an editor is automatically
|
|
||||||
// opened. Get the editor. You must specify the type
|
|
||||||
// that you expect the asset to be, and the type to cast
|
|
||||||
// the editor to. Does not generate errors.
|
|
||||||
//
|
|
||||||
template<class AssetType, class EditorType>
|
|
||||||
EditorType* CastEditor()
|
|
||||||
{
|
|
||||||
if (!CheckAssetIsA(AssetType::StaticClass())) return nullptr;
|
|
||||||
return static_cast<EditorType*>(Editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calling SkipNotify disables change notifications
|
// Calling SkipNotify disables change notifications
|
||||||
// for objects visited by this fetcher. Useful for
|
// for objects visited by this fetcher. Useful for
|
||||||
// read-only operations that don't modify anything.
|
// read-only operations that don't modify anything.
|
||||||
@@ -131,9 +119,8 @@ private:
|
|||||||
TStrongObjectPtr<UObject> Obj;
|
TStrongObjectPtr<UObject> Obj;
|
||||||
UEdGraphPin* ResultPin = nullptr;
|
UEdGraphPin* ResultPin = nullptr;
|
||||||
|
|
||||||
// The Starting Asset and the Editor we Opened.
|
// The Starting Asset.
|
||||||
TStrongObjectPtr<UObject> OriginalAsset;
|
TStrongObjectPtr<UObject> OriginalAsset;
|
||||||
IAssetEditorInstance* Editor = nullptr;
|
|
||||||
|
|
||||||
// True if an error has occurred.
|
// True if an error has occurred.
|
||||||
bool bError = false;
|
bool bError = false;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class UAnimStateTransitionNode;
|
|||||||
class IPropertyHandle;
|
class IPropertyHandle;
|
||||||
class UScriptStruct;
|
class UScriptStruct;
|
||||||
class UEnum;
|
class UEnum;
|
||||||
|
class IAssetEditorInstance;
|
||||||
struct FBPInterfaceDescription;
|
struct FBPInterfaceDescription;
|
||||||
struct FWingProperty;
|
struct FWingProperty;
|
||||||
class IPropertyHandle;
|
class IPropertyHandle;
|
||||||
@@ -247,6 +248,9 @@ public:
|
|||||||
static TArray<UBlueprint*> GetAncestorBlueprints(UBlueprint *BP, bool OldestFirst = false);
|
static TArray<UBlueprint*> GetAncestorBlueprints(UBlueprint *BP, bool OldestFirst = false);
|
||||||
static UObject *GetGeneratedCDO(UBlueprint *BP);
|
static UObject *GetGeneratedCDO(UBlueprint *BP);
|
||||||
|
|
||||||
|
// ----- Editor helpers -----
|
||||||
|
static IAssetEditorInstance* CheckOpenEditorForAsset(UObject* Asset, WingOut Errors);
|
||||||
|
|
||||||
// ----- Material helpers -----
|
// ----- Material helpers -----
|
||||||
static void EnsureMaterialGraph(UMaterial* Material);
|
static void EnsureMaterialGraph(UMaterial* Material);
|
||||||
|
|
||||||
@@ -277,4 +281,3 @@ public:
|
|||||||
static bool CheckCanRename(UEdGraphNode* Node, const FString &Name, WingOut Errors);
|
static bool CheckCanRename(UEdGraphNode* Node, const FString &Name, WingOut Errors);
|
||||||
static bool CheckNewObjectNotNull(UObject *Obj, const TCHAR *Kind, WingOut Errors);
|
static bool CheckNewObjectNotNull(UObject *Obj, const TCHAR *Kind, WingOut Errors);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user