2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "SourceControlPrivatePCH.h"
# include "SSourceControlPicker.h"
# include "SourceControlModule.h"
# include "SSourceControlLogin.h"
# if SOURCE_CONTROL_WITH_SLATE
# define LOCTEXT_NAMESPACE "SSourceControlPicker"
void SSourceControlPicker : : Construct ( const FArguments & InArgs )
{
ChildSlot
[
2014-04-02 18:09:23 -04:00
SNew ( SBorder )
. BorderImage ( FEditorStyle : : GetBrush ( " DetailsView.CategoryTop " ) )
. Padding ( FMargin ( 0.0f , 3.0f , 1.0f , 0.0f ) )
2014-03-14 14:13:41 -04:00
[
2014-04-02 18:09:23 -04:00
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. VAlign ( VAlign_Center )
. FillWidth ( 1.0f )
. Padding ( 2.0f )
2014-03-14 14:13:41 -04:00
[
SNew ( STextBlock )
2014-04-02 18:09:23 -04:00
. Text ( LOCTEXT ( " ProviderLabel " , " Provider " ) )
2014-03-14 14:13:41 -04:00
. Font ( FEditorStyle : : GetFontStyle ( TEXT ( " SourceControl.LoginWindow.Font " ) ) )
]
2014-04-02 18:09:23 -04:00
+ SHorizontalBox : : Slot ( )
. FillWidth ( 2.0f )
[
SNew ( SComboButton )
. OnGetMenuContent ( this , & SSourceControlPicker : : OnGetMenuContent )
. ContentPadding ( 1 )
. ToolTipText ( LOCTEXT ( " ChooseProvider " , " Choose the source control provider you want to use before you edit login settings. " ) )
. ButtonContent ( )
[
SNew ( STextBlock )
. Text ( this , & SSourceControlPicker : : OnGetButtonText )
. Font ( FEditorStyle : : GetFontStyle ( TEXT ( " SourceControl.LoginWindow.Font " ) ) )
]
]
2014-03-14 14:13:41 -04:00
]
] ;
}
void SSourceControlPicker : : ChangeSourceControlProvider ( int32 ProviderIndex ) const
{
FSourceControlModule & SourceControlModule = FSourceControlModule : : Get ( ) ;
SourceControlModule . SetCurrentSourceControlProvider ( ProviderIndex ) ;
if ( SourceControlModule . GetLoginWidget ( ) . IsValid ( ) )
{
SourceControlModule . GetLoginWidget ( ) - > RefreshSettings ( ) ;
}
}
TSharedRef < SWidget > SSourceControlPicker : : OnGetMenuContent ( ) const
{
FSourceControlModule & SourceControlModule = FSourceControlModule : : Get ( ) ;
FMenuBuilder MenuBuilder ( true , NULL ) ;
// Get the provider names first so that we can sort them for the UI
TArray < TPair < FName , int32 > > SortedProviderNames ;
const int NumProviders = SourceControlModule . GetNumSourceControlProviders ( ) ;
SortedProviderNames . Reserve ( NumProviders ) ;
for ( int ProviderIndex = 0 ; ProviderIndex < NumProviders ; + + ProviderIndex )
{
const FName ProviderName = SourceControlModule . GetSourceControlProviderName ( ProviderIndex ) ;
2015-01-19 06:43:28 -05:00
int32 ProviderSortKey = ProviderName = = FName ( " None " ) ? - 1 * ProviderIndex : ProviderIndex ;
SortedProviderNames . Add ( TPairInitializer < FName , int32 > ( ProviderName , ProviderSortKey ) ) ;
2014-03-14 14:13:41 -04:00
}
2015-01-19 06:43:28 -05:00
// Sort based on the provider index
2014-03-14 14:13:41 -04:00
SortedProviderNames . Sort ( [ ] ( const TPair < FName , int32 > & One , const TPair < FName , int32 > & Two )
{
2015-01-19 06:43:28 -05:00
return One . Value < Two . Value ;
2014-03-14 14:13:41 -04:00
} ) ;
for ( auto SortedProviderNameIter = SortedProviderNames . CreateConstIterator ( ) ; SortedProviderNameIter ; + + SortedProviderNameIter )
{
const FText ProviderText = GetProviderText ( SortedProviderNameIter - > Key ) ;
const int32 ProviderIndex = SortedProviderNameIter - > Value ;
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " ProviderName " ) , ProviderText ) ;
MenuBuilder . AddMenuEntry (
ProviderText ,
FText : : Format ( LOCTEXT ( " SourceControlProvider_Tooltip " , " Use {ProviderName} as source control provider " ) , Arguments ) ,
FSlateIcon ( ) ,
FUIAction (
2015-01-19 06:43:28 -05:00
FExecuteAction : : CreateSP ( this , & SSourceControlPicker : : ChangeSourceControlProvider , FMath : : Abs ( ProviderIndex ) ) ,
2014-03-14 14:13:41 -04:00
FCanExecuteAction ( )
)
) ;
}
return MenuBuilder . MakeWidget ( ) ;
}
FText SSourceControlPicker : : OnGetButtonText ( ) const
{
return GetProviderText ( ISourceControlModule : : Get ( ) . GetProvider ( ) . GetName ( ) ) ;
}
FText SSourceControlPicker : : GetProviderText ( const FName & InName ) const
{
if ( InName = = " None " )
{
2015-01-30 10:30:56 -05:00
return LOCTEXT ( " NoProviderDescription " , " None (source control disabled) " ) ;
2014-03-14 14:13:41 -04:00
}
2015-01-30 10:30:56 -05:00
// @todo: Remove this block after the Git plugin has been exhaustively tested (also remember to change the Git plugin's "IsBetaVersion" setting to false.)
if ( InName = = " Git " )
{
return LOCTEXT ( " GitBetaProviderName " , " Git (beta version) " ) ;
}
2014-03-14 14:13:41 -04:00
return FText : : FromName ( InName ) ;
}
# undef LOCTEXT_NAMESPACE
# endif // SOURCE_CONTROL_WITH_SLATE