89 lines
No EOL
3.2 KiB
C#
89 lines
No EOL
3.2 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.Windows.Threading;
|
|
using JD.WPF.Models;
|
|
using JD.WPF.Models.Menus;
|
|
|
|
namespace JD.SceneExplorer.ViewModels
|
|
{
|
|
public class ObjectWithRefHierarchy : DataModelBase
|
|
{
|
|
private ObjectWithRef m_currentObject;
|
|
private readonly ObservableCollection<HierarchyItem> m_objectHierarchy;
|
|
private readonly ObjectWithRef m_separator;
|
|
private readonly SceneExplorerPlugin m_mainModel;
|
|
|
|
public ObjectWithRefHierarchy(SceneExplorerPlugin mainModel)
|
|
{
|
|
m_currentObject = ObjectWithRef.InvalidObject;
|
|
m_objectHierarchy = new ObservableCollection<HierarchyItem>();
|
|
m_objectHierarchy.Add(new HierarchyItem(m_separator));
|
|
m_separator = new ObjectWithRef(0, null, null);
|
|
m_separator.FriendlyName = " > ";
|
|
m_mainModel = mainModel;
|
|
}
|
|
|
|
public ObservableCollection<HierarchyItem> Hierarchy
|
|
{
|
|
get { return m_objectHierarchy; }
|
|
}
|
|
|
|
public ObjectWithRef Separator
|
|
{
|
|
get { return m_separator; }
|
|
}
|
|
|
|
public void FillHierarchy(Dispatcher maintThreadDispatcher, ObjectWithRef currentObject)
|
|
{
|
|
maintThreadDispatcher.Invoke(() => {
|
|
m_objectHierarchy.Clear();
|
|
m_currentObject = currentObject;
|
|
if (m_currentObject != null && m_currentObject.IsSelected)
|
|
FillHierarchyInternal(m_currentObject);
|
|
|
|
RaisePropertyChanged("HierarchyText");
|
|
});
|
|
}
|
|
|
|
private void FillHierarchyInternal(ObjectWithRef currentObject)
|
|
{
|
|
if (m_objectHierarchy.Count != 0)
|
|
m_objectHierarchy.Insert(0, new HierarchyItem(m_separator));
|
|
m_objectHierarchy.Insert(0, new HierarchyItem(currentObject, m_mainModel));
|
|
if (currentObject.Parent != null)
|
|
FillHierarchyInternal(currentObject.Parent as ObjectWithRef);
|
|
}
|
|
|
|
public struct HierarchyItem
|
|
{
|
|
private readonly ObjectWithRef m_item;
|
|
public MenuItemDataCollection m_contextMenu;
|
|
|
|
public HierarchyItem(ObjectWithRef item)
|
|
{
|
|
m_item = item;
|
|
m_contextMenu = null;
|
|
}
|
|
|
|
public HierarchyItem(ObjectWithRef item, SceneExplorerPlugin mainModel)
|
|
{
|
|
m_item = item;
|
|
m_contextMenu = new MenuItemDataCollection();
|
|
//BuildContextMenu(mainModel); // Unsafe : need better multithread checks.
|
|
}
|
|
|
|
public ObjectWithRef Item { get { return m_item; } }
|
|
public MenuItemDataCollection ContextMenu { get { return m_contextMenu; } }
|
|
|
|
/*private void BuildContextMenu(SceneExplorerModel mainModel)
|
|
{
|
|
if (m_item.Parent != null)
|
|
{
|
|
foreach (ObjectWithRef child in m_item.Parent.Children)
|
|
{
|
|
m_contextMenu.Add(new MenuItemData(child.FriendlyName, null, command: new SelectItemCommand(mainModel), data: child));
|
|
}
|
|
}
|
|
}*/
|
|
}
|
|
}
|
|
} |