Skip to content

Commit

Permalink
Merge pull request #23 from swittlich/main
Browse files Browse the repository at this point in the history
Creation of a project settings window for selecting the tool chain as the cornerstone for enabling one-click builds
  • Loading branch information
HendrikMennen authored Oct 31, 2024
2 parents 56d05f3 + f54736e commit 90e285c
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ private void ConstructContextMenu(IReadOnlyList<IProjectExplorerNode> selected,
Command = new AsyncRelayCommand(() => _projectExplorerService.ReloadAsync(root)),
IconObservable = Application.Current!.GetResourceObservable("VsImageLib.RefreshGrey16X")
});
menuItems.Add(new MenuItemViewModel("EditUI")
{
Header = "Edit",
Command = new RelayCommand(() => _ = CreateFolderDialogAsync(root))
});
menuItems.Add(new MenuItemViewModel("Edit")
{
Header = $"Edit {Path.GetFileName(root.ProjectFilePath)}",
Expand Down Expand Up @@ -190,4 +195,15 @@ private void ConstructContextMenu(IReadOnlyList<IProjectExplorerNode> selected,
break;
}
}

public async Task CreateFolderDialogAsync(UniversalFpgaProjectRoot root)
{
// UniversalFpgaProjectRoot root
await _windowService.ShowDialogAsync(new UniversalFpgaProjectSettingsEditorView()
{
DataContext = new UniversalFpgaProjectSettingsEditorViewModel(root)
/* ContainerLocator.Container.Resolve<UniversalFpgaProjectSettingsEditorViewModel>() */
});

}
}
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ public void ToggleProjectLoader(IFpgaLoader loader)
}

public async Task CompileAsync()
{
if (ProjectExplorerService.ActiveProject is UniversalFpgaProjectRoot project)
{
var name = project.Properties["Fpga"]?.ToString();
if (name == null) {
await OpenPinPlannerAsync();
return;
}

var firstOrDefault = FpgaService.FpgaPackages.FirstOrDefault(obj => obj.Name == name);
if (firstOrDefault == null) {
await OpenPinPlannerAsync();
return;
}

await project.RunToolchainAsync(new FpgaModel(firstOrDefault.LoadFpga()));
}
}

public async Task OpenPinPlannerAsync()
{
if (ProjectExplorerService.ActiveProject is UniversalFpgaProjectRoot project)
await _windowService.ShowDialogAsync(new UniversalFpgaProjectCompileView
Expand All @@ -101,6 +121,17 @@ await _windowService.ShowDialogAsync(new UniversalFpgaProjectCompileView
});
}

public async Task OpenProjectSettingsAsync()
{
if (ProjectExplorerService.ActiveProject is UniversalFpgaProjectRoot project)
await _windowService.ShowDialogAsync(new UniversalFpgaProjectSettingsEditorView()
{
DataContext =
ContainerLocator.Container.Resolve<UniversalFpgaProjectSettingsEditorViewModel>((
typeof(UniversalFpgaProjectRoot), project))
});
}

public async Task DownloadAsync()
{
if (ProjectExplorerService.ActiveProject is UniversalFpgaProjectRoot { Loader: not null } project)
Expand Down
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>
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,14 @@
<Button>
<Button.Flyout>
<Flyout FlyoutPresenterTheme="{StaticResource FlyoutNoPadding}">
<ItemsControl ItemsSource="{Binding FpgaService.Toolchains}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="services:IFpgaToolchain">
<MenuItem Header="{Binding Name}"
Command="{Binding $parent[UserControl].((viewModels:UniversalFpgaProjectToolBarViewModel)DataContext).ToggleProjectToolchain, FallbackValue={x:Null}}"
CommandParameter="{Binding}">
<MenuItem.Icon>
<CheckBox BorderThickness="0">
<CheckBox.IsChecked>
<MultiBinding
Converter="{x:Static converters:SharedConverters.ObjectsEqualConverter}">
<Binding FallbackValue="{x:Null}"
Path="$parent[UserControl].((viewModels:UniversalFpgaProjectToolBarViewModel)DataContext).ProjectExplorerService.((models:UniversalFpgaProjectRoot)ActiveProject).Toolchain"/>
<Binding />
</MultiBinding>
</CheckBox.IsChecked>
</CheckBox>
</MenuItem.Icon>
</MenuItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel>
<Button HorizontalContentAlignment="Left" Content="Open Pin Planner"
Command="{Binding OpenPinPlannerAsync}"
/>
<Button HorizontalContentAlignment="Left" Content="Open Project Settings"
Command="{Binding OpenProjectSettingsAsync}"
/>
</StackPanel>
</Flyout>
</Button.Flyout>
<Image Source="{DynamicResource MaterialDesign.KeyboardArrowDown}" Width="10" Height="10" Margin="1 0" />
Expand All @@ -67,35 +53,6 @@
<TextBlock Text="Download" VerticalAlignment="Center" />
</StackPanel>
</Button>
<Button>
<Button.Flyout>
<Flyout FlyoutPresenterTheme="{StaticResource FlyoutNoPadding}">
<ItemsControl ItemsSource="{Binding FpgaService.Loaders}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="services:IFpgaLoader">
<MenuItem Header="{Binding Name}"
Command="{Binding $parent[UserControl].((viewModels:UniversalFpgaProjectToolBarViewModel)DataContext).ToggleProjectLoader, FallbackValue={x:Null}}"
CommandParameter="{Binding}">
<MenuItem.Icon>
<CheckBox BorderThickness="0">
<CheckBox.IsChecked>
<MultiBinding
Converter="{x:Static converters:SharedConverters.ObjectsEqualConverter}">
<Binding FallbackValue="{x:Null}"
Path="$parent[UserControl].((viewModels:UniversalFpgaProjectToolBarViewModel)DataContext).ProjectExplorerService.((models:UniversalFpgaProjectRoot)ActiveProject).Loader"/>
<Binding />
</MultiBinding>
</CheckBox.IsChecked>
</CheckBox>
</MenuItem.Icon>
</MenuItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Flyout>
</Button.Flyout>
<Image Source="{DynamicResource MaterialDesign.KeyboardArrowDown}" Width="10" Height="10" Margin="1 0" />
</Button>
<Button>
<Button.Flyout>
<Flyout FlyoutPresenterTheme="{StaticResource FlyoutNoPadding}">
Expand Down

0 comments on commit 90e285c

Please sign in to comment.