-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from swittlich/main
Creation of a project settings window for selecting the tool chain as the cornerstone for enabling one-click builds
- Loading branch information
Showing
6 changed files
with
193 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...Ware.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectSettingsEditorViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Text.Json.Nodes; | ||
using System.Windows.Input; | ||
using Avalonia.Controls; | ||
using DynamicData; | ||
using OneWare.Essentials.Controls; | ||
using OneWare.Essentials.Models; | ||
using OneWare.Essentials.Services; | ||
using OneWare.Essentials.ViewModels; | ||
using OneWare.Settings.ViewModels; | ||
using OneWare.Settings.ViewModels.SettingTypes; | ||
using OneWare.Settings.Views.SettingTypes; | ||
using OneWare.UniversalFpgaProjectSystem.Models; | ||
using OneWare.UniversalFpgaProjectSystem.Services; | ||
using Prism.Ioc; | ||
|
||
namespace OneWare.UniversalFpgaProjectSystem.ViewModels; | ||
|
||
public class UniversalFpgaProjectSettingsEditorViewModel : FlexibleWindowViewModelBase | ||
{ | ||
public SettingsCollectionViewModel SettingsCollection { get; } = new("") | ||
{ | ||
ShowTitle = false | ||
}; | ||
|
||
private UniversalFpgaProjectRoot _root; | ||
|
||
private ComboBoxSetting _toolchain; | ||
private ComboBoxSetting _loader; | ||
|
||
private ListBoxSetting _includesSettings; | ||
private ListBoxSetting _excludesSettings; | ||
|
||
public UniversalFpgaProjectSettingsEditorViewModel(UniversalFpgaProjectRoot root) | ||
{ | ||
_root = root; | ||
Title = $"{_root.Name} Settings"; | ||
|
||
var includes = _root.Properties["Include"]!.AsArray().Select(node => node!.ToString()).ToArray(); | ||
var exclude = _root.Properties["Exclude"]!.AsArray().Select(node => node!.ToString()).ToArray(); | ||
|
||
var toolchains = ContainerLocator.Container.Resolve<FpgaService>().Toolchains.Select(toolchain => toolchain.Name); | ||
var currentToolchain = _root.Properties["Toolchain"]!.ToString(); | ||
_toolchain = new ComboBoxSetting("Toolchain", "test", currentToolchain, toolchains); | ||
|
||
var loader = ContainerLocator.Container.Resolve<FpgaService>().Loaders.Select(loader => loader.Name); | ||
var currentLoader = _root.Properties["Loader"]!.ToString(); | ||
_loader = new ComboBoxSetting("Loader", "test", currentLoader, loader); | ||
|
||
_includesSettings = new ListBoxSetting("Files to Include", "test", includes); | ||
_excludesSettings = new ListBoxSetting("Files to Exclude", "test", exclude); | ||
|
||
SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_toolchain) ); | ||
SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_loader) ); | ||
SettingsCollection.SettingModels.Add(new ListBoxSettingViewModel(_includesSettings) ); | ||
SettingsCollection.SettingModels.Add(new ListBoxSettingViewModel(_excludesSettings) ); | ||
} | ||
|
||
private async Task SaveAsync() | ||
{ | ||
_root.Properties["Toolchain"] = _toolchain.Value.ToString(); | ||
_root.Properties["Loader"] = _loader.Value.ToString(); | ||
|
||
UpdateJsonArray(_root.Properties["Include"]!, _includesSettings.Items.Select(item => item.ToString()).ToArray()); | ||
UpdateJsonArray(_root.Properties["Exclude"]!, _excludesSettings.Items.Select(item => item.ToString()).ToArray()); | ||
|
||
await ContainerLocator.Container.Resolve<IProjectExplorerService>().SaveProjectAsync(_root); | ||
} | ||
|
||
private void UpdateJsonArray(JsonNode? jsonObject, string[] newValues) | ||
{ | ||
jsonObject?.AsArray().Clear(); | ||
foreach (var value in newValues) | ||
{ | ||
jsonObject?.AsArray().Add(value); | ||
} | ||
} | ||
|
||
public async Task SaveAndCloseAsync(FlexibleWindow window) | ||
{ | ||
await SaveAsync(); | ||
Close(window); | ||
} | ||
|
||
|
||
public void Close(FlexibleWindow window) | ||
{ | ||
window.Close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/OneWare.UniversalFpgaProjectSystem/Views/UniversalFpgaProjectSettingsEditorView.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<controls:FlexibleWindow xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:viewModels="clr-namespace:OneWare.UniversalFpgaProjectSystem.ViewModels" | ||
xmlns:controls="clr-namespace:OneWare.Essentials.Controls;assembly=OneWare.Essentials" | ||
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450" | ||
PrefHeight="450" PrefWidth="600" Padding="4" | ||
WindowBackground="{DynamicResource ThemeBackgroundBrush}" | ||
WindowStartupLocation="CenterOwner" | ||
Title="{Binding Title}" | ||
CustomIcon="{DynamicResource CreateIcon}" | ||
x:Class="OneWare.UniversalFpgaProjectSystem.Views.UniversalFpgaProjectSettingsEditorView" | ||
x:DataType="viewModels:UniversalFpgaProjectSettingsEditorViewModel" | ||
Name="UniversalFpgaProjectCompileViewView"> | ||
<DockPanel> | ||
<ScrollViewer DockPanel.Dock="Top"> | ||
<ContentControl Padding="4" Content="{Binding SettingsCollection}" /> | ||
</ScrollViewer> | ||
|
||
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="8" Classes="WindowButtons" | ||
HorizontalAlignment="Right" | ||
VerticalAlignment="Bottom"> | ||
<Button Command="{Binding SaveAndCloseAsync}" | ||
CommandParameter="{Binding #UniversalFpgaProjectCompileViewView}"> | ||
<TextBlock Text="Save and Close" Margin="5 0" /> | ||
</Button> | ||
<Button Command="{Binding Close}" | ||
CommandParameter="{Binding #UniversalFpgaProjectCompileViewView}"> | ||
<TextBlock Text="Close" Margin="5 0" /> | ||
</Button> | ||
</StackPanel> | ||
</DockPanel> | ||
</controls:FlexibleWindow> |
14 changes: 14 additions & 0 deletions
14
src/OneWare.UniversalFpgaProjectSystem/Views/UniversalFpgaProjectSettingsEditorView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using OneWare.Essentials.Controls; | ||
|
||
namespace OneWare.UniversalFpgaProjectSystem.Views; | ||
|
||
public partial class UniversalFpgaProjectSettingsEditorView : FlexibleWindow | ||
{ | ||
public UniversalFpgaProjectSettingsEditorView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters