diff --git a/Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.cpp b/Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.cpp new file mode 100644 index 0000000..6a448e5 --- /dev/null +++ b/Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.cpp @@ -0,0 +1,13 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. + +#include "TextAssetEditorSettings.h" + +#include "Misc/Paths.h" + + +UTextAssetEditorSettings::UTextAssetEditorSettings() + : BackgroundColor(FLinearColor::White) + , ForegroundColor(FLinearColor::Black) + , Font(FSlateFontInfo(FPaths::EngineContentDir() / TEXT("Slate/Fonts/DroidSansMono.ttf"), 10)) + , Margin(4.0f) +{ } diff --git a/Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.h b/Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.h new file mode 100644 index 0000000..5a8b8da --- /dev/null +++ b/Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.h @@ -0,0 +1,40 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "Fonts/SlateFontInfo.h" +#include "Styling/SlateColor.h" +#include "UObject/ObjectMacros.h" + +#include "TextAssetEditorSettings.generated.h" + + +UCLASS(config=Editor) +class TEXTASSETEDITOR_API UTextAssetEditorSettings + : public UObject +{ + GENERATED_BODY() + +public: + + /** Color of the TextAsset editor's background. */ + UPROPERTY(config, EditAnywhere, Category=Appearance) + FSlateColor BackgroundColor; + + /** Color of the TextAsset editor's text. */ + UPROPERTY(config, EditAnywhere, Category=Appearance) + FSlateColor ForegroundColor; + + /** The font to use in the TextAsset editor window. */ + UPROPERTY(config, EditAnywhere, Category=Appearance) + FSlateFontInfo Font; + + /** The margin around the TextAsset editor window (in pixels). */ + UPROPERTY(config, EditAnywhere, Category=Appearance) + float Margin; + +public: + + /** Default constructor. */ + UTextAssetEditorSettings(); +}; diff --git a/Source/TextAssetEditor/Private/TextAssetEditorModule.cpp b/Source/TextAssetEditor/Private/TextAssetEditorModule.cpp index 169e58c..8699c52 100644 --- a/Source/TextAssetEditor/Private/TextAssetEditorModule.cpp +++ b/Source/TextAssetEditor/Private/TextAssetEditorModule.cpp @@ -1,6 +1,8 @@ // Copyright 1998-2017 Epic Games, Inc. All Rights Reserved. #include "Containers/Array.h" +#include "ISettingsModule.h" +#include "ISettingsSection.h" #include "Modules/ModuleInterface.h" #include "Modules/ModuleManager.h" #include "Templates/SharedPointer.h" @@ -8,6 +10,7 @@ #include "AssetTools/TextAssetActions.h" #include "Styles/TextAssetEditorStyle.h" +#include "TextAssetEditorSettings.h" #define LOCTEXT_NAMESPACE "FTextAssetEditorModule" @@ -51,12 +54,14 @@ class FTextAssetEditorModule RegisterAssetTools(); RegisterMenuExtensions(); + RegisterSettings(); } virtual void ShutdownModule() override { UnregisterAssetTools(); UnregisterMenuExtensions(); + UnregisterSettings(); } virtual bool SupportsDynamicReloading() override @@ -86,6 +91,21 @@ class FTextAssetEditorModule RegisteredAssetTypeActions.Add(Action); } + /** Register the text asset editor settings. */ + void RegisterSettings() + { + ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("Settings"); + + if (SettingsModule != nullptr) + { + ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings("Editor", "Plugins", "TextAsset", + LOCTEXT("TextAssetSettingsName", "Text Asset"), + LOCTEXT("TextAssetSettingsDescription", "Configure the Text Asset plug-in."), + GetMutableDefault() + ); + } + } + /** Unregisters asset tool actions. */ void UnregisterAssetTools() { @@ -102,6 +122,17 @@ class FTextAssetEditorModule } } + /** Unregister the text asset editor settings. */ + void UnregisterSettings() + { + ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("Settings"); + + if (SettingsModule != nullptr) + { + SettingsModule->UnregisterSettings("Editor", "Plugins", "TextAsset"); + } + } + protected: /** Registers main menu and tool bar menu extensions. */ diff --git a/Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp b/Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp index 097bd1a..99f21aa 100644 --- a/Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp +++ b/Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp @@ -2,11 +2,15 @@ #include "STextAssetEditor.h" +#include "Fonts/SlateFontInfo.h" #include "Internationalization/Text.h" #include "TextAsset.h" +#include "UObject/Class.h" #include "Widgets/SBoxPanel.h" #include "Widgets/Input/SMultiLineEditableTextBox.h" +#include "TextAssetEditorSettings.h" + #define LOCTEXT_NAMESPACE "STextAssetEditor" @@ -24,6 +28,8 @@ void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAss { TextAsset = InTextAsset; + auto Settings = GetDefault(); + ChildSlot [ SNew(SVerticalBox) @@ -32,6 +38,10 @@ void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAss .FillHeight(1.0f) [ SAssignNew(EditableTextBox, SMultiLineEditableTextBox) + .BackgroundColor((Settings != nullptr) ? Settings->BackgroundColor : FLinearColor::White) + .Font((Settings != nullptr) ? Settings->Font : FSlateFontInfo()) + .ForegroundColor((Settings != nullptr) ? Settings->ForegroundColor : FLinearColor::Black) + .Margin((Settings != nullptr) ? Settings->Margin : 4.0f) .OnTextChanged(this, &STextAssetEditor::HandleEditableTextBoxTextChanged) .OnTextCommitted(this, &STextAssetEditor::HandleEditableTextBoxTextCommitted) .Text(TextAsset->Text) diff --git a/Source/TextAssetEditor/TextAssetEditor.Build.cs b/Source/TextAssetEditor/TextAssetEditor.Build.cs index f83af6b..d2b63f7 100644 --- a/Source/TextAssetEditor/TextAssetEditor.Build.cs +++ b/Source/TextAssetEditor/TextAssetEditor.Build.cs @@ -21,7 +21,8 @@ public TextAssetEditor(ReadOnlyTargetRules Target) : base(Target) "TextAssetEditor/Private", "TextAssetEditor/Private/AssetTools", "TextAssetEditor/Private/Factories", - "TextAssetEditor/Private/Styles", + "TextAssetEditor/Private/Shared", + "TextAssetEditor/Private/Styles", "TextAssetEditor/Private/Toolkits", "TextAssetEditor/Private/Widgets", }