Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Apollo.Client/Apollo.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="KristofferStrube.Blazor.WebWorkers" Version="0.1.0-alpha.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.5" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="9.0.0" />
<PackageReference Include="System.Security.Permissions" Version="6.0.0" />
<PackageReference Include="xunit" Version="2.9.2" />
Expand Down
24 changes: 24 additions & 0 deletions Apollo.Components/Editor/ApolloCodeEditor.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@using System.Text.Json
@using Apollo.Components.Analysis
@using Apollo.Components.Settings
@using Apollo.Components.Settings.Events
@using Apollo.Components.Solutions
@using BlazorMonaco
@using CSharpier
Expand All @@ -19,6 +21,7 @@
@using Command = BlazorMonaco.Languages.Command
@using InsertTextRule = BlazorMonaco.Languages
@implements IDisposable
@inherits Apollo.Components.Infrastructure.MessageBus.ComponentConsumer<Apollo.Components.Settings.Events.SettingsModelChanged>

<StandaloneCodeEditor @ref="_editor" Id="apollo-editor" ConstructionOptions="@DefaultOptions" OnDidInit="Initialize" OnDidChangeModelContent="OnModelDidChangeHandler" />

Expand All @@ -28,6 +31,7 @@
[Inject] CodeAnalysisConsoleService Console { get; set; } = default!;
[Inject] IJSRuntime JsRuntime { get; set; } = default!;
[Inject] ILogger<ApolloCodeEditor> Logger { get; set; } = default!;
[Inject] SettingsState Settings { get; set; } = default!;

private List<TextModel> _files = [];

Expand All @@ -39,6 +43,7 @@
AutomaticLayout = true,
Language = "csharp",
Value = SolutionsState.ActiveFile.Data,
LineHeight = ((EditorSettings)Settings.GetSettingsModels().First(model => model.Type == typeof(EditorSettings))).LineHeight,
};

private StandaloneCodeEditor? _editor;
Expand Down Expand Up @@ -66,6 +71,18 @@
SolutionsState.ActiveFileChangeRequested += async (file) => await HandleBeforeFileChanged(file);
SolutionsState.SaveProjectRequested += SaveActiveFileAsync;
SolutionsState.SolutionFilesChanged += async () => await HandleIfProjectClosedAsync();
base.OnInitialized();
}

private async Task HandleSettingsChangedAsync(EditorSettings settings)
{
if (_editor != null)
{
await _editor.UpdateOptions(new()
{
LineHeight = settings.LineHeight
});
}
}

protected async Task HandleIfProjectClosedAsync()
Expand Down Expand Up @@ -421,4 +438,11 @@
SolutionsState.SaveProjectRequested -= SaveActiveFileAsync;
}

protected override async Task Consume(SettingsModelChanged message, CancellationToken cancellationToken)
{
if (message.Type != typeof(EditorSettings)) return;

await HandleSettingsChangedAsync((EditorSettings)message.Model);
}

}
16 changes: 16 additions & 0 deletions Apollo.Components/Editor/EditorSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Apollo.Components.Settings;
using Apollo.Components.Settings.Attributes;

namespace Apollo.Components.Editor;

public class EditorSettings : SettingsBase
{
[Setting(label: "Editor line height")]
public int LineHeight { get; set; } = 2;

public override string Section => "Editor";

public override Type Type => typeof(EditorSettings);

public override object Model => this;
}
1 change: 1 addition & 0 deletions Apollo.Components/Infrastructure/RegistrationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.FluentUI.AspNetCore.Components;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using MudBlazor;
using MudBlazor.Services;
using Assembly = System.Reflection.Assembly;
Expand Down
14 changes: 14 additions & 0 deletions Apollo.Components/Settings/Attributes/SettingsAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Apollo.Components.Settings.Attributes;

[AttributeUsage(AttributeTargets.Property)]
public class SettingAttribute : Attribute
{
public string Label { get; }
public string? Description { get; set; }
public int Order { get; set; } = 0;

public SettingAttribute(string label)
{
Label = label;
}
}
5 changes: 5 additions & 0 deletions Apollo.Components/Settings/Events/SettingsModelChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Apollo.Components.Settings.Events;

public record SettingsModelChanged<T>(T Model) where T : SettingsBase;

public record SettingsModelChanged(Type Type, object Model);
14 changes: 14 additions & 0 deletions Apollo.Components/Settings/ISettingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Components;

namespace Apollo.Components.Settings;

// ToDo figure out what this should be
public class ISettingsService<T> where T : SettingsBase
{
public ISettingsService(T model)
{
Model = model;
}

public T Model { get; }
}
12 changes: 12 additions & 0 deletions Apollo.Components/Settings/SettingsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Reflection;

namespace Apollo.Components.Settings;

public abstract class SettingsBase
{
public virtual string Section { get; }

public virtual Type Type { get; }

public virtual object Model { get; }
}
35 changes: 35 additions & 0 deletions Apollo.Components/Settings/SettingsDialog.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@using System.Reflection
@using Apollo.Components.Analysis
@using Apollo.Components.Code
@using Apollo.Components.Console
@using Apollo.Components.Hosting
@using Apollo.Components.Infrastructure.MessageBus
@using Apollo.Components.Settings.Attributes
@using Apollo.Components.Settings.Events
@using Apollo.Components.Shared
@using Apollo.Components.Theme
@using Apollo.Components.Shared.ApolloSwitch
Expand Down Expand Up @@ -115,6 +119,36 @@
@bind-Value="WebHostConsoleService.AutoScroll" />
</MudStack>
</MudItem>

@foreach (var settingsGroup in Settings.GetSettingsModels())
{
<MudItem xs="12">
<MudDivider Class="my-4"/>
<MudText Class="mb-4 mud-text-secondary">@settingsGroup.Section</MudText>
<MudStack>
@foreach (var property in settingsGroup.Type.GetProperties())
{
if (property.PropertyType == typeof(bool))
{
<ApolloSwitch
LabelPlacement="Placement.Left"
Color="Color.Secondary"
Label="@((property.GetCustomAttribute(typeof(SettingAttribute), false) as SettingAttribute)?.Label)"
Value="@((bool)property.GetValue(settingsGroup, null))"/>
}
else if (property.PropertyType == typeof(int))
{
<MudInputLabel>@((property.GetCustomAttribute(typeof(SettingAttribute), true) as SettingAttribute)?.Label)</MudInputLabel>
<MudInput
T="int"
Label="@((property.GetCustomAttribute(typeof(SettingAttribute), true) as SettingAttribute)?.Label)"
Value="@((int)property.GetValue(settingsGroup, null))"
ValueChanged="(async (value) => { property.SetValue(settingsGroup, value); await Bus.PublishAsync(new SettingsModelChanged(settingsGroup.Type, settingsGroup)); })"/>
}
}
</MudStack>
</MudItem>
}
</MudGrid>
</DialogContent>
<DialogActions>
Expand All @@ -132,6 +166,7 @@
[Inject] private CodeAnalysisState CodeAnalysisState { get; set; }
[Inject] private WebHostConsoleService WebHostConsoleService { get; set; }
[Inject] private CodeAnalysisConsoleService CodeAnalysisConsoleService { get; set; }
[Inject] private IMessageBus Bus { get; set; }

private bool _codeAnalysisEnabled
{
Expand Down
25 changes: 25 additions & 0 deletions Apollo.Components/Settings/SettingsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Apollo.Components.Editor;
using Apollo.Components.Infrastructure.MessageBus;
using Apollo.Components.Settings.Events;

namespace Apollo.Components.Settings;

public class SettingsProvider
{
private readonly IMessageBus _bus;
private List<SettingsBase> _settings = [];

public List<SettingsBase> Settings => _settings;

public SettingsProvider(IMessageBus bus)
{
_bus = bus;
var editorSettings = new EditorSettings();
_settings.Add(editorSettings);
}

public async Task SettingsModelChanged<T>(T model) where T : SettingsBase
{
await _bus.PublishAsync(new SettingsModelChanged<T>(model));
}
}
7 changes: 7 additions & 0 deletions Apollo.Components/Settings/SettingsState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SettingsState
private ThemeMode _themeMode = ThemeMode.Dark;
private EditorThemeDefinition _currentTheme = ApolloTheme.Instance.Theme;
private ThemeMode _systemTheme = Settings.ThemeMode.Dark;
private readonly SettingsProvider _settingsProvider;
public event Action SettingsChanged;

public SettingsState(IMessageBus bus, ILocalStorageService localStorageService, IJSRuntime jsRuntime)
Expand All @@ -25,6 +26,7 @@ public SettingsState(IMessageBus bus, ILocalStorageService localStorageService,
_localStorageService = localStorageService;
_jsRuntime = jsRuntime;
_currentTheme.Initialize(this);
_settingsProvider = new SettingsProvider(bus);
}

public async Task TryLoadSettingsFromStorageAsync()
Expand Down Expand Up @@ -97,6 +99,11 @@ public bool IsDarkMode
}
}

public List<SettingsBase> GetSettingsModels()
{
return _settingsProvider.Settings;
}

private async void NotifyStateChanged()
{
SettingsChanged?.Invoke();
Expand Down
2 changes: 1 addition & 1 deletion Apollo.Components/Settings/SettingsStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Apollo.Components.Settings;

public class SettingsStorage
public static class SettingsStorage
{
public const string UserPreferencesKey = "__apollo_user_preference";
}
Loading