2014-08-14 07:42:47 -04:00
|
|
|
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "IntroTutorialsPrivatePCH.h"
|
|
|
|
|
#include "STutorialEditableText.h"
|
|
|
|
|
#include "IDocumentation.h"
|
|
|
|
|
#include "ISourceCodeAccessModule.h"
|
|
|
|
|
#include "ContentBrowserModule.h"
|
2014-08-27 20:35:19 -04:00
|
|
|
#include "SColorPicker.h"
|
2014-08-29 15:31:27 -04:00
|
|
|
#include "DesktopPlatformModule.h"
|
Converted STextBlock to use an FTextLayout
This solves a wrapping issue where STextBlock would incorrectly consume new-line characters when wrapping, as well as allowing it to use custom wrapping behavior (eg, CamelCase wrapping for asset names in the content browser).
This change also implements FString -> FText passthrough for SLATE_TEXT_ATTRIBUTE (it was previously performing FText -> FString passthrough, however this didn't fit well with the fact that FText has a more efficient method of comparing whether a bound text attribute has changed (see FTextSnapshot), so can quickly work out that the FTextLayout doesn't need updating).
This change adds FTextBlockLayout to handle the text layout cache for text block types (STextBlock and SRichTextBlock) and serves a dual purpose of moving the duplicated caching logic into a single place, as well as hiding it from the widget (so allowing the cache to mutate, even when called from immutable widget functions).
This change also increases the unification between the STextBlock and SRichTextBlock construction parameters, by allowing STextBlock to specify a Justification, Margin, and LineHeightPercentage, and allowing SRichTextBlock to specify its HighlightText as an attribute.
ReviewedBy Nick.Atamas, Justin.Sargent
[CL 2280351 by Jamie Dale in Main branch]
2014-09-01 06:28:16 -04:00
|
|
|
#include "RichTextLayoutMarshaller.h"
|
2014-08-14 07:42:47 -04:00
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "STutorialEditableText"
|
|
|
|
|
|
2014-08-27 20:35:19 -04:00
|
|
|
|
2014-08-14 07:42:47 -04:00
|
|
|
namespace TutorialTextHelpers
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
void OnBrowserLinkClicked(const FSlateHyperlinkRun::FMetadata& Metadata)
|
|
|
|
|
{
|
|
|
|
|
const FString* Url = Metadata.Find(TEXT("href"));
|
|
|
|
|
if(Url)
|
|
|
|
|
{
|
|
|
|
|
FPlatformProcess::LaunchURL(**Url, nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnDocLinkClicked(const FSlateHyperlinkRun::FMetadata& Metadata)
|
|
|
|
|
{
|
|
|
|
|
const FString* Url = Metadata.Find(TEXT("href"));
|
|
|
|
|
if(Url)
|
|
|
|
|
{
|
|
|
|
|
IDocumentation::Get()->Open(*Url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTutorialLinkClicked(const FSlateHyperlinkRun::FMetadata& Metadata)
|
|
|
|
|
{
|
|
|
|
|
const FString* Url = Metadata.Find(TEXT("href"));
|
|
|
|
|
if(Url)
|
|
|
|
|
{
|
|
|
|
|
// ParseTutorialLink(*Url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ParseCodeLink(const FString &InternalLink)
|
|
|
|
|
{
|
|
|
|
|
// Tokens used by the code parsing. Details in the parse section
|
|
|
|
|
static const FString ProjectSpecifier(TEXT("[PROJECT]"));
|
|
|
|
|
static const FString ProjectRoot(TEXT("[PROJECT]/Source/[PROJECT]/"));
|
|
|
|
|
static const FString ProjectSuffix(TEXT(".uproject"));
|
|
|
|
|
|
|
|
|
|
FString Path;
|
|
|
|
|
int32 Line = 0;
|
|
|
|
|
int32 Col = 0;
|
|
|
|
|
|
|
|
|
|
TArray<FString> Tokens;
|
|
|
|
|
InternalLink.ParseIntoArray(&Tokens, TEXT(","), 0);
|
|
|
|
|
int32 TokenStringsCount = Tokens.Num();
|
|
|
|
|
if (TokenStringsCount > 0)
|
|
|
|
|
{
|
|
|
|
|
Path = Tokens[0];
|
|
|
|
|
}
|
|
|
|
|
if (TokenStringsCount > 1)
|
|
|
|
|
{
|
|
|
|
|
TTypeFromString<int32>::FromString(Line, *Tokens[1]);
|
|
|
|
|
}
|
|
|
|
|
if (TokenStringsCount > 2)
|
|
|
|
|
{
|
|
|
|
|
TTypeFromString<int32>::FromString(Col, *Tokens[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISourceCodeAccessModule& SourceCodeAccessModule = FModuleManager::LoadModuleChecked<ISourceCodeAccessModule>("SourceCodeAccess");
|
|
|
|
|
ISourceCodeAccessor& SourceCodeAccessor = SourceCodeAccessModule.GetAccessor();
|
|
|
|
|
|
|
|
|
|
// If we specified generic project specified as the project name try to replace the name with the name of this project
|
|
|
|
|
if (InternalLink.Contains(ProjectSpecifier) == true)
|
|
|
|
|
{
|
|
|
|
|
FString ProjectName = TEXT("Marble");
|
|
|
|
|
// Try to extract the name of the project
|
|
|
|
|
FString ProjectPath = FPaths::GetProjectFilePath();
|
|
|
|
|
if (ProjectPath.EndsWith(ProjectSuffix))
|
|
|
|
|
{
|
|
|
|
|
int32 ProjectPathEndIndex;
|
|
|
|
|
if (ProjectPath.FindLastChar(TEXT('/'), ProjectPathEndIndex) == true)
|
|
|
|
|
{
|
|
|
|
|
ProjectName = ProjectPath.RightChop(ProjectPathEndIndex + 1);
|
|
|
|
|
ProjectName.RemoveFromEnd(*ProjectSuffix);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Replace the root path with the name of this project
|
|
|
|
|
FString RebuiltPath = ProjectRoot + Path;
|
|
|
|
|
RebuiltPath.ReplaceInline(*ProjectSpecifier, *ProjectName);
|
|
|
|
|
Path = RebuiltPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally create the complete path - project name and all
|
|
|
|
|
int32 PathEndIndex;
|
2014-08-29 15:31:27 -04:00
|
|
|
FString SolutionPath;
|
|
|
|
|
if( FDesktopPlatformModule::Get()->GetSolutionPath( SolutionPath ) && SolutionPath.FindLastChar(TEXT('/'), PathEndIndex) == true)
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
|
|
|
|
SolutionPath = SolutionPath.LeftChop(SolutionPath.Len() - PathEndIndex - 1);
|
|
|
|
|
SolutionPath += Path;
|
|
|
|
|
SourceCodeAccessor.OpenFileAtLine(SolutionPath, Line, Col);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnCodeLinkClicked(const FSlateHyperlinkRun::FMetadata& Metadata)
|
|
|
|
|
{
|
|
|
|
|
const FString* Url = Metadata.Find(TEXT("href"));
|
|
|
|
|
if(Url)
|
|
|
|
|
{
|
|
|
|
|
ParseCodeLink(*Url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ParseAssetLink(const FString& InternalLink, const FString& Action)
|
|
|
|
|
{
|
|
|
|
|
UObject* RequiredObject = FindObject<UObject>(ANY_PACKAGE, *InternalLink);
|
|
|
|
|
if (RequiredObject != nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (Action == TEXT("edit"))
|
|
|
|
|
{
|
|
|
|
|
FAssetEditorManager::Get().OpenEditorForAsset(RequiredObject);
|
|
|
|
|
}
|
|
|
|
|
else if(Action == TEXT("select"))
|
|
|
|
|
{
|
|
|
|
|
FContentBrowserModule& ContentBrowserModule = FModuleManager::Get().LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
|
|
|
|
|
TArray<UObject*> AssetToBrowse;
|
|
|
|
|
AssetToBrowse.Add(RequiredObject);
|
|
|
|
|
ContentBrowserModule.Get().SyncBrowserToAssets(AssetToBrowse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnAssetLinkClicked(const FSlateHyperlinkRun::FMetadata& Metadata)
|
|
|
|
|
{
|
|
|
|
|
const FString* Url = Metadata.Find(TEXT("href"));
|
|
|
|
|
const FString* Action = Metadata.Find(TEXT("action"));
|
|
|
|
|
if(Url && Action)
|
|
|
|
|
{
|
|
|
|
|
ParseAssetLink(*Url, *Action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
|
|
|
void STutorialEditableText::Construct(const FArguments& InArgs)
|
|
|
|
|
{
|
|
|
|
|
OnTextChanged = InArgs._OnTextChanged;
|
|
|
|
|
OnTextCommitted = InArgs._OnTextCommitted;
|
|
|
|
|
|
|
|
|
|
CurrentHyperlinkType = EHyperlinkType::Browser;
|
2014-09-03 06:25:58 -04:00
|
|
|
bNewHyperlink = true;
|
2014-08-14 07:42:47 -04:00
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
// Setup text styles
|
|
|
|
|
StylesAndNames.Add(MakeShareable(new FTextStyleAndName(TEXT("Tutorials.Content.Text"), LOCTEXT("NormalTextDesc", "Normal"))));
|
|
|
|
|
StylesAndNames.Add(MakeShareable(new FTextStyleAndName(TEXT("Tutorials.Content.TextBold"), LOCTEXT("BoldTextDesc", "Bold"))));
|
|
|
|
|
StylesAndNames.Add(MakeShareable(new FTextStyleAndName(TEXT("Tutorials.Content.HeaderText2"), LOCTEXT("Header2TextDesc", "Header 2"))));
|
|
|
|
|
StylesAndNames.Add(MakeShareable(new FTextStyleAndName(TEXT("Tutorials.Content.HeaderText1"), LOCTEXT("Header1TextDesc", "Header 1"))));
|
|
|
|
|
ActiveStyle = StylesAndNames[0];
|
|
|
|
|
|
|
|
|
|
HyperlinkStyle = MakeShareable(new FTextStyleAndName(TEXT("Tutorials.Content.HyperlinkText"), LOCTEXT("HyperlinkTextDesc", "Hyperlink")));
|
|
|
|
|
StylesAndNames.Add(HyperlinkStyle);
|
2014-08-14 07:42:47 -04:00
|
|
|
|
|
|
|
|
TSharedRef<FRichTextLayoutMarshaller> RichTextMarshaller = FRichTextLayoutMarshaller::Create(
|
|
|
|
|
TArray<TSharedRef<ITextDecorator>>(),
|
|
|
|
|
&FEditorStyle::Get(),
|
2014-09-03 06:25:58 -04:00
|
|
|
FEditorStyle::Get().GetWidgetStyle<FTextBlockStyle>("Tutorials.Content.Text")
|
2014-08-14 07:42:47 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
OnBrowserLinkClicked = FSlateHyperlinkRun::FOnClick::CreateStatic(&TutorialTextHelpers::OnBrowserLinkClicked);
|
|
|
|
|
OnDocLinkClicked = FSlateHyperlinkRun::FOnClick::CreateStatic(&TutorialTextHelpers::OnDocLinkClicked);
|
|
|
|
|
OnTutorialLinkClicked = FSlateHyperlinkRun::FOnClick::CreateStatic(&TutorialTextHelpers::OnTutorialLinkClicked);
|
|
|
|
|
OnCodeLinkClicked = FSlateHyperlinkRun::FOnClick::CreateStatic(&TutorialTextHelpers::OnCodeLinkClicked);
|
|
|
|
|
OnAssetLinkClicked = FSlateHyperlinkRun::FOnClick::CreateStatic(&TutorialTextHelpers::OnAssetLinkClicked);
|
|
|
|
|
RichTextMarshaller->AppendInlineDecorator(FHyperlinkDecorator::Create(TEXT("browser"), OnBrowserLinkClicked));
|
|
|
|
|
RichTextMarshaller->AppendInlineDecorator(FHyperlinkDecorator::Create(TEXT("udn"), OnDocLinkClicked));
|
|
|
|
|
RichTextMarshaller->AppendInlineDecorator(FHyperlinkDecorator::Create(TEXT("tutorial"), OnTutorialLinkClicked));
|
|
|
|
|
RichTextMarshaller->AppendInlineDecorator(FHyperlinkDecorator::Create(TEXT("code"), OnCodeLinkClicked));
|
|
|
|
|
RichTextMarshaller->AppendInlineDecorator(FHyperlinkDecorator::Create(TEXT("asset"), OnAssetLinkClicked));
|
2014-09-03 06:25:58 -04:00
|
|
|
RichTextMarshaller->AppendInlineDecorator(FTextStyleDecorator::Create());
|
2014-08-14 07:42:47 -04:00
|
|
|
|
|
|
|
|
this->ChildSlot
|
|
|
|
|
[
|
|
|
|
|
SNew(SVerticalBox)
|
|
|
|
|
|
|
|
|
|
+SVerticalBox::Slot()
|
|
|
|
|
.AutoHeight()
|
|
|
|
|
.Padding(FMargin(0.0f, 0.0f, 0.0f, 0.0f))
|
|
|
|
|
[
|
|
|
|
|
SAssignNew(RichEditableTextBox, SMultiLineEditableTextBox)
|
2014-09-03 06:25:58 -04:00
|
|
|
.Font(FEditorStyle::Get().GetWidgetStyle<FTextBlockStyle>("Tutorials.Content.Text").Font)
|
2014-08-14 07:42:47 -04:00
|
|
|
.Text(InArgs._Text)
|
|
|
|
|
.OnTextChanged(this, &STutorialEditableText::HandleRichEditableTextChanged)
|
|
|
|
|
.OnTextCommitted(this, &STutorialEditableText::HandleRichEditableTextCommitted)
|
|
|
|
|
.OnCursorMoved(this, &STutorialEditableText::HandleRichEditableTextCursorMoved)
|
|
|
|
|
.Marshaller(RichTextMarshaller)
|
|
|
|
|
.AutoWrapText(true)
|
|
|
|
|
.Margin(4)
|
|
|
|
|
.LineHeightPercentage(1.1f)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
+SVerticalBox::Slot()
|
|
|
|
|
.AutoHeight()
|
|
|
|
|
.Padding(FMargin(0.0f, 0.0f, 0.0f, 4.0f))
|
|
|
|
|
[
|
|
|
|
|
SNew(SBorder)
|
|
|
|
|
.Visibility(this, &STutorialEditableText::GetToolbarVisibility)
|
|
|
|
|
.BorderImage(FEditorStyle::Get().GetBrush("TutorialEditableText.RoundedBackground"))
|
|
|
|
|
.Padding(FMargin(4))
|
|
|
|
|
[
|
|
|
|
|
SNew(SHorizontalBox)
|
|
|
|
|
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
[
|
2014-09-03 06:25:58 -04:00
|
|
|
SAssignNew(FontComboBox, SComboBox<TSharedPtr<FTextStyleAndName>>)
|
2014-08-14 07:42:47 -04:00
|
|
|
.ComboBoxStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.ComboBox")
|
2014-09-03 06:25:58 -04:00
|
|
|
.OptionsSource(&StylesAndNames)
|
|
|
|
|
.OnSelectionChanged(this, &STutorialEditableText::OnActiveStyleChanged)
|
|
|
|
|
.OnGenerateWidget(this, &STutorialEditableText::GenerateStyleComboEntry)
|
|
|
|
|
.ContentPadding(0.0f)
|
|
|
|
|
.InitiallySelectedItem(nullptr)
|
2014-08-14 07:42:47 -04:00
|
|
|
[
|
|
|
|
|
SNew(SBox)
|
|
|
|
|
.Padding(FMargin(0.0f, 0.0f, 2.0f, 0.0f))
|
2014-09-03 06:25:58 -04:00
|
|
|
.MinDesiredWidth(100.0f)
|
2014-08-14 07:42:47 -04:00
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
2014-09-03 06:25:58 -04:00
|
|
|
.Text(this, &STutorialEditableText::GetActiveStyleName)
|
2014-08-14 07:42:47 -04:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.Padding(FMargin(4.0f, 0.0f, 0.0f, 0.0f))
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
[
|
|
|
|
|
SAssignNew(HyperlinkComboButton, SComboButton)
|
2014-09-03 06:25:58 -04:00
|
|
|
.ToolTipText(LOCTEXT("HyperlinkButtonTooltip", "Insert or Edit Hyperlink"))
|
2014-08-14 07:42:47 -04:00
|
|
|
.ComboButtonStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.ComboButton")
|
|
|
|
|
.OnComboBoxOpened(this, &STutorialEditableText::HandleHyperlinkComboOpened)
|
2014-09-03 06:25:58 -04:00
|
|
|
.IsEnabled(this, &STutorialEditableText::IsHyperlinkComboEnabled)
|
|
|
|
|
.ContentPadding(1.0f)
|
2014-08-14 07:42:47 -04:00
|
|
|
.ButtonContent()
|
|
|
|
|
[
|
2014-09-03 06:25:58 -04:00
|
|
|
SNew(SImage)
|
|
|
|
|
.Image(FEditorStyle::Get().GetBrush("TutorialEditableText.Toolbar.HyperlinkImage"))
|
2014-08-14 07:42:47 -04:00
|
|
|
]
|
|
|
|
|
.MenuContent()
|
|
|
|
|
[
|
|
|
|
|
SNew(SGridPanel)
|
|
|
|
|
.FillColumn(1, 1.0f)
|
|
|
|
|
|
|
|
|
|
+SGridPanel::Slot(0, 0)
|
|
|
|
|
.HAlign(HAlign_Right)
|
|
|
|
|
.Padding(FMargin(2.0f))
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
|
|
|
|
.Text(LOCTEXT("HyperlinkNameLabel", "Name:"))
|
|
|
|
|
]
|
|
|
|
|
+SGridPanel::Slot(1, 0)
|
|
|
|
|
.Padding(FMargin(2.0f))
|
|
|
|
|
[
|
|
|
|
|
SNew(SBox)
|
|
|
|
|
.WidthOverride(300)
|
|
|
|
|
[
|
2014-09-03 06:25:58 -04:00
|
|
|
SAssignNew(HyperlinkNameTextBlock, STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
2014-08-14 07:42:47 -04:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
+SGridPanel::Slot(0, 1)
|
|
|
|
|
.HAlign(HAlign_Right)
|
|
|
|
|
.Padding(FMargin(2.0f))
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
|
|
|
|
.Text(LOCTEXT("HyperlinkURLLabel", "URL:"))
|
|
|
|
|
]
|
|
|
|
|
+SGridPanel::Slot(1, 1)
|
|
|
|
|
.Padding(FMargin(2.0f))
|
|
|
|
|
[
|
|
|
|
|
SNew(SBox)
|
|
|
|
|
.WidthOverride(300)
|
|
|
|
|
[
|
|
|
|
|
SAssignNew(HyperlinkURLTextBox, SEditableTextBox)
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
+SGridPanel::Slot(0, 2)
|
|
|
|
|
.HAlign(HAlign_Right)
|
|
|
|
|
.Padding(FMargin(2.0f))
|
|
|
|
|
.ColumnSpan(2)
|
|
|
|
|
[
|
|
|
|
|
SNew(SHorizontalBox)
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
.VAlign(VAlign_Center)
|
|
|
|
|
[
|
|
|
|
|
SNew(SCheckBox)
|
|
|
|
|
.Style(FEditorStyle::Get(), "RadioButton")
|
|
|
|
|
.Type(ESlateCheckBoxType::CheckBox)
|
|
|
|
|
.IsChecked(this, &STutorialEditableText::IsCreatingBrowserLink)
|
|
|
|
|
.OnCheckStateChanged(this, &STutorialEditableText::OnCheckBrowserLink)
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
|
|
|
|
.Text(LOCTEXT("BrowserLinkTypeLabel", "URL"))
|
|
|
|
|
.ToolTipText(LOCTEXT("BrowserLinkTypeTooltip", "A link that opens a browser window (e.g. http://www.unrealengine.com)"))
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
.VAlign(VAlign_Center)
|
|
|
|
|
[
|
|
|
|
|
SNew(SCheckBox)
|
|
|
|
|
.IsEnabled(false)
|
|
|
|
|
.Style(FEditorStyle::Get(), "RadioButton")
|
|
|
|
|
.Type(ESlateCheckBoxType::CheckBox)
|
|
|
|
|
.IsChecked(this, &STutorialEditableText::IsCreatingUDNLink)
|
|
|
|
|
.OnCheckStateChanged(this, &STutorialEditableText::OnCheckUDNLink)
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
|
|
|
|
.Text(LOCTEXT("UDNLinkTypeLabel", "UDN"))
|
|
|
|
|
.ToolTipText(LOCTEXT("UDNLinkTypeTooltip", "A link that opens some UDN documentation (e.g. /Engine/Blueprints/UserGuide/Types/ClassBlueprint)"))
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
.VAlign(VAlign_Center)
|
|
|
|
|
[
|
|
|
|
|
SNew(SCheckBox)
|
|
|
|
|
.IsEnabled(false)
|
|
|
|
|
.Style(FEditorStyle::Get(), "RadioButton")
|
|
|
|
|
.Type(ESlateCheckBoxType::CheckBox)
|
|
|
|
|
.IsChecked(this, &STutorialEditableText::IsCreatingAssetLink)
|
|
|
|
|
.OnCheckStateChanged(this, &STutorialEditableText::OnCheckAssetLink)
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
|
|
|
|
.Text(LOCTEXT("AssetLinkTypeLabel", "Asset"))
|
|
|
|
|
.ToolTipText(LOCTEXT("AssetLinkTypeTooltip", "A link that opens an asset (e.g. Game/StaticMeshes/SphereMesh)"))
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
.VAlign(VAlign_Center)
|
|
|
|
|
[
|
|
|
|
|
SNew(SCheckBox)
|
|
|
|
|
.IsEnabled(false)
|
|
|
|
|
.Style(FEditorStyle::Get(), "RadioButton")
|
|
|
|
|
.Type(ESlateCheckBoxType::CheckBox)
|
|
|
|
|
.IsChecked(this, &STutorialEditableText::IsCreatingCodeLink)
|
|
|
|
|
.OnCheckStateChanged(this, &STutorialEditableText::OnCheckCodeLink)
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
|
|
|
|
.Text(LOCTEXT("CodeLinkTypeLabel", "Code"))
|
|
|
|
|
.ToolTipText(LOCTEXT("CodeLinkTypeTooltip", "A link that opens code (e.g. Private/SourceFile.cpp,1,1)"))
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.AutoWidth()
|
|
|
|
|
.Padding(FMargin(5.0f, 0.0f, 0.0f, 0.0f))
|
|
|
|
|
[
|
|
|
|
|
SNew(SButton)
|
|
|
|
|
.ButtonStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Button")
|
2014-09-03 06:25:58 -04:00
|
|
|
.OnClicked(this, &STutorialEditableText::HandleInsertHyperLinkClicked)
|
2014-08-14 07:42:47 -04:00
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.TextStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Text")
|
2014-09-03 06:25:58 -04:00
|
|
|
.Text(this, &STutorialEditableText::GetHyperlinkButtonText)
|
2014-08-14 07:42:47 -04:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::HandleRichEditableTextChanged(const FText& Text)
|
|
|
|
|
{
|
|
|
|
|
OnTextChanged.ExecuteIfBound(Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::HandleRichEditableTextCommitted(const FText& Text, ETextCommit::Type Type)
|
|
|
|
|
{
|
|
|
|
|
OnTextCommitted.ExecuteIfBound(Text, Type);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
static bool AreRunsTheSame(const TArray<TSharedRef<const IRun>>& Runs)
|
|
|
|
|
{
|
|
|
|
|
if(Runs.Num() == 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSharedRef<const IRun> FirstRun = Runs[0];
|
|
|
|
|
for(const auto& Run : Runs)
|
|
|
|
|
{
|
|
|
|
|
if(Run != FirstRun)
|
|
|
|
|
{
|
|
|
|
|
if(Run->GetRunInfo().Name != FirstRun->GetRunInfo().Name)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(const auto& MetaData : FirstRun->GetRunInfo().MetaData)
|
|
|
|
|
{
|
|
|
|
|
const FString* FoundMetaData = Run->GetRunInfo().MetaData.Find(MetaData.Key);
|
|
|
|
|
if(FoundMetaData == nullptr || *FoundMetaData != MetaData.Value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSharedPtr<const IRun> STutorialEditableText::GetCurrentRun() const
|
|
|
|
|
{
|
|
|
|
|
if(!RichEditableTextBox->GetSelectedText().IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
const TArray<TSharedRef<const IRun>> Runs = RichEditableTextBox->GetSelectedRuns();
|
|
|
|
|
if(Runs.Num() == 1 || AreRunsTheSame(Runs))
|
|
|
|
|
{
|
|
|
|
|
return Runs[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return RichEditableTextBox->GetRunUnderCursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TSharedPtr<const IRun>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 07:42:47 -04:00
|
|
|
void STutorialEditableText::HandleRichEditableTextCursorMoved(const FTextLocation& NewCursorPosition )
|
|
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
TSharedPtr<const IRun> Run = GetCurrentRun();
|
|
|
|
|
|
|
|
|
|
if(Run.IsValid())
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
if(Run->GetRunInfo().Name == TEXT("TextStyle"))
|
|
|
|
|
{
|
|
|
|
|
ActiveStyle = StylesAndNames[0];
|
2014-08-14 07:42:47 -04:00
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
FName StyleName = FTextStyleAndName::GetStyleFromRunInfo(Run->GetRunInfo());
|
|
|
|
|
for(const auto& StyleAndName : StylesAndNames)
|
|
|
|
|
{
|
|
|
|
|
if(StyleAndName->Style == StyleName)
|
|
|
|
|
{
|
|
|
|
|
ActiveStyle = StyleAndName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(Run->GetRunInfo().Name == TEXT("a"))
|
|
|
|
|
{
|
|
|
|
|
ActiveStyle = HyperlinkStyle;
|
|
|
|
|
}
|
2014-08-14 07:42:47 -04:00
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
FontComboBox->SetSelectedItem(ActiveStyle);
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
FontComboBox->SetSelectedItem(nullptr);
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
FText STutorialEditableText::GetActiveStyleName() const
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
return ActiveStyle.IsValid() ? ActiveStyle->DisplayName : FText();
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
void STutorialEditableText::OnActiveStyleChanged(TSharedPtr<FTextStyleAndName> NewValue, ESelectInfo::Type SelectionType)
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
ActiveStyle = NewValue;
|
|
|
|
|
if(SelectionType != ESelectInfo::Direct)
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
// style text if it was the user that made this selection
|
|
|
|
|
if(NewValue == HyperlinkStyle)
|
|
|
|
|
{
|
|
|
|
|
HandleHyperlinkComboOpened();
|
|
|
|
|
HyperlinkComboButton->SetIsOpen(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StyleSelectedText();
|
|
|
|
|
}
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
TSharedRef<SWidget> STutorialEditableText::GenerateStyleComboEntry(TSharedPtr<FTextStyleAndName> SourceEntry)
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
return SNew(SBorder)
|
|
|
|
|
.BorderImage( FCoreStyle::Get().GetBrush( "NoBorder" ) )
|
|
|
|
|
.ForegroundColor(FCoreStyle::Get().GetSlateColor("InvertedForeground"))
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.Text(SourceEntry->DisplayName)
|
|
|
|
|
.TextStyle(&FEditorStyle::Get().GetWidgetStyle<FTextBlockStyle>(SourceEntry->Style))
|
|
|
|
|
];
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::StyleSelectedText()
|
|
|
|
|
{
|
|
|
|
|
// Apply the current style to the selected text
|
|
|
|
|
// If no text is selected, then a new (empty) run will be inserted with the appropriate style
|
2014-09-03 06:25:58 -04:00
|
|
|
if(ActiveStyle.IsValid())
|
|
|
|
|
{
|
|
|
|
|
const FRunInfo RunInfo = ActiveStyle->CreateRunInfo();
|
|
|
|
|
const FTextBlockStyle TextBlockStyle = ActiveStyle->CreateTextBlockStyle();
|
|
|
|
|
RichEditableTextBox->ApplyToSelection(RunInfo, TextBlockStyle);
|
|
|
|
|
FSlateApplication::Get().SetKeyboardFocus(RichEditableTextBox, EKeyboardFocusCause::SetDirectly);
|
|
|
|
|
}
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
|
2014-08-14 07:42:47 -04:00
|
|
|
void STutorialEditableText::HandleHyperlinkComboOpened()
|
|
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
HyperlinkURLTextBox->SetText(FText());
|
|
|
|
|
HyperlinkNameTextBlock->SetText(FText());
|
|
|
|
|
|
2014-08-14 07:42:47 -04:00
|
|
|
// Read any currently selected text, and use this as the default name of the hyperlink
|
|
|
|
|
FString SelectedText = RichEditableTextBox->GetSelectedText().ToString();
|
2014-09-03 06:25:58 -04:00
|
|
|
if(SelectedText.Len() > 0)
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
for(int32 SelectedTextIndex = 0; SelectedTextIndex < SelectedText.Len(); ++SelectedTextIndex)
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
if(FChar::IsLinebreak(SelectedText[SelectedTextIndex]))
|
|
|
|
|
{
|
|
|
|
|
SelectedText = SelectedText.Left(SelectedTextIndex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
2014-09-03 06:25:58 -04:00
|
|
|
HyperlinkNameTextBlock->SetText(FText::FromString(SelectedText));
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
TSharedPtr<const IRun> Run = GetCurrentRun();
|
2014-08-14 07:42:47 -04:00
|
|
|
if(Run.IsValid() && Run->GetRunInfo().Name == TEXT("a"))
|
|
|
|
|
{
|
|
|
|
|
const FString* const URLUnderCursor = Run->GetRunInfo().MetaData.Find(TEXT("href"));
|
|
|
|
|
HyperlinkURLTextBox->SetText((URLUnderCursor) ? FText::FromString(*URLUnderCursor) : FText());
|
2014-09-03 06:25:58 -04:00
|
|
|
FString RunText;
|
|
|
|
|
Run->AppendTextTo(RunText);
|
|
|
|
|
HyperlinkNameTextBlock->SetText(FText::FromString(RunText));
|
|
|
|
|
}
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
bool STutorialEditableText::IsHyperlinkComboEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return ActiveStyle == HyperlinkStyle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FReply STutorialEditableText::HandleInsertHyperLinkClicked()
|
2014-08-14 07:42:47 -04:00
|
|
|
{
|
|
|
|
|
HyperlinkComboButton->SetIsOpen(false);
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
const FText& Name = HyperlinkNameTextBlock->GetText();
|
|
|
|
|
if(!Name.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
const FText& URL = HyperlinkURLTextBox->GetText();
|
2014-08-14 07:42:47 -04:00
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
// Create the correct meta-information for this run, so that valid source rich-text formatting can be generated for it
|
|
|
|
|
FRunInfo RunInfo(TEXT("a"));
|
|
|
|
|
RunInfo.MetaData.Add(TEXT("id"), TEXT("browser"));
|
|
|
|
|
RunInfo.MetaData.Add(TEXT("href"), URL.ToString());
|
|
|
|
|
RunInfo.MetaData.Add(TEXT("style"), TEXT("Tutorials.Content.Hyperlink"));
|
2014-08-14 07:42:47 -04:00
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
// Create the new run, and then insert it at the cursor position
|
|
|
|
|
TSharedRef<FSlateHyperlinkRun> HyperlinkRun = FSlateHyperlinkRun::Create(
|
|
|
|
|
RunInfo,
|
|
|
|
|
MakeShareable(new FString(Name.ToString())),
|
|
|
|
|
FEditorStyle::Get().GetWidgetStyle<FHyperlinkStyle>(FName(TEXT("Tutorials.Content.Hyperlink"))),
|
|
|
|
|
OnBrowserLinkClicked
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// @todo: if the rich editable text box allowed us to replace a run that we found under the cursor (or returned a non-const
|
|
|
|
|
// instance of it) then we could edit the hyperlink here. This would mean the user does not need to select the whole hyperlink
|
|
|
|
|
// to edit its URL.
|
|
|
|
|
RichEditableTextBox->InsertRunAtCursor(HyperlinkRun);
|
|
|
|
|
}
|
2014-08-14 07:42:47 -04:00
|
|
|
|
|
|
|
|
return FReply::Handled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EVisibility STutorialEditableText::GetToolbarVisibility() const
|
|
|
|
|
{
|
2014-09-03 06:25:58 -04:00
|
|
|
return FontComboBox->IsOpen() || HyperlinkComboButton->IsOpen() || HasKeyboardFocus() || HasFocusedDescendants() ? EVisibility::Visible : EVisibility::Collapsed;
|
2014-08-14 07:42:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESlateCheckBoxState::Type STutorialEditableText::IsCreatingBrowserLink() const
|
|
|
|
|
{
|
|
|
|
|
return CurrentHyperlinkType == EHyperlinkType::Browser ? ESlateCheckBoxState::Checked : ESlateCheckBoxState::Unchecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::OnCheckBrowserLink(ESlateCheckBoxState::Type State)
|
|
|
|
|
{
|
|
|
|
|
if(State == ESlateCheckBoxState::Checked)
|
|
|
|
|
{
|
|
|
|
|
CurrentHyperlinkType = EHyperlinkType::Browser;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESlateCheckBoxState::Type STutorialEditableText::IsCreatingUDNLink() const
|
|
|
|
|
{
|
|
|
|
|
return CurrentHyperlinkType == EHyperlinkType::UDN ? ESlateCheckBoxState::Checked : ESlateCheckBoxState::Unchecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::OnCheckUDNLink(ESlateCheckBoxState::Type State)
|
|
|
|
|
{
|
|
|
|
|
if(State == ESlateCheckBoxState::Checked)
|
|
|
|
|
{
|
|
|
|
|
CurrentHyperlinkType = EHyperlinkType::UDN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESlateCheckBoxState::Type STutorialEditableText::IsCreatingTutorialLink() const
|
|
|
|
|
{
|
|
|
|
|
return CurrentHyperlinkType == EHyperlinkType::Tutorial ? ESlateCheckBoxState::Checked : ESlateCheckBoxState::Unchecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::OnCheckTutorialLink(ESlateCheckBoxState::Type State)
|
|
|
|
|
{
|
|
|
|
|
if(State == ESlateCheckBoxState::Checked)
|
|
|
|
|
{
|
|
|
|
|
CurrentHyperlinkType = EHyperlinkType::Tutorial;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESlateCheckBoxState::Type STutorialEditableText::IsCreatingCodeLink() const
|
|
|
|
|
{
|
|
|
|
|
return CurrentHyperlinkType == EHyperlinkType::Code ? ESlateCheckBoxState::Checked : ESlateCheckBoxState::Unchecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::OnCheckCodeLink(ESlateCheckBoxState::Type State)
|
|
|
|
|
{
|
|
|
|
|
if(State == ESlateCheckBoxState::Checked)
|
|
|
|
|
{
|
|
|
|
|
CurrentHyperlinkType = EHyperlinkType::Code;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ESlateCheckBoxState::Type STutorialEditableText::IsCreatingAssetLink() const
|
|
|
|
|
{
|
|
|
|
|
return CurrentHyperlinkType == EHyperlinkType::Asset ? ESlateCheckBoxState::Checked : ESlateCheckBoxState::Unchecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STutorialEditableText::OnCheckAssetLink(ESlateCheckBoxState::Type State)
|
|
|
|
|
{
|
|
|
|
|
if(State == ESlateCheckBoxState::Checked)
|
|
|
|
|
{
|
|
|
|
|
CurrentHyperlinkType = EHyperlinkType::Asset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 06:25:58 -04:00
|
|
|
FText STutorialEditableText::GetHyperlinkButtonText() const
|
|
|
|
|
{
|
|
|
|
|
return bNewHyperlink ? LOCTEXT("HyperlinkInsertLabel", "Insert Hyperlink") : LOCTEXT("HyperlinkSetLabel", "Set Hyperlink");
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 07:42:47 -04:00
|
|
|
#undef LOCTEXT_NAMESPACE
|