// Copyright Epic Games, Inc. All Rights Reserved. #include "SSelectStreamWindow.h" #include "SlateUGSStyle.h" #include "Framework/Application/SlateApplication.h" #include "UGSTab.h" #include "SGameSyncTab.h" #include "SPrimaryButton.h" #include "Widgets/Layout/SHeader.h" #include "Widgets/Views/STreeView.h" #define LOCTEXT_NAMESPACE "UGSNewWorkspaceWindow" struct FStreamNode { FStreamNode(const FString& InLabel, const FString& InFullStreamPath, bool bInIsStream) : Label(FText::FromString(InLabel)) , FullStreamPath(InFullStreamPath) , bIsStream(bInIsStream) {} virtual ~FStreamNode() {} FText Label; FString FullStreamPath; bool bIsStream; TArray> Children; }; void SSelectStreamWindow::Construct(const FArguments& InArgs, UGSTab* InTab, FString* OutSelectedStreamPath) { Tab = InTab; SelectedStreamPath = OutSelectedStreamPath; PopulateStreamsTree(); SWindow::Construct(SWindow::FArguments() .Title(LOCTEXT("WindowTitleSelect", "Select Stream")) .SizingRule(ESizingRule::FixedSize) .ClientSize(FVector2D(600, 500)) [ SNew(SBox) .Padding(30.0f, 15.0f, 30.0f, 0.0f) [ SNew(SVerticalBox) +SVerticalBox::Slot() .AutoHeight() [ SNew(SEditableTextBox) // Todo: change hint and enable when filters are supported .HintText(LOCTEXT("FilterHint", "Filter (under construction, does not work yet)")) .IsEnabled(false) ] +SVerticalBox::Slot() .Padding(0.0f, 15.0f, 0.0f, 0.0f) [ SNew(STreeView>) .TreeItemsSource(&StreamsTree) .OnGenerateRow(this, &SSelectStreamWindow::OnGenerateRow) .OnGetChildren(this, &SSelectStreamWindow::OnGetChildren) .OnSelectionChanged(this, &SSelectStreamWindow::OnSelectionChanged) ] +SVerticalBox::Slot() .AutoHeight() .VAlign(VAlign_Bottom) [ SNew(SBox) .HAlign(HAlign_Right) .Padding(10.0f) [ SNew(SHorizontalBox) +SHorizontalBox::Slot() .Padding(0.0f, 0.0f, 10.0f, 0.0f) [ SNew(SPrimaryButton) .Text(LOCTEXT("OkButtonText", "Ok")) .OnClicked(this, &SSelectStreamWindow::OnOkClicked) .IsEnabled(this, &SSelectStreamWindow::IsOkButtonEnabled) ] +SHorizontalBox::Slot() .AutoWidth() [ SNew(SButton) .Text(LOCTEXT("CancelButtonText", "Cancel")) .OnClicked(this, &SSelectStreamWindow::OnCancelClicked) ] ] ] ] ]); } TSharedRef SSelectStreamWindow::OnGenerateRow(TSharedRef InItem, const TSharedRef& InOwnerTable) { return SNew(STableRow>, InOwnerTable) [ SNew(SHorizontalBox) +SHorizontalBox::Slot() .AutoWidth() .HAlign(HAlign_Left) .Padding(0.0f, 0.0f, 5.0f, 0.0f) // [ // SNew(SImage) // // Todo: replace text with keys to actuall perforce depot/stream icons // .Image(FSlateUGSStyle::Get().GetBrush(InItem->bIsStream ? "FILL ME IN" : "FILL ME IN TOO)) // ] +SHorizontalBox::Slot() .VAlign(VAlign_Center) [ SNew(STextBlock) .Text(InItem->Label) ] ]; } void SSelectStreamWindow::OnGetChildren(TSharedRef InItem, TArray>& OutChildren) { for (int32 ChildIndex = 0; ChildIndex < InItem->Children.Num(); ++ChildIndex) { TSharedPtr Child = InItem->Children[ChildIndex]; if (Child.IsValid()) { OutChildren.Add(Child.ToSharedRef()); } } } void SSelectStreamWindow::PopulateStreamsTree() { TArray Streams = Tab->GetAllStreamNames(); FString CurrentRoot = ""; for (const FString& Stream : Streams) { TArray StreamPath; Stream.RightChop(2).ParseIntoArray(StreamPath, TEXT("/")); if (StreamPath[0] != CurrentRoot) { CurrentRoot = StreamPath[0]; StreamsTree.Add(MakeShareable(new FStreamNode(StreamPath[0], Stream, false))); } FString CurrentChild = Stream.RightChop(CurrentRoot.Len() + 3); StreamsTree.Last()->Children.Add(MakeShareable(new FStreamNode(CurrentChild, Stream, true))); } } void SSelectStreamWindow::OnSelectionChanged(TSharedPtr NewSelection, ESelectInfo::Type SelectInfo) { SelectedStream = NewSelection; } FReply SSelectStreamWindow::OnOkClicked() { *SelectedStreamPath = SelectedStream->FullStreamPath; FSlateApplication::Get().FindWidgetWindow(AsShared())->RequestDestroyWindow(); return FReply::Handled(); } FReply SSelectStreamWindow::OnCancelClicked() { FSlateApplication::Get().FindWidgetWindow(AsShared())->RequestDestroyWindow(); return FReply::Handled(); } bool SSelectStreamWindow::IsOkButtonEnabled() const { return SelectedStream.IsValid() && SelectedStream->bIsStream; } #undef LOCTEXT_NAMESPACE