WIn_RustTools/RustTools/Editor/EditorWin.xaml.cs

216 lines
7.2 KiB
C#
Raw Normal View History

2024-08-09 07:05:40 +00:00
using System.Collections.ObjectModel;
using System.ComponentModel;
2024-08-09 07:05:40 +00:00
using System.Diagnostics;
using System.IO;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using Microsoft.UI;
2024-08-09 07:05:40 +00:00
using Microsoft.UI.Text;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
2024-08-09 07:05:40 +00:00
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using RustTools.muqing;
using Windows.ApplicationModel.Core;
2024-08-09 07:05:40 +00:00
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
2024-08-09 07:05:40 +00:00
using Windows.Graphics.Imaging;
using Windows.Storage.Pickers;
using Windows.Storage;
using Windows.UI.Core;
using Windows.UI.Core.Preview;
using Windows.UI.Popups;
using Windows.UI.WindowManagement;
using WinRT.Interop;
namespace RustTools.Editor;
/// <summary>
/// <20><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public sealed partial class EditorWin : WindowEx
{
2024-08-09 07:05:40 +00:00
//Ŀ¼<C4BF>б<EFBFBD>
public ObservableCollection<ExplorerItem> DataSource=new ();
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);
2024-08-09 07:05:40 +00:00
page.RequestedTheme = frame.ActualTheme;
}
//WindowManager.Get(this).IsMinimizable = false;
//app = GetAppWindowForCurrentWindow();
//app.Closing += OnClosing;
//Closed += EditorWin_Closed;
2024-08-09 07:05:40 +00:00
var directoryInfo = new DirectoryInfo("D:\\steam\\steamapps\\common\\Rusted Warfare\\mods\\units\\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD>0.9<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0.2");
DataSource = new EditorLoad().GetData(directoryInfo.FullName);
Title=directoryInfo.Name;
TitleText.Text = directoryInfo.Name;
Closed += EditorWin_Closed;
2024-08-09 07:05:40 +00:00
var v = wj.dqwb("D:\\steam\\steamapps\\common\\Rusted Warfare\\mods\\units\\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD>0.9<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0.2\\<5C><>ʴ<EFBFBD>߹<EFBFBD><DFB9>͹<EFBFBD>\\ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\corrode_command.ini");
//CodeEditor.Document.SetText(TextSetOptions.None,v);
//EditorView.Editor.SetText(v);
//CodeEditorControl.HighlightingLanguage.
}
2024-08-09 07:05:40 +00:00
//<2F>û<EFBFBD><C3BB><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD>
private bool IsSave = false;
private ContentDialog? ClosedDialog;
private async void EditorWin_Closed(object sender, WindowEventArgs e)
{
if (IsSave == false)
{
// <20><>ֹ<EFBFBD><D6B9><EFBFBD>ڹر<DAB9>
e.Handled = true;
}
if (ClosedDialog != null) {
return;
}
// <20><>ʾһ<CABE><D2BB><EFBFBD>Ի<EFBFBD><D4BB>򣬸<EFBFBD>֪<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ܹر<DCB9>
ClosedDialog = new ContentDialog
{
2024-08-09 07:05:40 +00:00
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;
}
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);
}
2024-08-09 07:05:40 +00:00
private void TreeView_ItemInvoked(TreeView sender, TreeViewItemInvokedEventArgs args)
{
// <20><>ȡ<EFBFBD><C8A1>ǰѡ<C7B0>е<EFBFBD><D0B5><EFBFBD>
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var invokedItem = args.InvokedItem;
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ظ<EFBFBD>ѡ<EFBFBD><D1A1>
if (sender.SelectedItem is ExplorerItem selectedItem && invokedItem != null && selectedItem == invokedItem)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD>ֱ<EEA3AC>ӷ<EFBFBD><D3B7>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return;
}
if (invokedItem is not ExplorerItem explorerItem)
{
return;
}
if (explorerItem.Type == ExplorerItem.ExplorerItemType.Folder)
{
var directoryInfo = new DirectoryInfo(explorerItem.Dir);
}
}
private void TreeView_DragItemsStarting(TreeView sender, TreeViewDragItemsStartingEventArgs args)
{
args.Cancel = true;
// <20><><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var items = args.Items.Cast<ExplorerItem>();
var v = items.ToList()[0];
args.Data.SetData("TreeViewItems", v.Dir);
args.Data.RequestedOperation = DataPackageOperation.Move;
}
//<2F><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD>Ŀ<EFBFBD><C4BF>ͣ<EFBFBD><CDA3> TreeView <20><>ʱ<EFBFBD><CAB1>Ϊ<EFBFBD><CEAA><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>Ӿ<EFBFBD><D3BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private void TreeView_DragOver(object sender, DragEventArgs e)
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> "TreeViewItems" <20><><EFBFBD><EFBFBD>
gj.sc("aaaaaa");
if (e.DataView.Contains("TreeViewItems"))
{
e.AcceptedOperation = DataPackageOperation.Move; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ϸ<EFBFBD>
}
else
{
gj.sc("No");
e.AcceptedOperation = DataPackageOperation.None; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷŲ<CFB7><C5B2><EFBFBD>
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>õ<EFBFBD><C3B5>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>µ<EFBFBD>λ<EFBFBD>á<EFBFBD>
private async void TreeView_Drop(object sender, DragEventArgs e)
{
gj.sc(e);
// <20><>ȡ<EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (e.DataView.Contains("TreeViewItems"))
{
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD>Ϊ<EFBFBD><CEAA>
if (await e.DataView.GetDataAsync("TreeViewItems") is string Dir)
{
gj.sc(Dir);
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>λ<EFBFBD>õ<EFBFBD> TreeViewItem
var treeView = sender as TreeView;
ExplorerItem v = treeView.DataContext is ExplorerItem;
//var dropPosition = e.GetPosition(treeView);
//data.Name
gj.sc(v.Name);
}
}
}
private IList<object> initialSelectedItems;
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>shift<66><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ״̬
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void treeView_KeyDown(object sender, KeyRoutedEventArgs e)
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Shift<66><74>
if (e.Key == Windows.System.VirtualKey.Shift)
{
gj.sc(e.Key);
// <20><><EFBFBD>ö<EFBFBD>ѡģʽ
treeView.SelectionMode = TreeViewSelectionMode.Multiple;
}
}
private void treeView_KeyUp(object sender, KeyRoutedEventArgs e)
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɿ<EFBFBD><C9BF><EFBFBD>Shift<66><74>
if (e.Key == Windows.System.VirtualKey.Shift)
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>ѡģʽ<C4A3><CABD>ѡ<EFBFBD>е<EFBFBD><D0B5><EFBFBD>Ŀ
var selectedItems = treeView.SelectedItems.ToList();
foreach (var item in selectedItems)
{
treeView.SelectedItems.Remove(item);
}
gj.sc(<><C8A1>");
// ȡ<><C8A1><EFBFBD><EFBFBD>ѡģʽ
treeView.SelectionMode = TreeViewSelectionMode.Single;
//treeView.SelectedItems.Clear();
}
}
private void tabView_TabCloseRequested(TabView sender, TabViewTabCloseRequestedEventArgs args)
{
sender.TabItems.Remove(args.Tab);
}
}