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 "EditorSettingsViewerPrivatePCH.h"
2014-10-27 07:53:18 -04:00
# include "ISettingsCategory.h"
2014-10-27 07:53:55 -04:00
# include "ISettingsContainer.h"
# include "ISettingsEditorModel.h"
# include "ISettingsEditorModule.h"
2014-10-27 07:53:18 -04:00
# include "ISettingsModule.h"
# include "ISettingsSection.h"
# include "ISettingsViewer.h"
# include "ModuleManager.h"
# include "SDockTab.h"
2014-05-29 17:01:48 -04:00
# include "Tests/AutomationTestSettings.h"
2014-09-12 18:42:03 -04:00
# include "BlueprintEditorSettings.h"
2014-10-27 07:53:18 -04:00
2014-06-12 23:22:18 -04:00
2014-03-14 14:13:41 -04:00
# define LOCTEXT_NAMESPACE "FEditorSettingsViewerModule"
static const FName EditorSettingsTabName ( " EditorSettings " ) ;
/**
* Implements the EditorSettingsViewer module .
*/
class FEditorSettingsViewerModule
: public IModuleInterface
, public ISettingsViewer
{
public :
2014-06-12 23:22:18 -04:00
// ISettingsViewer interface
2014-03-14 14:13:41 -04:00
2014-06-12 23:22:18 -04:00
virtual void ShowSettings ( const FName & CategoryName , const FName & SectionName ) override
2014-03-14 14:13:41 -04:00
{
FGlobalTabmanager : : Get ( ) - > InvokeTab ( EditorSettingsTabName ) ;
ISettingsEditorModelPtr SettingsEditorModel = SettingsEditorModelPtr . Pin ( ) ;
if ( SettingsEditorModel . IsValid ( ) )
{
ISettingsCategoryPtr Category = SettingsEditorModel - > GetSettingsContainer ( ) - > GetCategory ( CategoryName ) ;
if ( Category . IsValid ( ) )
{
SettingsEditorModel - > SelectSection ( Category - > GetSection ( SectionName ) ) ;
}
}
}
public :
2014-06-12 23:22:18 -04:00
// IModuleInterface interface
2014-03-14 14:13:41 -04:00
2014-10-27 07:53:18 -04:00
virtual void StartupModule ( ) override
2014-03-14 14:13:41 -04:00
{
2014-10-27 07:53:18 -04:00
ISettingsModule * SettingsModule = FModuleManager : : GetModulePtr < ISettingsModule > ( " Settings " ) ;
2014-03-14 14:13:41 -04:00
if ( SettingsModule ! = nullptr )
{
RegisterGeneralSettings ( * SettingsModule ) ;
RegisterLevelEditorSettings ( * SettingsModule ) ;
RegisterContentEditorsSettings ( * SettingsModule ) ;
SettingsModule - > RegisterViewer ( " Editor " , * this ) ;
}
FGlobalTabmanager : : Get ( ) - > RegisterNomadTabSpawner ( EditorSettingsTabName , FOnSpawnTab : : CreateRaw ( this , & FEditorSettingsViewerModule : : HandleSpawnSettingsTab ) )
. SetDisplayName ( LOCTEXT ( " EditorSettingsTabTitle " , " Editor Preferences " ) )
2014-10-27 09:51:25 -04:00
. SetMenuType ( ETabSpawnerMenuType : : Hidden ) ;
2014-03-14 14:13:41 -04:00
}
2014-10-27 07:53:18 -04:00
virtual void ShutdownModule ( ) override
2014-03-14 14:13:41 -04:00
{
FGlobalTabmanager : : Get ( ) - > UnregisterNomadTabSpawner ( EditorSettingsTabName ) ;
UnregisterSettings ( ) ;
}
2014-10-27 07:53:18 -04:00
virtual bool SupportsDynamicReloading ( ) override
2014-03-14 14:13:41 -04:00
{
return true ;
}
protected :
/**
* Registers general Editor settings .
2014-10-27 07:53:18 -04:00
*
* @ param SettingsModule A reference to the settings module .
2014-03-14 14:13:41 -04:00
*/
void RegisterGeneralSettings ( ISettingsModule & SettingsModule )
{
2014-10-27 07:53:18 -04:00
// automation
2014-04-02 18:09:23 -04:00
SettingsModule . RegisterSettings ( " Editor " , " General " , " AutomationTest " ,
LOCTEXT ( " AutomationSettingsName " , " Automation " ) ,
LOCTEXT ( " AutomationSettingsDescription " , " Set up automation test assets. " ) ,
2014-04-23 19:10:37 -04:00
GetMutableDefault < UAutomationTestSettings > ( )
2014-04-02 18:09:23 -04:00
) ;
2014-10-27 07:53:18 -04:00
// region & language
ISettingsSectionPtr RegionAndLanguageSettingsSection = SettingsModule . RegisterSettings ( " Editor " , " General " , " Internationalization " ,
2014-04-02 18:09:23 -04:00
LOCTEXT ( " InternationalizationSettingsModelName " , " Region & Language " ) ,
LOCTEXT ( " InternationalizationSettingsModelDescription " , " Configure the editor's behavior to use a language and fit a region's culture. " ) ,
2014-10-27 07:53:18 -04:00
GetMutableDefault < UInternationalizationSettingsModel > ( )
2014-04-23 19:10:37 -04:00
) ;
2014-04-02 18:09:23 -04:00
2014-10-27 07:53:18 -04:00
if ( RegionAndLanguageSettingsSection . IsValid ( ) )
{
RegionAndLanguageSettingsSection - > OnExport ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleRegionAndLanguageExport ) ;
RegionAndLanguageSettingsSection - > OnImport ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleRegionAndLanguageImport ) ;
RegionAndLanguageSettingsSection - > OnSaveDefaults ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleRegionAndLanguageSaveDefaults ) ;
RegionAndLanguageSettingsSection - > OnResetDefaults ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleRegionAndLanguageResetToDefault ) ;
2015-02-16 07:54:27 -05:00
GetMutableDefault < UInternationalizationSettingsModel > ( ) - > OnSettingChanged ( ) . AddRaw ( this , & FEditorSettingsViewerModule : : HandleRegionAndLanguageSettingChanged ) ;
2014-10-27 07:53:18 -04:00
}
// input bindings
2014-05-29 17:37:19 -04:00
TWeakPtr < SWidget > InputBindingEditorPanel = FModuleManager : : LoadModuleChecked < IInputBindingEditorModule > ( " InputBindingEditor " ) . CreateInputBindingEditorPanel ( ) ;
2014-10-27 07:53:18 -04:00
ISettingsSectionPtr InputBindingSettingsSection = SettingsModule . RegisterSettings ( " Editor " , " General " , " InputBindings " ,
2014-03-14 14:13:41 -04:00
LOCTEXT ( " InputBindingsSettingsName " , " Keyboard Shortcuts " ) ,
LOCTEXT ( " InputBindingsSettingsDescription " , " Configure keyboard shortcuts to quickly invoke operations. " ) ,
2014-10-27 07:53:18 -04:00
InputBindingEditorPanel . Pin ( ) . ToSharedRef ( )
2014-03-14 14:13:41 -04:00
) ;
2014-10-27 07:53:18 -04:00
if ( InputBindingSettingsSection . IsValid ( ) )
{
InputBindingSettingsSection - > OnExport ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleInputBindingsExport ) ;
InputBindingSettingsSection - > OnImport ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleInputBindingsImport ) ;
InputBindingSettingsSection - > OnResetDefaults ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleInputBindingsResetToDefault ) ;
InputBindingSettingsSection - > OnSave ( ) . BindRaw ( this , & FEditorSettingsViewerModule : : HandleInputBindingsSave ) ;
}
2014-03-14 14:13:41 -04:00
// loading & saving features
SettingsModule . RegisterSettings ( " Editor " , " General " , " LoadingSaving " ,
LOCTEXT ( " LoadingSavingSettingsName " , " Loading & Saving " ) ,
LOCTEXT ( " LoadingSavingSettingsDescription " , " Change how the Editor loads and saves files. " ) ,
2014-05-16 15:13:39 -04:00
GetMutableDefault < UEditorLoadingSavingSettings > ( )
2014-03-14 14:13:41 -04:00
) ;
// @todo thomass: proper settings support for source control module
GetMutableDefault < UEditorLoadingSavingSettings > ( ) - > SccHackInitialize ( ) ;
// misc unsorted settings
SettingsModule . RegisterSettings ( " Editor " , " General " , " UserSettings " ,
LOCTEXT ( " UserSettingsName " , " Miscellaneous " ) ,
LOCTEXT ( " UserSettingsDescription " , " Customize the behavior, look and feel of the editor. " ) ,
2015-04-20 10:12:55 -04:00
GetMutableDefault < UEditorPerProjectUserSettings > ( )
2014-03-14 14:13:41 -04:00
) ;
// experimental features
SettingsModule . RegisterSettings ( " Editor " , " General " , " Experimental " ,
LOCTEXT ( " ExperimentalettingsName " , " Experimental " ) ,
LOCTEXT ( " ExperimentalSettingsDescription " , " Enable and configure experimental Editor features. " ) ,
2014-04-23 19:10:37 -04:00
GetMutableDefault < UEditorExperimentalSettings > ( )
2014-03-14 14:13:41 -04:00
) ;
}
/**
2014-10-27 07:53:18 -04:00
* Registers Level Editor settings .
*
* @ param SettingsModule A reference to the settings module .
2014-03-14 14:13:41 -04:00
*/
void RegisterLevelEditorSettings ( ISettingsModule & SettingsModule )
{
// play-in settings
SettingsModule . RegisterSettings ( " Editor " , " LevelEditor " , " PlayIn " ,
LOCTEXT ( " LevelEditorPlaySettingsName " , " Play " ) ,
LOCTEXT ( " LevelEditorPlaySettingsDescription " , " Set up window sizes and other options for the Play In Editor (PIE) feature. " ) ,
2014-04-23 19:10:37 -04:00
GetMutableDefault < ULevelEditorPlaySettings > ( )
2014-03-14 14:13:41 -04:00
) ;
// view port settings
SettingsModule . RegisterSettings ( " Editor " , " LevelEditor " , " Viewport " ,
LOCTEXT ( " LevelEditorViewportSettingsName " , " Viewports " ) ,
LOCTEXT ( " LevelEditorViewportSettingsDescription " , " Configure the look and feel of the Level Editor view ports. " ) ,
2014-04-23 19:10:37 -04:00
GetMutableDefault < ULevelEditorViewportSettings > ( )
2014-03-14 14:13:41 -04:00
) ;
}
/**
2014-10-27 07:53:18 -04:00
* Registers Other Tools settings .
*
* @ param SettingsModule A reference to the settings module .
2014-03-14 14:13:41 -04:00
*/
void RegisterContentEditorsSettings ( ISettingsModule & SettingsModule )
{
// content browser
SettingsModule . RegisterSettings ( " Editor " , " ContentEditors " , " ContentBrowser " ,
LOCTEXT ( " ContentEditorsContentBrowserSettingsName " , " Content Browser " ) ,
LOCTEXT ( " ContentEditorsContentBrowserSettingsDescription " , " Change the behavior of the Content Browser. " ) ,
2014-04-23 19:10:37 -04:00
GetMutableDefault < UContentBrowserSettings > ( )
2014-03-14 14:13:41 -04:00
) ;
// destructable mesh editor
/* SettingsModule.RegisterSettings("Editor", "ContentEditors", "DestructableMeshEditor",
LOCTEXT ( " ContentEditorsDestructableMeshEditorSettingsName " , " Destructable Mesh Editor " ) ,
LOCTEXT ( " ContentEditorsDestructableMeshEditorSettingsDescription " , " Change the behavior of the Destructable Mesh Editor. " ) ,
2014-04-23 19:10:37 -04:00
GetMutableDefault < UDestructableMeshEditorSettings > ( )
2014-03-14 14:13:41 -04:00
) ; */
2014-05-20 19:00:53 -04:00
// graph editors
SettingsModule . RegisterSettings ( " Editor " , " ContentEditors " , " GraphEditor " ,
LOCTEXT ( " ContentEditorsGraphEditorSettingsName " , " Graph Editors " ) ,
LOCTEXT ( " ContentEditorsGraphEditorSettingsDescription " , " Customize Anim, Blueprint and Material Editor. " ) ,
GetMutableDefault < UGraphEditorSettings > ( )
) ;
2014-09-12 18:42:03 -04:00
// graph editors
SettingsModule . RegisterSettings ( " Editor " , " ContentEditors " , " BlueprintEditor " ,
LOCTEXT ( " ContentEditorsBlueprintEditorSettingsName " , " Blueprint Editor " ) ,
LOCTEXT ( " ContentEditorsGraphBlueprintSettingsDescription " , " Customize Blueprint Editors. " ) ,
GetMutableDefault < UBlueprintEditorSettings > ( )
) ;
2015-02-06 14:15:24 -05:00
// Persona editors
SettingsModule . RegisterSettings ( " Editor " , " ContentEditors " , " Persona " ,
LOCTEXT ( " ContentEditorsPersonaSettingsName " , " Animation Editor " ) ,
LOCTEXT ( " ContentEditorsPersonaSettingsDescription " , " Customize Persona Editor. " ) ,
GetMutableDefault < UPersonaOptions > ( )
) ;
2014-03-14 14:13:41 -04:00
}
2014-10-27 07:53:18 -04:00
/** Unregisters all settings. */
void UnregisterSettings ( )
2014-03-14 14:13:41 -04:00
{
2014-10-27 07:53:18 -04:00
ISettingsModule * SettingsModule = FModuleManager : : GetModulePtr < ISettingsModule > ( " Settings " ) ;
2014-03-14 14:13:41 -04:00
if ( SettingsModule ! = nullptr )
{
SettingsModule - > UnregisterViewer ( " Editor " ) ;
// general settings
SettingsModule - > UnregisterSettings ( " Editor " , " General " , " InputBindings " ) ;
SettingsModule - > UnregisterSettings ( " Editor " , " General " , " LoadingSaving " ) ;
SettingsModule - > UnregisterSettings ( " Editor " , " General " , " GameAgnostic " ) ;
SettingsModule - > UnregisterSettings ( " Editor " , " General " , " UserSettings " ) ;
SettingsModule - > UnregisterSettings ( " Editor " , " General " , " AutomationTest " ) ;
2015-02-16 07:54:27 -05:00
SettingsModule - > UnregisterSettings ( " Editor " , " General " , " Internationalization " ) ;
2014-03-14 14:13:41 -04:00
SettingsModule - > UnregisterSettings ( " Editor " , " General " , " Experimental " ) ;
// level editor settings
SettingsModule - > UnregisterSettings ( " Editor " , " LevelEditor " , " PlayIn " ) ;
SettingsModule - > UnregisterSettings ( " Editor " , " LevelEditor " , " Viewport " ) ;
// other tools
SettingsModule - > UnregisterSettings ( " Editor " , " ContentEditors " , " ContentBrowser " ) ;
// SettingsModule->UnregisterSettings("Editor", "ContentEditors", "DestructableMeshEditor");
2014-05-20 19:00:53 -04:00
SettingsModule - > UnregisterSettings ( " Editor " , " ContentEditors " , " GraphEditor " ) ;
2015-02-06 14:15:24 -05:00
SettingsModule - > UnregisterSettings ( " Editor " , " ContentEditors " , " Persona " ) ;
2014-03-14 14:13:41 -04:00
}
}
private :
2014-10-27 07:53:18 -04:00
/** Handles creating the editor settings tab. */
2014-03-14 14:13:41 -04:00
TSharedRef < SDockTab > HandleSpawnSettingsTab ( const FSpawnTabArgs & SpawnTabArgs )
{
2014-10-27 07:53:18 -04:00
ISettingsModule * SettingsModule = FModuleManager : : GetModulePtr < ISettingsModule > ( " Settings " ) ;
2014-03-14 14:13:41 -04:00
TSharedRef < SWidget > SettingsEditor = SNullWidget : : NullWidget ;
if ( SettingsModule ! = nullptr )
{
ISettingsContainerPtr SettingsContainer = SettingsModule - > GetContainer ( " Editor " ) ;
if ( SettingsContainer . IsValid ( ) )
{
2014-10-27 07:53:55 -04:00
ISettingsEditorModule & SettingsEditorModule = FModuleManager : : GetModuleChecked < ISettingsEditorModule > ( " SettingsEditor " ) ;
2014-03-14 14:13:41 -04:00
ISettingsEditorModelRef SettingsEditorModel = SettingsEditorModule . CreateModel ( SettingsContainer . ToSharedRef ( ) ) ;
SettingsEditor = SettingsEditorModule . CreateEditor ( SettingsEditorModel ) ;
SettingsEditorModelPtr = SettingsEditorModel ;
}
}
return SNew ( SDockTab )
. TabRole ( ETabRole : : NomadTab )
[
SettingsEditor
] ;
}
private :
// Show a warning that the editor will require a restart and return its result
EAppReturnType : : Type ShowRestartWarning ( const FText & Title ) const
{
2014-05-21 02:13:29 -04:00
return OpenMsgDlgInt ( EAppMsgType : : OkCancel , LOCTEXT ( " ActionRestartMsg " , " Imported settings won't be applied until the editor is restarted. Do you wish to restart now (you will be prompted to save any changes) ? " ), Title) ;
2014-03-14 14:13:41 -04:00
}
// Backup a file
bool BackupFile ( const FString & SrcFilename , const FString & DstFilename )
{
if ( IFileManager : : Get ( ) . Copy ( * DstFilename , * SrcFilename ) = = COPY_OK )
{
return true ;
}
// log error
FMessageLog EditorErrors ( " EditorErrors " ) ;
if ( ! FPaths : : FileExists ( SrcFilename ) )
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " FileName " ) , FText : : FromString ( SrcFilename ) ) ;
EditorErrors . Warning ( FText : : Format ( LOCTEXT ( " UnsuccessfulBackup_NoExist_Notification " , " Unsuccessful backup! {FileName} does not exist! " ) , Arguments ) ) ;
}
else if ( IFileManager : : Get ( ) . IsReadOnly ( * DstFilename ) )
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " FileName " ) , FText : : FromString ( DstFilename ) ) ;
EditorErrors . Warning ( FText : : Format ( LOCTEXT ( " UnsuccessfulBackup_ReadOnly_Notification " , " Unsuccessful backup! {FileName} is read-only! " ) , Arguments ) ) ;
}
else
{
FFormatNamedArguments Arguments ;
Arguments . Add ( TEXT ( " SourceFileName " ) , FText : : FromString ( SrcFilename ) ) ;
Arguments . Add ( TEXT ( " BackupFileName " ) , FText : : FromString ( DstFilename ) ) ;
// We don't specifically know why it failed, this is a fallback.
EditorErrors . Warning ( FText : : Format ( LOCTEXT ( " UnsuccessfulBackup_Fallback_Notification " , " Unsuccessful backup of {SourceFileName} to {BackupFileName} " ) , Arguments ) ) ;
}
EditorErrors . Notify ( LOCTEXT ( " BackupUnsuccessful_Title " , " Backup Unsuccessful! " ) ) ;
return false ;
}
// Handles exporting input bindings to a file
bool HandleInputBindingsExport ( const FString & Filename )
{
FInputBindingManager : : Get ( ) . SaveInputBindings ( ) ;
GConfig - > Flush ( false , GEditorKeyBindingsIni ) ;
return BackupFile ( GEditorKeyBindingsIni , Filename ) ;
}
// Handles importing input bindings from a file
bool HandleInputBindingsImport ( const FString & Filename )
{
if ( EAppReturnType : : Ok = = ShowRestartWarning ( LOCTEXT ( " ImportKeyBindings_Title " , " Import Key Bindings " ) ) )
{
FUnrealEdMisc : : Get ( ) . SetConfigRestoreFilename ( Filename , GEditorKeyBindingsIni ) ;
FUnrealEdMisc : : Get ( ) . RestartEditor ( false ) ;
return true ;
}
return false ;
}
// Handles resetting input bindings back to the defaults
bool HandleInputBindingsResetToDefault ( )
{
if ( EAppReturnType : : Ok = = ShowRestartWarning ( LOCTEXT ( " ResetKeyBindings_Title " , " Reset Key Bindings " ) ) )
{
2015-03-17 11:36:28 -04:00
FInputBindingManager : : Get ( ) . RemoveUserDefinedChords ( ) ;
2014-03-14 14:13:41 -04:00
GConfig - > Flush ( false , GEditorKeyBindingsIni ) ;
FUnrealEdMisc : : Get ( ) . RestartEditor ( false ) ;
return true ;
}
return false ;
}
2014-05-21 02:13:29 -04:00
// Handles saving default input bindings.
// This only gets called by SSettingsEditor::HandleImportButtonClicked when importing new settings,
// and its implementation here is just to flush custom input bindings so that editor shutdown doesn't
// overwrite the imported settings just copied across.
bool HandleInputBindingsSave ( )
{
2015-03-17 11:36:28 -04:00
FInputBindingManager : : Get ( ) . RemoveUserDefinedChords ( ) ;
2014-05-21 02:13:29 -04:00
GConfig - > Flush ( false , GEditorKeyBindingsIni ) ;
return true ;
}
2014-04-02 18:09:23 -04:00
bool HandleRegionAndLanguageExport ( const FString & FileName )
{
FString CultureName = GetMutableDefault < UInternationalizationSettingsModel > ( ) - > GetCultureName ( ) ;
GConfig - > SetString ( TEXT ( " Internationalization " ) , TEXT ( " Culture " ) , * CultureName , FileName ) ;
GConfig - > Flush ( false , FileName ) ;
return true ;
}
bool HandleRegionAndLanguageImport ( const FString & FileName )
{
FString CultureName ;
GConfig - > LoadFile ( FileName ) ;
GConfig - > GetString ( TEXT ( " Internationalization " ) , TEXT ( " Culture " ) , CultureName , FileName ) ;
GetMutableDefault < UInternationalizationSettingsModel > ( ) - > SetCultureName ( CultureName ) ;
return true ;
}
bool HandleRegionAndLanguageSaveDefaults ( )
{
GetMutableDefault < UInternationalizationSettingsModel > ( ) - > SaveDefaults ( ) ;
return true ;
}
bool HandleRegionAndLanguageResetToDefault ( )
{
GetMutableDefault < UInternationalizationSettingsModel > ( ) - > ResetToDefault ( ) ;
return true ;
}
2015-02-16 07:54:27 -05:00
void HandleRegionAndLanguageSettingChanged ( )
{
ISettingsEditorModule & SettingsEditorModule = FModuleManager : : GetModuleChecked < ISettingsEditorModule > ( " SettingsEditor " ) ;
SettingsEditorModule . OnApplicationRestartRequired ( ) ;
}
2014-03-14 14:13:41 -04:00
private :
2014-10-27 07:53:18 -04:00
/** Holds a pointer to the settings editor's view model. */
2014-03-14 14:13:41 -04:00
TWeakPtr < ISettingsEditorModel > SettingsEditorModelPtr ;
} ;
IMPLEMENT_MODULE ( FEditorSettingsViewerModule , EditorSettingsViewer ) ;
# undef LOCTEXT_NAMESPACE