/// <summary> /// Handler called every time a state is inserted in the controller. /// </summary> /// <param name="operation">Details of the operation performed.</param> private protected override void OnStateInserted(WriteableInsertNodeOperation operation) { base.OnStateInserted(operation); IFocusNodeState ChildState = ((FocusInsertNodeOperation)operation).ChildState; Debug.Assert(ChildState != null); Debug.Assert(StateViewTable.ContainsKey(ChildState)); IFocusBrowsingCollectionNodeIndex BrowsingIndex = ((FocusInsertNodeOperation)operation).BrowsingIndex; Debug.Assert(ChildState.ParentIndex == BrowsingIndex); MoveFocusToState(ChildState); }
/// <summary> /// Checks if an existing item can be removed at the focus. /// </summary> /// <param name="inner">Inner to use to remove the item upon return.</param> /// <param name="index">Index of the item to remove upon return.</param> /// <returns>True if an item can be removed at the focus.</returns> public virtual bool IsItemRemoveable(out IFocusCollectionInner inner, out IFocusBrowsingCollectionNodeIndex index) { inner = null; index = null; bool IsRemoveable = false; IFocusNodeState State = Focus.CellView.StateView.State; if (Focus.CellView.Frame is IFocusInsertFrame AsInsertFrame) { IsRemoveable = false; } else { IsRemoveable = false; // Search recursively for a collection parent, up to 4 levels up. for (int i = 0; i < 4 && State != null; i++) { if (State.ParentInner is IFocusCollectionInner AsCollectionInner) { inner = AsCollectionInner; index = State.ParentIndex as IFocusBrowsingCollectionNodeIndex; Debug.Assert(index != null); if (Controller.IsRemoveable(inner, index)) { IsRemoveable = true; break; } } State = State.ParentState; } } return(IsRemoveable); }
/// <summary> /// Checks if an existing item at the focus can be moved up or down. /// </summary> /// <param name="direction">Direction of the move, relative to the current position of the item.</param> /// <param name="inner">Inner to use to move the item upon return.</param> /// <param name="index">Index of the item to move upon return.</param> /// <returns>True if an item can be moved at the focus.</returns> public virtual bool IsItemMoveable(int direction, out IFocusCollectionInner inner, out IFocusBrowsingCollectionNodeIndex index) { inner = null; index = null; bool IsMoveable = false; IFocusNodeState State = Focus.CellView.StateView.State; if (Focus.CellView.Frame is IFocusInsertFrame AsInsertFrame) { IsMoveable = false; } else { IsMoveable = false; // Search recursively for a collection parent, up to 3 levels up. for (int i = 0; i < 3 && State != null; i++) { IFocusCollectionInner ListInner = null; if (State.ParentInner is IFocusBlockListInner AsBlockListInner) { ListInner = AsBlockListInner; } else if (State.ParentInner is IFocusListInner AsListInner && IsDeepestList(State)) { ListInner = AsListInner; } if (ListInner != null) { inner = ListInner; index = State.ParentIndex as IFocusBrowsingCollectionNodeIndex; Debug.Assert(index != null); if (Controller.IsMoveable(inner, index, direction)) { IsMoveable = true; } break; } State = State.ParentState; } } return(IsMoveable); }