/// <summary> /// Initializes a new instance of the <see cref="BranchState" /> class. /// </summary> /// <param name="firstChild">The first child</param> /// <param name="secondChild">The second child</param> /// <param name="orientation">The split orientation</param> /// <param name="ratio">The split ratio</param> public BranchState(BranchItemState <TTabModel> firstChild, BranchItemState <TTabModel> secondChild, Orientation orientation, double ratio) { FirstChild = firstChild; SecondChild = secondChild; Orientation = orientation; Ratio = ratio; }
/// <summary> /// Gets the state of a branch. /// </summary> /// <typeparam name="TTabModel">The type of tab model</typeparam> /// <typeparam name="TTabViewModel">The type of tab view model, currently displayed in the app.</typeparam> /// <param name="branchVisitor">The branch to be inspected</param> /// <param name="tabContentModelConverter">The converter that transforms tab view models to models</param> /// <returns>The read state of the branch</returns> private static BranchState <TTabModel> GetBranchState <TTabModel, TTabViewModel> (BranchAccessor branchVisitor, Func <TTabViewModel, TTabModel> tabContentModelConverter) { var firstState = (BranchItemState <TTabModel>)null; var secondState = (BranchItemState <TTabModel>)null; if (branchVisitor.FirstItemBranchAccessor != null) { firstState = new BranchItemState <TTabModel> (GetBranchState(branchVisitor.FirstItemBranchAccessor, tabContentModelConverter), null); } else { firstState = new BranchItemState <TTabModel> (null, GetTabSetState(branchVisitor.FirstItemTabablzControl, tabContentModelConverter)); } if (branchVisitor.SecondItemBranchAccessor != null) { secondState = new BranchItemState <TTabModel> (GetBranchState(branchVisitor.SecondItemBranchAccessor, tabContentModelConverter), null); } else { secondState = new BranchItemState <TTabModel> (null, GetTabSetState(branchVisitor.SecondItemTabablzControl, tabContentModelConverter)); } return(new BranchState <TTabModel> (firstState, secondState, branchVisitor.Branch.Orientation, branchVisitor.Branch.GetFirstProportion( ))); }
/// <summary> /// Gets the state of a single window from its layout. /// </summary> /// <typeparam name="TTabModel">The type of tab model</typeparam> /// <typeparam name="TTabViewModel">The type of tab view model, currently displayed in the app.</typeparam> /// <typeparam name="TWindowSettings">The type of custom window settings.</typeparam> /// <param name="layout">The layout to be inspected</param> /// <param name="tabContentModelConverter">The converter that transforms tab view models to models</param> /// <param name="windowSettingsConverter">The function that serializes custom window settings</param> /// <returns>The state of the specified window</returns> public static LayoutWindowState <TTabModel, TWindowSettings> GetLayoutState <TTabModel, TTabViewModel, TWindowSettings> (Layout layout, Func <TTabViewModel, TTabModel> tabContentModelConverter, Func <Window, TWindowSettings> windowSettingsConverter) { var window = Window.GetWindow(layout) ?? throw new InvalidOperationException("The layout is not bound to any window"); var root = (BranchItemState <TTabModel>)null; layout.Query( ).Visit( branchAccessor => root = new BranchItemState <TTabModel> (GetBranchState(branchAccessor, tabContentModelConverter), null), tabablzControl => root = new BranchItemState <TTabModel> (null, GetTabSetState(tabablzControl, tabContentModelConverter)) ); return(new LayoutWindowState <TTabModel, TWindowSettings> (GetWindowPlacement(window), root, windowSettingsConverter(window))); }
/// <summary> /// Gets the state of a single window /// </summary> /// <typeparam name="TTabModel">The type of tab model</typeparam> /// <typeparam name="TTabViewModel">The type of tab view model, currently displayed in the app.</typeparam> /// <param name="layout">The layout to be inspected</param> /// <param name="tabContentModelConverter">The converter that transforms tab view models to models</param> /// <returns>The state of the specified window</returns> private static LayoutWindowState <TTabModel> GetLayoutState <TTabModel, TTabViewModel>(Layout layout, Func <TTabViewModel, TTabModel> tabContentModelConverter) { var window = Window.GetWindow(layout); if (window == null) { throw new InvalidOperationException("The layout is not bound to any window"); } var layoutAccessor = layout.Query(); BranchItemState <TTabModel> root = null; layoutAccessor.Visit( branchVisitor => root = new BranchItemState <TTabModel>(GetBranchState(branchVisitor, tabContentModelConverter), null), tabablzControl => root = new BranchItemState <TTabModel>(null, GetTabSetState(tabablzControl, tabContentModelConverter)) ); return(new LayoutWindowState <TTabModel>(window.Left, window.Top, window.Width, window.Height, window.WindowState, root)); }
/// <summary> /// Restores the state of a branch item /// </summary> /// <typeparam name="TTabModel">The type of tab model</typeparam> /// <typeparam name="TTabViewModel">The type of tab view model to be displayed in the app.</typeparam> /// <param name="tabablzControl">The control in which to restore the items</param> /// <param name="branchItemState">The state of the branch item to be restored</param> /// <param name="viewModelFactory">The function that creates the view model based on a model</param> private static void RestoreBranchItemState <TTabModel, TTabViewModel> (TabablzControl tabablzControl, BranchItemState <TTabModel> branchItemState, Func <TTabModel, TTabViewModel> viewModelFactory) { if (branchItemState.TabSet != null) { RestoreTabSetState(tabablzControl, branchItemState.TabSet, viewModelFactory); } else if (branchItemState.Branch != null) { RestoreBranchState(tabablzControl, branchItemState.Branch, viewModelFactory); } }
/// <summary> /// The constructor /// </summary> /// <param name="x">The X position of the window</param> /// <param name="y">The Y position of the window</param> /// <param name="width">The window width</param> /// <param name="height">The window height</param> /// <param name="windowState">The window state</param> /// <param name="child">The root of this layout</param> public LayoutWindowState(double x, double y, double width, double height, WindowState windowState, BranchItemState <TTabModel> child) { this.X = x; this.Y = y; this.Width = width; this.Height = height; this.WindowState = windowState; this.Child = child; }