129 lines
3.6 KiB
C#
129 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using NexvaneHub.Models;
|
|
|
|
namespace NexvaneHub.ViewModels;
|
|
|
|
public enum HubSection
|
|
{
|
|
Projects,
|
|
Sdk,
|
|
Packages,
|
|
}
|
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
|
{
|
|
public MainWindowViewModel()
|
|
{
|
|
_projects = new ObservableCollection<ProjectItemViewModel>
|
|
{
|
|
new(new ProjectModel
|
|
{
|
|
Name = "Project A",
|
|
LastModified = new DateTime(2026, 9, 6),
|
|
Directory = @"C:\Dev\ProjectA",
|
|
ProjectVersion = "1.2.0",
|
|
SdkVersion = "1.4.2",
|
|
DefaultCompiler = "MSVC",
|
|
DefaultArchitecture = "Auto",
|
|
}),
|
|
new(new ProjectModel
|
|
{
|
|
Name = "Project B",
|
|
LastModified = new DateTime(2026, 8, 2),
|
|
Directory = @"C:\Dev\ProjectB",
|
|
ProjectVersion = "0.9.4",
|
|
SdkVersion = "1.3.0",
|
|
DefaultCompiler = "Clang",
|
|
DefaultArchitecture = "x64",
|
|
}),
|
|
new(new ProjectModel
|
|
{
|
|
Name = "Project C",
|
|
LastModified = new DateTime(2026, 6, 18),
|
|
Directory = @"C:\Dev\ProjectC",
|
|
ProjectVersion = "1.0.0",
|
|
SdkVersion = "1.4.2",
|
|
DefaultCompiler = "MSVC",
|
|
DefaultArchitecture = "Auto",
|
|
}),
|
|
new(new ProjectModel
|
|
{
|
|
Name = "Project D",
|
|
LastModified = new DateTime(2026, 5, 30),
|
|
Directory = @"C:\Dev\ProjectD",
|
|
ProjectVersion = "0.4.1",
|
|
SdkVersion = "1.2.7",
|
|
DefaultCompiler = "GCC",
|
|
DefaultArchitecture = "ARM64",
|
|
}),
|
|
};
|
|
|
|
_selectedProject = _projects.Count > 0 ? _projects[0] : null;
|
|
}
|
|
|
|
[ObservableProperty]
|
|
private HubSection _currentSection = HubSection.Projects;
|
|
|
|
[ObservableProperty]
|
|
private ObservableCollection<ProjectItemViewModel> _projects;
|
|
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(OpenProjectCommand))]
|
|
[NotifyCanExecuteChangedFor(nameof(DeleteProjectCommand))]
|
|
private ProjectItemViewModel? _selectedProject;
|
|
|
|
[ObservableProperty]
|
|
private bool _isProjectSectionExpanded = true;
|
|
|
|
[ObservableProperty]
|
|
private bool _isSdkSectionExpanded = true;
|
|
|
|
[RelayCommand]
|
|
private void NavigateTo(HubSection section)
|
|
{
|
|
CurrentSection = section;
|
|
}
|
|
|
|
[RelayCommand(CanExecute = nameof(HasSelectedProject))]
|
|
private void OpenProject()
|
|
{
|
|
// TODO: hook this up to actually launching the editor process
|
|
// against SelectedProject.Directory.
|
|
}
|
|
|
|
[RelayCommand(CanExecute = nameof(HasSelectedProject))]
|
|
private void DeleteProject()
|
|
{
|
|
if (SelectedProject is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var index = Projects.IndexOf(SelectedProject);
|
|
Projects.Remove(SelectedProject);
|
|
|
|
SelectedProject = Projects.Count == 0
|
|
? null
|
|
: Projects[Math.Min(index, Projects.Count - 1)];
|
|
}
|
|
|
|
private bool HasSelectedProject() => SelectedProject is not null;
|
|
|
|
[RelayCommand]
|
|
private void CreateNewProject()
|
|
{
|
|
var project = new ProjectItemViewModel(new ProjectModel
|
|
{
|
|
Name = $"New Project {Projects.Count + 1}",
|
|
LastModified = DateTime.Now,
|
|
Directory = @"C:\Dev\NewProject",
|
|
});
|
|
|
|
Projects.Insert(0, project);
|
|
SelectedProject = project;
|
|
}
|
|
}
|