コード例 #1
0
        /// <summary>
        /// Called on copy, cut or drag.
        /// For a copy or cut, the supplied elements are the model elements, and the call comes, via AddGroupFormat, from ClipboardCommands.ProcessOnMenuCopy().
        /// For a drag operation, the elements are the selected shapes and connectors, and the call comes from Diagram.DoDragDrop, if CanMove or CanCopy are true.
        /// In the drag case, we want to add the model elements so that we can do a copy
        /// if the user presses CTRL while dragging.
        ///
        /// See http://msdn.microsoft.com/library/ff521398.aspx
        /// </summary>
        /// <param name="shapeOrModelElements">The shape or model elements being copied - usually the current selection.</param>
        /// <param name="closureType">Copy or Delete</param>
        /// <returns>Group to be stored in the clipboard.</returns>
        protected override ElementGroup CreateElementGroup(ICollection <ModelElement> shapeOrModelElements, ClosureType closureType)
        {
            // CreateElementGroup respects the settings of PropagateCopy.
            // Notice that we have set PropagateCopy on the roles from components to the terminals,
            // so that terminals will always be copied along with their parents.

            // Add the specified group of shapes or elements:
            ElementGroup group = base.CreateElementGroup(shapeOrModelElements, closureType);

            // If this a set of shapes, add their model elements:
            if (shapeOrModelElements.FirstOrDefault() is PresentationElement)
            {
                // Get the model elements of the shapes:
                ICollection <ModelElement> modelElements =
                    shapeOrModelElements.OfType <PresentationElement>()
                    // Filter out shapes such as labels that don't have model elements:
                    .Where(pel => pel.ModelElement != null)
                    .Select(pel => pel.ModelElement).ToList();

                ElementGroup melGroup = base.CreateElementGroup(modelElements, closureType);
                group.AddRange(melGroup.GetElements());
            }

            return(group);

            // 2011-03-21 Thanks to Joeul in VMSDK Forum for a bug fix here.
            // http://social.msdn.microsoft.com/Forums/en-US/dslvsarchx/thread/0b0b16d4-6014-4b35-9e5a-e27ea02e0ee3
        }