mirror of
https://onedev.site.tesses.net/crosslang/crosslangdevstudio
synced 2026-02-08 09:15:45 +00:00
First Commit
This commit is contained in:
66
ViewModels/WelcomeViewModel.cs
Normal file
66
ViewModels/WelcomeViewModel.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user