Call InitAssetEditor of FAssetEditorToolkit in editor class and set parameter bCreateDefaultStandaloneMenu true.
virtual void InitAssetEditor(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost>& InitToolkitHost, const FName AppIdentifier, const TSharedRef<FTabManager::FLayout>& StandaloneDefaultLayout, const bool bCreateDefaultStandaloneMenu, const bool bCreateDefaultToolbar, UObject* ObjectToEdit, const bool bInIsToolbarFocusable = false, const bool bInUseSmallToolbarIcons = false);
Call AddMenuExtender of FAssetEditorToolkit to extend menu item.
For example:
void FBehaviorTreeEditor::ExtendMenu()
{
struct Local
{
static void FillEditMenu(FMenuBuilder& MenuBuilder)
{
MenuBuilder.BeginSection("EditSearch", LOCTEXT("EditMenu_SearchHeading", "Search"));
{
MenuBuilder.AddMenuEntry(FBTCommonCommands::Get().SearchBT);
}
MenuBuilder.EndSection();
}
};
TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender);
// Extend the Edit menu
MenuExtender->AddMenuExtension(
"EditHistory",
EExtensionHook::After,
GetToolkitCommands(),
FMenuExtensionDelegate::CreateStatic(&Local::FillEditMenu));
AddMenuExtender(MenuExtender);
}
The example add a menu item to Edit.
Call RegisterTabSpawners of FAssetEditorToolkit to register toolbar tab, so you should call this function in your editor class (subclass of FAssetEditorToolkit).
void FAssetEditorToolkit::RegisterTabSpawners(const TSharedRef<class FTabManager>& InTabManager)
{
const auto& LocalCategories = InTabManager->GetLocalWorkspaceMenuRoot()->GetChildItems();
TSharedRef<FWorkspaceItem> ToolbarSpawnerCategory = LocalCategories.Num() > 0 ? LocalCategories[0] : InTabManager->GetLocalWorkspaceMenuRoot();
InTabManager->RegisterTabSpawner( ToolbarTabId, FOnSpawnTab::CreateSP(this, &FAssetEditorToolkit::SpawnTab_Toolbar) )
.SetDisplayName( LOCTEXT("ToolbarTab", "Toolbar") )
.SetGroup( ToolbarSpawnerCategory )
.SetIcon( FSlateIcon(FEditorStyle::GetStyleSetName(), "Toolbar.Icon") );
}
Call InitAssetEditor in editor class and set parameter bCreateDefaultToolbar to true to spawn default toolbar, including save and browser button.
Call AddToolbarExtender to extend toolbar.
void FTestEditorToolbar::AddTestToolbar(TSharedPtr<FExtender> Extender)
{
check(TestEditor.IsValid());
TSharedPtr<FTestEditor> TestEditorPtr = TestEditor.Pin();
TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
ToolbarExtender->AddToolBarExtension("Asset", EExtensionHook::After, TestEditorPtr->GetToolkitCommands(), FToolBarExtensionDelegate::CreateSP(this, &FTestEditorToolbar::FillTestToolbar));
TestEditorPtr->AddToolbarExtender(ToolbarExtender);
}
void FTestEditorToolbar::FillTestToolbar(FToolBarBuilder& ToolbarBuilder)
{
check(TestEditor.IsValid());
TSharedPtr<FTestEditor> TestEditorPtr = TestEditor.Pin();
ToolbarBuilder.BeginSection("ExtendToolbarItem");
{
const FText NewNodeLabel = LOCTEXT("NewNode_Label", "New");
const FText NewNodeTooltip = LOCTEXT("NewNode_ToolTip", "Create a new node");
const FSlateIcon NewNodeIcon = FSlateIcon(TEXT("EditorStyle"), "SessionConsole.Clear");
ToolbarBuilder.AddToolBarButton(
FUIAction(
FExecuteAction::CreateSP(TestEditorPtr.Get(), &FTestEditor::CreateNewNode),
FCanExecuteAction::CreateSP(TestEditorPtr.Get(), &FTestEditor::CanCreateNewNode),
FIsActionChecked()
),
NAME_None,
NewNodeLabel,
NewNodeTooltip,
NewNodeIcon
);
}
ToolbarBuilder.EndSection();
}
FExecuteAction::CreateSP to create click action.