Files
UnrealEngineUWP/Engine/Source/Editor/DataTableEditor/Private/DataTableEditor.h
Chris Gagnon 930e33cb48 Copying //UE4/Dev-Editor to Dev-Main (//UE4/Dev-Main) for 4.23 From CL 6837861
#rb none

[CL 6838042 by Chris Gagnon in Main branch]
2019-06-04 15:42:48 -04:00

228 lines
7.9 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Styling/SlateColor.h"
#include "Types/SlateStructs.h"
#include "Widgets/SWidget.h"
#include "Widgets/SBoxPanel.h"
#include "Toolkits/IToolkitHost.h"
#include "IDataTableEditor.h"
#include "Widgets/Views/STableViewBase.h"
#include "Widgets/Views/STableRow.h"
#include "EditorUndoClient.h"
#include "Kismet2/StructureEditorUtils.h"
#include "DataTableEditorUtils.h"
#include "SRowEditor.h"
class FJsonObject;
DECLARE_DELEGATE_OneParam(FOnRowHighlighted, FName /*Row name*/);
/** Viewer/editor for a DataTable */
class FDataTableEditor : public IDataTableEditor
, public FEditorUndoClient
, public FStructureEditorUtils::INotifyOnStructChanged
, public FDataTableEditorUtils::INotifyOnDataTableChanged
{
friend class SDataTableListViewRow;
public:
virtual void RegisterTabSpawners(const TSharedRef<class FTabManager>& TabManager) override;
virtual void UnregisterTabSpawners(const TSharedRef<class FTabManager>& TabManager) override;
/**
* Edits the specified table
*
* @param Mode Asset editing mode for this editor (standalone or world-centric)
* @param InitToolkitHost When Mode is WorldCentric, this is the level editor instance to spawn this editor within
* @param Table The table to edit
*/
virtual void InitDataTableEditor( const EToolkitMode::Type Mode, const TSharedPtr< class IToolkitHost >& InitToolkitHost, UDataTable* Table );
/** Constructor */
FDataTableEditor();
/** Destructor */
virtual ~FDataTableEditor();
/** IToolkit interface */
virtual FName GetToolkitFName() const override;
virtual FText GetBaseToolkitName() const override;
virtual FString GetWorldCentricTabPrefix() const override;
virtual FLinearColor GetWorldCentricTabColorScale() const override;
// FEditorUndoClient
virtual void PostUndo(bool bSuccess) override;
virtual void PostRedo(bool bSuccess) override;
void HandleUndoRedo();
// INotifyOnStructChanged
virtual void PreChange(const class UUserDefinedStruct* Struct, FStructureEditorUtils::EStructureEditorChangeInfo Info) override;
virtual void PostChange(const class UUserDefinedStruct* Struct, FStructureEditorUtils::EStructureEditorChangeInfo Info) override;
// INotifyOnDataTableChanged
virtual void PreChange(const UDataTable* Changed, FDataTableEditorUtils::EDataTableChangeInfo Info) override;
virtual void PostChange(const UDataTable* Changed, FDataTableEditorUtils::EDataTableChangeInfo Info) override;
virtual void SelectionChange(const UDataTable* Changed, FName RowName) override;
/** Get the data table being edited */
const UDataTable* GetDataTable() const;
void HandlePostChange();
void SetHighlightedRow(FName Name);
FText GetFilterText() const;
FSlateColor GetRowTextColor(FName RowName) const;
protected:
void RefreshCachedDataTable(const FName InCachedSelection = NAME_None, const bool bUpdateEvenIfValid = false);
void UpdateVisibleRows(const FName InCachedSelection = NAME_None, const bool bUpdateEvenIfValid = false);
void RestoreCachedSelection(const FName InCachedSelection, const bool bUpdateEvenIfValid = false);
void OnFilterTextChanged(const FText& InFilterText);
virtual void PostRegenerateMenusAndToolbars() override;
FReply OnFindRowInContentBrowserClicked();
void OnNavigateToDataTableRowCode();
FText GetCellText(FDataTableEditorRowListViewDataPtr InRowDataPointer, int32 ColumnIndex) const;
FText GetCellToolTipText(FDataTableEditorRowListViewDataPtr InRowDataPointer, int32 ColumnIndex) const;
TSharedRef<SVerticalBox> CreateContentBox();
TSharedRef<SWidget> CreateRowEditorBox();
virtual TSharedRef<SRowEditor> CreateRowEditor(UDataTable* Table);
/** Spawns the tab with the data table inside */
TSharedRef<SDockTab> SpawnTab_DataTable( const FSpawnTabArgs& Args );
/** Spawns the tab with the data table inside */
TSharedRef<SDockTab> SpawnTab_DataTableDetails(const FSpawnTabArgs& Args);
/** Spawns the tab with the Row Editor inside */
TSharedRef<SDockTab> SpawnTab_RowEditor(const FSpawnTabArgs& Args);
FOptionalSize GetRowNameColumnWidth() const;
float GetColumnWidth(const int32 ColumnIndex) const;
void OnColumnResized(const float NewWidth, const int32 ColumnIndex);
void LoadLayoutData();
void SaveLayoutData();
/** Make the widget for a row name entry in the data table row list view */
TSharedRef<ITableRow> MakeRowNameWidget(FDataTableEditorRowListViewDataPtr InRowDataPtr, const TSharedRef<STableViewBase>& OwnerTable);
/** Make the widget for a row entry in the data table row list view */
TSharedRef<ITableRow> MakeRowWidget(FDataTableEditorRowListViewDataPtr InRowDataPtr, const TSharedRef<STableViewBase>& OwnerTable);
/** Make the widget for a cell entry in the data table row list view */
TSharedRef<SWidget> MakeCellWidget(FDataTableEditorRowListViewDataPtr InRowDataPtr, const int32 InRowIndex, const FName& InColumnId);
void OnRowNamesListViewScrolled(double InScrollOffset);
void OnCellsListViewScrolled(double InScrollOffset);
void OnRowSelectionChanged(FDataTableEditorRowListViewDataPtr InNewSelection, ESelectInfo::Type InSelectInfo);
void CopySelectedRow();
void PasteOnSelectedRow();
void DuplicateSelectedRow();
/** Helper function for creating and registering the tab containing the data table data */
virtual void CreateAndRegisterDataTableTab(const TSharedRef<class FTabManager>& InTabManager);
/** Helper function for creating and registering the tab containing the data table details */
virtual void CreateAndRegisterDataTableDetailsTab(const TSharedRef<class FTabManager>& InTabManager);
/** Helper function for creating and registering the tab containing the row editor */
virtual void CreateAndRegisterRowEditorTab(const TSharedRef<class FTabManager>& InTabManager);
protected:
/** Struct holding information about the current column widths */
struct FColumnWidth
{
FColumnWidth()
: bIsAutoSized(true)
, CurrentWidth(0.0f)
{
}
/** True if this column is being auto-sized rather than sized by the user */
bool bIsAutoSized;
/** The width of the column, either sized by the user, or auto-sized */
float CurrentWidth;
};
/** UI for the "Data Table" tab */
TSharedPtr<SWidget> DataTableTabWidget;
/** Property viewing widget */
TSharedPtr<class IDetailsView> PropertyView;
/** UI for the "Row Editor" tab */
TSharedPtr<SWidget> RowEditorTabWidget;
/** Array of the columns that are available for editing */
TArray<FDataTableEditorColumnHeaderDataPtr> AvailableColumns;
/** Array of the rows that are available for editing */
TArray<FDataTableEditorRowListViewDataPtr> AvailableRows;
/** Array of the rows that match the active filter(s) */
TArray<FDataTableEditorRowListViewDataPtr> VisibleRows;
/** Header row containing entries for each column in AvailableColumns */
TSharedPtr<SHeaderRow> ColumnNamesHeaderRow;
/** List view responsible for showing the row names column */
TSharedPtr<SListView<FDataTableEditorRowListViewDataPtr>> RowNamesListView;
/** List view responsible for showing the rows in VisibleRows for each entry in AvailableColumns */
TSharedPtr<SListView<FDataTableEditorRowListViewDataPtr>> CellsListView;
/** Width of the row name column */
float RowNameColumnWidth;
/** Widths of data table cell columns */
TArray<FColumnWidth> ColumnWidths;
/** The layout data for the currently loaded data table */
TSharedPtr<FJsonObject> LayoutData;
/** The name of the currently selected row */
FName HighlightedRowName;
/** The current filter text applied to the data table */
FText ActiveFilterText;
FOnRowHighlighted CallbackOnRowHighlighted;
FSimpleDelegate CallbackOnDataTableUndoRedo;
/** The tab id for the data table tab */
static const FName DataTableTabId;
/** The tab id for the data table details tab */
static const FName DataTableDetailsTabId;
/** The tab id for the row editor tab */
static const FName RowEditorTabId;
/** The column id for the row name list view column */
static const FName RowNameColumnId;
};