Skip to content

Commit

Permalink
set active save
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 21, 2023
1 parent aa9bc6f commit 464bfbd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
19 changes: 13 additions & 6 deletions src/OneWare.ProjectExplorer/ViewModels/ProjectExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private async Task<bool> AskForIncludeDialogAsync(IProjectRoot root, string rela
return result;
}

public async Task<IProjectRoot?> LoadProjectAsync(string path, IProjectManager manager, bool expand = true)
public async Task<IProjectRoot?> LoadProjectAsync(string path, IProjectManager manager, bool expand = true, bool setActive = true)
{
var project = await manager.LoadProjectAsync(path);

Expand All @@ -354,7 +354,8 @@ private async Task<bool> AskForIncludeDialogAsync(IProjectRoot root, string rela
if (expand) project.IsExpanded = expand;

Insert(project);
ActiveProject = project;

if(setActive) ActiveProject = project;

return project;
}
Expand Down Expand Up @@ -787,10 +788,13 @@ public async Task SaveLastProjectsFileAsync()
{
var roots = Items.Where(x => x is IProjectRoot).Cast<IProjectRoot>();
var serialization = roots
.Select(x => new ProjectSerialization(x.ProjectTypeId, x.ProjectPath, x.IsExpanded)).ToArray();
.Select(x => new ProjectSerialization(x.ProjectTypeId, x.ProjectPath, x.IsExpanded, x.IsActive)).ToArray();
await using var stream = File.OpenWrite(_lastProjectsFile);
stream.SetLength(0);
await JsonSerializer.SerializeAsync(stream, serialization);
await JsonSerializer.SerializeAsync(stream, serialization, new JsonSerializerOptions()
{
WriteIndented = true
});
}
catch (Exception e)
{
Expand All @@ -814,7 +818,7 @@ public async Task OpenLastProjectsFileAsync()
var manager = _projectManagerService.GetManager(l.ProjectType);
if (manager != null)
{
loadProjectTasks.Add(LoadProjectAsync(l.Path, manager, l.IsExpanded));
loadProjectTasks.Add(LoadProjectAsync(l.Path, manager, l.IsExpanded, l.IsActive));
}
else
ContainerLocator.Container.Resolve<ILogger>()?
Expand All @@ -840,12 +844,15 @@ private class ProjectSerialization
public string ProjectType { get; set; }
public string Path { get; set; }
public bool IsExpanded { get; set; }

public bool IsActive { get; set; }

public ProjectSerialization(string projectType, string path, bool isExpanded)
public ProjectSerialization(string projectType, string path, bool isExpanded, bool isActive)
{
ProjectType = projectType;
Path = path;
IsExpanded = isExpanded;
IsActive = isActive;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
mc:Ignorable="d" d:DesignWidth="150" d:DesignHeight="30"
x:Class="OneWare.ProjectExplorer.Views.ProjectExplorerMainWindowToolBarExtension" x:DataType="viewModels:ProjectExplorerViewModel">

<ComboBox Width="150" IsEnabled="{Binding Active.ActiveProcess.State, Converter={x:Static converters:SharedConverters.ComparisonConverter}, ConverterParameter={x:Static enums:AppState.Idle}}"
<ComboBox Width="200" IsEnabled="{Binding Active.ActiveProcess.State, Converter={x:Static converters:SharedConverters.ComparisonConverter}, ConverterParameter={x:Static enums:AppState.Idle}}"
BorderThickness="0"
ItemsSource="{Binding Items}"
SelectedItem="{Binding ActiveProject}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@
using OneWare.Shared.Services;
using OneWare.Shared.ViewModels;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Services;

namespace OneWare.UniversalFpgaProjectSystem.ViewModels;

public class UniversalFpgaProjectCreatorViewModel : FlexibleWindowViewModelBase
{
public IPaths Paths { get; }
private readonly IProjectExplorerService _projectExplorerService;
private readonly FpgaService _fpgaService;
private readonly ILogger _logger;
private readonly UniversalFpgaProjectManager _manager;

private readonly TextBoxSetting _nameSetting;
private readonly ComboBoxSetting _templateSetting;
private readonly FolderPathSetting _folderPathSetting;
private readonly TitledSetting _createNewFolderSetting;
private readonly ComboBoxSetting _toolchainSetting;
private readonly ComboBoxSetting _loaderSetting;

public SettingsCollectionViewModel SettingsCollection { get; } = new("Project Properties")
{
ShowTitle = false
};

public UniversalFpgaProjectCreatorViewModel(IPaths paths, IProjectExplorerService projectExplorerService, ILogger logger, UniversalFpgaProjectManager manager)
public UniversalFpgaProjectCreatorViewModel(IPaths paths, IProjectExplorerService projectExplorerService, ILogger logger, FpgaService fpgaService, UniversalFpgaProjectManager manager)
{
_projectExplorerService = projectExplorerService;
_fpgaService = fpgaService;
_logger = logger;
_manager = manager;
Paths = paths;
Expand All @@ -43,11 +48,23 @@ public UniversalFpgaProjectCreatorViewModel(IPaths paths, IProjectExplorerServic

_createNewFolderSetting = new TitledSetting("Create new Folder",
"Set if a new folder should be created in the selected location", true);

_toolchainSetting = new ComboBoxSetting("Toolchain",
"Set the toolchain to use for the project (can be changed later)", fpgaService.Toolchains.FirstOrDefault()?.Name ?? "Unset",
new[] { "Unset" }.Concat(fpgaService.Toolchains
.Select(x => x.Name)));

_loaderSetting = new ComboBoxSetting("Loader",
"Set the loader to use for the project (can be changed later)", fpgaService.Loaders.FirstOrDefault()?.Name ?? "Unset",
new[] { "Unset" }.Concat(fpgaService.Loaders
.Select(x => x.Name)));

SettingsCollection.SettingModels.Add(new TextBoxSettingViewModel(_nameSetting));
SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_templateSetting));
SettingsCollection.SettingModels.Add(new PathSettingViewModel(_folderPathSetting));
SettingsCollection.SettingModels.Add(new CheckBoxSettingViewModel(_createNewFolderSetting));
SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_toolchainSetting));
SettingsCollection.SettingModels.Add(new ComboBoxSettingViewModel(_loaderSetting));
}

public async Task SaveAsync(FlexibleWindow window)
Expand Down Expand Up @@ -82,10 +99,16 @@ public async Task SaveAsync(FlexibleWindow window)
var defaultProperties = new JsonObject()
{
["Include"] = new JsonArray("*.vhd", "*.vhdl", "*.v"),
["Exclude"] = new JsonArray("bin"),
["Exclude"] = new JsonArray("build"),
};
var root = new UniversalFpgaProjectRoot(projectFile, defaultProperties);

if (_fpgaService.Toolchains.FirstOrDefault(x => x.Name == _toolchainSetting.Value.ToString()) is {} tc)
root.Toolchain = tc;

if (_fpgaService.Loaders.FirstOrDefault(x => x.Name == _loaderSetting.Value.ToString()) is {} loader)
root.Loader = loader;

await _manager.SaveProjectAsync(root);

_projectExplorerService.Insert(root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
<behaviours:CommandOnEnterBehaviour Command="{Binding SaveAsync}"
CommandParameter="{Binding #UniversalFpgaProjectCreator}" />
</Interaction.Behaviors>
<Grid RowDefinitions="*, Auto">
<ContentControl Padding="4" Content="{Binding SettingsCollection}"/>
<StackPanel Grid.Row="1" DockPanel.Dock="Bottom" Margin="8" Classes="WindowButtons" HorizontalAlignment="Right"
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" Margin="8" Classes="WindowButtons" HorizontalAlignment="Right"
VerticalAlignment="Bottom">
<Button Background="{DynamicResource HighlightBrush}" Command="{Binding SaveAsync}"
CommandParameter="{Binding #UniversalFpgaProjectCreator}">
<TextBlock Text="Save" />
</Button>
</StackPanel>
</Grid>
<ScrollViewer DockPanel.Dock="Top" >
<ContentControl Padding="4" Content="{Binding SettingsCollection}"/>
</ScrollViewer>
</DockPanel>
</controls:FlexibleWindow>

0 comments on commit 464bfbd

Please sign in to comment.