2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-07-21 17:31:27 -04:00
# include "UnrealEd.h"
# include "EditorClassUtils.h"
# include "IDocumentation.h"
# include "SourceCodeNavigation.h"
2014-10-14 22:50:06 -04:00
# include "SHyperlink.h"
2014-07-21 17:31:27 -04:00
2014-07-30 13:01:03 -04:00
FString FEditorClassUtils : : GetDocumentationPage ( const UClass * Class )
2014-07-28 13:25:15 -04:00
{
2014-07-30 13:01:03 -04:00
return ( Class ? FString : : Printf ( TEXT ( " Shared/Types/%s%s " ) , Class - > GetPrefixCPP ( ) , * Class - > GetName ( ) ) : FString ( ) ) ;
2014-07-28 13:25:15 -04:00
}
2014-07-30 13:01:03 -04:00
FString FEditorClassUtils : : GetDocumentationExcerpt ( const UClass * Class )
2014-07-28 13:25:15 -04:00
{
2014-07-30 13:01:03 -04:00
return ( Class ? FString : : Printf ( TEXT ( " %s%s " ) , Class - > GetPrefixCPP ( ) , * Class - > GetName ( ) ) : FString ( ) ) ;
2014-07-28 13:25:15 -04:00
}
2014-07-21 17:31:27 -04:00
TSharedRef < SToolTip > FEditorClassUtils : : GetTooltip ( const UClass * Class )
{
2014-08-11 10:55:47 -04:00
return ( Class ? GetTooltip ( Class , Class - > GetToolTipText ( ) ) : SNew ( SToolTip ) ) ;
}
TSharedRef < SToolTip > FEditorClassUtils : : GetTooltip ( const UClass * Class , const TAttribute < FText > & OverrideText )
{
return ( Class ? IDocumentation : : Get ( ) - > CreateToolTip ( OverrideText , nullptr , GetDocumentationPage ( Class ) , GetDocumentationExcerpt ( Class ) ) : SNew ( SToolTip ) ) ;
2014-07-21 17:31:27 -04:00
}
2014-09-05 08:25:23 -04:00
FString FEditorClassUtils : : GetDocumentationLinkFromExcerpt ( const FString & DocLink , const FString DocExcerpt )
2014-07-21 17:31:27 -04:00
{
FString DocumentationLink ;
TSharedRef < IDocumentation > Documentation = IDocumentation : : Get ( ) ;
2014-09-05 08:25:23 -04:00
if ( Documentation - > PageExists ( DocLink ) )
2014-07-21 17:31:27 -04:00
{
2014-09-05 08:25:23 -04:00
TSharedRef < IDocumentationPage > ClassDocs = Documentation - > GetPage ( DocLink , NULL ) ;
2014-08-12 09:31:30 -04:00
2014-07-21 17:31:27 -04:00
FExcerpt Excerpt ;
2014-09-05 08:25:23 -04:00
if ( ClassDocs - > GetExcerpt ( DocExcerpt , Excerpt ) )
2014-07-21 17:31:27 -04:00
{
2014-09-05 08:25:23 -04:00
FString * FullDocumentationLink = Excerpt . Variables . Find ( TEXT ( " ToolTipFullLink " ) ) ;
2014-07-21 17:31:27 -04:00
if ( FullDocumentationLink )
{
DocumentationLink = * FullDocumentationLink ;
}
}
}
return DocumentationLink ;
}
2014-09-05 08:25:23 -04:00
FString FEditorClassUtils : : GetDocumentationLink ( const UClass * Class , const FString & OverrideExcerpt )
{
const FString ClassDocsPage = GetDocumentationPage ( Class ) ;
const FString ExcerptSection = ( OverrideExcerpt . IsEmpty ( ) ? GetDocumentationExcerpt ( Class ) : OverrideExcerpt ) ;
return GetDocumentationLinkFromExcerpt ( ClassDocsPage , ExcerptSection ) ;
}
2014-07-21 17:31:27 -04:00
TSharedRef < SWidget > FEditorClassUtils : : GetDocumentationLinkWidget ( const UClass * Class )
{
TSharedRef < SWidget > DocLinkWidget = SNullWidget : : NullWidget ;
const FString DocumentationLink = GetDocumentationLink ( Class ) ;
if ( ! DocumentationLink . IsEmpty ( ) )
{
DocLinkWidget = IDocumentation : : Get ( ) - > CreateAnchor ( DocumentationLink ) ;
}
return DocLinkWidget ;
}
TSharedRef < SWidget > FEditorClassUtils : : GetSourceLink ( const UClass * Class , const TWeakObjectPtr < UObject > ObjectWeakPtr )
2015-02-05 05:41:34 -05:00
{
2015-02-16 08:38:28 -05:00
const FText BlueprintFormat = NSLOCTEXT ( " SourceHyperlink " , " EditBlueprint " , " Edit {0} " ) ;
const FText CodeFormat = NSLOCTEXT ( " SourceHyperlink " , " GoToCode " , " Open {0} " ) ;
2015-02-05 05:41:34 -05:00
return GetSourceLinkFormatted ( Class , ObjectWeakPtr , BlueprintFormat , CodeFormat ) ;
}
TSharedRef < SWidget > FEditorClassUtils : : GetSourceLinkFormatted ( const UClass * Class , const TWeakObjectPtr < UObject > ObjectWeakPtr , const FText & BlueprintFormat , const FText & CodeFormat )
2014-07-21 17:31:27 -04:00
{
2014-08-25 13:41:38 -04:00
TSharedRef < SWidget > SourceHyperlink = SNew ( SSpacer ) ;
2014-07-30 13:01:03 -04:00
UBlueprint * Blueprint = ( Class ? Cast < UBlueprint > ( Class - > ClassGeneratedBy ) : nullptr ) ;
2014-07-21 17:31:27 -04:00
2014-07-30 13:01:03 -04:00
if ( Blueprint )
2014-07-21 17:31:27 -04:00
{
struct Local
{
static void OnEditBlueprintClicked ( TWeakObjectPtr < UBlueprint > InBlueprint , TWeakObjectPtr < UObject > InAsset )
{
2015-02-25 12:55:30 -05:00
if ( UBlueprint * BlueprintToEdit = InBlueprint . Get ( ) )
2014-07-21 17:31:27 -04:00
{
// Set the object being debugged if given an actor reference (if we don't do this before we edit the object the editor wont know we are debugging something)
if ( UObject * Asset = InAsset . Get ( ) )
{
2015-02-25 12:55:30 -05:00
check ( Asset - > GetClass ( ) - > ClassGeneratedBy = = BlueprintToEdit ) ;
BlueprintToEdit - > SetObjectBeingDebugged ( Asset ) ;
2014-07-21 17:31:27 -04:00
}
// Open the blueprint
2015-02-25 12:55:30 -05:00
GEditor - > EditObject ( BlueprintToEdit ) ;
2014-07-21 17:31:27 -04:00
}
}
} ;
TWeakObjectPtr < UBlueprint > BlueprintPtr = Blueprint ;
2014-10-10 15:37:56 -04:00
SourceHyperlink = SNew ( SHyperlink )
2015-02-16 08:38:28 -05:00
. Style ( FEditorStyle : : Get ( ) , " Common.GotoBlueprintHyperlink " )
2014-07-21 17:31:27 -04:00
. OnNavigate_Static ( & Local : : OnEditBlueprintClicked , BlueprintPtr , ObjectWeakPtr )
2015-02-05 05:41:34 -05:00
. Text ( FText : : Format ( BlueprintFormat , FText : : FromString ( Blueprint - > GetName ( ) ) ) )
2014-07-21 17:31:27 -04:00
. ToolTipText ( NSLOCTEXT ( " SourceHyperlink " , " EditBlueprint_ToolTip " , " Click to edit the blueprint " ) ) ;
}
else if ( FSourceCodeNavigation : : IsCompilerAvailable ( ) )
{
FString ClassHeaderPath ;
if ( FSourceCodeNavigation : : FindClassHeaderPath ( Class , ClassHeaderPath ) & & IFileManager : : Get ( ) . FileSize ( * ClassHeaderPath ) ! = INDEX_NONE )
{
struct Local
{
static void OnEditCodeClicked ( FString InClassHeaderPath )
{
FString AbsoluteHeaderPath = IFileManager : : Get ( ) . ConvertToAbsolutePathForExternalAppForRead ( * InClassHeaderPath ) ;
FSourceCodeNavigation : : OpenSourceFile ( AbsoluteHeaderPath ) ;
}
} ;
2014-10-10 15:37:56 -04:00
SourceHyperlink = SNew ( SHyperlink )
2015-02-16 08:38:28 -05:00
. Style ( FEditorStyle : : Get ( ) , " Common.GotoNativeCodeHyperlink " )
2014-07-21 17:31:27 -04:00
. OnNavigate_Static ( & Local : : OnEditCodeClicked , ClassHeaderPath )
2015-02-05 05:41:34 -05:00
. Text ( FText : : Format ( CodeFormat , FText : : FromString ( FPaths : : GetCleanFilename ( * ClassHeaderPath ) ) ) )
2015-02-10 13:26:26 -05:00
. ToolTipText ( FText : : Format ( NSLOCTEXT ( " SourceHyperlink " , " GoToCode_ToolTip " , " Click to open this source file in {0} " ) , FSourceCodeNavigation : : GetSuggestedSourceCodeIDE ( ) ) ) ;
2014-07-21 17:31:27 -04:00
}
}
return SourceHyperlink ;
2014-08-06 10:11:22 -04:00
}
UClass * FEditorClassUtils : : GetClassFromString ( const FString & ClassName )
{
if ( ClassName . IsEmpty ( ) | | ClassName = = " None " )
{
return nullptr ;
}
UClass * Class = FindObject < UClass > ( ANY_PACKAGE , * ClassName ) ;
if ( ! Class )
{
Class = LoadObject < UClass > ( nullptr , * ClassName ) ;
}
return Class ;
}