Example #1
0
        protected bool RemoveContextsFrom(bool forward, SelectionHelper sel, ILcmOwningSequence <IPhSimpleContext> seq,
                                          bool preRemovalSideEffects, out int index)
        {
            index = -1;
            bool reconstruct = true;

            ICmObject[] ctxts = seq.Cast <ICmObject>().ToArray();
            // if the selection is a range remove all items in the selection
            if (sel.IsRange)
            {
                int[] indices = GetIndicesToRemove(ctxts, sel);
                // return index of the item before the removed items
                if (indices.Length > 0)
                {
                    index = indices[0] - 1;
                }
                foreach (int idx in indices)
                {
                    // Sometimes when deleting a range, DeleteUnderlyingObject() takes out
                    // parts of the rule before this loop gets to it. [LT-9775]
                    if (ctxts[idx].IsValidObject)
                    {
                        ProcessIndicesSimpleContext(seq, ctxts, preRemovalSideEffects, idx);
                    }
                }
            }
            else
            {
                int idx = GetIndexToRemove(ctxts, sel, forward);
                if (idx > -1)
                {
                    // return index of the item before the removed items
                    index = idx - 1;
                    ProcessIndicesSimpleContext(seq, ctxts, preRemovalSideEffects, idx);
                }
                else
                {
                    // if the backspace button is pressed at the beginning of a cell or the delete
                    // button is pressed at the end of a cell, don't do anything
                    reconstruct = false;
                }
            }
            return(reconstruct);
        }
Example #2
0
        protected int InsertContextInto(IPhSimpleContext ctxt, SelectionHelper sel, ILcmOwningSequence <IPhSimpleContext> seq)
        {
            ICmObject[] ctxts = seq.Cast <ICmObject>().ToArray();
            int         index = GetInsertionIndex(ctxts, sel);

            // if the current selection is a range remove the items we are overwriting
            if (sel.IsRange)
            {
                var indices = GetIndicesToRemove(ctxts, sel);
                foreach (int idx in indices)
                {
                    var c = (IPhSimpleContext)ctxts[idx];
                    c.PreRemovalSideEffects();
                    seq.Remove(c);
                }
            }
            seq.Insert(index, ctxt);
            return(index);
        }