Skip to content

Commit

Permalink
Added editor settings for foreground and background color, font, and …
Browse files Browse the repository at this point in the history
…margin.

#2
  • Loading branch information
gmpreussner committed Jul 5, 2017
1 parent 8cc5519 commit 8da8625
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.cpp
Original file line number Diff line number Diff line change
@@ -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)
{ }
40 changes: 40 additions & 0 deletions Source/TextAssetEditor/Private/Shared/TextAssetEditorSettings.h
Original file line number Diff line number Diff line change
@@ -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();
};
31 changes: 31 additions & 0 deletions Source/TextAssetEditor/Private/TextAssetEditorModule.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// 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"
#include "Toolkits/AssetEditorToolkit.h"

#include "AssetTools/TextAssetActions.h"
#include "Styles/TextAssetEditorStyle.h"
#include "TextAssetEditorSettings.h"


#define LOCTEXT_NAMESPACE "FTextAssetEditorModule"
Expand Down Expand Up @@ -51,12 +54,14 @@ class FTextAssetEditorModule

RegisterAssetTools();
RegisterMenuExtensions();
RegisterSettings();
}

virtual void ShutdownModule() override
{
UnregisterAssetTools();
UnregisterMenuExtensions();
UnregisterSettings();
}

virtual bool SupportsDynamicReloading() override
Expand Down Expand Up @@ -86,6 +91,21 @@ class FTextAssetEditorModule
RegisteredAssetTypeActions.Add(Action);
}

/** Register the text asset editor settings. */
void RegisterSettings()
{
ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");

if (SettingsModule != nullptr)
{
ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings("Editor", "Plugins", "TextAsset",
LOCTEXT("TextAssetSettingsName", "Text Asset"),
LOCTEXT("TextAssetSettingsDescription", "Configure the Text Asset plug-in."),
GetMutableDefault<UTextAssetEditorSettings>()
);
}
}

/** Unregisters asset tool actions. */
void UnregisterAssetTools()
{
Expand All @@ -102,6 +122,17 @@ class FTextAssetEditorModule
}
}

/** Unregister the text asset editor settings. */
void UnregisterSettings()
{
ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");

if (SettingsModule != nullptr)
{
SettingsModule->UnregisterSettings("Editor", "Plugins", "TextAsset");
}
}

protected:

/** Registers main menu and tool bar menu extensions. */
Expand Down
10 changes: 10 additions & 0 deletions Source/TextAssetEditor/Private/Widgets/STextAssetEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

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

auto Settings = GetDefault<UTextAssetEditorSettings>();

ChildSlot
[
SNew(SVerticalBox)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion Source/TextAssetEditor/TextAssetEditor.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down

0 comments on commit 8da8625

Please sign in to comment.