/// <summary>
        /// Selects <paramref name="selectable"/> and considers the Control/Shift buttons.
        /// </summary>
        /// <param name="selectionService"></param>
        /// <param name="selectable"></param>
        public static void SelectWithKeyboardModifiers(this ISelectionService selectionService, ISelectable selectable)
        {
            if (selectionService == null)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }

            //Determine if we're adding to the selection
            var isAddingToSelection = Keyboard.Modifiers == ModifierKeys.Control ||
                                      Keyboard.Modifiers == ModifierKeys.Shift;

            //See if this item is aready selected
            if (selectable.IsSelected)
            {
                //It is selected. Unselect it.
                selectionService.Unselect(selectable);
            }
            else
            {
                //Unless we're adding to the selection, unselect everything.
                if (!isAddingToSelection)
                {
                    selectionService.SelectNone();
                }

                //Select the current item.
                selectionService.Select(selectable);
            }
        }
Exemple #2
0
        public bool Drop(IElementClipboardData data, bool insertAtBeginning)
        {
            if (CanDrop(data))
            {
                var elements = this.CreateElements(data);

                var index = insertAtBeginning ? 0 : Elements.Count;

                foreach (var element in elements)
                {
                    Elements.Insert(index++, element);
                }

                MarkDirty();

                SaveUndoState();

                //Make sure that the new items are selected.
                SelectionService.SelectNone();

                foreach (var selectable in elements)
                {
                    SelectionService.Select(selectable);
                }

                return(true);
            }

            return(false);
        }
Exemple #3
0
        private static void SelectBetween(this ISelectionService selectionService,
                                          ISelectable[] siblings,
                                          ISelectable start,
                                          ISelectable end)
        {
            //Select nothing
            selectionService.SelectNone();

            //Determine the start and stop
            var startIndex = siblings.IndexOf(s => s == start);
            var endIndex   = siblings.IndexOf(s => s == end);

            //If for some reason the siblings weren't found, bail
            if (startIndex == null || endIndex == null)
            {
                return;
            }

            //Always start from the "first" sibling
            var effectiveStart = Math.Min(startIndex.Value, endIndex.Value);
            var effectiveEnd   = Math.Max(startIndex.Value, endIndex.Value);

            //Mark them all as selected.
            for (int index = effectiveStart; index <= effectiveEnd; index++)
            {
                selectionService.Select(siblings[index]);
            }
        }
        public static void RightClick(this ISelectionService selectionService, ISelectable selectable)
        {
            if (selectionService == null)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }
            if (!selectable.IsSelected)
            {
                selectionService.SelectNone();

                //Select the current item.
                selectionService.Select(selectable);
            }
        }
Exemple #5
0
        public static void DragSelected(this ISelectionService selectionService, DependencyObject dragSource)
        {
            if (selectionService == null)
            {
                throw new ArgumentNullException(nameof(selectionService));
            }

            var selected = selectionService.GetSelected();

            //Make sure we have something to work with
            if (selected.Length == 0)
            {
                return;
            }

            var elements = selected.OfType <IElement>()
                           .ToArray();

            //Make sure that these are all elements
            if (elements.Length != selected.Length)
            {
                return;
            }

            //Serialize for the clipboard
            var momento = new ElementClipboardData(elements);

            //Perform the operation
            var result = DragDrop.DoDragDrop(dragSource, momento, DragDropEffects.Copy | DragDropEffects.Move);

            if ((result & DragDropEffects.Move) == DragDropEffects.Move)
            {
                //Unselect these - they're going away.
                selectionService.SelectNone();

                //Remove the originals from their spots
                foreach (var element in elements)
                {
                    //Remove the element from where it came from
                    element.Parent?.RemoveElement(element);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Selects <paramref name="selectable"/> and considers the Control/Shift buttons.
        /// </summary>
        /// <param name="selectionService"></param>
        /// <param name="selectable"></param>
        public static void SelectWithKeyboardModifiers(this ISelectionService selectionService, ISelectable selectable)
        {
            if (selectionService == null)
            {
                return;
            }

            if (selectable == null)
            {
                return;
            }

            switch (Keyboard.Modifiers)
            {
            case ModifierKeys.Control:

                if (selectable.IsSelected)
                {
                    selectionService.Unselect(selectable);
                }
                else
                {
                    selectionService.Select(selectable);
                }

                break;

            case ModifierKeys.Shift:

                selectionService.ShiftSelect(selectable);

                break;

            case ModifierKeys.None:

                selectionService.SelectNone();
                selectionService.Select(selectable);

                break;
            }
        }