Skip to content

Commit 8da8625

Browse files
committed
Added editor settings for foreground and background color, font, and margin.
#2
1 parent 8cc5519 commit 8da8625

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2+
3+
#include "TextAssetEditorSettings.h"
4+
5+
#include "Misc/Paths.h"
6+
7+
8+
UTextAssetEditorSettings::UTextAssetEditorSettings()
9+
: BackgroundColor(FLinearColor::White)
10+
, ForegroundColor(FLinearColor::Black)
11+
, Font(FSlateFontInfo(FPaths::EngineContentDir() / TEXT("Slate/Fonts/DroidSansMono.ttf"), 10))
12+
, Margin(4.0f)
13+
{ }
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include "Fonts/SlateFontInfo.h"
6+
#include "Styling/SlateColor.h"
7+
#include "UObject/ObjectMacros.h"
8+
9+
#include "TextAssetEditorSettings.generated.h"
10+
11+
12+
UCLASS(config=Editor)
13+
class TEXTASSETEDITOR_API UTextAssetEditorSettings
14+
: public UObject
15+
{
16+
GENERATED_BODY()
17+
18+
public:
19+
20+
/** Color of the TextAsset editor's background. */
21+
UPROPERTY(config, EditAnywhere, Category=Appearance)
22+
FSlateColor BackgroundColor;
23+
24+
/** Color of the TextAsset editor's text. */
25+
UPROPERTY(config, EditAnywhere, Category=Appearance)
26+
FSlateColor ForegroundColor;
27+
28+
/** The font to use in the TextAsset editor window. */
29+
UPROPERTY(config, EditAnywhere, Category=Appearance)
30+
FSlateFontInfo Font;
31+
32+
/** The margin around the TextAsset editor window (in pixels). */
33+
UPROPERTY(config, EditAnywhere, Category=Appearance)
34+
float Margin;
35+
36+
public:
37+
38+
/** Default constructor. */
39+
UTextAssetEditorSettings();
40+
};

Source/TextAssetEditor/Private/TextAssetEditorModule.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
22

33
#include "Containers/Array.h"
4+
#include "ISettingsModule.h"
5+
#include "ISettingsSection.h"
46
#include "Modules/ModuleInterface.h"
57
#include "Modules/ModuleManager.h"
68
#include "Templates/SharedPointer.h"
79
#include "Toolkits/AssetEditorToolkit.h"
810

911
#include "AssetTools/TextAssetActions.h"
1012
#include "Styles/TextAssetEditorStyle.h"
13+
#include "TextAssetEditorSettings.h"
1114

1215

1316
#define LOCTEXT_NAMESPACE "FTextAssetEditorModule"
@@ -51,12 +54,14 @@ class FTextAssetEditorModule
5154

5255
RegisterAssetTools();
5356
RegisterMenuExtensions();
57+
RegisterSettings();
5458
}
5559

5660
virtual void ShutdownModule() override
5761
{
5862
UnregisterAssetTools();
5963
UnregisterMenuExtensions();
64+
UnregisterSettings();
6065
}
6166

6267
virtual bool SupportsDynamicReloading() override
@@ -86,6 +91,21 @@ class FTextAssetEditorModule
8691
RegisteredAssetTypeActions.Add(Action);
8792
}
8893

94+
/** Register the text asset editor settings. */
95+
void RegisterSettings()
96+
{
97+
ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");
98+
99+
if (SettingsModule != nullptr)
100+
{
101+
ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings("Editor", "Plugins", "TextAsset",
102+
LOCTEXT("TextAssetSettingsName", "Text Asset"),
103+
LOCTEXT("TextAssetSettingsDescription", "Configure the Text Asset plug-in."),
104+
GetMutableDefault<UTextAssetEditorSettings>()
105+
);
106+
}
107+
}
108+
89109
/** Unregisters asset tool actions. */
90110
void UnregisterAssetTools()
91111
{
@@ -102,6 +122,17 @@ class FTextAssetEditorModule
102122
}
103123
}
104124

125+
/** Unregister the text asset editor settings. */
126+
void UnregisterSettings()
127+
{
128+
ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");
129+
130+
if (SettingsModule != nullptr)
131+
{
132+
SettingsModule->UnregisterSettings("Editor", "Plugins", "TextAsset");
133+
}
134+
}
135+
105136
protected:
106137

107138
/** Registers main menu and tool bar menu extensions. */

Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
#include "STextAssetEditor.h"
44

5+
#include "Fonts/SlateFontInfo.h"
56
#include "Internationalization/Text.h"
67
#include "TextAsset.h"
8+
#include "UObject/Class.h"
79
#include "Widgets/SBoxPanel.h"
810
#include "Widgets/Input/SMultiLineEditableTextBox.h"
911

12+
#include "TextAssetEditorSettings.h"
13+
1014

1115
#define LOCTEXT_NAMESPACE "STextAssetEditor"
1216

@@ -24,6 +28,8 @@ void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAss
2428
{
2529
TextAsset = InTextAsset;
2630

31+
auto Settings = GetDefault<UTextAssetEditorSettings>();
32+
2733
ChildSlot
2834
[
2935
SNew(SVerticalBox)
@@ -32,6 +38,10 @@ void STextAssetEditor::Construct(const FArguments& InArgs, UTextAsset* InTextAss
3238
.FillHeight(1.0f)
3339
[
3440
SAssignNew(EditableTextBox, SMultiLineEditableTextBox)
41+
.BackgroundColor((Settings != nullptr) ? Settings->BackgroundColor : FLinearColor::White)
42+
.Font((Settings != nullptr) ? Settings->Font : FSlateFontInfo())
43+
.ForegroundColor((Settings != nullptr) ? Settings->ForegroundColor : FLinearColor::Black)
44+
.Margin((Settings != nullptr) ? Settings->Margin : 4.0f)
3545
.OnTextChanged(this, &STextAssetEditor::HandleEditableTextBoxTextChanged)
3646
.OnTextCommitted(this, &STextAssetEditor::HandleEditableTextBoxTextCommitted)
3747
.Text(TextAsset->Text)

Source/TextAssetEditor/TextAssetEditor.Build.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public TextAssetEditor(ReadOnlyTargetRules Target) : base(Target)
2121
"TextAssetEditor/Private",
2222
"TextAssetEditor/Private/AssetTools",
2323
"TextAssetEditor/Private/Factories",
24-
"TextAssetEditor/Private/Styles",
24+
"TextAssetEditor/Private/Shared",
25+
"TextAssetEditor/Private/Styles",
2526
"TextAssetEditor/Private/Toolkits",
2627
"TextAssetEditor/Private/Widgets",
2728
}

0 commit comments

Comments
 (0)