mirror of
https://onedev.site.tesses.net/crosslang/crosslangdevstudio
synced 2026-02-08 09:15:45 +00:00
65 lines
1.4 KiB
C#
65 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
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 FileEditorViewModel : ViewModelBase, ISavable
|
|
{
|
|
TabItemViewModel tab;
|
|
public string FilePath { get; }
|
|
bool _modified = false;
|
|
private bool Modified
|
|
{
|
|
get => _modified;
|
|
set
|
|
{
|
|
_modified = value;
|
|
|
|
if (value)
|
|
{
|
|
tab.Header = $"{Path.GetFileName(FilePath)}*";
|
|
}
|
|
else
|
|
{
|
|
tab.Header = Path.GetFileName(FilePath);
|
|
}
|
|
}
|
|
}
|
|
|
|
private string _text = "";
|
|
|
|
public string Text
|
|
{
|
|
get => _text;
|
|
set
|
|
{
|
|
|
|
Modified = true;
|
|
this.SetProperty(ref _text, value, nameof(Text));
|
|
}
|
|
}
|
|
|
|
public FileEditorViewModel(string path,TabItemViewModel tab)
|
|
{
|
|
this.tab = tab;
|
|
FilePath = path;
|
|
_text = File.ReadAllText(path);
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
File.WriteAllText(FilePath, Text);
|
|
Modified = false;
|
|
}
|
|
} |