diff --git a/RustTools/Editor/EditorLoad.cs b/RustTools/Editor/EditorLoad.cs index 5cda551..e8ef08a 100644 --- a/RustTools/Editor/EditorLoad.cs +++ b/RustTools/Editor/EditorLoad.cs @@ -52,6 +52,7 @@ public class EditorLoad } } + public ObservableCollection GetData(string dir) { var list = new ObservableCollection(); diff --git a/RustTools/Editor/EditorTreeView.cs b/RustTools/Editor/EditorTreeView.cs index 34fa585..8587ecf 100644 --- a/RustTools/Editor/EditorTreeView.cs +++ b/RustTools/Editor/EditorTreeView.cs @@ -8,6 +8,7 @@ using Windows.Storage; using RustTools.Helpers; using Microsoft.UI.Xaml.Media; using Windows.Foundation; +using System.Diagnostics; namespace RustTools.Editor; @@ -17,33 +18,35 @@ public class EditorTreeView: TreeView { //CanDragItems = false; //CanReorderItems =false; - DragEnter += EditorTreeView_DragEnter; + //DragEnter += EditorTreeView_DragEnter; DragItemsStarting += TreeView_DragItemsStarting; DragItemsCompleted += EditorTreeView_DragItemsCompleted; - DragOver += TreeView_DragOver; - Drop += TreeView_Drop; + //DragOver += TreeView_DragOver; + //Drop += TreeView_Drop; // 在构造函数中注册事件处理程序 } - - private void EditorTreeView_DragEnter(object sender, DragEventArgs e){ - - gj.sc("EditorTreeView_DragEnter "+e); - } - private void TreeView_DragItemsStarting(TreeView sender, TreeViewDragItemsStartingEventArgs e) { //gj.sc("TreeView_DragItemsStarting"+e); - var items = e.Items.Cast(); - var firstItem = items.FirstOrDefault(); + var items = e.Items.Cast().ToList(); + var firstItem = items.First(); gj.sc(firstItem.Dir); e.Data.SetData("path", firstItem.Dir); e.Data.RequestedOperation = DataPackageOperation.Move; // Use Copy to avoid moving items } private void EditorTreeView_DragItemsCompleted(TreeView sender, TreeViewDragItemsCompletedEventArgs e) { - var items = e.Items.Cast(); - var firstItem = items.FirstOrDefault(); - gj.sc("放下了 " + firstItem.Dir); + // 获取拖拽的项 + var items = e.Items.Cast().ToList(); + + // 检查是否有至少一个项被放下 + if (items.Any()) + { + var firstItem = items.First(); // 获取第一个放下的项 + + // 输出放下项的信息 + Debug.WriteLine($"放下了 {firstItem.Dir}"); + } } /// diff --git a/RustTools/Editor/EditorWin.xaml b/RustTools/Editor/EditorWin.xaml index bcb81f4..c9e1def 100644 --- a/RustTools/Editor/EditorWin.xaml +++ b/RustTools/Editor/EditorWin.xaml @@ -29,7 +29,7 @@ - + diff --git a/RustTools/Editor/ExplorerItemTemplateSelector.cs b/RustTools/Editor/ExplorerItemTemplateSelector.cs index ec2845f..10350b1 100644 --- a/RustTools/Editor/ExplorerItemTemplateSelector.cs +++ b/RustTools/Editor/ExplorerItemTemplateSelector.cs @@ -30,7 +30,7 @@ public class ExplorerItem : INotifyPropertyChanged { public enum ExplorerItemType { Folder, File }; public event PropertyChangedEventHandler PropertyChanged; - public string Name + public string? Name { get; set; } @@ -38,40 +38,31 @@ public class ExplorerItem : INotifyPropertyChanged { get; set; } - public string Dir + public string? Dir { get;set; } - private ObservableCollection m_children; + private ObservableCollection? m_children; public ObservableCollection Children { get { - if (m_children == null) - { - m_children = new ObservableCollection(); - } + m_children ??= new ObservableCollection(); return m_children; } - set - { - m_children = value; - } + set => m_children = value; } private bool m_isExpanded; public bool IsExpanded { - get - { - return m_isExpanded; - } + get => m_isExpanded; set { if (m_isExpanded != value) { m_isExpanded = value; - NotifyPropertyChanged("IsExpanded"); + NotifyPropertyChanged(nameof(IsExpanded)); } } }