88 lines
2.0 KiB
C#
88 lines
2.0 KiB
C#
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;
|
|
public string Name
|
|
{
|
|
get; set;
|
|
}
|
|
public ExplorerItemType Type
|
|
{
|
|
get; set;
|
|
}
|
|
public string Dir
|
|
{
|
|
get;set;
|
|
}
|
|
private ObservableCollection<ExplorerItem> m_children;
|
|
public ObservableCollection<ExplorerItem> Children
|
|
{
|
|
get
|
|
{
|
|
if (m_children == null)
|
|
{
|
|
m_children = new ObservableCollection<ExplorerItem>();
|
|
}
|
|
return m_children;
|
|
}
|
|
set
|
|
{
|
|
m_children = value;
|
|
}
|
|
}
|
|
|
|
private bool m_isExpanded;
|
|
public bool IsExpanded
|
|
{
|
|
get
|
|
{
|
|
return m_isExpanded;
|
|
}
|
|
set
|
|
{
|
|
if (m_isExpanded != value)
|
|
{
|
|
m_isExpanded = value;
|
|
NotifyPropertyChanged("IsExpanded");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NotifyPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
public static implicit operator ExplorerItem(bool v)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |