Пример #1
0
        public BranchAccessor(Branch branch)
        {
            if (branch == null)
            {
                throw new ArgumentNullException(nameof(branch));
            }

            _branch = branch;

            var firstChildBranch = branch.FirstItem as Branch;

            if (firstChildBranch != null)
            {
                _firstBranchAccessor = new BranchAccessor(firstChildBranch);
            }
            else
            {
                _firstDockControl = FindDockControl(branch.FirstItem, branch.FirstContentPresenter);
            }

            var secondChildBranch = branch.SecondItem as Branch;

            if (secondChildBranch != null)
            {
                _secondBranchAccessor = new BranchAccessor(secondChildBranch);
            }
            else
            {
                _secondDockControl = FindDockControl(branch.SecondItem, branch.SecondContentPresenter);
            }
        }
Пример #2
0
        public LayoutAccessor(Layout layout)
        {
            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            _layout = layout;

            var branch = Layout.Content as Branch;

            if (branch != null)
            {
                _branchAccessor = new BranchAccessor(branch);
            }
            else
            {
                _dockControl = Layout.Content as DockControl;
            }
        }
Пример #3
0
        /// <summary>
        /// Helper method for <see cref="BranchAccessor.Visit"/> which allows a context to be passed through.
        /// </summary>
        /// <typeparam name="TContext"></typeparam>
        /// <param name="branchAccessor"></param>
        /// <param name="context"></param>
        /// <param name="childItem"></param>
        /// <param name="branchVisitor"></param>
        /// <param name="dockControlVisitor"></param>
        /// <param name="contentVisitor"></param>
        /// <returns></returns>
        public static BranchAccessor Visit <TContext>(
            this BranchAccessor branchAccessor,
            TContext context,
            BranchItem childItem,
            Action <TContext, BranchAccessor> branchVisitor   = null,
            Action <TContext, DockControl> dockControlVisitor = null,
            Action <TContext, object> contentVisitor          = null)
        {
            if (branchAccessor == null)
            {
                throw new ArgumentNullException(nameof(branchAccessor));
            }

            branchAccessor.Visit(
                childItem,
                WrapVisitor(context, branchVisitor),
                WrapVisitor(context, dockControlVisitor),
                WrapVisitor(context, contentVisitor)
                );

            return(branchAccessor);
        }
Пример #4
0
 private static void BranchVisitor(LocationReportBuilder locationReportBuilder, BranchAccessor branchAccessor)
 {
     if (Equals(branchAccessor.FirstDockControl, locationReportBuilder.TargetDockControl))
     {
         locationReportBuilder.MarkFound(branchAccessor.Branch, false);
     }
     else if (Equals(branchAccessor.SecondDockControl, locationReportBuilder.TargetDockControl))
     {
         locationReportBuilder.MarkFound(branchAccessor.Branch, true);
     }
     else
     {
         branchAccessor.Visit(BranchItem.First, ba => BranchVisitor(locationReportBuilder, ba));
         if (locationReportBuilder.IsFound)
         {
             return;
         }
         branchAccessor.Visit(BranchItem.Second, ba => BranchVisitor(locationReportBuilder, ba));
     }
 }