mirror of
https://onedev.site.tesses.net/crosslang/crosslangdevstudio
synced 2026-02-08 09:15:45 +00:00
66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
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<RecentProject> RecentProjects { get; set; } = new ObservableCollection<RecentProject>();
|
|
|
|
[RelayCommand]
|
|
private async Task NewProjectAsync()
|
|
{
|
|
await Main.NewProjectAsync();
|
|
}
|
|
[RelayCommand]
|
|
private async Task OpenProjectAsync()
|
|
{
|
|
await Main.OpenProjectAsync();
|
|
}
|
|
}
|
|
|
|
public partial class RecentProject(string path, Action<string> 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);
|
|
}
|
|
} |