2018-12-14 13:41:00 -05:00
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
2014-08-14 07:42:47 -04:00
# include "STutorialEditableText.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
# include "Misc/PackageName.h"
# include "SlateOptMacros.h"
# include "Framework/Text/SlateImageRun.h"
# include "Widgets/Images/SImage.h"
# include "Framework/Text/ITextDecorator.h"
# include "Widgets/Layout/SGridPanel.h"
# include "Widgets/Input/SMultiLineEditableTextBox.h"
# include "Widgets/Input/SEditableTextBox.h"
# include "Widgets/Input/SButton.h"
# include "Widgets/Input/SCheckBox.h"
# include "EditorStyleSet.h"
# include "EditorDirectories.h"
# include "Framework/Text/RichTextLayoutMarshaller.h"
2014-09-12 05:28:34 -04:00
# include "TutorialText.h"
2014-09-18 08:09:29 -04:00
# include "TutorialImageDecorator.h"
# include "DesktopPlatformModule.h"
2014-08-14 07:42:47 -04:00
# define LOCTEXT_NAMESPACE "STutorialEditableText"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void STutorialEditableText : : Construct ( const FArguments & InArgs )
{
OnTextChanged = InArgs . _OnTextChanged ;
OnTextCommitted = InArgs . _OnTextCommitted ;
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 > > ( ) ,
2014-09-18 08:09:29 -04:00
& FEditorStyle : : Get ( )
2014-08-14 07:42:47 -04:00
) ;
2014-09-04 09:59:45 -04:00
2014-09-12 05:28:34 -04:00
TArray < TSharedRef < class ITextDecorator > > Decorators ;
2014-10-08 06:07:52 -04:00
const bool bForEditing = true ;
FTutorialText : : GetRichTextDecorators ( bForEditing , Decorators ) ;
2014-09-04 09:59:45 -04:00
2014-09-12 05:28:34 -04:00
for ( auto & Decorator : Decorators )
2014-09-04 09:59:45 -04:00
{
2014-09-12 05:28:34 -04:00
RichTextMarshaller - > AppendInlineDecorator ( Decorator ) ;
2014-09-04 09:59:45 -04:00
}
2014-09-12 05:28:34 -04:00
CurrentHyperlinkType = FTutorialText : : GetHyperLinkDescs ( ) [ 0 ] ;
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 )
2015-06-25 08:43:42 -04:00
. ClearTextSelectionOnFocusLoss ( false )
2014-08-14 07:42:47 -04:00
. 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 )
2014-09-04 09:59:45 -04:00
. VAlign ( VAlign_Center )
2014-08-14 07:42:47 -04:00
. 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 )
2014-09-04 09:59:45 -04:00
. VAlign ( VAlign_Center )
2014-08-14 07:42:47 -04:00
. 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 )
2014-09-04 09:59:45 -04:00
. VAlign ( VAlign_Center )
2014-08-14 07:42:47 -04:00
. Padding ( FMargin ( 2.0f ) )
2014-09-04 09:59:45 -04:00
[
SNew ( STextBlock )
. TextStyle ( FEditorStyle : : Get ( ) , " TutorialEditableText.Toolbar.Text " )
. Text ( LOCTEXT ( " HyperlinkTypeLabel " , " Type: " ) )
]
+ SGridPanel : : Slot ( 1 , 2 )
. Padding ( FMargin ( 2.0f ) )
. VAlign ( VAlign_Center )
2014-08-14 07:42:47 -04:00
. ColumnSpan ( 2 )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
[
2014-09-04 09:59:45 -04:00
SNew ( SComboBox < TSharedPtr < FHyperlinkTypeDesc > > )
2014-09-12 05:28:34 -04:00
. OptionsSource ( & FTutorialText : : GetHyperLinkDescs ( ) )
2014-09-04 09:59:45 -04:00
. ComboBoxStyle ( FEditorStyle : : Get ( ) , " TutorialEditableText.Toolbar.ComboBox " )
. OnSelectionChanged ( this , & STutorialEditableText : : OnActiveHyperlinkChanged )
. OnGenerateWidget ( this , & STutorialEditableText : : GenerateHyperlinkComboEntry )
. ContentPadding ( 0.0f )
2014-09-12 05:28:34 -04:00
. InitiallySelectedItem ( FTutorialText : : GetHyperLinkDescs ( ) [ 0 ] )
2014-09-04 09:59:45 -04:00
. Content ( )
2014-08-14 07:42:47 -04:00
[
2014-09-04 09:59:45 -04:00
SNew ( SBox )
. Padding ( FMargin ( 0.0f , 0.0f , 2.0f , 0.0f ) )
. MinDesiredWidth ( 100.0f )
[
SNew ( STextBlock )
. TextStyle ( FEditorStyle : : Get ( ) , " TutorialEditableText.Toolbar.Text " )
. Text ( this , & STutorialEditableText : : GetActiveHyperlinkName )
. ToolTipText ( this , & STutorialEditableText : : GetActiveHyperlinkTooltip )
]
2014-08-14 07:42:47 -04:00
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
2014-09-04 09:59:45 -04:00
. Padding ( 5.0f , 0.0f , 0.0f , 0.0f )
2014-08-14 07:42:47 -04:00
[
SNew ( SCheckBox )
2014-09-04 09:59:45 -04:00
. ToolTipText ( LOCTEXT ( " OpenAssetTooltip " , " Should this link open the asset or just highlight it in the content browser? " ) )
. Visibility ( this , & STutorialEditableText : : GetOpenAssetVisibility )
. IsChecked ( this , & STutorialEditableText : : IsOpenAssetChecked )
. OnCheckStateChanged ( this , & STutorialEditableText : : HandleOpenAssetCheckStateChanged )
2014-08-14 07:42:47 -04:00
[
SNew ( STextBlock )
. TextStyle ( FEditorStyle : : Get ( ) , " TutorialEditableText.Toolbar.Text " )
2014-09-04 09:59:45 -04:00
. Text ( LOCTEXT ( " OpenAssetLabel " , " Open Asset " ) )
2014-08-14 07:42:47 -04:00
]
]
+ SHorizontalBox : : Slot ( )
2014-09-12 05:28:34 -04:00
. AutoWidth ( )
. VAlign ( VAlign_Center )
. Padding ( 5.0f , 0.0f , 0.0f , 0.0f )
[
SAssignNew ( UDNExcerptTextBox , SEditableTextBox )
. HintText ( LOCTEXT ( " ExcerptHint " , " Excerpt " ) )
. ToolTipText ( LOCTEXT ( " ExcerptAssetTooltip " , " Enter the excerpt that should be used for this link's rich tooltip " ) )
. Visibility ( this , & STutorialEditableText : : GetExcerptVisibility )
]
+ SHorizontalBox : : Slot ( )
2014-09-04 09:59:45 -04:00
. FillWidth ( 1.0f )
2014-08-14 07:42:47 -04:00
. VAlign ( VAlign_Center )
2014-09-04 09:59:45 -04:00
. HAlign ( HAlign_Right )
2014-08-14 07:42:47 -04:00
[
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
]
]
]
]
]
2014-09-18 08:09:29 -04:00
+ SHorizontalBox : : Slot ( )
. Padding ( FMargin ( 4.0f , 0.0f , 0.0f , 0.0f ) )
. AutoWidth ( )
[
SNew ( SButton )
. ToolTipText ( LOCTEXT ( " ImageButtonTooltip " , " Insert Image " ) )
. ButtonStyle ( FEditorStyle : : Get ( ) , " TutorialEditableText.Toolbar.Button " )
. OnClicked ( this , & STutorialEditableText : : HandleImageButtonClicked )
. ContentPadding ( 1.0f )
. Content ( )
[
SNew ( SImage )
. Image ( FEditorStyle : : Get ( ) . GetBrush ( " TutorialEditableText.Toolbar.ImageImage " ) )
]
]
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 ) ;
2014-10-30 12:29:36 -04:00
FSlateApplication : : Get ( ) . SetKeyboardFocus ( RichEditableTextBox , EFocusCause : : SetDirectly ) ;
2014-09-03 06:25:58 -04:00
}
2014-08-14 07:42:47 -04:00
}
2014-09-04 09:59:45 -04:00
TSharedPtr < FHyperlinkTypeDesc > STutorialEditableText : : GetHyperlinkTypeFromId ( const FString & InId ) const
{
TSharedPtr < FHyperlinkTypeDesc > FoundType ;
2014-09-12 05:28:34 -04:00
for ( const auto & Desc : FTutorialText : : GetHyperLinkDescs ( ) )
2014-09-04 09:59:45 -04:00
{
if ( Desc - > Id = = InId )
{
return Desc ;
}
}
return FoundType ;
}
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-04 09:59:45 -04:00
const FString * const IdUnderCursor = Run - > GetRunInfo ( ) . MetaData . Find ( TEXT ( " id " ) ) ;
2014-09-12 05:28:34 -04:00
CurrentHyperlinkType = IdUnderCursor ? GetHyperlinkTypeFromId ( * IdUnderCursor ) : FTutorialText : : GetHyperLinkDescs ( ) [ 0 ] ;
2014-09-04 09:59:45 -04:00
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 " ) ) ;
2014-09-04 09:59:45 -04:00
RunInfo . MetaData . Add ( TEXT ( " id " ) , CurrentHyperlinkType - > Id ) ;
2014-09-03 06:25:58 -04:00
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-04 09:59:45 -04:00
if ( CurrentHyperlinkType - > Type = = EHyperlinkType : : Asset )
{
RunInfo . MetaData . Add ( TEXT ( " action " ) , bOpenAsset ? TEXT ( " edit " ) : TEXT ( " select " ) ) ;
}
2014-09-12 05:28:34 -04:00
else if ( CurrentHyperlinkType - > Type = = EHyperlinkType : : UDN & & ! UDNExcerptTextBox - > GetText ( ) . IsEmpty ( ) )
{
RunInfo . MetaData . Add ( TEXT ( " excerpt " ) , UDNExcerptTextBox - > GetText ( ) . ToString ( ) ) ;
}
2014-09-04 09:59:45 -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 " ) ) ) ,
2014-09-12 06:48:53 -04:00
CurrentHyperlinkType - > OnClickedDelegate ,
CurrentHyperlinkType - > TooltipDelegate ,
CurrentHyperlinkType - > TooltipTextDelegate
2014-09-03 06:25:58 -04:00
) ;
// @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
}
2014-09-03 06:25:58 -04:00
FText STutorialEditableText : : GetHyperlinkButtonText ( ) const
{
return bNewHyperlink ? LOCTEXT ( " HyperlinkInsertLabel " , " Insert Hyperlink " ) : LOCTEXT ( " HyperlinkSetLabel " , " Set Hyperlink " ) ;
}
2014-09-04 09:59:45 -04:00
void STutorialEditableText : : OnActiveHyperlinkChanged ( TSharedPtr < FHyperlinkTypeDesc > NewValue , ESelectInfo : : Type SelectionType )
{
CurrentHyperlinkType = NewValue ;
}
TSharedRef < SWidget > STutorialEditableText : : GenerateHyperlinkComboEntry ( TSharedPtr < FHyperlinkTypeDesc > SourceEntry )
{
return SNew ( SBorder )
. BorderImage ( FCoreStyle : : Get ( ) . GetBrush ( " NoBorder " ) )
. ForegroundColor ( FCoreStyle : : Get ( ) . GetSlateColor ( " InvertedForeground " ) )
[
SNew ( STextBlock )
. Text ( SourceEntry - > Text )
. ToolTipText ( SourceEntry - > TooltipText )
. TextStyle ( & FEditorStyle : : Get ( ) . GetWidgetStyle < FTextBlockStyle > ( " TutorialEditableText.Toolbar.Text " ) )
] ;
}
FText STutorialEditableText : : GetActiveHyperlinkName ( ) const
{
if ( CurrentHyperlinkType . IsValid ( ) )
{
return CurrentHyperlinkType - > Text ;
}
return FText ( ) ;
}
FText STutorialEditableText : : GetActiveHyperlinkTooltip ( ) const
{
if ( CurrentHyperlinkType . IsValid ( ) )
{
return CurrentHyperlinkType - > TooltipText ;
}
return FText ( ) ;
}
EVisibility STutorialEditableText : : GetOpenAssetVisibility ( ) const
{
return CurrentHyperlinkType . IsValid ( ) & & CurrentHyperlinkType - > Type = = EHyperlinkType : : Asset ? EVisibility : : Visible : EVisibility : : Collapsed ;
}
2014-12-10 14:24:09 -05:00
void STutorialEditableText : : HandleOpenAssetCheckStateChanged ( ECheckBoxState InCheckState )
2014-09-04 09:59:45 -04:00
{
bOpenAsset = ! bOpenAsset ;
}
2014-12-10 14:24:09 -05:00
ECheckBoxState STutorialEditableText : : IsOpenAssetChecked ( ) const
2014-09-04 09:59:45 -04:00
{
2014-12-10 14:24:09 -05:00
return bOpenAsset ? ECheckBoxState : : Checked : ECheckBoxState : : Unchecked ;
2014-09-04 09:59:45 -04:00
}
2014-09-12 05:28:34 -04:00
EVisibility STutorialEditableText : : GetExcerptVisibility ( ) const
{
return CurrentHyperlinkType . IsValid ( ) & & CurrentHyperlinkType - > Type = = EHyperlinkType : : UDN ? EVisibility : : Visible : EVisibility : : Collapsed ;
}
2014-09-18 08:09:29 -04:00
FReply STutorialEditableText : : HandleImageButtonClicked ( )
{
IDesktopPlatform * DesktopPlatform = FDesktopPlatformModule : : Get ( ) ;
if ( DesktopPlatform )
{
TArray < FString > OutFiles ;
const FString Extension ( TEXT ( " png " ) ) ;
const FString Filter = FString : : Printf ( TEXT ( " %s files (*.%s)|*.%s " ) , * Extension , * Extension , * Extension ) ;
const FString DefaultPath = FEditorDirectories : : Get ( ) . GetLastDirectory ( ELastDirectory : : GENERIC_IMPORT ) ;
TSharedPtr < SWindow > ParentWindow = FSlateApplication : : Get ( ) . FindWidgetWindow ( AsShared ( ) ) ;
void * ParentWindowHandle = ( ParentWindow . IsValid ( ) & & ParentWindow - > GetNativeWindow ( ) . IsValid ( ) ) ? ParentWindow - > GetNativeWindow ( ) - > GetOSWindowHandle ( ) : nullptr ;
if ( DesktopPlatform - > OpenFileDialog ( ParentWindowHandle , FText : : Format ( LOCTEXT ( " ImagePickerDialogTitle " , " Choose a {0} file " ) , FText : : FromString ( Extension ) ) . ToString ( ) , DefaultPath , TEXT ( " " ) , Filter , EFileDialogFlags : : None , OutFiles ) )
{
check ( OutFiles . Num ( ) = = 1 ) ;
FRunInfo RunInfo ( TEXT ( " img " ) ) ;
// the path to the image needs to be stored either as a 'long package name' version of itself
// (minus png extension) or as a literal (base dir relative) path.
FString ContentPath ;
if ( FPackageName : : TryConvertFilenameToLongPackageName ( OutFiles [ 0 ] , ContentPath ) )
{
RunInfo . MetaData . Add ( TEXT ( " src " ) , ContentPath ) ;
}
else
{
RunInfo . MetaData . Add ( TEXT ( " src " ) , OutFiles [ 0 ] ) ;
}
TSharedRef < FSlateImageRun > ImageRun = FSlateImageRun : : Create (
RunInfo ,
MakeShareable ( new FString ( TEXT ( " \x200B " ) ) ) , // Zero-Width Breaking Space
FName ( * FTutorialImageDecorator : : GetPathToImage ( OutFiles [ 0 ] ) ) ,
0
) ;
RichEditableTextBox - > InsertRunAtCursor ( ImageRun ) ;
FEditorDirectories : : Get ( ) . SetLastDirectory ( ELastDirectory : : GENERIC_IMPORT , FPaths : : GetPath ( OutFiles [ 0 ] ) ) ;
}
}
return FReply : : Handled ( ) ;
}
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
# undef LOCTEXT_NAMESPACE