2020-05-20 12:48:17 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
2020-05-20 13:04:13 -04:00
# include "SourceControlMenuHelpers.h"
2020-05-20 12:48:17 -04:00
# include "ISourceControlOperation.h"
# include "SourceControlOperations.h"
# include "ISourceControlProvider.h"
# include "ISourceControlModule.h"
2021-01-11 15:31:58 -04:00
# include "ISourceControlWindowsModule.h"
2020-05-20 12:48:17 -04:00
# include "SourceControlMenuHelpers.h"
# include "SourceControlWindows.h"
# include "FileHelpers.h"
# include "ToolMenuContext.h"
# include "ToolMenus.h"
2022-05-09 13:12:28 -04:00
# include "Styling/AppStyle.h"
2020-05-20 13:04:13 -04:00
# include "Widgets/Input/SComboButton.h"
# include "Widgets/Images/SImage.h"
2021-10-20 14:15:53 -04:00
# include "LevelEditorActions.h"
2020-05-20 12:48:17 -04:00
# define LOCTEXT_NAMESPACE "SourceControlCommands"
TSharedRef < FUICommandList > FSourceControlCommands : : ActionList ( new FUICommandList ( ) ) ;
FSourceControlCommands : : FSourceControlCommands ( )
: TCommands < FSourceControlCommands >
(
" SourceControl " ,
NSLOCTEXT ( " Contexts " , " SourceControl " , " Source Control " ) ,
" LevelEditor " ,
2022-05-09 13:12:28 -04:00
FAppStyle : : GetAppStyleSetName ( )
2020-05-20 12:48:17 -04:00
)
{ }
/**
* Initialize commands
*/
void FSourceControlCommands : : RegisterCommands ( )
{
2021-10-20 14:15:53 -04:00
UI_COMMAND ( ConnectToSourceControl , " Connect to Source Control... " , " Connect to source control to allow source control operations to be performed on content and levels. " , EUserInterfaceActionType : : Button , FInputChord ( ) ) ;
2020-05-20 12:48:17 -04:00
UI_COMMAND ( ChangeSourceControlSettings , " Change Source Control Settings... " , " Opens a dialog to change source control settings. " , EUserInterfaceActionType : : Button , FInputChord ( ) ) ;
2021-10-20 14:15:53 -04:00
UI_COMMAND ( ViewChangelists , " View Changelists " , " Opens a dialog displaying current changelists. " , EUserInterfaceActionType : : Button , FInputChord ( ) ) ;
UI_COMMAND ( SubmitContent , " Submit Content " , " Opens a dialog with check in options for content and levels. " , EUserInterfaceActionType : : Button , FInputChord ( ) ) ;
UI_COMMAND ( CheckOutModifiedFiles , " Check Out Modified Files " , " Opens a dialog to check out any assets which have been modified. " , EUserInterfaceActionType : : Button , FInputChord ( ) ) ;
2020-05-20 12:48:17 -04:00
ActionList - > MapAction (
ConnectToSourceControl ,
2021-01-11 15:31:58 -04:00
FExecuteAction : : CreateStatic ( & FSourceControlCommands : : ConnectToSourceControl_Clicked )
2020-05-20 12:48:17 -04:00
) ;
ActionList - > MapAction (
ChangeSourceControlSettings ,
FExecuteAction : : CreateStatic ( & FSourceControlCommands : : ConnectToSourceControl_Clicked )
) ;
2021-01-11 15:31:58 -04:00
ActionList - > MapAction (
ViewChangelists ,
FExecuteAction : : CreateStatic ( & FSourceControlCommands : : ViewChangelists_Clicked ) ,
FCanExecuteAction : : CreateStatic ( & FSourceControlCommands : : ViewChangelists_CanExecute )
) ;
2021-10-20 14:15:53 -04:00
ActionList - > MapAction (
SubmitContent ,
FExecuteAction : : CreateLambda ( [ ] ( ) { FSourceControlWindows : : ChoosePackagesToCheckIn ( ) ; } ) ,
FCanExecuteAction : : CreateStatic ( & FSourceControlWindows : : CanChoosePackagesToCheckIn )
) ;
2020-05-20 12:48:17 -04:00
ActionList - > MapAction (
CheckOutModifiedFiles ,
FExecuteAction : : CreateStatic ( & FSourceControlCommands : : CheckOutModifiedFiles_Clicked ) ,
FCanExecuteAction : : CreateStatic ( & FSourceControlCommands : : CheckOutModifiedFiles_CanExecute )
) ;
}
void FSourceControlCommands : : ConnectToSourceControl_Clicked ( )
{
// Show login window regardless of current status - its useful as a shortcut to change settings.
ISourceControlModule & SourceControlModule = ISourceControlModule : : Get ( ) ;
SourceControlModule . ShowLoginDialog ( FSourceControlLoginClosed ( ) , ELoginWindowMode : : Modeless , EOnLoginWindowStartup : : PreserveProvider ) ;
}
2021-01-11 15:31:58 -04:00
bool FSourceControlCommands : : ViewChangelists_CanExecute ( )
{
2021-03-17 13:43:31 -04:00
return ISourceControlWindowsModule : : Get ( ) . CanShowChangelistsTab ( ) ;
2021-01-11 15:31:58 -04:00
}
void FSourceControlCommands : : ViewChangelists_Clicked ( )
{
ISourceControlWindowsModule : : Get ( ) . ShowChangelistsTab ( ) ;
}
2020-05-20 12:48:17 -04:00
bool FSourceControlCommands : : CheckOutModifiedFiles_CanExecute ( )
{
ISourceControlModule & SourceControlModule = ISourceControlModule : : Get ( ) ;
if ( ISourceControlModule : : Get ( ) . IsEnabled ( ) & &
ISourceControlModule : : Get ( ) . GetProvider ( ) . IsAvailable ( ) )
{
TArray < UPackage * > PackagesToSave ;
FEditorFileUtils : : GetDirtyWorldPackages ( PackagesToSave ) ;
FEditorFileUtils : : GetDirtyContentPackages ( PackagesToSave ) ;
return PackagesToSave . Num ( ) > 0 ;
}
return false ;
}
void FSourceControlCommands : : CheckOutModifiedFiles_Clicked ( )
{
TArray < UPackage * > PackagesToSave ;
FEditorFileUtils : : GetDirtyWorldPackages ( PackagesToSave ) ;
FEditorFileUtils : : GetDirtyContentPackages ( PackagesToSave ) ;
const bool bCheckDirty = true ;
const bool bPromptUserToSave = false ;
FEditorFileUtils : : PromptForCheckoutAndSave ( PackagesToSave , bCheckDirty , bPromptUserToSave ) ;
}
FSourceControlMenuHelpers : : EQueryState FSourceControlMenuHelpers : : QueryState = FSourceControlMenuHelpers : : EQueryState : : NotQueried ;
void FSourceControlMenuHelpers : : CheckSourceControlStatus ( )
{
ISourceControlModule & SourceControlModule = ISourceControlModule : : Get ( ) ;
if ( SourceControlModule . IsEnabled ( ) )
{
SourceControlModule . GetProvider ( ) . Execute ( ISourceControlOperation : : Create < FConnect > ( ) ,
EConcurrency : : Asynchronous ,
FSourceControlOperationComplete : : CreateStatic ( & FSourceControlMenuHelpers : : OnSourceControlOperationComplete ) ) ;
QueryState = EQueryState : : Querying ;
}
}
void FSourceControlMenuHelpers : : OnSourceControlOperationComplete ( const FSourceControlOperationRef & InOperation , ECommandResult : : Type InResult )
{
QueryState = EQueryState : : Queried ;
}
TSharedRef < SWidget > FSourceControlMenuHelpers : : GenerateSourceControlMenuContent ( )
{
UToolMenu * SourceControlMenu = UToolMenus : : Get ( ) - > RegisterMenu ( " StatusBar.ToolBar.SourceControl " , NAME_None , EMultiBoxType : : Menu , false ) ;
FToolMenuSection & Section = SourceControlMenu - > AddSection ( " SourceControlActions " , LOCTEXT ( " SourceControlMenuHeadingActions " , " Actions " ) ) ;
2021-01-11 15:31:58 -04:00
Section . AddMenuEntry (
FSourceControlCommands : : Get ( ) . ViewChangelists ,
TAttribute < FText > ( ) ,
TAttribute < FText > ( ) ,
2022-05-09 13:12:28 -04:00
FSlateIcon ( FAppStyle : : GetAppStyleSetName ( ) , " SourceControl.ChangelistsTab " )
2021-01-11 15:31:58 -04:00
) ;
2021-10-20 14:15:53 -04:00
Section . AddMenuEntry (
FSourceControlCommands : : Get ( ) . SubmitContent ,
TAttribute < FText > ( ) ,
TAttribute < FText > ( ) ,
2022-05-09 13:12:28 -04:00
FSlateIcon ( FAppStyle : : GetAppStyleSetName ( ) , " SourceControl.Actions.Submit " )
2021-10-20 14:15:53 -04:00
) ;
2020-05-20 12:48:17 -04:00
Section . AddMenuEntry (
FSourceControlCommands : : Get ( ) . CheckOutModifiedFiles ,
TAttribute < FText > ( ) ,
TAttribute < FText > ( ) ,
2022-05-09 13:12:28 -04:00
FSlateIcon ( FAppStyle : : GetAppStyleSetName ( ) , " SourceControl.Actions.CheckOut " )
2020-05-20 12:48:17 -04:00
) ;
2021-10-20 14:15:53 -04:00
Section . AddDynamicEntry ( " ConnectToSourceControl " , FNewToolMenuSectionDelegate : : CreateLambda ( [ ] ( FToolMenuSection & InSection )
{
ISourceControlModule & SourceControlModule = ISourceControlModule : : Get ( ) ;
if ( ISourceControlModule : : Get ( ) . IsEnabled ( ) & & ISourceControlModule : : Get ( ) . GetProvider ( ) . IsAvailable ( ) )
{
InSection . AddMenuEntry (
FSourceControlCommands : : Get ( ) . ChangeSourceControlSettings ,
TAttribute < FText > ( ) ,
TAttribute < FText > ( ) ,
2022-05-09 13:12:28 -04:00
FSlateIcon ( FAppStyle : : GetAppStyleSetName ( ) , " SourceControl.Actions.ChangeSettings " )
2021-10-20 14:15:53 -04:00
) ;
}
else
{
InSection . AddMenuEntry (
FSourceControlCommands : : Get ( ) . ConnectToSourceControl ,
TAttribute < FText > ( ) ,
TAttribute < FText > ( ) ,
2022-05-09 13:12:28 -04:00
FSlateIcon ( FAppStyle : : GetAppStyleSetName ( ) , " SourceControl.Actions.Connect " )
2021-10-20 14:15:53 -04:00
) ;
}
} ) ) ;
2020-05-20 12:48:17 -04:00
return UToolMenus : : Get ( ) - > GenerateWidget ( " StatusBar.ToolBar.SourceControl " , FToolMenuContext ( FSourceControlCommands : : ActionList ) ) ;
}
FText FSourceControlMenuHelpers : : GetSourceControlStatusText ( )
{
if ( QueryState = = EQueryState : : Querying )
{
return LOCTEXT ( " SourceControlStatus_Querying " , " Contacting Server.... " ) ;
}
else
{
ISourceControlModule & SourceControlModule = ISourceControlModule : : Get ( ) ;
if ( SourceControlModule . IsEnabled ( ) )
{
if ( ! SourceControlModule . GetProvider ( ) . IsAvailable ( ) )
{
2022-03-04 16:10:23 -05:00
return LOCTEXT ( " SourceControlStatus_Error_ServerUnavailable " , " Server Unavailable " ) ;
2020-05-20 12:48:17 -04:00
}
else
{
return LOCTEXT ( " SourceControlStatus_Available " , " Source Control " ) ;
}
}
else
{
2022-03-04 16:10:23 -05:00
return LOCTEXT ( " SourceControlStatus_Error_Off " , " Source Control Off " ) ;
2020-05-20 12:48:17 -04:00
}
}
}
FText FSourceControlMenuHelpers : : GetSourceControlTooltip ( )
{
if ( QueryState = = EQueryState : : Querying )
{
return LOCTEXT ( " SourceControlUnknown " , " Source control status is unknown " ) ;
}
else
{
return ISourceControlModule : : Get ( ) . GetProvider ( ) . GetStatusText ( ) ;
}
}
const FSlateBrush * FSourceControlMenuHelpers : : GetSourceControlIcon ( )
{
if ( QueryState = = EQueryState : : Querying )
{
static const FSlateBrush * QueryBrush = FAppStyle : : Get ( ) . GetBrush ( " SourceControl.StatusIcon.Unknown " ) ;
return QueryBrush ;
}
else
{
ISourceControlModule & SourceControlModule = ISourceControlModule : : Get ( ) ;
if ( SourceControlModule . IsEnabled ( ) )
{
if ( ! SourceControlModule . GetProvider ( ) . IsAvailable ( ) )
{
static const FSlateBrush * ErrorBrush = FAppStyle : : Get ( ) . GetBrush ( " SourceControl.StatusIcon.Error " ) ;
return ErrorBrush ;
}
else
{
static const FSlateBrush * OnBrush = FAppStyle : : Get ( ) . GetBrush ( " SourceControl.StatusIcon.On " ) ;
return OnBrush ;
}
}
else
{
static const FSlateBrush * OffBrush = FAppStyle : : Get ( ) . GetBrush ( " SourceControl.StatusIcon.Off " ) ;
return OffBrush ;
}
}
}
TSharedRef < SWidget > FSourceControlMenuHelpers : : MakeSourceControlStatusWidget ( )
{
return
SNew ( SComboButton )
. ContentPadding ( FMargin ( 6.0f , 0.0f ) )
. ToolTipText_Static ( & FSourceControlMenuHelpers : : GetSourceControlTooltip )
. MenuPlacement ( MenuPlacement_AboveAnchor )
. ComboButtonStyle ( & FAppStyle : : Get ( ) . GetWidgetStyle < FComboButtonStyle > ( " StatusBar.StatusBarComboButton " ) )
. ButtonContent ( )
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
. HAlign ( HAlign_Center )
[
SNew ( SImage )
. Image_Static ( & FSourceControlMenuHelpers : : GetSourceControlIcon )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. VAlign ( VAlign_Center )
2021-01-05 16:38:18 -04:00
. Padding ( FMargin ( 5 , 0 , 0 , 0 ) )
2020-05-20 12:48:17 -04:00
[
SNew ( STextBlock )
. TextStyle ( & FAppStyle : : Get ( ) . GetWidgetStyle < FTextBlockStyle > ( " NormalText " ) )
. Text_Static ( & FSourceControlMenuHelpers : : GetSourceControlStatusText )
]
]
2021-05-27 13:50:26 -04:00
. OnGetMenuContent ( FOnGetContent : : CreateStatic ( & FSourceControlMenuHelpers : : GenerateSourceControlMenuContent ) )
;
2020-05-20 12:48:17 -04:00
}
# undef LOCTEXT_NAMESPACE