示例#1
0
        public static void CopySelected(this ISelectionService selectionService)
        {
            if (selectionService == null)
            {
                throw new ArgumentNullException(nameof(selectionService));
            }

            //Get the selected elements
            var elements = selectionService.GetSelected()
                           .OfType <IElement>();

            ClipboardUtility.Copy(elements);
        }
示例#2
0
        private static void ShiftSelect(this ISelectionService selectionService, ISelectable selectable)
        {
            var siblings = selectable.GetSiblings();

            //See if there are any non sibinglings that need to be
            var nonSiblingSelected = selectionService.GetSelected()
                                     .Where(s => !siblings.Contains(s))
                                     .ToArray();

            foreach (var toUnselect in nonSiblingSelected)
            {
                selectionService.Unselect(toUnselect);
            }

            //Now, only existing siblings should be selected
            var selected = selectionService.GetSelected();

            //If there are none selected, then select all of the sibings up to this one
            if (!selected.Any())
            {
                foreach (var sibling in siblings)
                {
                    selectionService.Select(sibling);

                    if (sibling == selectable)
                    {
                        break;
                    }
                }
            }
            else
            {
                //Do a range selection
                selectionService.SelectBetween(siblings, selectable, selected.LastOrDefault());
            }
        }
示例#3
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);
                }
            }
        }
示例#4
0
 protected IEnumerable <IDeleteable> GetSelectedDeleteables() => _selectionService.GetSelected().OfType <IDeleteable>();