Esempio n. 1
0
        private void RemoveAt(int index, bool repairIndex)
        {
            var wrapper        = m_ranges[index];
            var rangeWithItems = wrapper.Value;

            Debug.Assert(wrapper.Index == index);

            if (!SelectedCellsStorage.IsEmpty(rangeWithItems))
            {
                var removed = m_map.Remove(SelectedCellsStorage.GetArea(rangeWithItems), wrapper);
                Debug.Assert(removed, "Failed to remove the selection range.");

                // Since there should be only a single instance of the wrapper within the collection, try an altenate strategy.
                if (!removed)
                {
                    var entry = m_map.FirstOrDefault(e => e.Item == wrapper);
                    if (entry.Item == wrapper)
                    {
                        removed = m_map.Remove(entry);
                    }

                    Debug.Assert(removed, "Failed to find the selection range.");
                }
            }

            m_ranges.RemoveAt(index);

            if (repairIndex)
            {
                this.RepairIndex(index);
            }
        }
Esempio n. 2
0
        private void Insert(int index, SelectionCellRangeWithItems item, bool repairIndex)
        {
            var wrapper = new SelectionCellRangeWithItemsWrapper(item, index);

            m_ranges.Insert(index, wrapper);

            if (repairIndex)
            {
                this.RepairIndex(index + 1);
            }

            if (!SelectedCellsStorage.IsEmpty(item))
            {
                m_map.Add(SelectedCellsStorage.GetArea(item), wrapper);
            }
        }
Esempio n. 3
0
        private IEnumerable <int> IndexOfOverlap(SelectionCellRange range)
        {
            // It improves performance to leave early.
            if (m_map.Count <= 0)
            {
                yield break;
            }

            foreach (var entry in m_map.GetEntriesWithin(SelectedCellsStorage.GetArea(range)))
            {
                var candidate = entry.Item;
                var target    = candidate.Value;
                var overlap   = range.Intersect(target.CellRange);

                Debug.Assert(!SelectedCellsStorage.IsEmpty(overlap));

                if (!SelectedCellsStorage.IsEmpty(overlap))
                {
                    yield return(candidate.Index);
                }
            }
        }
Esempio n. 4
0
 private static RSTree2D <SelectionCellRangeWithItemsWrapper> .Area GetArea(SelectionCellRangeWithItems range)
 {
     return(SelectedCellsStorage.GetArea(range.CellRange));
 }