You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
SLATE_TEXT_ATTRIBUTE was the macro that allowed the FString -> FText pass-through support, and was deprecated in 4.8 in favour of using SLATE_ATTRIBUTE with an FText type. This is being removed for 4.10 and SlateFileDialogs was still relying on the deprecated behaviour. This change removes its reliance on SLATE_TEXT_ATTRIBUTE, and also cleans up a load of SLATE_ATTRIBUTE parameters should have been using SLATE_ARGUMENT instead. #codereview Dmitry.Rekman [CL 2628829 by Jamie Dale in Main branch]
295 lines
8.5 KiB
C++
295 lines
8.5 KiB
C++
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
#include "SlateBasics.h"
|
|
#include "STextComboBox.h"
|
|
#include "SBreadcrumbTrail.h"
|
|
#include "SInlineEditableTextBlock.h"
|
|
#include "SlateFileDialogsStyles.h"
|
|
#include "DirectoryWatcherModule.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "SlateFileDialogsNamespace"
|
|
|
|
class SSlateFileOpenDlg;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
struct FFileEntry
|
|
{
|
|
FString Label;
|
|
FString ModDate;
|
|
FString FileSize;
|
|
bool bIsSelected;
|
|
bool bIsDirectory;
|
|
|
|
FFileEntry() { }
|
|
|
|
FFileEntry(FString InLabel, FString InModDate, FString InFileSize, bool InIsDirectory)
|
|
: Label(MoveTemp(InLabel))
|
|
, ModDate(MoveTemp(InModDate))
|
|
, FileSize(MoveTemp(InFileSize))
|
|
, bIsSelected(false)
|
|
, bIsDirectory(InIsDirectory)
|
|
{
|
|
}
|
|
|
|
inline static bool ConstPredicate ( const TSharedPtr<FFileEntry> Entry1, const TSharedPtr<FFileEntry> Entry2)
|
|
{
|
|
return (Entry1->Label.Compare( Entry2->Label ) < 0);
|
|
}
|
|
};
|
|
|
|
typedef TSharedPtr<FFileEntry> SSlateFileDialogItemPtr;
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
class FSlateFileDlgWindow
|
|
{
|
|
public:
|
|
enum EResult
|
|
{
|
|
Cancel = 0,
|
|
Accept = 1,
|
|
Engine = 2,
|
|
Project = 3
|
|
};
|
|
|
|
FSlateFileDlgWindow(FSlateFileDialogsStyle *InStyleSet);
|
|
|
|
bool OpenFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
|
|
const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames, int32& OutFilterIndex);
|
|
|
|
bool OpenFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
|
|
const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames);
|
|
|
|
bool OpenDirectoryDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
|
|
FString& OutFoldername);
|
|
|
|
bool SaveFileDialog(const void* ParentWindowHandle, const FString& DialogTitle, const FString& DefaultPath,
|
|
const FString& DefaultFile, const FString& FileTypes, uint32 Flags, TArray<FString>& OutFilenames);
|
|
|
|
private:
|
|
TSharedPtr<class SSlateFileOpenDlg> DialogWidget;
|
|
FString CurrentDirectory;
|
|
|
|
FSlateFileDialogsStyle* StyleSet;
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
class SSlateFileOpenDlg : public SCompoundWidget
|
|
{
|
|
public:
|
|
struct FDirNode
|
|
{
|
|
FString Label;
|
|
TSharedPtr<STextBlock> TextBlock;
|
|
TSharedPtr<SButton> Button;
|
|
|
|
FDirNode() { }
|
|
|
|
FDirNode(FString InLabel, TSharedPtr<STextBlock> InTextBlock)
|
|
{
|
|
Label = InLabel;
|
|
TextBlock = InTextBlock;
|
|
}
|
|
};
|
|
|
|
SLATE_BEGIN_ARGS(SSlateFileOpenDlg)
|
|
: _CurrentPath(TEXT("")),
|
|
_Filters(TEXT("")),
|
|
_bMultiSelectEnabled(false),
|
|
_WindowTitleText(TEXT("")),
|
|
_AcceptText(LOCTEXT("SlateDialogOpen","Open")),
|
|
_bDirectoriesOnly(false),
|
|
_bSaveFile(false),
|
|
_OutNames(nullptr),
|
|
_OutFilterIndex(nullptr),
|
|
_ParentWindow(nullptr),
|
|
_StyleSet(nullptr)
|
|
{}
|
|
|
|
SLATE_ARGUMENT(FString, CurrentPath)
|
|
SLATE_ARGUMENT(FString, Filters)
|
|
SLATE_ARGUMENT(bool, bMultiSelectEnabled)
|
|
SLATE_ARGUMENT(FString, WindowTitleText)
|
|
SLATE_ARGUMENT(FText, AcceptText)
|
|
SLATE_ARGUMENT(bool, bDirectoriesOnly)
|
|
SLATE_ARGUMENT(bool, bSaveFile)
|
|
SLATE_ARGUMENT(TArray<FString>*, OutNames)
|
|
SLATE_ARGUMENT(int32*, OutFilterIndex)
|
|
SLATE_ARGUMENT(TWeakPtr<SWindow>, ParentWindow)
|
|
SLATE_ARGUMENT(FSlateFileDialogsStyle*, StyleSet)
|
|
SLATE_END_ARGS()
|
|
|
|
void Construct(const FArguments& InArgs);
|
|
FSlateFileDlgWindow::EResult GetResponse() { return UserResponse; }
|
|
void SetOutNames(TArray<FString>* Ptr) { OutNames = Ptr; }
|
|
void SetOutFilterIndex(int32* InOutFilterIndex) { OutFilterIndex = InOutFilterIndex; }
|
|
void SetDefaultFile(FString DefaultFile);
|
|
|
|
private:
|
|
void OnPathClicked( const FString& CrumbData );
|
|
TSharedPtr<SWidget> OnGetCrumbDelimiterContent(const FString& CrumbData) const;
|
|
void RebuildFileTable();
|
|
void BuildDirectoryPath();
|
|
void ReadDir(bool bIsRefresh = false);
|
|
void RefreshCrumbs();
|
|
void OnPathMenuItemClicked( FString ClickedPath );
|
|
void OnItemSelected(TSharedPtr<FFileEntry> Item, ESelectInfo::Type SelectInfo);
|
|
|
|
void Tick(const FGeometry &AllottedGeometry, const double InCurrentTime, const float InDeltaTime);
|
|
|
|
TSharedRef<ITableRow> OnGenerateWidgetForList(TSharedPtr<FFileEntry> Item, const TSharedRef<STableViewBase> &OwnerTable);
|
|
void OnItemDoubleClicked(TSharedPtr<FFileEntry> Item);
|
|
|
|
void OnFilterChanged(TSharedPtr<FString> NewValue, ESelectInfo::Type SelectInfo);
|
|
FReply OnAcceptCancelClick(FSlateFileDlgWindow::EResult ButtonID);
|
|
FReply OnQuickLinkClick(FSlateFileDlgWindow::EResult ButtonID);
|
|
FReply OnDirSublevelClick(int32 Level);
|
|
void OnDirectoryChanged(const TArray <FFileChangeData> &FileChanges);
|
|
void OnFileNameCommitted(const FText& InText, ETextCommit::Type InCommitType);
|
|
|
|
void OnNewDirectoryCommitted(const FText& InText, ETextCommit::Type InCommitType);
|
|
FReply OnNewDirectoryClick();
|
|
bool OnNewDirectoryTextChanged(const FText &InText, FText &ErrorMsg);
|
|
FReply OnNewDirectoryAcceptCancelClick(FSlateFileDlgWindow::EResult ButtonID);
|
|
|
|
/** Collects the output files. */
|
|
void SetOutputFiles();
|
|
|
|
bool GetFilterExtension(FString &OutString);
|
|
void ParseFilters();
|
|
|
|
TArray< FDirNode > DirectoryNodesArray;
|
|
TArray<TSharedPtr<FFileEntry>> FoldersArray;
|
|
TArray<TSharedPtr<FFileEntry>> FilesArray;
|
|
TArray<TSharedPtr<FFileEntry>> LineItemArray;
|
|
|
|
TSharedPtr<STextComboBox> FilterCombo;
|
|
TSharedPtr<SHorizontalBox> FilterHBox;
|
|
TSharedPtr<SInlineEditableTextBlock> SaveFilenameEditBox;
|
|
TSharedPtr<SInlineEditableTextBlock> NewDirectoryEditBox;
|
|
TSharedPtr<SBox> SaveFilenameSizeBox;
|
|
TSharedPtr<STextBlock> WindowTitle;
|
|
TSharedPtr<SListView<TSharedPtr<FFileEntry>>> ListView;
|
|
TSharedPtr<SBreadcrumbTrail<FString>> PathBreadcrumbTrail;
|
|
|
|
TSharedPtr<SButton> NewDirCancelButton;
|
|
TSharedPtr<SBox> NewDirectorySizeBox;
|
|
TSharedPtr<STextBlock> DirErrorMsg;
|
|
|
|
TArray<TSharedPtr<FString>> FilterNameArray;
|
|
TArray<TSharedPtr<FString>> FilterListArray;
|
|
|
|
int32 FilterIndex;
|
|
|
|
FSlateFileDlgWindow::EResult UserResponse;
|
|
|
|
bool bNeedsBuilding;
|
|
bool bRebuildDirPath;
|
|
bool bDirectoryHasChanged;
|
|
|
|
int32 DirNodeIndex;
|
|
FString SaveFilename;
|
|
|
|
TWeakPtr<SWindow> ParentWindow;
|
|
FString CurrentPath;
|
|
FString Filters;
|
|
FString WindowTitleText;
|
|
bool bMultiSelectEnabled;
|
|
TArray<FString>* OutNames;
|
|
int32* OutFilterIndex;
|
|
bool bDirectoriesOnly;
|
|
bool bSaveFile;
|
|
FText AcceptText;
|
|
FSlateFileDialogsStyle* StyleSet;
|
|
|
|
IDirectoryWatcher *DirectoryWatcher;
|
|
FDelegateHandle OnDialogDirectoryChangedDelegateHandle;
|
|
FString RegisteredPath;
|
|
FString NewDirectoryName;
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
class SSlateFileDialogRow : public SMultiColumnTableRow<SSlateFileDialogItemPtr>
|
|
{
|
|
public:
|
|
|
|
SLATE_BEGIN_ARGS(SSlateFileDialogRow) { }
|
|
SLATE_ARGUMENT(SSlateFileDialogItemPtr, DialogItem)
|
|
SLATE_ARGUMENT(FSlateFileDialogsStyle *, StyleSet)
|
|
SLATE_END_ARGS()
|
|
|
|
|
|
void Construct(const FArguments& InArgs, const TSharedRef<STableViewBase> &InOwnerTableView)
|
|
{
|
|
check(InArgs._DialogItem.IsValid());
|
|
|
|
DialogItem = InArgs._DialogItem;
|
|
StyleSet = InArgs._StyleSet;
|
|
|
|
SMultiColumnTableRow<SSlateFileDialogItemPtr>::Construct(FSuperRowType::FArguments(), InOwnerTableView);
|
|
}
|
|
|
|
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
virtual TSharedRef<SWidget> GenerateWidgetForColumn( const FName& ColumnName ) override
|
|
{
|
|
FSlateFontInfo ItemFont = StyleSet->GetFontStyle("SlateFileDialogs.Dialog");
|
|
struct EVisibility FolderIconVisibility = DialogItem->bIsDirectory ? EVisibility::Visible : EVisibility::Hidden;
|
|
|
|
if (ColumnName == TEXT("Pathname"))
|
|
{
|
|
return SNew(SHorizontalBox)
|
|
|
|
+ SHorizontalBox::Slot()
|
|
.HAlign(HAlign_Left)
|
|
.VAlign(VAlign_Top)
|
|
.AutoWidth()
|
|
.Padding(FMargin(5.0f, 2.0f))
|
|
[
|
|
SNew(SImage)
|
|
.Image(StyleSet->GetBrush("SlateFileDialogs.Folder16"))
|
|
.Visibility(FolderIconVisibility)
|
|
]
|
|
|
|
+ SHorizontalBox::Slot()
|
|
.HAlign(HAlign_Left)
|
|
.VAlign(VAlign_Top)
|
|
.AutoWidth()
|
|
.Padding(FMargin(5.0f, 0.0f, 0.0f, 0.0f))
|
|
[
|
|
SNew(STextBlock)
|
|
.Text(FText::FromString(DialogItem->Label))
|
|
.Font(ItemFont)
|
|
];
|
|
}
|
|
else if (ColumnName == TEXT("ModDate"))
|
|
{
|
|
return SNew(STextBlock)
|
|
.Text(FText::FromString(DialogItem->ModDate))
|
|
.Font(ItemFont);
|
|
}
|
|
else if (ColumnName == TEXT("FileSize"))
|
|
{
|
|
return SNew(STextBlock)
|
|
.Text(FText::FromString(DialogItem->FileSize))
|
|
.Font(ItemFont);
|
|
}
|
|
else
|
|
{
|
|
return SNullWidget::NullWidget;
|
|
}
|
|
}
|
|
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
|
|
|
|
private:
|
|
SSlateFileDialogItemPtr DialogItem;
|
|
FSlateFileDialogsStyle* StyleSet;
|
|
};
|
|
|
|
#undef LOCTEXT_NAMESPACE
|