WIn_RustTools/Editor/EditorWin.xaml.cs

125 lines
3.5 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;
重构 EditorTreeView 以使用 Microsoft.UI.Xaml.Controls 在 `EditorTreeView.cs` 中: - 添加了 `Microsoft.UI.Xaml.Controls`、`RustTools.muqing` 和 `WinUIEditor` 的引用。 - 将 `EditorTreeView` 类从继承 `TreeView` 改为继承 `Microsoft.UI.Xaml.Controls.TreeView`。 - 修改了事件处理程序的绑定方式,去掉了 `this` 关键字。 - 修改了 `TreeView_ItemInvoked`、`TreeView_Expanding` 和 `TreeView_Collapsed` 方法的参数类型,使用了 `Microsoft.UI.Xaml.Controls.TreeView`。 - 在 `TreeView_ItemInvoked` 方法中,添加了处理文件点击事件的逻辑,包括创建 `CodeEditorControl` 实例并将其添加到 `TabViewItem` 中。 - 添加了 `AddTabItem` 事件。 在 `EditorWin.xaml` 中: - 添加了 `WinUIEditor` 的命名空间引用。 - 在 `Grid` 中添加了 `RowDefinition`,用于定义 `TabView` 的头部和内容区域的高度。 - 注释掉了 `CodeEditorControl` 的 XAML 定义。 在 `EditorWin.xaml.cs` 中: - 添加了 `Microsoft.UI.Xaml.Media` 和 `WinUIEditor` 的引用。 - 在 `EditorWin` 构造函数中,添加了 `gridedit.SizeChanged` 事件处理程序,用于调整 `TabView` 的高度。 - 添加了 `TreeView_AddTabItem` 方法,用于处理 `AddTabItem` 事件。 - 删除了 `MyTabView_AddTabButtonClick` 方法。 在 `RustTools.csproj` 中: - 添加了 `WinUIEdit` 包的引用。 重构 EditorTreeView 并添加 WinUI 支持 将 EditorTreeView 类更改为 Microsoft.UI.Xaml.Controls.TreeView,添加相关命名空间引用。更新方法参数类型并处理文件点击事件。调整 EditorWin.xaml 和 EditorWin.xaml.cs 文件,添加事件处理逻辑。移除 MyTabView_AddTabButtonClick 方法,并在 RustTools.csproj 中添加 WinUIEdit 包引用。
2025-01-21 11:26:04 +00:00
using Microsoft.UI.Xaml.Media;
using RustTools.muqing;
using WinRT.Interop;
重构 EditorTreeView 以使用 Microsoft.UI.Xaml.Controls 在 `EditorTreeView.cs` 中: - 添加了 `Microsoft.UI.Xaml.Controls`、`RustTools.muqing` 和 `WinUIEditor` 的引用。 - 将 `EditorTreeView` 类从继承 `TreeView` 改为继承 `Microsoft.UI.Xaml.Controls.TreeView`。 - 修改了事件处理程序的绑定方式,去掉了 `this` 关键字。 - 修改了 `TreeView_ItemInvoked`、`TreeView_Expanding` 和 `TreeView_Collapsed` 方法的参数类型,使用了 `Microsoft.UI.Xaml.Controls.TreeView`。 - 在 `TreeView_ItemInvoked` 方法中,添加了处理文件点击事件的逻辑,包括创建 `CodeEditorControl` 实例并将其添加到 `TabViewItem` 中。 - 添加了 `AddTabItem` 事件。 在 `EditorWin.xaml` 中: - 添加了 `WinUIEditor` 的命名空间引用。 - 在 `Grid` 中添加了 `RowDefinition`,用于定义 `TabView` 的头部和内容区域的高度。 - 注释掉了 `CodeEditorControl` 的 XAML 定义。 在 `EditorWin.xaml.cs` 中: - 添加了 `Microsoft.UI.Xaml.Media` 和 `WinUIEditor` 的引用。 - 在 `EditorWin` 构造函数中,添加了 `gridedit.SizeChanged` 事件处理程序,用于调整 `TabView` 的高度。 - 添加了 `TreeView_AddTabItem` 方法,用于处理 `AddTabItem` 事件。 - 删除了 `MyTabView_AddTabButtonClick` 方法。 在 `RustTools.csproj` 中: - 添加了 `WinUIEdit` 包的引用。 重构 EditorTreeView 并添加 WinUI 支持 将 EditorTreeView 类更改为 Microsoft.UI.Xaml.Controls.TreeView,添加相关命名空间引用。更新方法参数类型并处理文件点击事件。调整 EditorWin.xaml 和 EditorWin.xaml.cs 文件,添加事件处理逻辑。移除 MyTabView_AddTabButtonClick 方法,并在 RustTools.csproj 中添加 WinUIEdit 包引用。
2025-01-21 11:26:04 +00:00
using WinUIEditor;
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;
重构 EditorTreeView 以使用 Microsoft.UI.Xaml.Controls 在 `EditorTreeView.cs` 中: - 添加了 `Microsoft.UI.Xaml.Controls`、`RustTools.muqing` 和 `WinUIEditor` 的引用。 - 将 `EditorTreeView` 类从继承 `TreeView` 改为继承 `Microsoft.UI.Xaml.Controls.TreeView`。 - 修改了事件处理程序的绑定方式,去掉了 `this` 关键字。 - 修改了 `TreeView_ItemInvoked`、`TreeView_Expanding` 和 `TreeView_Collapsed` 方法的参数类型,使用了 `Microsoft.UI.Xaml.Controls.TreeView`。 - 在 `TreeView_ItemInvoked` 方法中,添加了处理文件点击事件的逻辑,包括创建 `CodeEditorControl` 实例并将其添加到 `TabViewItem` 中。 - 添加了 `AddTabItem` 事件。 在 `EditorWin.xaml` 中: - 添加了 `WinUIEditor` 的命名空间引用。 - 在 `Grid` 中添加了 `RowDefinition`,用于定义 `TabView` 的头部和内容区域的高度。 - 注释掉了 `CodeEditorControl` 的 XAML 定义。 在 `EditorWin.xaml.cs` 中: - 添加了 `Microsoft.UI.Xaml.Media` 和 `WinUIEditor` 的引用。 - 在 `EditorWin` 构造函数中,添加了 `gridedit.SizeChanged` 事件处理程序,用于调整 `TabView` 的高度。 - 添加了 `TreeView_AddTabItem` 方法,用于处理 `AddTabItem` 事件。 - 删除了 `MyTabView_AddTabButtonClick` 方法。 在 `RustTools.csproj` 中: - 添加了 `WinUIEdit` 包的引用。 重构 EditorTreeView 并添加 WinUI 支持 将 EditorTreeView 类更改为 Microsoft.UI.Xaml.Controls.TreeView,添加相关命名空间引用。更新方法参数类型并处理文件点击事件。调整 EditorWin.xaml 和 EditorWin.xaml.cs 文件,添加事件处理逻辑。移除 MyTabView_AddTabButtonClick 方法,并在 RustTools.csproj 中添加 WinUIEdit 包引用。
2025-01-21 11:26:04 +00:00
//<2F><><EFBFBD><EFBFBD>TabView<65>ĸ߶<C4B8>
gridedit.SizeChanged += (sender, args) =>
{
tabview.Height = gridedit.ActualHeight - 10;
};
重构 EditorTreeView 以使用 Microsoft.UI.Xaml.Controls 在 `EditorTreeView.cs` 中: - 添加了 `Microsoft.UI.Xaml.Controls`、`RustTools.muqing` 和 `WinUIEditor` 的引用。 - 将 `EditorTreeView` 类从继承 `TreeView` 改为继承 `Microsoft.UI.Xaml.Controls.TreeView`。 - 修改了事件处理程序的绑定方式,去掉了 `this` 关键字。 - 修改了 `TreeView_ItemInvoked`、`TreeView_Expanding` 和 `TreeView_Collapsed` 方法的参数类型,使用了 `Microsoft.UI.Xaml.Controls.TreeView`。 - 在 `TreeView_ItemInvoked` 方法中,添加了处理文件点击事件的逻辑,包括创建 `CodeEditorControl` 实例并将其添加到 `TabViewItem` 中。 - 添加了 `AddTabItem` 事件。 在 `EditorWin.xaml` 中: - 添加了 `WinUIEditor` 的命名空间引用。 - 在 `Grid` 中添加了 `RowDefinition`,用于定义 `TabView` 的头部和内容区域的高度。 - 注释掉了 `CodeEditorControl` 的 XAML 定义。 在 `EditorWin.xaml.cs` 中: - 添加了 `Microsoft.UI.Xaml.Media` 和 `WinUIEditor` 的引用。 - 在 `EditorWin` 构造函数中,添加了 `gridedit.SizeChanged` 事件处理程序,用于调整 `TabView` 的高度。 - 添加了 `TreeView_AddTabItem` 方法,用于处理 `AddTabItem` 事件。 - 删除了 `MyTabView_AddTabButtonClick` 方法。 在 `RustTools.csproj` 中: - 添加了 `WinUIEdit` 包的引用。 重构 EditorTreeView 并添加 WinUI 支持 将 EditorTreeView 类更改为 Microsoft.UI.Xaml.Controls.TreeView,添加相关命名空间引用。更新方法参数类型并处理文件点击事件。调整 EditorWin.xaml 和 EditorWin.xaml.cs 文件,添加事件处理逻辑。移除 MyTabView_AddTabButtonClick 方法,并在 RustTools.csproj 中添加 WinUIEdit 包引用。
2025-01-21 11:26:04 +00:00
tabview.TabItemsSource = TabViewList;
treeView.AddTabItem += TreeView_AddTabItem;
2024-08-11 11:16:42 +00:00
}
重构 EditorTreeView 以使用 Microsoft.UI.Xaml.Controls 在 `EditorTreeView.cs` 中: - 添加了 `Microsoft.UI.Xaml.Controls`、`RustTools.muqing` 和 `WinUIEditor` 的引用。 - 将 `EditorTreeView` 类从继承 `TreeView` 改为继承 `Microsoft.UI.Xaml.Controls.TreeView`。 - 修改了事件处理程序的绑定方式,去掉了 `this` 关键字。 - 修改了 `TreeView_ItemInvoked`、`TreeView_Expanding` 和 `TreeView_Collapsed` 方法的参数类型,使用了 `Microsoft.UI.Xaml.Controls.TreeView`。 - 在 `TreeView_ItemInvoked` 方法中,添加了处理文件点击事件的逻辑,包括创建 `CodeEditorControl` 实例并将其添加到 `TabViewItem` 中。 - 添加了 `AddTabItem` 事件。 在 `EditorWin.xaml` 中: - 添加了 `WinUIEditor` 的命名空间引用。 - 在 `Grid` 中添加了 `RowDefinition`,用于定义 `TabView` 的头部和内容区域的高度。 - 注释掉了 `CodeEditorControl` 的 XAML 定义。 在 `EditorWin.xaml.cs` 中: - 添加了 `Microsoft.UI.Xaml.Media` 和 `WinUIEditor` 的引用。 - 在 `EditorWin` 构造函数中,添加了 `gridedit.SizeChanged` 事件处理程序,用于调整 `TabView` 的高度。 - 添加了 `TreeView_AddTabItem` 方法,用于处理 `AddTabItem` 事件。 - 删除了 `MyTabView_AddTabButtonClick` 方法。 在 `RustTools.csproj` 中: - 添加了 `WinUIEdit` 包的引用。 重构 EditorTreeView 并添加 WinUI 支持 将 EditorTreeView 类更改为 Microsoft.UI.Xaml.Controls.TreeView,添加相关命名空间引用。更新方法参数类型并处理文件点击事件。调整 EditorWin.xaml 和 EditorWin.xaml.cs 文件,添加事件处理逻辑。移除 MyTabView_AddTabButtonClick 方法,并在 RustTools.csproj 中添加 WinUIEdit 包引用。
2025-01-21 11:26:04 +00:00
private void TreeView_AddTabItem(TabViewItem obj,CodeEditorControl codeEditorControl){
tabview.SelectedItem = obj;
var title = obj.Header.ToString();
codeEditorControl.Editor.UpdateUI += (sender, args) =>
{
//<2F>Ƿ<EFBFBD><C7B7>п<EFBFBD><D0BF>Գ<EFBFBD><D4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7>¼
var a = codeEditorControl.Editor.CanUndo();
if (a)
{
obj.Header = $"{title} *";
}
else
{
obj.Header = title;
}
Debug.WriteLine($"UpdateUI :" + a);
};
}
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;
}
// <20>ر<EFBFBD>ѡ<EFBFBD>
private void MyTabView_TabCloseRequested(TabView sender, TabViewTabCloseRequestedEventArgs args)
{
if (args.Tab is TabViewItem tab)
{
TabViewList.Remove(tab);
}
}
}