86 lines
3.2 KiB
C#
86 lines
3.2 KiB
C#
using Lattice.Core.Docking.Abstractions;
|
||
using Lattice.Core.Docking.Engine;
|
||
using Lattice.Core.Docking.Models;
|
||
using Lattice.UI.Docking.Abstractions;
|
||
using Lattice.UI.Docking.Factories;
|
||
|
||
namespace Lattice.UI.Docking.Utilities;
|
||
|
||
/// <summary>
|
||
/// Предоставляет утилитарные методы для работы с док-системой.
|
||
/// </summary>
|
||
public static class DockUtilities
|
||
{
|
||
/// <summary>
|
||
/// Создает дерево контролов для указанного менеджера макета.
|
||
/// </summary>
|
||
public static IDockControl? CreateControlTree(LayoutManager manager,
|
||
IDockControlFactory factory, IDockControl? parentControl = null)
|
||
{
|
||
if (manager == null) throw new ArgumentNullException(nameof(manager));
|
||
if (factory == null) throw new ArgumentNullException(nameof(factory));
|
||
|
||
return CreateControlForElement(manager.Root, factory, parentControl);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Создает контрол для указанного элемента.
|
||
/// </summary>
|
||
public static IDockControl? CreateControlForElement(IDockElement? element,
|
||
IDockControlFactory factory, IDockControl? parentControl = null)
|
||
{
|
||
if (element == null) return null;
|
||
|
||
var control = factory.CreateControlForElement(element);
|
||
if (control == null) return null;
|
||
|
||
if (parentControl != null)
|
||
{
|
||
// Здесь может быть установка дополнительных связей
|
||
}
|
||
|
||
if (element is DockGroup group && control is IDockGroupControl groupControl)
|
||
{
|
||
var firstChild = CreateControlForElement(group.First, factory, control);
|
||
var secondChild = CreateControlForElement(group.Second, factory, control);
|
||
groupControl.SetChildren(firstChild, secondChild);
|
||
}
|
||
|
||
return control;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Находит контрол для указанного элемента в дереве контролов.
|
||
/// </summary>
|
||
public static IDockControl? FindControlForElement(IDockControl? root, IDockElement element)
|
||
{
|
||
if (root == null || element == null) return null;
|
||
|
||
if (root.Model?.Id == element.Id)
|
||
return root;
|
||
|
||
if (root is IDockGroupControl groupControl)
|
||
{
|
||
var found = FindControlForElement(groupControl.FirstChild, element);
|
||
if (found != null) return found;
|
||
|
||
found = FindControlForElement(groupControl.SecondChild, element);
|
||
if (found != null) return found;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Обновляет дерево контролов при изменении макета.
|
||
/// </summary>
|
||
public static void UpdateControlTree(IDockControl root, LayoutManager manager,
|
||
IDockControlFactory factory)
|
||
{
|
||
if (root == null) throw new ArgumentNullException(nameof(root));
|
||
if (manager == null) throw new ArgumentNullException(nameof(manager));
|
||
if (factory == null) throw new ArgumentNullException(nameof(factory));
|
||
|
||
// TODO: Реализовать эффективное обновление дерева контролов
|
||
}
|
||
} |