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:
65
ViewModels/FileEditorViewModel.cs
Normal file
65
ViewModels/FileEditorViewModel.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user