2024-08-09 07:05:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
|
|
namespace RustTools.Editor;
|
|
|
|
|
public class ExplorerItemTemplateSelector : DataTemplateSelector
|
|
|
|
|
{
|
|
|
|
|
public DataTemplate FolderTemplate
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public DataTemplate FileTemplate
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DataTemplate SelectTemplateCore(object item)
|
|
|
|
|
{
|
|
|
|
|
var explorerItem = (ExplorerItem)item;
|
|
|
|
|
return explorerItem.Type == ExplorerItem.ExplorerItemType.Folder ? FolderTemplate : FileTemplate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class ExplorerItem : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
public enum ExplorerItemType { Folder, File };
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
2024-08-13 11:30:40 +00:00
|
|
|
|
public string? Name
|
2024-08-09 07:05:40 +00:00
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
public ExplorerItemType Type
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2024-08-13 11:30:40 +00:00
|
|
|
|
public string? Dir
|
2024-08-09 07:05:40 +00:00
|
|
|
|
{
|
|
|
|
|
get;set;
|
|
|
|
|
}
|
2024-08-13 11:30:40 +00:00
|
|
|
|
private ObservableCollection<ExplorerItem>? m_children;
|
2024-08-09 07:05:40 +00:00
|
|
|
|
public ObservableCollection<ExplorerItem> Children
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2024-08-13 11:30:40 +00:00
|
|
|
|
m_children ??= new ObservableCollection<ExplorerItem>();
|
2024-08-09 07:05:40 +00:00
|
|
|
|
return m_children;
|
|
|
|
|
}
|
2024-08-13 11:30:40 +00:00
|
|
|
|
set => m_children = value;
|
2024-08-09 07:05:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool m_isExpanded;
|
|
|
|
|
public bool IsExpanded
|
|
|
|
|
{
|
2024-08-13 11:30:40 +00:00
|
|
|
|
get => m_isExpanded;
|
2024-08-09 07:05:40 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (m_isExpanded != value)
|
|
|
|
|
{
|
|
|
|
|
m_isExpanded = value;
|
2024-08-13 11:30:40 +00:00
|
|
|
|
NotifyPropertyChanged(nameof(IsExpanded));
|
2024-08-09 07:05:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NotifyPropertyChanged(string propertyName)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator ExplorerItem(bool v)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|