2014-03-14 14:13:41 -04:00
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
# include "SettingsEditorPrivatePCH.h"
2014-07-18 14:18:55 -04:00
# include "EngineAnalytics.h"
# include "AnalyticsEventAttribute.h"
# include "IAnalyticsProvider.h"
2014-09-18 23:05:52 -04:00
# include "SSettingsEditorCheckoutNotice.h"
2014-03-14 14:13:41 -04:00
# define LOCTEXT_NAMESPACE "SSettingsEditor"
/* SSettingsEditor structors
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SSettingsEditor : : ~ SSettingsEditor ( )
{
Model - > OnSelectionChanged ( ) . RemoveAll ( this ) ;
SettingsContainer - > OnCategoryModified ( ) . RemoveAll ( this ) ;
2014-04-23 19:25:46 -04:00
FCoreDelegates : : OnCultureChanged . RemoveAll ( this ) ;
2014-03-14 14:13:41 -04:00
}
/* SSettingsEditor interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SSettingsEditor : : Construct ( const FArguments & InArgs , const ISettingsEditorModelRef & InModel )
{
Model = InModel ;
SettingsContainer = InModel - > GetSettingsContainer ( ) ;
// initialize settings view
FDetailsViewArgs DetailsViewArgs ;
{
DetailsViewArgs . bAllowSearch = true ;
DetailsViewArgs . bHideSelectionTip = true ;
DetailsViewArgs . bLockable = false ;
DetailsViewArgs . bObjectsUseNameArea = false ;
DetailsViewArgs . bSearchInitialKeyFocus = true ;
DetailsViewArgs . bUpdatesFromSelection = false ;
DetailsViewArgs . NotifyHook = this ;
DetailsViewArgs . bShowOptions = true ;
DetailsViewArgs . bShowModifiedPropertiesOption = false ;
}
SettingsView = FModuleManager : : GetModuleChecked < FPropertyEditorModule > ( " PropertyEditor " ) . CreateDetailView ( DetailsViewArgs ) ;
SettingsView - > SetVisibility ( TAttribute < EVisibility > : : Create ( TAttribute < EVisibility > : : FGetter : : CreateSP ( this , & SSettingsEditor : : HandleSettingsViewVisibility ) ) ) ;
2014-04-02 18:09:23 -04:00
SettingsView - > SetIsPropertyEditingEnabledDelegate ( FIsPropertyEditingEnabled : : CreateSP ( this , & SSettingsEditor : : HandleSettingsViewEnabled ) ) ;
2014-03-14 14:13:41 -04:00
2014-09-19 00:01:10 -04:00
// Create the watcher widget for the default config file (checks file status / SCC state)
FileWatcherWidget =
SNew ( SSettingsEditorCheckoutNotice )
. Visibility ( this , & SSettingsEditor : : HandleDefaultConfigNoticeVisibility )
2014-09-19 00:46:17 -04:00
. OnFileProbablyModifiedExternally ( this , & SSettingsEditor : : ReloadConfigObject )
2014-09-19 00:01:10 -04:00
. ConfigFilePath ( this , & SSettingsEditor : : GetConfigFileName ) ;
2014-03-14 14:13:41 -04:00
ChildSlot
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. FillHeight ( 1.0f )
2014-09-09 12:13:47 -04:00
. Padding ( 16.0f , 0.0f )
2014-03-14 14:13:41 -04:00
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
2014-09-09 12:13:47 -04:00
. Padding ( 0.0f , 16.0f )
2014-03-14 14:13:41 -04:00
[
// categories menu
SNew ( SScrollBox )
+ SScrollBox : : Slot ( )
[
2014-04-02 18:09:23 -04:00
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
SAssignNew ( CategoriesBox , SVerticalBox )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
SNew ( SSpacer )
. Size ( FVector2D ( 24.0f , 0.0f ) )
]
2014-03-14 14:13:41 -04:00
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( FMargin ( 24.0f , 0.0f , 24.0f , 0.0f ) )
[
SNew ( SSeparator )
2014-04-23 19:25:46 -04:00
. Orientation ( Orient_Vertical )
2014-03-14 14:13:41 -04:00
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 1.0f )
2014-09-09 12:13:47 -04:00
. Padding ( 0.0f , 16.0f )
2014-03-14 14:13:41 -04:00
[
SNew ( SVerticalBox )
. Visibility ( this , & SSettingsEditor : : HandleSettingsBoxVisibility )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
[
// title and button bar
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. FillWidth ( 1.0f )
[
SNew ( SVerticalBox )
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
[
// category title
SNew ( STextBlock )
. Font ( FSlateFontInfo ( FPaths : : EngineContentDir ( ) / TEXT ( " Slate/Fonts/Roboto-Regular.ttf " ) , 18 ) )
. Text ( this , & SSettingsEditor : : HandleSettingsBoxTitleText )
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
. Padding ( 0.0f , 8.0f , 0.0f , 0.0f )
[
// category description
SNew ( STextBlock )
. ColorAndOpacity ( FSlateColor : : UseSubduedForeground ( ) )
. Text ( this , & SSettingsEditor : : HandleSettingsBoxDescriptionText )
]
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Bottom )
. Padding ( 16.0f , 0.0f , 0.0f , 0.0f )
[
2014-05-07 14:46:21 -04:00
// set as default button
2014-03-14 14:13:41 -04:00
SNew ( SButton )
2014-09-17 19:13:07 -04:00
. Visibility ( this , & SSettingsEditor : : EditingNonDefaultSettingsVisibility )
2014-05-07 14:46:21 -04:00
. IsEnabled ( this , & SSettingsEditor : : HandleSetAsDefaultButtonEnabled )
. OnClicked ( this , & SSettingsEditor : : HandleSetAsDefaultButtonClicked )
2014-03-14 14:13:41 -04:00
. Text ( LOCTEXT ( " SaveDefaultsButtonText " , " Set as Default " ) )
. ToolTipText ( LOCTEXT ( " SaveDefaultsButtonTooltip " , " Save the values below as the new default settings " ) )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Bottom )
. Padding ( 8.0f , 0.0f , 0.0f , 0.0f )
[
// export button
SNew ( SButton )
. IsEnabled ( this , & SSettingsEditor : : HandleExportButtonEnabled )
. OnClicked ( this , & SSettingsEditor : : HandleExportButtonClicked )
. Text ( LOCTEXT ( " ExportButtonText " , " Export... " ) )
. ToolTipText ( LOCTEXT ( " ExportButtonTooltip " , " Export these settings to a file on your computer " ) )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Bottom )
. Padding ( 8.0f , 0.0f , 0.0f , 0.0f )
[
// import button
SNew ( SButton )
. IsEnabled ( this , & SSettingsEditor : : HandleImportButtonEnabled )
. OnClicked ( this , & SSettingsEditor : : HandleImportButtonClicked )
. Text ( LOCTEXT ( " ImportButtonText " , " Import... " ) )
. ToolTipText ( LOCTEXT ( " ImportButtonTooltip " , " Import these settings from a file on your computer " ) )
]
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. HAlign ( HAlign_Right )
. VAlign ( VAlign_Bottom )
. Padding ( 8.0f , 0.0f , 0.0f , 0.0f )
[
// reset defaults button
SNew ( SButton )
2014-09-17 19:13:07 -04:00
. Visibility ( this , & SSettingsEditor : : EditingNonDefaultSettingsVisibility )
2014-03-14 14:13:41 -04:00
. IsEnabled ( this , & SSettingsEditor : : HandleResetToDefaultsButtonEnabled )
. OnClicked ( this , & SSettingsEditor : : HandleResetDefaultsButtonClicked )
. Text ( LOCTEXT ( " ResetDefaultsButtonText " , " Reset to Defaults " ) )
. ToolTipText ( LOCTEXT ( " ResetDefaultsButtonTooltip " , " Reset the settings below to their default values " ) )
]
]
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
2014-09-19 00:46:17 -04:00
. Padding ( 0.0f , 16.0f , 0.0f , 0.0f )
2014-03-14 14:13:41 -04:00
[
2014-09-19 00:01:10 -04:00
FileWatcherWidget . ToSharedRef ( )
2014-03-14 14:13:41 -04:00
]
+ SVerticalBox : : Slot ( )
. FillHeight ( 1.0f )
2014-09-19 18:15:51 -04:00
. Padding ( 0.0f , 16.0f , 0.0f , 0.0f )
2014-03-14 14:13:41 -04:00
[
// settings area
SNew ( SOverlay )
+ SOverlay : : Slot ( )
[
SettingsView . ToSharedRef ( )
]
+ SOverlay : : Slot ( )
. Expose ( CustomWidgetSlot )
]
]
]
] ;
2014-04-23 19:25:46 -04:00
FCoreDelegates : : OnCultureChanged . AddSP ( this , & SSettingsEditor : : HandleCultureChanged ) ;
2014-03-14 14:13:41 -04:00
Model - > OnSelectionChanged ( ) . AddSP ( this , & SSettingsEditor : : HandleModelSelectionChanged ) ;
SettingsContainer - > OnCategoryModified ( ) . AddSP ( this , & SSettingsEditor : : HandleSettingsContainerCategoryModified ) ;
ReloadCategories ( ) ;
}
/* FNotifyHook interface
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SSettingsEditor : : NotifyPostChange ( const FPropertyChangedEvent & PropertyChangedEvent , class FEditPropertyChain * PropertyThatChanged )
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) & & ( PropertyChangedEvent . ChangeType ! = EPropertyChangeType : : Interactive ) )
{
2014-07-18 14:18:55 -04:00
RecordPreferenceChangedAnalytics ( SelectedSection , PropertyChangedEvent ) ;
2014-03-14 14:13:41 -04:00
SelectedSection - > Save ( ) ;
}
}
/* SSettingsEditor implementation
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool SSettingsEditor : : CheckOutDefaultConfigFile ( )
{
2014-05-29 17:31:02 -04:00
TWeakObjectPtr < UObject > SettingsObject = GetSelectedSettingsObject ( ) ;
if ( ! SettingsObject . IsValid ( ) )
{
return false ;
}
2014-03-14 14:13:41 -04:00
FText ErrorMessage ;
// check out configuration file
2014-05-29 17:31:02 -04:00
FString AbsoluteConfigFilePath = GetDefaultConfigFilePath ( SettingsObject ) ;
TArray < FString > FilesToBeCheckedOut ;
FilesToBeCheckedOut . Add ( AbsoluteConfigFilePath ) ;
2014-03-14 14:13:41 -04:00
2014-05-29 17:31:02 -04:00
ISourceControlProvider & SourceControlProvider = ISourceControlModule : : Get ( ) . GetProvider ( ) ;
FSourceControlStatePtr SourceControlState = SourceControlProvider . GetState ( AbsoluteConfigFilePath , EStateCacheUsage : : ForceUpdate ) ;
if ( SourceControlState . IsValid ( ) )
2014-03-14 14:13:41 -04:00
{
2014-05-29 17:31:02 -04:00
if ( SourceControlState - > IsDeleted ( ) )
2014-03-14 14:13:41 -04:00
{
2014-05-29 17:31:02 -04:00
ErrorMessage = LOCTEXT ( " ConfigFileMarkedForDeleteError " , " Error: The configuration file is marked for deletion. " ) ;
}
else if ( ! SourceControlState - > IsCurrent ( ) )
{
if ( false )
2014-03-14 14:13:41 -04:00
{
2014-05-29 17:31:02 -04:00
if ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FSync > ( ) , FilesToBeCheckedOut ) = = ECommandResult : : Succeeded )
2014-03-14 14:13:41 -04:00
{
2014-05-29 17:31:02 -04:00
SettingsObject - > ReloadConfig ( ) ;
}
else
{
ErrorMessage = LOCTEXT ( " FailedToSyncConfigFileError " , " Error: Failed to sync the configuration file to head revision. " ) ;
2014-03-14 14:13:41 -04:00
}
}
2014-05-29 17:31:02 -04:00
}
else if ( SourceControlState - > CanCheckout ( ) | | SourceControlState - > IsCheckedOutOther ( ) )
{
if ( SourceControlProvider . Execute ( ISourceControlOperation : : Create < FCheckOut > ( ) , FilesToBeCheckedOut ) = = ECommandResult : : Failed )
2014-03-14 14:13:41 -04:00
{
2014-05-29 17:31:02 -04:00
ErrorMessage = LOCTEXT ( " FailedToCheckOutConfigFileError " , " Error: Failed to check out the configuration file. " ) ;
2014-03-14 14:13:41 -04:00
}
}
}
// show errors, if any
if ( ! ErrorMessage . IsEmpty ( ) )
{
FMessageDialog : : Open ( EAppMsgType : : Ok , ErrorMessage ) ;
return false ;
}
return true ;
}
2014-05-29 17:31:02 -04:00
FString SSettingsEditor : : GetDefaultConfigFilePath ( const TWeakObjectPtr < UObject > & SettingsObject ) const
{
2014-09-22 09:41:38 -04:00
FString RelativeConfigFilePath = SettingsObject - > GetDefaultConfigFilename ( ) ;
2014-05-29 17:31:02 -04:00
return FPaths : : ConvertRelativePathToFull ( RelativeConfigFilePath ) ;
}
2014-03-14 14:13:41 -04:00
TWeakObjectPtr < UObject > SSettingsEditor : : GetSelectedSettingsObject ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
return SelectedSection - > GetSettingsObject ( ) ;
}
return nullptr ;
}
TSharedRef < SWidget > SSettingsEditor : : MakeCategoryWidget ( const ISettingsCategoryRef & Category )
{
// create section widgets
TSharedRef < SVerticalBox > SectionsBox = SNew ( SVerticalBox ) ;
TArray < ISettingsSectionPtr > Sections ;
if ( Category - > GetSections ( Sections ) = = 0 )
{
return SNullWidget : : NullWidget ;
}
2014-04-23 19:25:46 -04:00
// sort the sections alphabetically
struct FSectionSortPredicate
{
FORCEINLINE bool operator ( ) ( ISettingsSectionPtr A , ISettingsSectionPtr B ) const
{
if ( ! A . IsValid ( ) & & ! B . IsValid ( ) )
{
return false ;
}
if ( A . IsValid ( ) ! = B . IsValid ( ) )
{
return B . IsValid ( ) ;
}
return ( A - > GetDisplayName ( ) . CompareTo ( B - > GetDisplayName ( ) ) < 0 ) ;
}
} ;
Sections . Sort ( FSectionSortPredicate ( ) ) ;
2014-03-14 14:13:41 -04:00
// list the sections
2014-05-08 20:23:50 -04:00
for ( const ISettingsSectionPtr Section : Sections )
2014-03-14 14:13:41 -04:00
{
SectionsBox - > AddSlot ( )
. HAlign ( HAlign_Left )
2014-09-09 12:13:47 -04:00
. Padding ( 0.0f , 10.0f , 0.0f , 0.0f )
2014-03-14 14:13:41 -04:00
[
SNew ( SHorizontalBox )
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
. Padding ( 0.0f , 0.0f , 4.0f , 0.0f )
. VAlign ( VAlign_Center )
[
SNew ( SImage )
. Image ( FEditorStyle : : Get ( ) . GetBrush ( " TreeArrow_Collapsed_Hovered " ) )
. Visibility ( this , & SSettingsEditor : : HandleSectionLinkImageVisibility , Section )
]
+ SHorizontalBox : : Slot ( )
. FillWidth ( 1.0f )
. VAlign ( VAlign_Center )
[
SNew ( SHyperlink )
. OnNavigate ( this , & SSettingsEditor : : HandleSectionLinkNavigate , Section )
. Text ( Section - > GetDisplayName ( ) )
. ToolTipText ( Section - > GetDescription ( ) )
]
] ;
2014-05-08 20:23:50 -04:00
if ( ! Model - > GetSelectedSection ( ) . IsValid ( ) )
{
Model - > SelectSection ( Section ) ;
}
2014-03-14 14:13:41 -04:00
}
// create category widget
2014-09-09 12:13:47 -04:00
return SNew ( SVerticalBox )
2014-03-14 14:13:41 -04:00
2014-09-09 12:13:47 -04:00
+ SVerticalBox : : Slot ( )
. AutoHeight ( )
2014-03-14 14:13:41 -04:00
[
2014-09-09 12:13:47 -04:00
// category title
SNew ( STextBlock )
. Font ( FSlateFontInfo ( FPaths : : EngineContentDir ( ) / TEXT ( " Slate/Fonts/Roboto-Regular.ttf " ) , 18 ) )
. Text ( Category - > GetDisplayName ( ) )
2014-03-14 14:13:41 -04:00
]
2014-09-09 12:13:47 -04:00
+ SVerticalBox : : Slot ( )
. FillHeight ( 1.0f )
2014-03-14 14:13:41 -04:00
[
2014-09-09 12:13:47 -04:00
// sections list
SectionsBox
2014-03-14 14:13:41 -04:00
] ;
}
2014-05-29 17:31:02 -04:00
bool SSettingsEditor : : MakeDefaultConfigFileWritable ( )
{
TWeakObjectPtr < UObject > SettingsObject = GetSelectedSettingsObject ( ) ;
if ( ! SettingsObject . IsValid ( ) )
{
return false ;
}
FString AbsoluteConfigFilePath = GetDefaultConfigFilePath ( SettingsObject ) ;
return FPlatformFileManager : : Get ( ) . GetPlatformFile ( ) . SetReadOnly ( * AbsoluteConfigFilePath , false ) ;
}
void SSettingsEditor : : ReloadCategories ( )
2014-03-14 14:13:41 -04:00
{
CategoriesBox - > ClearChildren ( ) ;
TArray < ISettingsCategoryPtr > Categories ;
SettingsContainer - > GetCategories ( Categories ) ;
2014-05-08 20:23:50 -04:00
for ( const ISettingsCategoryPtr Category : Categories )
2014-03-14 14:13:41 -04:00
{
CategoriesBox - > AddSlot ( )
. AutoHeight ( )
2014-09-09 12:13:47 -04:00
. Padding ( 0.0f , 0.0f , 0.0f , 16.0f )
2014-03-14 14:13:41 -04:00
[
2014-05-08 20:23:50 -04:00
MakeCategoryWidget ( Category . ToSharedRef ( ) )
2014-03-14 14:13:41 -04:00
] ;
}
}
2014-05-07 14:46:21 -04:00
void SSettingsEditor : : ShowNotification ( const FText & Text , SNotificationItem : : ECompletionState CompletionState ) const
{
FNotificationInfo Notification ( Text ) ;
Notification . ExpireDuration = 3.f ;
Notification . bUseSuccessFailIcons = false ;
FSlateNotificationManager : : Get ( ) . AddNotification ( Notification ) - > SetCompletionState ( CompletionState ) ;
}
2014-03-14 14:13:41 -04:00
/* SSettingsEditor callbacks
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-04-23 19:25:46 -04:00
void SSettingsEditor : : HandleCultureChanged ( )
{
ReloadCategories ( ) ;
}
2014-05-08 20:23:50 -04:00
2014-07-18 14:18:55 -04:00
void SSettingsEditor : : RecordPreferenceChangedAnalytics ( ISettingsSectionPtr SelectedSection , const FPropertyChangedEvent & PropertyChangedEvent ) const
{
UProperty * ChangedProperty = PropertyChangedEvent . MemberProperty ;
// submit analytics data
if ( FEngineAnalytics : : IsAvailable ( ) & & ChangedProperty ! = nullptr )
{
TArray < FAnalyticsEventAttribute > EventAttributes ;
EventAttributes . Add ( FAnalyticsEventAttribute ( TEXT ( " PropertySection " ) , SelectedSection - > GetDisplayName ( ) . ToString ( ) ) ) ;
EventAttributes . Add ( FAnalyticsEventAttribute ( TEXT ( " PropertyClass " ) , ChangedProperty - > GetOwnerClass ( ) - > GetName ( ) ) ) ;
EventAttributes . Add ( FAnalyticsEventAttribute ( TEXT ( " PropertyName " ) , ChangedProperty - > GetName ( ) ) ) ;
FEngineAnalytics : : GetProvider ( ) . RecordEvent ( TEXT ( " Editor.Usage.PreferencesChanged " ) , EventAttributes ) ;
}
}
2014-09-19 00:01:10 -04:00
FString SSettingsEditor : : GetConfigFileName ( ) const
{
TWeakObjectPtr < UObject > SettingsObject = GetSelectedSettingsObject ( ) ;
if ( SettingsObject . IsValid ( ) & & SettingsObject - > GetClass ( ) - > HasAnyClassFlags ( CLASS_Config | CLASS_DefaultConfig ) )
{
return GetDefaultConfigFilePath ( SettingsObject ) ;
}
else
{
return FString ( ) ;
}
}
2014-03-14 14:13:41 -04:00
EVisibility SSettingsEditor : : HandleDefaultConfigNoticeVisibility ( ) const
{
TWeakObjectPtr < UObject > SettingsObject = GetSelectedSettingsObject ( ) ;
if ( SettingsObject . IsValid ( ) & & SettingsObject - > GetClass ( ) - > HasAnyClassFlags ( CLASS_DefaultConfig ) )
{
return EVisibility : : Visible ;
}
return EVisibility : : Collapsed ;
}
FReply SSettingsEditor : : HandleExportButtonClicked ( )
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
if ( LastExportDir . IsEmpty ( ) )
{
LastExportDir = FPaths : : GetPath ( GEditorUserSettingsIni ) ;
}
FString DefaultFileName = FString : : Printf ( TEXT ( " %s Backup %s.ini " ) , * SelectedSection - > GetDisplayName ( ) . ToString ( ) , * FDateTime : : Now ( ) . ToString ( TEXT ( " %Y-%m-%d %H%M%S " ) ) ) ;
TArray < FString > OutFiles ;
TSharedPtr < SWindow > ParentWindow = FSlateApplication : : Get ( ) . FindWidgetWindow ( AsShared ( ) ) ;
void * ParentWindowHandle = ( ParentWindow . IsValid ( ) & & ParentWindow - > GetNativeWindow ( ) . IsValid ( ) ) ? ParentWindow - > GetNativeWindow ( ) - > GetOSWindowHandle ( ) : nullptr ;
if ( FDesktopPlatformModule : : Get ( ) - > SaveFileDialog ( ParentWindowHandle , LOCTEXT ( " ExportSettingsDialogTitle " , " Export settings... " ) . ToString ( ) , LastExportDir , DefaultFileName , TEXT ( " Config files (*.ini)|*.ini " ) , EFileDialogFlags : : None , OutFiles ) )
{
if ( SelectedSection - > Export ( OutFiles [ 0 ] ) )
{
2014-05-07 14:46:21 -04:00
ShowNotification ( LOCTEXT ( " ExportSettingsSuccess " , " Export settings succeeded " ) , SNotificationItem : : CS_Success ) ;
}
else
{
ShowNotification ( LOCTEXT ( " ExportSettingsFailure " , " Export settings failed " ) , SNotificationItem : : CS_Fail ) ;
}
2014-03-14 14:13:41 -04:00
}
}
return FReply : : Handled ( ) ;
}
bool SSettingsEditor : : HandleExportButtonEnabled ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
return SelectedSection - > CanExport ( ) ;
}
return false ;
}
FReply SSettingsEditor : : HandleImportButtonClicked ( )
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
TArray < FString > OutFiles ;
TSharedPtr < SWindow > ParentWindow = FSlateApplication : : Get ( ) . FindWidgetWindow ( AsShared ( ) ) ;
void * ParentWindowHandle = ( ParentWindow . IsValid ( ) & & ParentWindow - > GetNativeWindow ( ) . IsValid ( ) ) ? ParentWindow - > GetNativeWindow ( ) - > GetOSWindowHandle ( ) : nullptr ;
if ( FDesktopPlatformModule : : Get ( ) - > OpenFileDialog ( ParentWindowHandle , LOCTEXT ( " ImportSettingsDialogTitle " , " Import settings... " ) . ToString ( ) , FPaths : : GetPath ( GEditorUserSettingsIni ) , TEXT ( " " ) , TEXT ( " Config files (*.ini)|*.ini " ) , EFileDialogFlags : : None , OutFiles ) )
{
2014-05-07 05:33:38 -04:00
if ( SelectedSection - > Import ( OutFiles [ 0 ] ) & & SelectedSection - > Save ( ) )
2014-05-07 14:46:21 -04:00
{
ShowNotification ( LOCTEXT ( " ImportSettingsSuccess " , " Import settings succeeded " ) , SNotificationItem : : CS_Success ) ;
}
else
{
ShowNotification ( LOCTEXT ( " ImportSettingsFailure " , " Import settings failed " ) , SNotificationItem : : CS_Fail ) ;
}
2014-03-14 14:13:41 -04:00
}
}
return FReply : : Handled ( ) ;
}
bool SSettingsEditor : : HandleImportButtonEnabled ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
2014-09-19 00:01:10 -04:00
return SelectedSection - > CanEdit ( ) & & SelectedSection - > CanImport ( ) & & ! IsDefaultConfigCheckOutNeeded ( ) ;
2014-03-14 14:13:41 -04:00
}
return false ;
}
void SSettingsEditor : : HandleModelSelectionChanged ( )
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
TSharedPtr < SWidget > CustomWidget = SelectedSection - > GetCustomWidget ( ) . Pin ( ) ;
// show settings widget
if ( CustomWidget . IsValid ( ) )
{
2014-07-28 06:53:40 -04:00
CustomWidgetSlot - > AttachWidget ( CustomWidget . ToSharedRef ( ) ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-07-28 06:53:40 -04:00
CustomWidgetSlot - > AttachWidget ( SNullWidget : : NullWidget ) ;
2014-03-14 14:13:41 -04:00
}
SettingsView - > SetObject ( SelectedSection - > GetSettingsObject ( ) . Get ( ) ) ;
// focus settings widget
TSharedPtr < SWidget > FocusWidget ;
if ( CustomWidget . IsValid ( ) )
{
FocusWidget = CustomWidget ;
}
else
{
FocusWidget = SettingsView ;
}
FWidgetPath FocusWidgetPath ;
if ( FSlateApplication : : Get ( ) . GeneratePathToWidgetUnchecked ( FocusWidget . ToSharedRef ( ) , FocusWidgetPath ) )
{
FSlateApplication : : Get ( ) . SetKeyboardFocus ( FocusWidgetPath , EKeyboardFocusCause : : SetDirectly ) ;
}
}
else
{
2014-07-28 06:53:40 -04:00
CustomWidgetSlot - > AttachWidget ( SNullWidget : : NullWidget ) ;
2014-03-14 14:13:41 -04:00
SettingsView - > SetObject ( nullptr ) ;
}
2014-09-19 00:01:10 -04:00
FileWatcherWidget - > Invalidate ( ) ;
2014-03-14 14:13:41 -04:00
}
FReply SSettingsEditor : : HandleResetDefaultsButtonClicked ( )
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
SelectedSection - > ResetDefaults ( ) ;
}
return FReply : : Handled ( ) ;
}
bool SSettingsEditor : : HandleResetToDefaultsButtonEnabled ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
return ( SelectedSection - > CanEdit ( ) & & SelectedSection - > CanResetDefaults ( ) ) ;
}
return false ;
}
2014-09-17 19:13:07 -04:00
EVisibility SSettingsEditor : : EditingNonDefaultSettingsVisibility ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
return ( SelectedSection . IsValid ( ) & & SelectedSection - > HasDefaultSettingsObject ( ) ) ? EVisibility : : Collapsed : EVisibility : : Visible ;
}
2014-05-07 14:46:21 -04:00
void SSettingsEditor : : HandleSectionLinkNavigate ( ISettingsSectionPtr Section )
{
Model - > SelectSection ( Section ) ;
}
EVisibility SSettingsEditor : : HandleSectionLinkImageVisibility ( ISettingsSectionPtr Section ) const
{
if ( Model - > GetSelectedSection ( ) = = Section )
{
return EVisibility : : Visible ;
}
return EVisibility : : Hidden ;
}
FReply SSettingsEditor : : HandleSetAsDefaultButtonClicked ( )
2014-03-14 14:13:41 -04:00
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
2014-09-19 00:01:10 -04:00
if ( IsDefaultConfigCheckOutNeeded ( ) )
2014-03-14 14:13:41 -04:00
{
if ( ISourceControlModule : : Get ( ) . IsEnabled ( ) )
{
2014-06-25 05:32:15 -04:00
if ( FMessageDialog : : Open ( EAppMsgType : : YesNo , LOCTEXT ( " SaveAsDefaultNeedsCheckoutMessage " , " The default configuration file for these settings is currently not checked out. Would you like to check it out from source control? " ) ) ! = EAppReturnType : : Yes )
2014-03-14 14:13:41 -04:00
{
return FReply : : Handled ( ) ;
}
CheckOutDefaultConfigFile ( ) ;
}
else
{
2014-05-29 17:31:02 -04:00
if ( FMessageDialog : : Open ( EAppMsgType : : YesNo , LOCTEXT ( " SaveAsDefaultsIsReadOnlyMessage " , " The default configuration file for these settings is currently not writeable. Would you like to make it writable? " ) ) ! = EAppReturnType : : Yes )
{
return FReply : : Handled ( ) ;
}
MakeDefaultConfigFileWritable ( ) ;
2014-03-14 14:13:41 -04:00
}
}
SelectedSection - > SaveDefaults ( ) ;
FMessageDialog : : Open ( EAppMsgType : : Ok , LOCTEXT ( " SaveAsDefaultsSucceededMessage " , " The default configuration file for these settings was updated successfully. " ) ) ;
}
return FReply : : Handled ( ) ;
}
2014-05-07 14:46:21 -04:00
bool SSettingsEditor : : HandleSetAsDefaultButtonEnabled ( ) const
2014-03-14 14:13:41 -04:00
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
return SelectedSection - > CanSaveDefaults ( ) ;
}
return false ;
}
FText SSettingsEditor : : HandleSettingsBoxDescriptionText ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
return SelectedSection - > GetDescription ( ) ;
}
return FText : : GetEmpty ( ) ;
}
FString SSettingsEditor : : HandleSettingsBoxTitleText ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
return SelectedSection - > GetCategory ( ) . Pin ( ) - > GetDisplayName ( ) . ToString ( ) + TEXT ( " - " ) + SelectedSection - > GetDisplayName ( ) . ToString ( ) ;
}
return FString ( ) ;
}
EVisibility SSettingsEditor : : HandleSettingsBoxVisibility ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) )
{
return EVisibility : : Visible ;
}
return EVisibility : : Hidden ;
}
void SSettingsEditor : : HandleSettingsContainerCategoryModified ( const FName & CategoryName )
{
ReloadCategories ( ) ;
}
bool SSettingsEditor : : HandleSettingsViewEnabled ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
2014-09-19 00:01:10 -04:00
return ( SelectedSection . IsValid ( ) & & SelectedSection - > CanEdit ( ) & & ( ! SelectedSection - > HasDefaultSettingsObject ( ) | | FileWatcherWidget - > IsUnlocked ( ) ) ) ;
2014-03-14 14:13:41 -04:00
}
EVisibility SSettingsEditor : : HandleSettingsViewVisibility ( ) const
{
ISettingsSectionPtr SelectedSection = Model - > GetSelectedSection ( ) ;
if ( SelectedSection . IsValid ( ) & & SelectedSection - > GetSettingsObject ( ) . IsValid ( ) )
{
return EVisibility : : Visible ;
}
return EVisibility : : Hidden ;
}
2014-09-19 00:01:10 -04:00
// Do we need to edit the default config file?
bool SSettingsEditor : : IsDefaultConfigCheckOutNeeded ( ) const
{
TWeakObjectPtr < UObject > SettingsObject = GetSelectedSettingsObject ( ) ;
if ( SettingsObject . IsValid ( ) & & SettingsObject - > GetClass ( ) - > HasAnyClassFlags ( CLASS_Config | CLASS_DefaultConfig ) )
{
return ! FileWatcherWidget - > IsUnlocked ( ) ;
}
else
{
return false ;
}
}
2014-09-19 00:46:17 -04:00
void SSettingsEditor : : ReloadConfigObject ( )
{
TWeakObjectPtr < UObject > SettingsObject = GetSelectedSettingsObject ( ) ;
if ( SettingsObject . IsValid ( ) & & SettingsObject - > GetClass ( ) - > HasAnyClassFlags ( CLASS_Config | CLASS_DefaultConfig ) )
{
SettingsObject - > ReloadConfig ( ) ;
}
}
2014-03-14 14:13:41 -04:00
# undef LOCTEXT_NAMESPACE