// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Containers/Array.h" #include "Delegates/Delegate.h" #include "IPinnedCommandList.h" #include "Input/Reply.h" #include "Internationalization/Text.h" #include "Layout/Margin.h" #include "Misc/Attribute.h" #include "Templates/SharedPointer.h" #include "UObject/NameTypes.h" #include "Widgets/DeclarativeSyntaxSupport.h" class FUICommandInfo; class FUICommandList; class FUICommandList_Pinnable; class ISlateStyle; class SCommand; class SWidget; class SWrapBox; struct FGeometry; struct FPointerEvent; /** Tracks a registered custom widget, so it can be persisted */ struct FRegisteredCustomWidget { /** Identifier for this custom widget */ FName CustomWidgetIdentifier; /** Widget creation delegate */ IPinnedCommandList::FOnGenerateCustomWidget OnGenerateCustomWidget; /** Display name for this custom widget, used in context menus and tooltips */ TAttribute CustomWidgetDisplayName; /** Padding to use for this custom widget */ FMargin CustomWidgetPadding; /** Whether to show the label for this custom widget */ bool bShowLabel; }; /** * A list of commands that were 'pinned' by the user, for easy re-use */ class SPinnedCommandList : public IPinnedCommandList { public: /** Delegate for when commands have changed */ DECLARE_DELEGATE( FOnCommandsChanged ); DECLARE_DELEGATE_RetVal( TSharedPtr, FOnGetContextMenu ); SLATE_BEGIN_ARGS( SPinnedCommandList ){} /** Called when a command is right clicked */ SLATE_EVENT( FOnGetContextMenu, OnGetContextMenu ) /** Delegate for when commands have changed */ SLATE_EVENT( FOnCommandsChanged, OnCommandsChanged ) SLATE_END_ARGS() SPinnedCommandList(); ~SPinnedCommandList(); /** Constructs this widget with InArgs */ void Construct(const FArguments& InArgs, const FName& InContextName); /** IPinnedCommandList interface */ virtual void BindCommandList(const TSharedRef& InUICommandList) override; virtual void BindCommandList(const TSharedRef& InUICommandList_Pinnable) override; virtual void RegisterCustomWidget(IPinnedCommandList::FOnGenerateCustomWidget InOnGenerateCustomWidget, FName InCustomWidgetIdentifier, TAttribute InCustomWidgetDisplayName, FMargin InCustomWidgetPadding = FMargin(2.0f, 1.0f), bool bShowLabel = true) override; virtual void AddCommand(const TSharedRef& InCommandInfo, const TSharedRef& InUICommandList) override; virtual void AddCustomWidget(FName InCustomWidgetIdentifier) override; virtual void RemoveCommand(const TSharedRef& InCommandInfo) override; virtual void RemoveCustomWidget(FName InCustomWidgetIdentifier) override; virtual bool HasAnyCommands() const override; virtual void RemoveAllCommands() override; virtual void SetStyle(const ISlateStyle* InStyleSet, const FName& InStyleName) override; /** Saves any settings to config that should be persistent between editor sessions */ void SaveSettings() const; /** Loads any settings to config that should be persistent between editor sessions */ void LoadSettings(); /** SWidget interface */ virtual FReply OnMouseButtonUp( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ); private: /** Adds a command and returns its widget. Creates a new widget if one does not already exist */ TSharedRef AddCommand_Internal(const TSharedRef& InCommandInfo, const TSharedRef& InUICommandList, const TSharedPtr& InUICommandListPinnable = nullptr); /** Adds a custom widget and returns its widget. Creates a new widget if one does not already exist */ TSharedPtr AddCustomWidget_Internal(FName InCustomWidgetIdentifier, const TSharedPtr& InUICommandListPinnable = nullptr); /** Adds a command to the end of the pinned commands box. */ void AddCommandWidget(const TSharedRef& CommandToAdd); /** Removes a command from the pinned commands box. */ void RemoveCommandWidget(const TSharedRef& CommandToRemove); /** Called when reset commands option is pressed */ void OnResetCommands(); /** Remove all commands but the one specified */ void RemoveAllCommandsButThis(const TSharedRef& CommandToRemove); /** Filter action execution */ void HandleExecuteAction(const TSharedRef& InCommandInfo, const TSharedRef& InUICommandList); /** Filter custom widget interactions */ void HandleCustomWidgetInteraction(FName InCustomWidgetIdentifier, const TSharedRef& InUICommandList); /** Sort commands */ void SortCommands(); /** Clear and re-add all widgets to slots */ void RefreshCommandWidgets(); private: /** Context name used to persist this widget's settings */ FName ContextName; /** The horizontal box which contains all the commands */ TSharedPtr CommandBox; /** All commands in the list */ TArray> Commands; /** UI command lists that we can execute commands to (used to re-bind the UI on reload) */ TArray> BoundCommandLists; /** UI command lists that we can execute commands to (used to re-bind the UI on reload) */ TArray> BoundPinnableCommandLists; /** Registered custom widgets */ TArray CustomWidgets; /** Delegate for getting the context menu. */ FOnGetContextMenu OnGetContextMenu; /** Delegate for when commands have changed */ FOnCommandsChanged OnCommandsChanged; /** The slate style to use when constructing command widgets */ const ISlateStyle* StyleSet; /** The menu style name to use when constructing command widgets */ FName StyleName; };