using System; using System.Collections.Generic; namespace Dragablz.Dockablz { /// /// Provides information about the instance. /// public class LayoutAccessor { private readonly Layout _layout; private readonly BranchAccessor _branchAccessor; private readonly TabablzControl _tabablzControl; public LayoutAccessor(Layout layout) { if (layout == null) throw new ArgumentNullException("layout"); _layout = layout; var branch = Layout.Content as Branch; if (branch != null) _branchAccessor = new BranchAccessor(branch); else _tabablzControl = Layout.Content as TabablzControl; } public Layout Layout { get { return _layout; } } public IEnumerable FloatingItems { get { return _layout.FloatingDragablzItems(); } } /// /// and are mutually exclusive, according to whether the layout has been split, or just contains a tab control. /// public BranchAccessor BranchAccessor { get { return _branchAccessor; } } /// /// and are mutually exclusive, according to whether the layout has been split, or just contains a tab control. /// public TabablzControl TabablzControl { get { return _tabablzControl; } } /// /// Visits the content of the layout, according to its content type. No more than one of the provided /// callbacks will be called. /// public LayoutAccessor Visit( Action branchVisitor = null, Action tabablzControlVisitor = null, Action contentVisitor = null) { if (_branchAccessor != null) { if (branchVisitor != null) { branchVisitor(_branchAccessor); } return this; } if (_tabablzControl != null) { if (tabablzControlVisitor != null) tabablzControlVisitor(_tabablzControl); return this; } if (_layout.Content != null && contentVisitor != null) contentVisitor(_layout.Content); return this; } /// /// Gets all the Tabablz controls in a Layout, regardless of location. /// /// public IEnumerable TabablzControls() { var tabablzControls = new List(); this.Visit(tabablzControls, BranchAccessorVisitor, TabablzControlVisitor); return tabablzControls; } private static void TabablzControlVisitor(IList resultSet, TabablzControl tabablzControl) { resultSet.Add(tabablzControl); } private static void BranchAccessorVisitor(IList resultSet, BranchAccessor branchAccessor) { branchAccessor .Visit(resultSet, BranchItem.First, BranchAccessorVisitor, TabablzControlVisitor) .Visit(resultSet, BranchItem.Second, BranchAccessorVisitor, TabablzControlVisitor); } } }