/// <summary> /// Checks if a new item can be inserted at the focus. /// </summary> /// <param name="inner">Inner to use to insert the new item upon return.</param> /// <param name="index">Index of the new item to insert upon return.</param> /// <returns>True if a new item can be inserted at the focus.</returns> public virtual bool IsNewItemInsertable(out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index) { inner = null; index = null; bool Result = false; IFocusNodeState State = Focus.CellView.StateView.State; IFocusFrame Frame = Focus.CellView.Frame; if (Frame is IFocusInsertFrame AsInsertFrame) { Result = IsNewItemInsertableAtInsertFrame(State, AsInsertFrame, out inner, out index); } else if (Focus.CellView is IFocusStringContentFocusableCellView AsStringContentFocusableCellView) { Result = IsNewItemInsertableAtStringContentCellView(State, AsStringContentFocusableCellView, out inner, out index); } return(Result); }
private protected virtual bool IsNewItemInsertableAtStringContentCellView(IFocusNodeState state, IFocusStringContentFocusableCellView cellView, out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index) { inner = null; index = null; bool Result = false; if (CaretPosition == 0) { Result = IsListExtremumItem(state, cellView, IsFirstFocusableCellView, InsertAbove, out inner, out index); } else if (CaretPosition == MaxCaretPosition) { Result = IsListExtremumItem(state, cellView, IsLastFocusableCellView, InsertBelow, out inner, out index); } return(Result); }
private protected virtual bool IsNewItemInsertableAtInsertFrame(IFocusNodeState state, IFocusInsertFrame frame, out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index) { inner = null; index = null; bool Result = false; Type InsertType = frame.InsertType; Debug.Assert(InsertType != Type.Missing); Debug.Assert(!InsertType.IsInterface); Debug.Assert(!InsertType.IsAbstract); // Type InterfaceType = NodeTreeHelper.NodeTypeToInterfaceType(InsertType); //Node NewItem = NodeHelper.CreateDefaultFromInterface(InterfaceType); Node NewItem = NodeHelper.CreateDefaultFromType(InsertType); IFocusCollectionInner CollectionInner = null; frame.CollectionNameToInner(ref state, ref CollectionInner); Debug.Assert(CollectionInner != null); if (CollectionInner is IFocusBlockListInner AsBlockListInner) { inner = AsBlockListInner; if (AsBlockListInner.Count == 0) { Pattern NewPattern = NodeHelper.CreateEmptyPattern(); Identifier NewSource = NodeHelper.CreateEmptyIdentifier(); index = CreateNewBlockNodeIndex(state.Node, CollectionInner.PropertyName, NewItem, 0, NewPattern, NewSource); } else { index = CreateExistingBlockNodeIndex(state.Node, CollectionInner.PropertyName, NewItem, 0, 0); } Result = true; } else if (CollectionInner is IFocusListInner AsListInner) { inner = AsListInner; index = CreateListNodeIndex(state.Node, AsListInner.PropertyName, NewItem, 0); Result = true; } return(Result); }
private protected virtual bool IsExtremumCheckParent(IFocusNodeState state, IFocusContentFocusableCellView cellView, System.Func <IFocusNodeState, IFocusContentFocusableCellView, bool> isGoodFocusableCellView, System.Func <int, int> getInsertPosition, out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index) { inner = null; index = null; bool Result = false; IFocusNodeState ParentState = state.ParentState; if (ParentState != null && isGoodFocusableCellView(state, cellView)) { Result = IsListExtremumItem(ParentState, cellView, isGoodFocusableCellView, getInsertPosition, out inner, out index); } return(Result); }
private protected virtual bool IsListExtremumItem(IFocusNodeState state, IFocusContentFocusableCellView cellView, System.Func <IFocusNodeState, IFocusContentFocusableCellView, bool> isGoodFocusableCellView, System.Func <int, int> getInsertPosition, out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index) { inner = null; index = null; IFocusInner ParentInner = state.ParentInner; if (ParentInner == null) { return(false); } Node NewItem; int BlockPosition; int ItemPosition; bool IsHandled = false; bool Result = false; switch (ParentInner) { case IFocusPlaceholderInner AsPlaceholderInner: case IFocusOptionalInner AsOptionalInner: Result = IsExtremumCheckParent(state, cellView, isGoodFocusableCellView, getInsertPosition, out inner, out index); IsHandled = true; break; // Check the parent state if there is a deeper list (typically, for a qualified name, there would be one). case IFocusListInner AsListInner: if (IsDeepestList(state)) { NewItem = NodeHelper.CreateDefaultFromType(AsListInner.InterfaceType); ItemPosition = (state.ParentIndex as IFocusBrowsingListNodeIndex).Index; inner = AsListInner; index = CreateListNodeIndex(inner.Owner.Node, inner.PropertyName, NewItem, getInsertPosition(ItemPosition)); Result = true; } else { Result = IsExtremumCheckParent(state, cellView, isGoodFocusableCellView, getInsertPosition, out inner, out index); } IsHandled = true; break; case IFocusBlockListInner AsBlockListInner: NewItem = NodeHelper.CreateDefaultFromType(AsBlockListInner.InterfaceType); BlockPosition = (state.ParentIndex as IFocusBrowsingExistingBlockNodeIndex).BlockIndex; ItemPosition = (state.ParentIndex as IFocusBrowsingExistingBlockNodeIndex).Index; inner = AsBlockListInner; index = CreateExistingBlockNodeIndex(inner.Owner.Node, inner.PropertyName, NewItem, BlockPosition, getInsertPosition(ItemPosition)); Result = true; IsHandled = true; break; } Debug.Assert(IsHandled); return(Result); }