Skip to content

Commit

Permalink
continue settings refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 13, 2024
1 parent 8fca589 commit 0458cc5
Show file tree
Hide file tree
Showing 20 changed files with 395 additions and 194 deletions.
57 changes: 32 additions & 25 deletions src/OneWare.Core/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,29 @@ protected override AvaloniaObject CreateShell()
settingsService.RegisterSettingCategory("Tools", 0, "FeatherIcons.Tool");

settingsService.RegisterSettingCategory("Languages", 0, "FluentIcons.ProofreadLanguageRegular");

settingsService.RegisterSetting("Editor", "Appearance", "Editor_FontFamily",
new ComboBoxSetting("Editor Font Family", "JetBrains Mono NL", ["JetBrains Mono NL", "IntelOne Mono", "Consolas", "Comic Sans MS", "Fira Code"]));

settingsService.RegisterSetting("Editor", "Appearance", "Editor_FontSize",
new ComboBoxSetting("Font Size", 15,Enumerable.Range(10, 30).Cast<object>()));

settingsService.RegisterTitledCombo("Editor", "Appearance", "Editor_FontFamily", "Font",
"Editor Font Family",
"JetBrains Mono NL",
"JetBrains Mono NL", "IntelOne Mono", "Consolas", "Comic Sans MS", "Fira Code");

settingsService.RegisterTitledCombo("Editor", "Appearance", "Editor_FontSize", "Font Size",
"Editor Font Size", 15, Enumerable.Range(10, 30).ToArray());

settingsService.RegisterTitledCombo("Editor", "Appearance", "Editor_SyntaxTheme_Dark", "Editor Theme Dark",
"Setts the theme for Syntax Highlighting in Dark Mode", ThemeName.DarkPlus,
Enum.GetValues<ThemeName>());

settingsService.RegisterTitledCombo("Editor", "Appearance", "Editor_SyntaxTheme_Light",
"Editor Theme Light",
"Setts the theme for Syntax Highlighting in Light Mode", ThemeName.LightPlus,
Enum.GetValues<ThemeName>());

//settingsService.RegisterTitled("Editor", "Appearance", "Editor_ErrorMarking_Mode", "Error Marking mode"); dfdf

settingsService.RegisterTitled("Editor", "Formatting", "Editor_UseAutoFormatting", "Use Auto Formatting",
"Use Auto Formatting in Editor", true);
settingsService.RegisterTitled("Editor", "Formatting", "Editor_UseAutoBracket", "Use Auto Bracket",
"Use Auto Bracket in Editor", true);
settingsService.RegisterSetting("Editor", "Appearance", "Editor_SyntaxTheme_Dark",
new ComboBoxSetting("Editor Theme Dark", ThemeName.DarkPlus,Enum.GetValues<ThemeName>().Cast<object>())
{
HoverDescription = "Sets the theme for Syntax Highlighting in Dark Mode"
});

settingsService.RegisterSetting("Editor", "Appearance", "Editor_SyntaxTheme_Light",
new ComboBoxSetting("Editor Theme Light", ThemeName.LightPlus,Enum.GetValues<ThemeName>().Cast<object>())
{
HoverDescription = "Sets the theme for Syntax Highlighting in Light Mode"
});

settingsService.RegisterSetting("Editor", "Formatting", "Editor_UseAutoFormatting",
new CheckBoxSetting("Use Auto Formatting", true));

settingsService.RegisterSetting("Editor", "Formatting", "Editor_UseAutoBracket", new CheckBoxSetting("Use Auto Bracket", true));

settingsService.RegisterTitled("Editor", "Folding", "Editor_UseFolding", "Use Folding",
"Use Folding in Editor", true);
Expand Down Expand Up @@ -257,11 +256,19 @@ protected override AvaloniaObject CreateShell()
var applicationCommandService = Container.Resolve<IApplicationCommandService>();

applicationCommandService.RegisterCommand(new SimpleApplicationCommand("Active light theme",
() => settingsService.SetSettingValue("General_SelectedTheme", "Light"),
() =>
{
settingsService.SetSettingValue("General_SelectedTheme", "Light");
settingsService.Save(paths.SettingsPath);
},
() => settingsService.GetSettingValue<string>("General_SelectedTheme") != "Light"));

applicationCommandService.RegisterCommand(new SimpleApplicationCommand("Active dark theme",
() => settingsService.SetSettingValue("General_SelectedTheme", "Dark"),
() =>
{
settingsService.SetSettingValue("General_SelectedTheme", "Dark");
settingsService.Save(paths.SettingsPath);
},
() => settingsService.GetSettingValue<string>("General_SelectedTheme") != "Dark"));

// applicationCommandService.RegisterCommand(new SimpleApplicationCommand("Show Success Notification",
Expand Down
38 changes: 18 additions & 20 deletions src/OneWare.Essentials/Models/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ public virtual object Value

public abstract class TitledSetting : Setting
{
public TitledSetting(string title, string description, object defaultValue) : base(defaultValue)
public TitledSetting(string title, object defaultValue) : base(defaultValue)
{
Title = title;
Description = description;
}

public string Title { get; }

public string Description { get; }
public string? HoverDescription { get; init; }

public string? MarkdownDocumentation { get; init; }

public IObservable<bool>? IsEnabledObservable { get; init; }

Expand All @@ -52,15 +53,14 @@ public TitledSetting(string title, string description, object defaultValue) : ba

public class CheckBoxSetting : TitledSetting
{
public CheckBoxSetting(string title, string description, bool defaultValue) : base(title, description, defaultValue)
public CheckBoxSetting(string title, bool defaultValue) : base(title, defaultValue)
{
}
}

public class TextBoxSetting : TitledSetting
{
public TextBoxSetting(string title, string description, object defaultValue, string? watermark) : base(title,
description, defaultValue)
public TextBoxSetting(string title, object defaultValue, string? watermark) : base(title, defaultValue)
{
Watermark = watermark;
}
Expand All @@ -70,8 +70,7 @@ public TextBoxSetting(string title, string description, object defaultValue, str

public class ComboBoxSetting : TitledSetting
{
public ComboBoxSetting(string title, string description, object defaultValue, IEnumerable<object> options) : base(
title, description, defaultValue)
public ComboBoxSetting(string title, object defaultValue, IEnumerable<object> options) : base(title, defaultValue)
{
Options = options.ToArray();
}
Expand All @@ -81,8 +80,7 @@ public ComboBoxSetting(string title, string description, object defaultValue, IE

public class ListBoxSetting : TitledSetting
{
public ListBoxSetting(string title, string description, params string[] defaultValue) : base(
title, description, new ObservableCollection<string>(defaultValue))
public ListBoxSetting(string title, params string[] defaultValue) : base(title, new ObservableCollection<string>(defaultValue))
{
}

Expand All @@ -93,13 +91,13 @@ public ObservableCollection<string> Items
}
}

public class ComboBoxSearchSetting(string title, string description, object defaultValue, IEnumerable<object> options)
: ComboBoxSetting(title, description, defaultValue, options);
public class ComboBoxSearchSetting(string title, object defaultValue, IEnumerable<object> options)
: ComboBoxSetting(title, defaultValue, options);

public class SliderSetting : TitledSetting
{
public SliderSetting(string title, string description, double defaultValue, double min, double max, double step) : base(
title, description, defaultValue)
title, defaultValue)
{
Min = min;
Max = max;
Expand All @@ -117,8 +115,8 @@ public abstract class PathSetting : TextBoxSetting
{
private bool _isValid = true;

protected PathSetting(string title, string description, object defaultValue, string? watermark,
string? startDirectory, Func<string, bool>? checkPath) : base(title, description, defaultValue, watermark)
protected PathSetting(string title, string defaultValue, string? watermark,
string? startDirectory, Func<string, bool>? checkPath) : base(title, defaultValue, watermark)
{
StartDirectory = startDirectory;

Expand All @@ -143,9 +141,9 @@ public bool IsValid

public class FolderPathSetting : PathSetting
{
public FolderPathSetting(string title, string description, object defaultValue, string? watermark,
public FolderPathSetting(string title, string defaultValue, string? watermark,
string? startDirectory, Func<string, bool>? checkPath)
: base(title, description, defaultValue, watermark, startDirectory, checkPath)
: base(title, defaultValue, watermark, startDirectory, checkPath)
{
}

Expand All @@ -158,9 +156,9 @@ public override async Task SelectPathAsync(TopLevel topLevel)

public class FilePathSetting : PathSetting
{
public FilePathSetting(string title, string description, object defaultValue, string? watermark,
public FilePathSetting(string title, string defaultValue, string? watermark,
string? startDirectory, Func<string, bool>? checkPath, params FilePickerFileType[] filters)
: base(title, description, defaultValue, watermark, startDirectory, checkPath)
: base(title, defaultValue, watermark, startDirectory, checkPath)
{
Filters = filters;
}
Expand All @@ -176,7 +174,7 @@ public override async Task SelectPathAsync(TopLevel topLevel)

public class ColorSetting : TitledSetting
{
public ColorSetting(string title, string description, Color defaultValue) : base(title, description, defaultValue)
public ColorSetting(string title, Color defaultValue) : base(title, defaultValue)
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ public OpenFpgaLoaderSettingsViewModel(UniversalFpgaProjectRoot projectRoot, IFp
var defaultProperties = fpga.Properties;
_settings = FpgaSettingsParser.LoadSettings(projectRoot, fpga.Name);

_boardSetting = new TextBoxSetting("Board", "OpenFPGALoader Board",
defaultProperties.GetValueOrDefault("openFpgaLoaderBoard") ?? "", null);
_boardSetting = new TextBoxSetting("Board", defaultProperties.GetValueOrDefault("openFpgaLoaderBoard") ?? "", null)
{
HoverDescription = "OpenFPGALoader Board"
};

_shortTermFlagsSetting = new TextBoxSetting("Short Term Arguments",
"OpenFPGALoader Flags for Short Term Programming",
defaultProperties.GetValueOrDefault("openFpgaLoaderShortTermFlags") ?? "", null);
defaultProperties.GetValueOrDefault("openFpgaLoaderShortTermFlags") ?? "", null)
{
HoverDescription = "OpenFPGALoader Flags for Short Term Programming"
};

_longTermFlagsSetting = new TextBoxSetting("Long Term Arguments",
"OpenFPGALoader Flags for Long Term Programming",
defaultProperties.GetValueOrDefault("openFpgaLoaderLongTermFlags") ?? "", null);
defaultProperties.GetValueOrDefault("openFpgaLoaderLongTermFlags") ?? "", null)
{
HoverDescription = "OpenFPGALoader Flags for Long Term Programming",
};

if (_settings.TryGetValue("openFpgaLoaderBoard", out var oflBoard))
_boardSetting.Value = oflBoard;
Expand All @@ -50,9 +56,9 @@ public OpenFpgaLoaderSettingsViewModel(UniversalFpgaProjectRoot projectRoot, IFp
if (_settings.TryGetValue("openFpgaLoaderLongTermFlags", out var oflLFlags))
_longTermFlagsSetting.Value = oflLFlags;

SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_boardSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_shortTermFlagsSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_longTermFlagsSetting));
SettingsCollection.SettingModels.Add(_boardSetting);
SettingsCollection.SettingModels.Add(_shortTermFlagsSetting);
SettingsCollection.SettingModels.Add(_longTermFlagsSetting);
}

public SettingsCollectionViewModel SettingsCollection { get; } = new("OpenFPGALoader Settings")
Expand All @@ -73,6 +79,6 @@ public void Save(FlexibleWindow flexibleWindow)

public void Reset()
{
foreach (var setting in SettingsCollection.SettingModels) setting.Setting.Value = setting.Setting.DefaultValue;
foreach (var setting in SettingsCollection.SettingModels) setting.Value = setting.DefaultValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public YosysCompileSettingsViewModel(UniversalFpgaProjectRoot fpgaProjectRoot, I
{
_fpgaProjectRoot = fpgaProjectRoot;
_selectedFpga = selectedFpga;

Title = "Yosys Compile Settings";
Id = "YosysCompileSettings";

Expand All @@ -39,7 +39,7 @@ public YosysCompileSettingsViewModel(UniversalFpgaProjectRoot fpgaProjectRoot, I
//Add missing default properties
foreach (var property in defaultProperties) _settings.TryAdd(property.Key, property.Value);

_yosysSynthToolSetting = new ComboBoxSetting("Yosys Synth Tool", "Set Yosys Synth tool",
_yosysSynthToolSetting = new ComboBoxSetting("Yosys Synth Tool",
defaultProperties.GetValueOrDefault("yosysToolchainYosysSynthTool") ?? "", [
"synth_achronix",
"synth_anlogic",
Expand All @@ -59,39 +59,59 @@ public YosysCompileSettingsViewModel(UniversalFpgaProjectRoot fpgaProjectRoot, I
"synth_quicklogic",
"synth_sf2",
"synth_xilinx"
]);
_yosysFlagSetting = new TextBoxSetting("Yosys Flags", "Set Yosys flags",
defaultProperties.GetValueOrDefault("yosysToolchainYosysFlags") ?? "", null);

_nextPnrToolSetting = new ComboBoxSetting("NextPnr Tool", "Set NextPnr tool",
])
{
HoverDescription = "Set Yosys Synth tool"
};
_yosysFlagSetting = new TextBoxSetting("Yosys Flags",
defaultProperties.GetValueOrDefault("yosysToolchainYosysFlags") ?? "", null)
{
HoverDescription = "Set Yosys flags"
};

_nextPnrToolSetting = new ComboBoxSetting("NextPnr Tool",
defaultProperties.GetValueOrDefault("yosysToolchainNextPnrTool") ?? "", [
"nextpnr-ecp5",
"nextpnr-generic",
"nextpnr-gowin",
"nextpnr-ice40",
"nextpnr-machxo2",
"nextpnr-nexus"
]);
_nextPnrFlagSetting = new TextBoxSetting("NextPnR Flags", "Set NextPnr flags",
defaultProperties.GetValueOrDefault("yosysToolchainNextPnrFlags") ?? "", null);

_packToolSetting = new ComboBoxSetting("Pack Tool", "Set Pack tool",
])
{
HoverDescription = "Set NextPnr tool"
};

_nextPnrFlagSetting = new TextBoxSetting("NextPnR Flags",
defaultProperties.GetValueOrDefault("yosysToolchainNextPnrFlags") ?? "", null)
{
HoverDescription = "Set NextPnr flags"
};

_packToolSetting = new ComboBoxSetting("Pack Tool",
defaultProperties.GetValueOrDefault("yosysToolchainPackTool") ?? "", [
"ecppack",
"gowin_pack",
"icepack"
]);
_packToolFlagSetting = new TextBoxSetting("Pack Flags", "Set Pack flags",
defaultProperties.GetValueOrDefault("yosysToolchainPackFlags") ?? "", null);
])
{
HoverDescription = "Set Pack tool"
};

_packToolFlagSetting = new TextBoxSetting("Pack Flags",
defaultProperties.GetValueOrDefault("yosysToolchainPackFlags") ?? "", null)
{
HoverDescription = "Set Pack flags"
};

SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_yosysSynthToolSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_yosysFlagSetting));
SettingsCollection.SettingModels.Add(_yosysSynthToolSetting);
SettingsCollection.SettingModels.Add(_yosysFlagSetting);

SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_nextPnrToolSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_nextPnrFlagSetting));
SettingsCollection.SettingModels.Add(_nextPnrToolSetting);
SettingsCollection.SettingModels.Add(_nextPnrFlagSetting);

SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_packToolSetting));
SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_packToolFlagSetting));
SettingsCollection.SettingModels.Add(_packToolSetting);
SettingsCollection.SettingModels.Add(_packToolFlagSetting);

if (_settings.TryGetValue("yosysToolchainYosysSynthTool", out var yTool))
_yosysSynthToolSetting.Value = yTool;
Expand Down Expand Up @@ -130,6 +150,6 @@ public void Save(FlexibleWindow flexibleWindow)

public void Reset()
{
foreach (var setting in SettingsCollection.SettingModels) setting.Setting.Value = setting.Setting.DefaultValue;
foreach (var setting in SettingsCollection.SettingModels) setting.Value = setting.DefaultValue;
}
}
11 changes: 10 additions & 1 deletion src/OneWare.PackageManager/PackageManagerModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.Input;
using OneWare.Essentials.Models;
using OneWare.Essentials.Services;
using OneWare.Essentials.ViewModels;
using OneWare.PackageManager.Services;
Expand Down Expand Up @@ -36,6 +37,14 @@ public void OnInitialized(IContainerProvider containerProvider)
ContainerLocator.Container.Resolve<ISettingsService>().RegisterSettingCategory("Package Manager", 0, "PackageManager");

ContainerLocator.Container.Resolve<ISettingsService>()
.RegisterTitledListBox("Package Manager", "Sources", "PackageManager_Sources", "Custom Package Sources", "Manage the sources to look for packages");
.RegisterSetting("Package Manager", "Sources", "PackageManager_Sources", new ListBoxSetting("Custom Package Sources", [])
{
MarkdownDocumentation = """
Add custom package sources to the package manager. These sources will be used to search for and install packages.
You can add either:
- A Package Repository
- A Direct link to a package manifest
""",
});
}
}
Loading

0 comments on commit 0458cc5

Please sign in to comment.