using System; using System.Collections.ObjectModel; using System.IO; using System.Threading.Tasks; using Avalonia; using Avalonia.Platform.Storage; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using CrossLangDevStudio.Messages; using CrossLangDevStudio.Views; namespace CrossLangDevStudio.ViewModels; public partial class WelcomeViewModel : ViewModelBase { public MainWindowViewModel Main { get; } public WelcomeViewModel(MainWindowViewModel main) { Main = main; foreach (var proj in CrossLangShell.GetRecentProjects()) { RecentProjects.Add(new RecentProject(proj,Main.LoadProject)); } } public ObservableCollection RecentProjects { get; set; } = new ObservableCollection(); [RelayCommand] private async Task NewProjectAsync() { await Main.NewProjectAsync(); } [RelayCommand] private async Task OpenProjectAsync() { await Main.OpenProjectAsync(); } } public partial class RecentProject(string path, Action onProjectClicked) : ObservableObject { public string ProjectPath { get; set; } = path; private string GetDir() { var projPath = ProjectPath; var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); if (projPath.StartsWith(path)) { projPath= projPath.Replace(path, "~"); } return projPath; } public string Name => $"{Path.GetFileName(ProjectPath)} ({GetDir()})"; [RelayCommand] private void Click() { onProjectClicked(ProjectPath); } }