Beispiel #1
0
// ReSharper disable MemberCanBePrivate.Global
        protected void AdjustSelectionAndCaretUponNavigation(Event e)
// ReSharper restore MemberCanBePrivate.Global
        {
            //Debug.Log("AdjustSelectionAndCaretUponNavigation");

            KeyboardEvent ke = (KeyboardEvent) e;

            // Some unrecognized key stroke was entered, return. 
            if (!NavigationUnitUtil.IsNavigationUnit(ke.KeyCode))
                return;

            NavigationUnit navigationUnit = NavigationUnitUtil.GetNavigationUnit(ke.KeyCode);
            //Debug.Log("navigationUnit:" + navigationUnit);
            //Debug.Log("CaretIndex:" + CaretIndex);
                
            var proposedNewIndex = Layout.GetNavigationDestinationIndex(CaretIndex, navigationUnit, ArrowKeysWrapFocus);

            //Debug.Log("proposedNewIndex:" + proposedNewIndex);
            
            // Note that the KeyboardEvent is canceled even if the current selected or in focus index
            // doesn't change because we don't want another component to start handling these
            // events when the index reaches a limit.
            if (proposedNewIndex == -1)
                return;
                
            e.PreventDefault(); 
            
            // Contiguous multi-selection action. Create the new selection
            // interval.   
            if (_allowMultipleSelection && ke.Shift && null != SelectedIndices)
            {
                var startIndex = GetLastSelectedIndex(); 
                var newInterval = new List<int>();  
                int i; 
                if (startIndex <= proposedNewIndex)
                {
                    for (i = startIndex; i <= proposedNewIndex; i++)
                    {
                        newInterval.Insert(0, i); 
                    }
                }
                else 
                {
                    for (i = startIndex; i >= proposedNewIndex; i--)
                    {
                        newInterval.Insert(0, i); 
                    }
                }
                SetSelectedIndices(newInterval, true);
                EnsureIndexIsVisible(proposedNewIndex); 
            }
            // Entering the caret state with the Ctrl key down 
            else if (ke.Control)
            {
                var oldCaretIndex = CaretIndex;
                SetCurrentCaretIndex(proposedNewIndex);
                var ice = new IndexChangeEvent(IndexChangeEvent.CARET_CHANGE)
                              {
                                  OldIndex = oldCaretIndex,
                                  NewIndex = CaretIndex
                              };
                DispatchEvent(ice);    
                EnsureIndexIsVisible(proposedNewIndex); 
            }
            // Its just a new selection action, select the new index.
            else
            {
                SetSelectedIndex(proposedNewIndex, true);
                EnsureIndexIsVisible(proposedNewIndex);
            }
        }
Beispiel #2
0
// ReSharper disable MemberCanBePrivate.Global
        protected List<int> CalculateSelectedIndices(int index, bool shiftKey, bool ctrlKey)
// ReSharper restore MemberCanBePrivate.Global
        {
            int i; 
            List<int> interval = new List<int>();  
            
            if (!shiftKey)
            {
                if (ctrlKey)
                {
                    if (!IsEmpty(SelectedIndices))
                    {
                        // Quick check to see if SelectedIndices had only one selected item
                        // and that item was de-selected
                        if (SelectedIndices.Count == 1 && (SelectedIndices[0] == index))
                        {
                            // We need to respect requireSelection 
                            if (!RequireSelection)
                                return interval;
                            
                            interval.Insert(0, SelectedIndices[0]); 
                            return interval;
                        }
                        // Go through and see if the index passed in was in the 
                        // selection model. If so, leave it out when constructing
                        // the new interval so it is de-selected. 
                        bool found = false; 
                        for (i = 0; i < _selectedIndices.Count; i++)
                        {
                            if (_selectedIndices[i] == index)
                                found = true; 
                            else if (_selectedIndices[i] != index)
                                interval.Insert(0, _selectedIndices[i]);
                        }
                        if (!found)
                        {
                            // Nothing from the selection model was de-selected. 
                            // Instead, the Ctrl key was held down and we're doing a  
                            // new add. 
                            interval.Insert(0, index);   
                        }
                        return interval;
                    }
                    // Ctrl+click with no previously selected items 
                    
                    interval.Insert(0, index); 
                    return interval;
                }
                
                // A single item was newly selected, add that to the selection interval.  
                interval.Insert(0, index); 
                return interval;
            }
            
            // A contiguous selection action has occurred. Figure out which new 
            // indices to add to the selection interval and return that. 
            var start = (!IsEmpty(SelectedIndices)) ? SelectedIndices[SelectedIndices.Count - 1] : 0; 
            var end = index; 
            if (start < end)
            {
                for (i = start; i <= end; i++)
                {
                    interval.Insert(0, i); 
                }
            }
            else 
            {
                for (i = start; i >= end; i--)
                {
                    interval.Insert(0, i); 
                }
            }
            return interval;
        }
Beispiel #3
0
        /// <summary>
        /// Changes the depth of a single child within the list
        /// </summary>
        /// <param name="depthList"></param>
        /// <param name="child"></param>
        /// <param name="depth"></param>
        /// <param name="makeRoom"></param>
        private static void SetDepth(List<DisplayListMember> depthList, DisplayListMember child, int depth, bool makeRoom)
        {
            //Debug.Log("Setting depth: " + depth + " [" + child + "]");

            child.Depth = depth;

            // remove
            depthList.Remove(child);

            var index = depthList.FindIndex(delegate(DisplayListMember displayListMember)
            {
                return displayListMember.Depth >= depth;
            });

            if (index == -1) // not found, meaning all depths are lower than the supplied one
                index = depthList.Count;

            // insert at index
            depthList.Insert(index, child);

            var len = depthList.Count;

            // fix other depths

            // say depth = 1
            // and that we have depths [0, 0, 1, 1, 1, 2, 6, 7] and inserting into the 3rd place (between 0 and 1)
            // ... [0, 0, *1, 1, 1, 1, 2, 6, 7] ...
            // we have to get [0, 0, *1, 2, 2, 2, 3, 6, 7] - note that some values are shifted up, but the values of 6, 7 are not because there's no need to

            //_prevDepth = depth;

            if (makeRoom)
            {
                // needs room?
                if (depthList.Count == index + 1 || depthList[index + 1].Depth > depth)
                    return; // this is the last item or the next item has a greater depth

                for (int i = index + 1; i < len; i++) // from 3rd place to the end
                {
                    depthList[index].Depth += 1;
                    //var item2 = depthList[index]; // 2
                    //if (item2.Depth != _prevDepth)
                    //    _prevDepth = item2.Depth; // _prevDepth = 1

                    //if (item2.Depth == _prevDepth) // 1 == 1
                    //{
                    //    item2.Depth = _prevDepth + 1; // item2.Depth = 2
                    //}
                }
            }
        }