79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
|
|
using System.Reflection;
|
|||
|
|
using System.Windows;
|
|||
|
|
|
|||
|
|
using AvalonDock.Themes;
|
|||
|
|
|
|||
|
|
using ICSharpCode.AvalonEdit.Highlighting;
|
|||
|
|
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
|
|||
|
|
|
|||
|
|
using Microsoft.CodeAnalysis.Differencing;
|
|||
|
|
|
|||
|
|
using RoslynPad.Editor;
|
|||
|
|
|
|||
|
|
namespace Szmedi.RvKits.RvScript
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Interaction logic for RoslynEditor.xaml
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class RoslynEditor
|
|||
|
|
{
|
|||
|
|
public RoslynEditor(RoslynEditorViewModel document)
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
DataContext = document;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void CodeEditor_Loaded(object sender, RoutedEventArgs e)
|
|||
|
|
{
|
|||
|
|
var editor = (RoslynCodeEditor)sender;
|
|||
|
|
editor.Loaded -= CodeEditor_Loaded;
|
|||
|
|
editor.Focus();
|
|||
|
|
|
|||
|
|
var viewModel = (RoslynEditorViewModel)DataContext;
|
|||
|
|
viewModel.CodeEditor = editor;
|
|||
|
|
var documentViewModel = (DocumentViewModel)editor.DataContext;
|
|||
|
|
var workingDirectory = Directory.GetCurrentDirectory();
|
|||
|
|
|
|||
|
|
var documentId = editor.Initialize(viewModel.Host, new ClassificationHighlightColors(),
|
|||
|
|
workingDirectory, string.Empty);
|
|||
|
|
|
|||
|
|
documentViewModel.Initialize(documentId);
|
|||
|
|
editor.Document.TextChanged += documentViewModel.OnTextChanged;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void dockManager_DocumentClosing(object sender, AvalonDock.DocumentClosingEventArgs e)
|
|||
|
|
{
|
|||
|
|
e.Cancel = true;
|
|||
|
|
var documentViewModel = (DocumentViewModel)e.Document.Content;
|
|||
|
|
var viewModel = (RoslynEditorViewModel)DataContext;
|
|||
|
|
viewModel.Close(documentViewModel);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//private void Window_Closed(object sender, EventArgs e)
|
|||
|
|
//{
|
|||
|
|
|
|||
|
|
// AppDomain.CurrentDomain.AssemblyResolve -= ScriptRunnerCmd.CurrentDomain_AssemblyResolve;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|||
|
|
{
|
|||
|
|
if (dockManager.ActiveContent is DocumentViewModel viewModel && viewModel.IsDirty)
|
|||
|
|
{
|
|||
|
|
var mes = MessageBox.Show("有文件未保存,确定关闭吗?", "关闭", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|||
|
|
|
|||
|
|
if (mes == MessageBoxResult.No)
|
|||
|
|
{
|
|||
|
|
e.Cancel = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
AppDomain.CurrentDomain.AssemblyResolve -= ScriptRunnerCmd.CurrentDomain_AssemblyResolve;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|