Beispiel #1
0
 private void MultiSelector_CollectSingle(ExplorerViewItem sender)
 {
     SelectedViewItems.ForEach(item => item.IsSelected = false);
     SelectedViewItems.Clear();
     sender.IsSelected = true;
     LastSelectedItem  = sender;
 }
Beispiel #2
0
        private List <ExplorerViewItem> MultiSelector_GetListInRange(ExplorerViewItem start, ExplorerViewItem end)
        {
            var items = MultiSelector_GetList(this, false);

            var startIndex = items.IndexOf(start);
            var endIndex   = items.IndexOf(end);
            var rangeStart = startIndex > endIndex || startIndex == -1 ? endIndex : startIndex;
            var rangeCount = startIndex > endIndex ? startIndex - endIndex + 1 : endIndex - startIndex + 1;

            if (startIndex == -1 && endIndex == -1)
            {
                rangeCount = 0;
            }

            else if (startIndex == -1 || endIndex == -1)
            {
                rangeCount = 1;
            }

            var res = rangeCount > 0 ? items.GetRange(rangeStart, rangeCount) : new List <ExplorerViewItem>();

            if (startIndex > endIndex)
            {
                res.Reverse();
            }

            return(res);
        }
Beispiel #3
0
        public void ExplorerView_ChangeSelectedItem(ExplorerViewItem sender)
        {
            if (Mouse.LeftButton == MouseButtonState.Released && Mouse.RightButton == MouseButtonState.Pressed)
            {
                if (IsShiftPressed == false && IsCtrlPressed == false)
                {
                    MultiSelector_CollectSingle(sender);
                }
            }
            else if (IsShiftPressed == true && AllowMultiSelect == true)
            {
                MultiSelector_CollectRange(sender);
            }
            else if (IsCtrlPressed == true && AllowMultiSelect == true)
            {
                sender.IsSelected = !sender.IsSelected;
                LastSelectedItem  = sender;
            }
            else
            {
                MultiSelector_CollectSingle(sender);
            }

            if (SelectedViewItems.Contains(sender) == true)
            {
                if (sender.IsSelected == false)
                {
                    SelectedViewItems.Remove(sender);
                }
            }
            else
            {
                SelectedViewItems.Add(sender);
            }

            SelectedItems.Clear();
            SelectedViewItems.ForEach(item => SelectedItems.Add(item.DataContext));
        }
Beispiel #4
0
        private void MultiSelector_CollectRange(ExplorerViewItem target)
        {
            if (LastSelectedItem == null)
            {
                return;
            }
            var collectedItems = MultiSelector_GetListInRange(LastSelectedItem, target);

            if (IsCtrlPressed == true)
            {
                collectedItems.ForEach(c => SelectedViewItems.Remove(c));
            }
            else
            {
                SelectedViewItems.ForEach(s => s.IsSelected = false);
                SelectedViewItems.Clear();
            }

            foreach (var c in collectedItems)
            {
                c.IsSelected = true;
                SelectedViewItems.Add(c);
            }
        }