mirror of
https://onedev.site.tesses.net/crosslang/crosslangdevstudio
synced 2026-02-08 09:15:45 +00:00
Get way further
This commit is contained in:
@@ -5,13 +5,22 @@ using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
using AvaloniaEdit;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CrossLangDevStudio.Messages;
|
||||
using CrossLangDevStudio.Views;
|
||||
|
||||
using AvaloniaEdit.CodeCompletion;
|
||||
using AvaloniaEdit.Document;
|
||||
using AvaloniaEdit.Editing;
|
||||
using AvaloniaEdit.Folding;
|
||||
using AvaloniaEdit.Rendering;
|
||||
using TextMateSharp.Grammars;
|
||||
using AvaloniaEdit.TextMate;
|
||||
using Avalonia.Input;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia.Media;
|
||||
namespace CrossLangDevStudio.ViewModels;
|
||||
|
||||
public partial class FileEditorViewModel : ViewModelBase, ISavable
|
||||
@@ -19,7 +28,7 @@ public partial class FileEditorViewModel : ViewModelBase, ISavable
|
||||
TabItemViewModel tab;
|
||||
public string FilePath { get; }
|
||||
bool _modified = false;
|
||||
private bool Modified
|
||||
public bool Modified
|
||||
{
|
||||
get => _modified;
|
||||
set
|
||||
@@ -36,30 +45,72 @@ public partial class FileEditorViewModel : ViewModelBase, ISavable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _text = "";
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => _text;
|
||||
set
|
||||
{
|
||||
|
||||
Modified = true;
|
||||
this.SetProperty(ref _text, value, nameof(Text));
|
||||
}
|
||||
}
|
||||
|
||||
public FileEditorViewModel(string path,TabItemViewModel tab)
|
||||
TextEditor textEdit = new TextEditor();
|
||||
|
||||
public TextEditor TextEditor => textEdit;
|
||||
|
||||
|
||||
|
||||
public FileEditorViewModel(string path, TabItemViewModel tab)
|
||||
{
|
||||
this.tab = tab;
|
||||
FilePath = path;
|
||||
_text = File.ReadAllText(path);
|
||||
textEdit.ShowLineNumbers = true;
|
||||
textEdit.FontSize = 24;
|
||||
string ext = Path.GetExtension(FilePath);
|
||||
if (ext == ".tcross")
|
||||
{
|
||||
ext = ".go";
|
||||
}
|
||||
{
|
||||
|
||||
var _registryOptions = new RegistryOptions(ThemeName.Dark);
|
||||
|
||||
var _textMateInstallation = textEdit.InstallTextMate(_registryOptions);
|
||||
|
||||
//definition.
|
||||
|
||||
|
||||
|
||||
//Here we are getting the language by the extension and right after that we are initializing grammar with this language.
|
||||
//And that's all 😀, you are ready to use AvaloniaEdit with syntax highlighting!
|
||||
try
|
||||
{
|
||||
//AssetLoader.Open(new Uri("avares://CrossLangDevStudio/Assets/crosslang.png")
|
||||
|
||||
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(ext).Id));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
textEdit.Text = File.ReadAllText(path);
|
||||
textEdit.TextChanged += (sender, e) =>
|
||||
{
|
||||
Modified = true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void Save()
|
||||
{
|
||||
File.WriteAllText(FilePath, Text);
|
||||
|
||||
File.WriteAllText(FilePath, textEdit.Text);
|
||||
Modified = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveRecovery(string path)
|
||||
{
|
||||
|
||||
File.WriteAllText(path, textEdit.Text);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user