2019-12-26 15:32:37 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-09-10 11:35:20 -04:00
|
|
|
|
|
|
|
|
#include "ToolMenuSection.h"
|
|
|
|
|
#include "ToolMenus.h"
|
|
|
|
|
#include "IToolMenusModule.h"
|
|
|
|
|
|
|
|
|
|
#include "Textures/SlateIcon.h"
|
|
|
|
|
#include "Framework/Commands/UIAction.h"
|
|
|
|
|
#include "Framework/MultiBox/MultiBox.h"
|
|
|
|
|
#include "Framework/MultiBox/MultiBoxBuilder.h"
|
|
|
|
|
#include "Internationalization/Internationalization.h"
|
|
|
|
|
|
2022-09-24 13:31:25 -04:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(ToolMenuSection)
|
|
|
|
|
|
2024-05-14 08:06:09 -04:00
|
|
|
FToolMenuSection::FToolMenuSection()
|
|
|
|
|
: ToolMenuSectionDynamic(nullptr)
|
Add Default, First, Middle, and Last alignment to ToolMenu sections
The new alignment support layers on top of the existing insertion-order support. Sections are added to the toolbar in groups where we first add all Left-aligned sections according to their insertion order, then all First-aligned sections, and then the Middle and Last-aligned sections. Note that this can break the specified insertion order if the user mixed alignments, but otherwise it's maintained.
The First and Default alignments are grouped together, with First-aligned sections appearing before Default-aligned sections. The result is a toolbar with visual empty space between the First-Default group, Middle group, and the Last group. A caveat here is that the Middle group won't necessarily appear perfectly centered on the toolbar because it's position depends on the sizes of the First-Default and Last groups.
#jira UE-212286
#rb brooke.hubert, ross.smith2
[CL 34230831 by sebastian arleryd in ue5-main branch]
2024-06-10 03:21:21 -04:00
|
|
|
, Alignment(EToolMenuSectionAlign::Default)
|
2024-05-14 08:06:09 -04:00
|
|
|
, bIsRegistering(false)
|
|
|
|
|
, bAddedDuringRegister(false)
|
2019-09-10 11:35:20 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FToolMenuSection::InitSection(const FName InName, const TAttribute< FText >& InLabel, const FToolMenuInsert InPosition)
|
|
|
|
|
{
|
|
|
|
|
Name = InName;
|
|
|
|
|
Label = InLabel;
|
|
|
|
|
InsertPosition = InPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FToolMenuSection::InitGeneratedSectionCopy(const FToolMenuSection& Source, FToolMenuContext& InContext)
|
|
|
|
|
{
|
|
|
|
|
Name = Source.Name;
|
|
|
|
|
Label = Source.Label;
|
|
|
|
|
InsertPosition = Source.InsertPosition;
|
|
|
|
|
Construct = Source.Construct;
|
|
|
|
|
Context = InContext;
|
Add Default, First, Middle, and Last alignment to ToolMenu sections
The new alignment support layers on top of the existing insertion-order support. Sections are added to the toolbar in groups where we first add all Left-aligned sections according to their insertion order, then all First-aligned sections, and then the Middle and Last-aligned sections. Note that this can break the specified insertion order if the user mixed alignments, but otherwise it's maintained.
The First and Default alignments are grouped together, with First-aligned sections appearing before Default-aligned sections. The result is a toolbar with visual empty space between the First-Default group, Middle group, and the Last group. A caveat here is that the Middle group won't necessarily appear perfectly centered on the toolbar because it's position depends on the sizes of the First-Default and Last groups.
#jira UE-212286
#rb brooke.hubert, ross.smith2
[CL 34230831 by sebastian arleryd in ue5-main branch]
2024-06-10 03:21:21 -04:00
|
|
|
Alignment = Source.Alignment;
|
2019-09-10 11:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-31 13:03:20 -04:00
|
|
|
bool FToolMenuSection::IsRegistering() const
|
|
|
|
|
{
|
|
|
|
|
return bIsRegistering;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 11:35:20 -04:00
|
|
|
FToolMenuEntry& FToolMenuSection::AddEntry(const FToolMenuEntry& Args)
|
|
|
|
|
{
|
|
|
|
|
if (Args.Name == NAME_None)
|
|
|
|
|
{
|
2019-10-31 13:03:20 -04:00
|
|
|
FToolMenuEntry& Result = Blocks.Add_GetRef(Args);
|
|
|
|
|
Result.bAddedDuringRegister = IsRegistering();
|
|
|
|
|
return Result;
|
2019-09-10 11:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 BlockIndex = IndexOfBlock(Args.Name);
|
|
|
|
|
if (BlockIndex != INDEX_NONE)
|
|
|
|
|
{
|
|
|
|
|
Blocks[BlockIndex] = Args;
|
2019-10-31 13:03:20 -04:00
|
|
|
Blocks[BlockIndex].bAddedDuringRegister = IsRegistering();
|
2019-09-10 11:35:20 -04:00
|
|
|
return Blocks[BlockIndex];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-31 13:03:20 -04:00
|
|
|
FToolMenuEntry& Result = Blocks.Add_GetRef(Args);
|
|
|
|
|
Result.bAddedDuringRegister = IsRegistering();
|
|
|
|
|
return Result;
|
2019-09-10 11:35:20 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddEntryObject(UToolMenuEntryScript* InObject)
|
|
|
|
|
{
|
|
|
|
|
// Avoid modifying objects that are saved as content on disk
|
|
|
|
|
UToolMenuEntryScript* DestObject = InObject;
|
|
|
|
|
if (DestObject->IsAsset())
|
|
|
|
|
{
|
|
|
|
|
DestObject = DuplicateObject<UToolMenuEntryScript>(InObject, UToolMenus::Get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry Args;
|
|
|
|
|
DestObject->ToMenuEntry(Args);
|
|
|
|
|
return AddEntry(Args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddMenuEntry(const FName InName, const TAttribute<FText>& InLabel, const TAttribute<FText>& InToolTip, const TAttribute<FSlateIcon>& InIcon, const FToolUIActionChoice& InAction, const EUserInterfaceActionType InUserInterfaceActionType, const FName InTutorialHighlightName)
|
|
|
|
|
{
|
|
|
|
|
return AddEntry(FToolMenuEntry::InitMenuEntry(InName, InLabel, InToolTip, InIcon, InAction, InUserInterfaceActionType, InTutorialHighlightName));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 15:40:24 -05:00
|
|
|
FToolMenuEntry& FToolMenuSection::AddMenuEntry(const TSharedPtr< const FUICommandInfo >& InCommand, const TAttribute<FText>& InLabelOverride, const TAttribute<FText>& InToolTipOverride, const TAttribute<FSlateIcon>& InIconOverride, const FName InTutorialHighlightName, const TOptional<FName> InNameOverride)
|
|
|
|
|
{
|
|
|
|
|
return AddEntry(FToolMenuEntry::InitMenuEntry(InCommand, InLabelOverride, InToolTipOverride, InIconOverride, InTutorialHighlightName, InNameOverride));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddMenuEntry(const FName InNameOverride, const TSharedPtr< const FUICommandInfo >& InCommand, const TAttribute<FText>& InLabelOverride, const TAttribute<FText>& InToolTipOverride, const TAttribute<FSlateIcon>& InIconOverride, const FName InTutorialHighlightName)
|
2019-09-10 11:35:20 -04:00
|
|
|
{
|
|
|
|
|
return AddEntry(FToolMenuEntry::InitMenuEntry(InCommand, InLabelOverride, InToolTipOverride, InIconOverride, InTutorialHighlightName, InNameOverride));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 03:55:33 -04:00
|
|
|
FToolMenuEntry& FToolMenuSection::AddMenuEntryWithCommandList(const TSharedPtr< const FUICommandInfo >& InCommand, const TSharedPtr< const FUICommandList >& InCommandList, const TAttribute<FText>& InLabelOverride, const TAttribute<FText>& InToolTipOverride, const TAttribute<FSlateIcon>& InIconOverride, const FName InTutorialHighlightName, const TOptional<FName> InNameOverride)
|
2019-09-10 11:35:20 -04:00
|
|
|
{
|
|
|
|
|
return AddEntry(FToolMenuEntry::InitMenuEntryWithCommandList(InCommand, InCommandList, InLabelOverride, InToolTipOverride, InIconOverride, InTutorialHighlightName, InNameOverride));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddDynamicEntry(const FName InName, const FNewToolMenuSectionDelegate& InConstruct)
|
|
|
|
|
{
|
2024-06-10 03:33:50 -04:00
|
|
|
return AddEntry(FToolMenuEntry::InitDynamicEntry(InName, InConstruct));
|
2019-09-10 11:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddDynamicEntry(const FName InName, const FNewToolMenuDelegateLegacy& InConstruct)
|
|
|
|
|
{
|
|
|
|
|
FToolMenuEntry& Entry = AddEntry(FToolMenuEntry(UToolMenus::Get()->CurrentOwner(), InName, EMultiBlockType::MenuEntry));
|
|
|
|
|
Entry.ConstructLegacy = InConstruct;
|
|
|
|
|
return Entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddMenuSeparator(const FName InName)
|
|
|
|
|
{
|
2020-04-08 10:05:51 -04:00
|
|
|
return AddSeparator(InName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddSeparator(const FName InName)
|
|
|
|
|
{
|
|
|
|
|
return AddEntry(FToolMenuEntry::InitSeparator(InName));
|
2019-09-10 11:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddSubMenu(const FName InName, const TAttribute<FText>& InLabel, const TAttribute<FText>& InToolTip, const FNewToolMenuChoice& InMakeMenu, const FToolUIActionChoice& InAction, const EUserInterfaceActionType InUserInterfaceActionType, bool bInOpenSubMenuOnClick, const TAttribute<FSlateIcon>& InIcon, const bool bInShouldCloseWindowAfterMenuSelection)
|
|
|
|
|
{
|
|
|
|
|
return AddEntry(FToolMenuEntry::InitSubMenu(InName, InLabel, InToolTip, InMakeMenu, InAction, InUserInterfaceActionType, bInOpenSubMenuOnClick, InIcon, bInShouldCloseWindowAfterMenuSelection));
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 23:36:03 -04:00
|
|
|
FToolMenuEntry& FToolMenuSection::AddSubMenu(const FName InName, const TAttribute<FText>& InLabel, const TAttribute<FText>& InToolTip, const FNewToolMenuChoice& InMakeMenu, bool bInOpenSubMenuOnClick, const TAttribute<FSlateIcon>& InIcon, const bool bShouldCloseWindowAfterMenuSelection, const FName InTutorialHighlightName)
|
2019-09-10 11:35:20 -04:00
|
|
|
{
|
2023-10-19 23:36:03 -04:00
|
|
|
return AddEntry(FToolMenuEntry::InitSubMenu(InName, InLabel, InToolTip, InMakeMenu, bInOpenSubMenuOnClick, InIcon, bShouldCloseWindowAfterMenuSelection, InTutorialHighlightName));
|
2019-09-10 11:35:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry& FToolMenuSection::AddSubMenu(const FName InName, const FToolUIActionChoice& InAction, const TSharedRef<SWidget>& InWidget, const FNewToolMenuChoice& InMakeMenu, bool bShouldCloseWindowAfterMenuSelection)
|
|
|
|
|
{
|
|
|
|
|
return AddEntry(FToolMenuEntry::InitSubMenu(InName, InAction, InWidget, InMakeMenu, bShouldCloseWindowAfterMenuSelection));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FToolMenuEntry* FToolMenuSection::FindEntry(const FName InName)
|
|
|
|
|
{
|
|
|
|
|
for (int32 i=0; i < Blocks.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (Blocks[i].Name == InName)
|
|
|
|
|
{
|
|
|
|
|
return &Blocks[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 20:41:42 -04:00
|
|
|
const FToolMenuEntry* FToolMenuSection::FindEntry(const FName InName) const
|
|
|
|
|
{
|
|
|
|
|
for (int32 i=0; i < Blocks.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (Blocks[i].Name == InName)
|
|
|
|
|
{
|
|
|
|
|
return &Blocks[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 11:35:20 -04:00
|
|
|
int32 FToolMenuSection::IndexOfBlock(const FName InName) const
|
|
|
|
|
{
|
|
|
|
|
for (int32 i=0; i < Blocks.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (Blocks[i].Name == InName)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return INDEX_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FToolMenuSection::IsNonLegacyDynamic() const
|
|
|
|
|
{
|
|
|
|
|
return ToolMenuSectionDynamic || Construct.NewToolMenuDelegate.IsBound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 FToolMenuSection::RemoveEntry(const FName InName)
|
|
|
|
|
{
|
|
|
|
|
return Blocks.RemoveAll([InName](const FToolMenuEntry& Block) { return Block.Name == InName; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 FToolMenuSection::RemoveEntriesByOwner(const FToolMenuOwner InOwner)
|
|
|
|
|
{
|
|
|
|
|
if (InOwner != FToolMenuOwner())
|
|
|
|
|
{
|
|
|
|
|
return Blocks.RemoveAll([InOwner](const FToolMenuEntry& Block) { return Block.Owner == InOwner; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 03:48:51 -04:00
|
|
|
// Note: This function is very similar to UToolMenu::FindInsertIndex.
|
2019-09-10 11:35:20 -04:00
|
|
|
int32 FToolMenuSection::FindBlockInsertIndex(const FToolMenuEntry& InBlock) const
|
|
|
|
|
{
|
|
|
|
|
const FToolMenuInsert InPosition = InBlock.InsertPosition;
|
|
|
|
|
|
2024-06-10 03:48:51 -04:00
|
|
|
// Insert a Default-positioned entry after all First and Default-positioned entries but before any Last-positioned
|
|
|
|
|
// entries.
|
2019-09-10 11:35:20 -04:00
|
|
|
if (InPosition.IsDefault())
|
|
|
|
|
{
|
2024-06-10 03:48:51 -04:00
|
|
|
for (int32 i = 0; i < Blocks.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (Blocks[i].InsertPosition.Position == EToolMenuInsertType::Last)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 11:35:20 -04:00
|
|
|
return Blocks.Num();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 03:48:51 -04:00
|
|
|
// Insert a First-positioned entry after any other First-positioned entries but before all Default and
|
|
|
|
|
// Last-positioned entries.
|
2019-09-10 11:35:20 -04:00
|
|
|
if (InPosition.Position == EToolMenuInsertType::First)
|
|
|
|
|
{
|
|
|
|
|
for (int32 i = 0; i < Blocks.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (Blocks[i].InsertPosition != InPosition)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Blocks.Num();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 03:48:51 -04:00
|
|
|
// Insert a Last-positioned entry after all other entries, include other Last-positioned entries.
|
|
|
|
|
if (InPosition.Position == EToolMenuInsertType::Last)
|
|
|
|
|
{
|
|
|
|
|
for (int32 i = Blocks.Num() - 1; i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
if (Blocks[i].InsertPosition.Position == InPosition.Position)
|
|
|
|
|
{
|
|
|
|
|
return i + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Blocks.Num();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 11:35:20 -04:00
|
|
|
int32 DestIndex = IndexOfBlock(InPosition.Name);
|
|
|
|
|
if (DestIndex == INDEX_NONE)
|
|
|
|
|
{
|
|
|
|
|
return INDEX_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 18:47:55 -05:00
|
|
|
if (InPosition.Position == EToolMenuInsertType::After)
|
2019-09-10 11:35:20 -04:00
|
|
|
{
|
|
|
|
|
++DestIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int32 i = DestIndex; i < Blocks.Num(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (Blocks[i].InsertPosition != InPosition)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Blocks.Num();
|
|
|
|
|
}
|
2022-09-24 13:31:25 -04:00
|
|
|
|