Пример #1
0
 private static void SelectSingleItem(MultiSelectTreeView treeView, TreeViewItem treeViewItem)
 {
     // first deselect all items
     treeView.DeselectAllItems();
     SetIsItemSelected(treeViewItem, true);
     SetStartItem(treeView, treeViewItem);
 }
Пример #2
0
 private void treeKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.C && Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
     {
         if (inputData.HasGrepLineSelection)
         {
             CopyGrepLines();
             e.Handled = true;
         }
         else if (inputData.HasGrepResultSelection)
         {
             CopyFileNames(true);
             e.Handled = true;
         }
     }
     else if (e.Key == Key.A && Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
     {
         MultiSelectTreeView.SelectAll(treeView);
         e.Handled = true;
     }
     else if (e.Key == Key.Delete)
     {
         ExcludeLines();
         e.Handled = true;
     }
 }
Пример #3
0
        private static void SelectItems(TreeViewItem treeViewItem, MultiSelectTreeView treeView)
        {
            if (treeViewItem != null && treeView != null)
            {
                bool isFunctionKeyDown = Keyboard.IsKeyDown(Key.F1) || Keyboard.IsKeyDown(Key.F2) || Keyboard.IsKeyDown(Key.F3) ||
                                         Keyboard.IsKeyDown(Key.F4) || Keyboard.IsKeyDown(Key.F5) || Keyboard.IsKeyDown(Key.F6) ||
                                         Keyboard.IsKeyDown(Key.F7) || Keyboard.IsKeyDown(Key.F7) || Keyboard.IsKeyDown(Key.F9) ||
                                         Keyboard.IsKeyDown(Key.F10) || Keyboard.IsKeyDown(Key.F11) || Keyboard.IsKeyDown(Key.F12);

                if (treeView.MultiSelectRootLevelOnly)
                {
                    bool isRoot = ItemsControl.ItemsControlFromItemContainer(treeViewItem) == treeView;
                    if (isRoot)
                    {
                        treeView.DeselectAllChildItems();

                        if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control | ModifierKeys.Shift) && !isFunctionKeyDown)
                        {
                            SelectMultipleItemsContinuously(treeView, treeViewItem, true);
                        }
                        else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && !isFunctionKeyDown)
                        {
                            SelectMultipleItemsRandomly(treeView, treeViewItem);
                        }
                        else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) && !isFunctionKeyDown)
                        {
                            SelectMultipleItemsContinuously(treeView, treeViewItem);
                        }
                        else
                        {
                            SelectSingleItem(treeView, treeViewItem);
                        }
                    }
                    else
                    {
                        SelectSingleItem(treeView, treeViewItem);
                    }
                }
                else
                {
                    if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control | ModifierKeys.Shift) && !isFunctionKeyDown)
                    {
                        SelectMultipleItemsContinuously(treeView, treeViewItem, true);
                    }
                    else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && !isFunctionKeyDown)
                    {
                        SelectMultipleItemsRandomly(treeView, treeViewItem);
                    }
                    else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) && !isFunctionKeyDown)
                    {
                        SelectMultipleItemsContinuously(treeView, treeViewItem);
                    }
                    else
                    {
                        SelectSingleItem(treeView, treeViewItem);
                    }
                }
            }
        }
Пример #4
0
        private static void SelectItems(TreeViewItem treeViewItem, MultiSelectTreeView treeView)
        {
            if (treeViewItem != null && treeView != null)
            {
                if (treeView.MultiSelectRootLevelOnly)
                {
                    bool isRoot = ItemsControl.ItemsControlFromItemContainer(treeViewItem) == treeView;
                    if (isRoot)
                    {
                        treeView.DeselectAllChildItems();

                        if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
                        {
                            SelectMultipleItemsContinuously(treeView, treeViewItem, true);
                        }
                        else if (Keyboard.Modifiers == ModifierKeys.Control)
                        {
                            SelectMultipleItemsRandomly(treeView, treeViewItem);
                        }
                        else if (Keyboard.Modifiers == ModifierKeys.Shift)
                        {
                            SelectMultipleItemsContinuously(treeView, treeViewItem);
                        }
                        else
                        {
                            SelectSingleItem(treeView, treeViewItem);
                        }
                    }
                    else
                    {
                        SelectSingleItem(treeView, treeViewItem);
                    }
                }
                else
                {
                    if ((Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
                    {
                        SelectMultipleItemsContinuously(treeView, treeViewItem, true);
                    }
                    else if (Keyboard.Modifiers == ModifierKeys.Control)
                    {
                        SelectMultipleItemsRandomly(treeView, treeViewItem);
                    }
                    else if (Keyboard.Modifiers == ModifierKeys.Shift)
                    {
                        SelectMultipleItemsContinuously(treeView, treeViewItem);
                    }
                    else
                    {
                        SelectSingleItem(treeView, treeViewItem);
                    }
                }
            }
        }
Пример #5
0
 private static void SelectMultipleItemsRandomly(MultiSelectTreeView treeView, TreeViewItem treeViewItem)
 {
     SetIsItemSelected(treeViewItem, !GetIsItemSelected(treeViewItem));
     if (GetStartItem(treeView) == null || Keyboard.Modifiers == ModifierKeys.Control)
     {
         if (GetIsItemSelected(treeViewItem))
         {
             SetStartItem(treeView, treeViewItem);
         }
     }
     else if (GetSelectedItems(treeView).Count == 0)
     {
         SetStartItem(treeView, null);
     }
 }
Пример #6
0
        private static void SelectMultipleItemsContinuously(MultiSelectTreeView treeView, TreeViewItem treeViewItem, bool shiftControl = false)
        {
            TreeViewItem startItem = GetStartItem(treeView);

            if (startItem != null)
            {
                if (startItem == treeViewItem)
                {
                    SelectSingleItem(treeView, treeViewItem);
                    return;
                }

                bool msRootOnly = treeView.MultiSelectRootLevelOnly;

                ICollection <ITreeItem> allItems = new List <ITreeItem>();
                GetAllItems(treeView, allItems);
                bool isBetween = false;
                foreach (var item in allItems)
                {
                    bool isRoot = item.Level == 0;

                    if (item == treeViewItem.DataContext || item == startItem.DataContext)
                    {
                        // toggle to true if first element is found and
                        // back to false if last element is found
                        isBetween = !isBetween;

                        // set boundary element
                        item.IsSelected = msRootOnly ? isRoot : true;
                        continue;
                    }

                    if (isBetween)
                    {
                        item.IsSelected = msRootOnly ? isRoot : true;
                        continue;
                    }

                    if (!shiftControl)
                    {
                        item.IsSelected = false;
                    }
                }
            }
        }