コード例 #1
0
        protected override void OnDrop(DragEventArgs e)
        {
            ModelTreeManager manager = this.Context.Services.GetService <ModelTreeManager>();

            // When dragging from toolbox:
            //     editingScope should not be null
            //     there should only be one item
            // When dragging from canvas:
            //     editingScope should be null
            // Call editingScope.Complete() to commit changes, otherwise the editing scope will be aborted
            using (EditingScope editingScope = ModelItemHelper.TryCreateImmediateEditingScope(manager, SR.PropertyChangeEditingScopeDescription))
            {
                List <object> droppedObjects = this.GetSortedObjectList(e);
#pragma warning disable 618
                DragDropHelper.SetDragDropCompletedEffects(e, DragDropEffects.None);
#pragma warning restore 618
                if (droppedObjects == null || droppedObjects.Count == 0)
                {
                    return;
                }
                if (droppedObjects.Count == 1)
                {
                    if (this.DoSingleDrop(droppedObjects[0], e))
                    {
                        if (editingScope != null)
                        {
                            editingScope.Complete();
                        }
                    }
                    return;
                }
                else
                {
                    // multi drop
                    Fx.Assert(editingScope == null, "editingScope should be null for dragging from canvas.");
                    this.DoAutoWrapDrop(InsertionPosition.None, e, droppedObjects);
                }
                base.OnDrop(e);
            }
        }
コード例 #2
0
        bool DoAutoWrapDrop(InsertionPosition insertionPos, DragEventArgs e, IList <object> droppedObjects = null)
        {
            if (droppedObjects == null)
            {
                ModelTreeManager manager      = this.Context.Services.GetRequiredService <ModelTreeManager>();
                EditingScope     editingScope = null;

                try
                {
                    editingScope = ModelItemHelper.TryCreateImmediateEditingScope(manager, SR.WrapInSequenceDescription);

                    droppedObjects = this.GetSortedObjectList(e);

                    if (!this.DoAutoWrapDrop(insertionPos, droppedObjects))
                    {
                        return(false);
                    }

                    if (editingScope != null)
                    {
                        editingScope.Complete();
                    }
                }
                finally
                {
                    if (editingScope != null)
                    {
                        editingScope.Dispose();
                        editingScope = null;
                    }
                }
            }
            else
            {
                if (!this.DoAutoWrapDrop(insertionPos, droppedObjects))
                {
                    return(false);
                }
            }

            if (!DragDropHelper.IsDraggingFromToolbox(e))
            {
                List <WorkflowViewElement> movedViewElements = ObjectList2WorkflowViewElementList(droppedObjects);
                DragDropHelper.SetDragDropMovedViewElements(e, movedViewElements);

                //Backward compatibility for 4.0
                if (droppedObjects.Count == 1 && movedViewElements.Count == 1)
                {
                    #pragma warning disable 618
                    DragDropHelper.SetDragDropCompletedEffects(e, DragDropEffects.Move);
                    #pragma warning restore 618
                }
            }
            else
            {
                Fx.Assert(droppedObjects.Count == 1, "Dropping from Toolbox with count != 1");

                // Set focus if it is dropping from ToolBox.
                // In common drag/drop, the selection setting is done at the end of
                // StartDragging().
                if (this.Item == null)
                {
                    return(true);
                }

                Fx.Assert(typeof(Sequence).IsAssignableFrom(this.Item.ItemType),
                          "Auto Wrap didn't add a sequence. Is Item.Properties[\"Activities\"] still correct?");
                foreach (ModelItem item in this.Item.Properties["Activities"].Collection)
                {
                    // Find the ModelItem whose value is an activity from Toolbox.
                    if (item.GetCurrentValue() == droppedObjects[0])
                    {
                        this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() =>
                        {
                            item.Focus();
                        }));
                        break;
                    }
                }
            }

            return(true);
        }