WIn_RustTools/Editor/EditorWin.xaml.cs

111 lines
3.0 KiB
C#
Raw Normal View History

2024-08-09 07:05:40 +00:00
using System.Collections.ObjectModel;
using System.Diagnostics;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
2024-08-09 07:05:40 +00:00
using Microsoft.UI.Xaml.Input;
using RustTools.muqing;
using WinRT.Interop;
namespace RustTools.Editor;
/// <summary>
/// <20><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public sealed partial class EditorWin : WindowEx
{
public static ObservableCollection<TabViewItem> TabViewList = new();
2024-08-09 07:05:40 +00:00
//Ŀ¼<C4BF>б<EFBFBD>
public ObservableCollection<FileItem> DataSource = new();
/// <summary>
/// <20><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
/// </summary>
/// <param name="path"></param>
public EditorWin(string path)
{
InitializeComponent();
gj.SetBackTheme(this);
ExtendsContentIntoTitleBar = true;
var frame = App.AppTitlebar as FrameworkElement;
if (frame != null)
{
gj.UpdateTitleBar(this, frame.ActualTheme);
2024-08-09 07:05:40 +00:00
page.RequestedTheme = frame.ActualTheme;
}
//Debug.WriteLine(path);
var directoryInfo = new DirectoryInfo(path);
2024-08-15 01:40:33 +00:00
Title = directoryInfo.Name;
2024-08-09 07:05:40 +00:00
TitleText.Text = directoryInfo.Name;
DataSource = EditorLoad.GetData(directoryInfo.FullName);
treeView.ItemsSource = DataSource;
Closed += EditorWin_Closed;
tabview.TabItemsSource = TabViewList;
2024-08-11 11:16:42 +00:00
}
//<2F>û<EFBFBD><C3BB><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD>
2024-08-11 11:16:42 +00:00
private bool IsSave = true;
2024-08-13 10:47:12 +00:00
private ContentDialog? ClosedDialog = null;
private async void EditorWin_Closed(object sender, WindowEventArgs e)
{
if (IsSave == false)
{
// <20><>ֹ<EFBFBD><D6B9><EFBFBD>ڹر<DAB9>
e.Handled = true;
}
2024-08-15 01:40:33 +00:00
if (ClosedDialog != null)
{
return;
}
// <20><>ʾһ<CABE><D2BB><EFBFBD>Ի<EFBFBD><D4BB>򣬸<EFBFBD>֪<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ܹر<DCB9>
ClosedDialog = new ContentDialog
{
XamlRoot = page.XamlRoot,
Title = "<22><><EFBFBD><EFBFBD>",
Content = "<22><EFBFBD><E3BBB9>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>",
PrimaryButtonText = "<22><><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>",
PrimaryButtonStyle = Application.Current.Resources["AccentButtonStyle"] as Style,
SecondaryButtonText = <>ӹر<D3B9>",
CloseButtonText = <><C8A1>"
};
var result = await ClosedDialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
IsSave = true;
Application.Current.Exit();
return;
}
2024-08-15 01:40:33 +00:00
else if (result == ContentDialogResult.Secondary)
{
2024-08-15 01:40:33 +00:00
IsSave = true;
Application.Current.Exit();
return;
}
ClosedDialog = null;
}
2024-08-13 10:47:12 +00:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>
private void MyTabView_AddTabButtonClick(TabView sender, object args)
{
var newTab = new TabViewItem
{
Header = $"New Tab {TabViewList.Count + 1}",
Content = new TextBlock { Text = "This is a new tab." }
};
TabViewList.Add(newTab);
}
// <20>ر<EFBFBD>ѡ<EFBFBD>
private void MyTabView_TabCloseRequested(TabView sender, TabViewTabCloseRequestedEventArgs args)
{
if (args.Tab is TabViewItem tab)
{
TabViewList.Remove(tab);
}
}
2024-08-13 10:47:12 +00:00
}