100 lines
2.9 KiB
C#
100 lines
2.9 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.InteropServices;
|
|
using Microsoft.UI;
|
|
using Microsoft.UI.Windowing;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using RustTools.muqing;
|
|
using Windows.ApplicationModel.Core;
|
|
using Windows.Foundation;
|
|
using Windows.UI.Core.Preview;
|
|
using Windows.UI.Popups;
|
|
using Windows.UI.WindowManagement;
|
|
using WinRT.Interop;
|
|
namespace RustTools.Editor;
|
|
/// <summary>
|
|
/// 编辑器主窗口
|
|
/// </summary>
|
|
public sealed partial class EditorWin : WindowEx
|
|
{
|
|
|
|
private Microsoft.UI.Windowing.AppWindow? app;
|
|
public EditorWin()
|
|
{
|
|
InitializeComponent();
|
|
gj.SetBackTheme(this);
|
|
ExtendsContentIntoTitleBar = true;
|
|
var frame = App.AppTitlebar as FrameworkElement;
|
|
if (frame != null)
|
|
{
|
|
gj.UpdateTitleBar(this, frame.ActualTheme);
|
|
grid.RequestedTheme = frame.ActualTheme;
|
|
}
|
|
|
|
//WindowManager.Get(this).IsMinimizable = false;
|
|
//WindowManager.Get(this).IsMaximizable = false;
|
|
//WindowManager.Get(this).IsResizable = false;
|
|
//WindowManager.Get(this).IsAlwaysOnTop = false;
|
|
//WindowManager.Get(this).IsTitleBarVisible = false;
|
|
|
|
|
|
//app = GetAppWindowForCurrentWindow();
|
|
//app.Closing += OnClosing;
|
|
//Closed += EditorWin_Closed;
|
|
|
|
Closed += EditorWin_Closed;
|
|
}
|
|
|
|
private async Task SaveDataAsync()
|
|
{
|
|
|
|
}
|
|
//用户有没有保存
|
|
private bool IsSave = false;
|
|
private ContentDialog? ClosedDialog;
|
|
private async void EditorWin_Closed(object sender, WindowEventArgs e)
|
|
{
|
|
if (IsSave == false)
|
|
{
|
|
// 防止窗口关闭
|
|
e.Handled = true;
|
|
}
|
|
if (ClosedDialog != null) {
|
|
return;
|
|
}
|
|
// 显示一个对话框,告知用户窗口不能关闭
|
|
ClosedDialog = new ContentDialog
|
|
{
|
|
XamlRoot = grid.XamlRoot,
|
|
Title = "警告",
|
|
Content = "你还有未保存的文件在编译器中。",
|
|
PrimaryButtonText = "保存关闭",
|
|
PrimaryButtonStyle = Application.Current.Resources["AccentButtonStyle"] as Style,
|
|
SecondaryButtonText = "直接关闭",
|
|
CloseButtonText = "取消"
|
|
};
|
|
var result = await ClosedDialog.ShowAsync();
|
|
if (result == ContentDialogResult.Primary)
|
|
{
|
|
IsSave = true;
|
|
Application.Current.Exit();
|
|
return;
|
|
}
|
|
else if (result == ContentDialogResult.Secondary)
|
|
{
|
|
|
|
IsSave = true;
|
|
Application.Current.Exit();
|
|
return;
|
|
}
|
|
ClosedDialog = null;
|
|
}
|
|
|
|
private Microsoft.UI.Windowing.AppWindow GetAppWindowForCurrentWindow()
|
|
{
|
|
var hWnd = WindowNative.GetWindowHandle(this);
|
|
var myWndId = Win32Interop.GetWindowIdFromWindow(hWnd);
|
|
return Microsoft.UI.Windowing.AppWindow.GetFromWindowId(myWndId);
|
|
}
|
|
}
|