Beispiel #1
0
 public override void Execute()
 {
     using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitPaste))
     {
         this.SceneViewModel.GetActiveSceneInsertionPoint(new InsertionPointContext(false));
         if (this.SceneViewModel.TextSelectionSet.IsActive)
         {
             try
             {
                 this.SceneViewModel.TextSelectionSet.TextEditProxy.EditingElement.Paste();
             }
             catch (ArgumentException ex)
             {
                 this.SceneViewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteTextFailedDialogMessage);
             }
         }
         else
         {
             ICollection <SceneNode> nodes = PasteCommand.PasteData(this.SceneViewModel, SafeDataObject.FromClipboard());
             if (nodes.Count > 0)
             {
                 this.SceneViewModel.ClearSelections();
                 this.SceneViewModel.SelectNodes(nodes);
             }
         }
         editTransaction.Commit();
     }
 }
Beispiel #2
0
        private static void StripTemplateBindings(SceneElement element)
        {
            List <DocumentNode> list = new List <DocumentNode>();

            foreach (DocumentNode documentNode1 in PasteCommand.FindTemplateBindingTargets(element))
            {
                foreach (DocumentNode documentNode2 in documentNode1.SelectChildNodes(typeof(TemplateBindingExtension)))
                {
                    list.Add(documentNode2);
                }
            }
            foreach (DocumentNode documentNode in list)
            {
                documentNode.Parent.ClearValue((IPropertyId)documentNode.SitePropertyKey);
            }
        }
Beispiel #3
0
        private static SceneElement PasteElement(SceneViewModel viewModel, SceneElement element, List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater, ISceneInsertionPoint insertionPoint)
        {
            SceneNodeIDHelper sceneNodeIdHelper = new SceneNodeIDHelper(viewModel, (SceneNode)insertionPoint.SceneNode.StoryboardContainer);
            SceneElement      element1          = (SceneElement)null;

            using (viewModel.ForceBaseValue())
            {
                PasteCommand.StripStoryboardsAndTriggers(element);
                PasteCommand.StripExtraNamespaces(element);
                BaseFrameworkElement frameworkElement = element as BaseFrameworkElement;
                if (frameworkElement != null || element is DataGridColumnNode)
                {
                    if (!(insertionPoint.SceneElement is Viewport3DElement) && !(insertionPoint.SceneElement is Base3DElement))
                    {
                        if (insertionPoint.CanInsert((ITypeId)element.Type))
                        {
                            if (!PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)insertionPoint.SceneElement.Type) && (!PlatformTypes.UserControl.Equals((object)insertionPoint.SceneElement.Type) || insertionPoint.SceneElement.DocumentNode.DocumentRoot.RootNode != insertionPoint.SceneElement.DocumentNode))
                            {
                                if (element.Name != null)
                                {
                                    string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)element, element.Name);
                                    sceneNodeIdHelper.SetLocalName((SceneNode)element, validCopiedElementId);
                                }
                                sceneNodeIdHelper.FixNameConflicts((SceneNode)element);
                            }
                            if (viewModel.DesignerContext.PrototypingService != null)
                            {
                                viewModel.DesignerContext.PrototypingService.ProcessElementBeforeInsertion(insertionPoint, element);
                            }
                            insertionPoint.Insert((SceneNode)element);
                            if (element.GetLocalValue(DesignTimeProperties.LayoutRectProperty) != null && frameworkElement != null)
                            {
                                elementsToTranslateLater.Add(new PasteCommand.DelayedElementTranslationInfo(frameworkElement));
                            }
                            element1 = element;
                        }
                    }
                    else if (element.TargetType == typeof(Image))
                    {
                        GeometryModel3DElement geometryModel3Delement = GeometryCreationHelper3D.ConvertImageTo3D(viewModel, frameworkElement, element.Name);
                        IChildContainer3D      childContainer3D       = insertionPoint.SceneElement as IChildContainer3D;
                        if (childContainer3D != null)
                        {
                            childContainer3D.AddChild(viewModel, (Base3DElement)geometryModel3Delement);
                            element1 = (SceneElement)geometryModel3Delement;
                        }
                    }
                }
                else
                {
                    Base3DElement child;
                    if ((child = element as Base3DElement) != null)
                    {
                        if (child.Name != null)
                        {
                            string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)child, child.Name);
                            sceneNodeIdHelper.SetLocalName((SceneNode)child, validCopiedElementId);
                        }
                        DependencyPropertyReferenceStep propertyReferenceStep = insertionPoint.Property as DependencyPropertyReferenceStep;
                        if (propertyReferenceStep != null && propertyReferenceStep.DependencyProperty == ModelVisual3D.ContentProperty)
                        {
                            Model3DElement model3Delement = BaseElement3DCoercionHelper.CoerceToModel3D(viewModel, (SceneElement)child);
                            if (model3Delement != null)
                            {
                                insertionPoint.Insert((SceneNode)model3Delement);
                                element1 = (SceneElement)model3Delement;
                            }
                        }
                        else
                        {
                            IChildContainer3D childContainer3D = insertionPoint.SceneElement as IChildContainer3D;
                            if (childContainer3D != null)
                            {
                                element1 = childContainer3D.AddChild(viewModel, child);
                            }
                        }
                    }
                }
                if (element1 != null)
                {
                    if (!(viewModel.ActiveEditingContainer is FrameworkTemplateElement))
                    {
                        PasteCommand.StripTemplateBindings(element1);
                    }
                }
            }
            return(element1);
        }
Beispiel #4
0
        private static void PasteChildProperty(SceneViewModel viewModel, SceneNode childProperty, IList <SceneNode> pastedNodes)
        {
            IList <SceneElement> list = (IList <SceneElement>)null;

            DocumentNodeHelper.StripExtraNamespaces(childProperty.DocumentNode);
            if (viewModel.ElementSelectionSet.Selection.Count != 0)
            {
                list = (IList <SceneElement>)viewModel.ElementSelectionSet.Selection;
            }
            else if (viewModel.ChildPropertySelectionSet.Selection.Count != 0 && !(childProperty is BehaviorBaseNode) && !(childProperty is BehaviorTriggerBaseNode))
            {
                list = (IList <SceneElement>) new List <SceneElement>();
                foreach (SceneNode sceneNode in viewModel.ChildPropertySelectionSet.Selection)
                {
                    SceneElement sceneElement = sceneNode.Parent as SceneElement;
                    list.Add(sceneElement);
                }
            }
            if (list == null)
            {
                return;
            }
            IProperty targetProperty = viewModel.ProjectContext.ResolveProperty(PasteCommand.ChildSceneNodeToPropertyId(childProperty));

            foreach (SceneElement sceneElement in (IEnumerable <SceneElement>)list)
            {
                PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(sceneElement, targetProperty);
                if (sceneInsertionPoint.CanInsert((ITypeId)childProperty.Type))
                {
                    if (ProjectNeutralTypes.BehaviorTriggerBase.IsAssignableFrom((ITypeId)childProperty.Type))
                    {
                        BehaviorTriggerBaseNode behaviorTriggerBaseNode1 = (BehaviorTriggerBaseNode)childProperty;
                        bool flag = true;
                        foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)behaviorTriggerBaseNode1.Actions)
                        {
                            if (!sceneInsertionPoint.CanInsert((ITypeId)sceneNode.Type))
                            {
                                flag = false;
                                break;
                            }
                        }
                        if (flag)
                        {
                            ISceneNodeCollection <SceneNode> collectionForProperty    = sceneElement.GetCollectionForProperty((IPropertyId)targetProperty);
                            BehaviorTriggerBaseNode          behaviorTriggerBaseNode2 = BehaviorHelper.FindMatchingTriggerNode(behaviorTriggerBaseNode1.DocumentNode, collectionForProperty);
                            if (behaviorTriggerBaseNode2 == null)
                            {
                                DocumentNode node = behaviorTriggerBaseNode1.DocumentNode.Clone(behaviorTriggerBaseNode1.DocumentContext);
                                behaviorTriggerBaseNode2 = (BehaviorTriggerBaseNode)viewModel.GetSceneNode(node);
                                collectionForProperty.Add((SceneNode)behaviorTriggerBaseNode2);
                            }
                            else
                            {
                                DocumentNode node = behaviorTriggerBaseNode1.Actions[0].DocumentNode.Clone(behaviorTriggerBaseNode1.Actions[0].DocumentNode.Context);
                                BehaviorTriggerActionNode triggerActionNode = (BehaviorTriggerActionNode)viewModel.GetSceneNode(node);
                                behaviorTriggerBaseNode2.Actions.Add((SceneNode)triggerActionNode);
                            }
                            BehaviorEventTriggerNode eventTriggerNode = behaviorTriggerBaseNode2 as BehaviorEventTriggerNode;
                            if (eventTriggerNode != null)
                            {
                                BehaviorEventTriggerNode.FixUpEventName(eventTriggerNode);
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        DocumentNode node      = childProperty.DocumentNode.Clone(childProperty.DocumentNode.Context);
                        SceneNode    sceneNode = viewModel.GetSceneNode(node);
                        sceneInsertionPoint.Insert(sceneNode);
                        if (sceneNode is EffectNode)
                        {
                            pastedNodes.Add(sceneNode);
                        }
                    }
                    TimelineItem timelineItem = viewModel.TimelineItemManager.FindTimelineItem((SceneNode)sceneElement);
                    if (timelineItem != null)
                    {
                        timelineItem.IsExpanded = true;
                    }
                }
            }
        }
Beispiel #5
0
        private static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject, ISceneInsertionPoint insertionPoint, bool allowInsertionPointChange, out bool canceledPasteOperation)
        {
            PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.PasteElements);
            canceledPasteOperation = false;
            List <SceneNode> list         = new List <SceneNode>();
            PastePackage     pastePackage = PastePackage.FromData(viewModel, dataObject);

            if (pastePackage != null)
            {
                if (allowInsertionPointChange)
                {
                    insertionPoint = PasteCommand.ComputeNewInsertionPoint(viewModel, insertionPoint, pastePackage);
                }
                if (!PasteCommand.CanAddMultipleElements(insertionPoint.SceneElement, pastePackage.Elements.Count))
                {
                    string name = insertionPoint.SceneElement.TargetType.Name;
                    viewModel.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PasteMultipleInSingleContainerError, new object[1]
                    {
                        (object)name
                    }));
                }
                else if (pastePackage.Elements.Count == 0 && pastePackage.Storyboards.Count == 0 && pastePackage.Resources.Count > 0)
                {
                    viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedNoElementsDialogMessage);
                }
                else
                {
                    IDictionary <DocumentNode, string> imageMap = (IDictionary <DocumentNode, string>) new Dictionary <DocumentNode, string>();
                    foreach (SceneNode sceneNode in pastePackage.Elements)
                    {
                        foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel))
                        {
                            imageMap.Add(keyValuePair);
                        }
                    }
                    foreach (SceneNode sceneNode in pastePackage.Resources)
                    {
                        foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel))
                        {
                            imageMap.Add(keyValuePair);
                        }
                    }
                    int index = 0;
                    ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(viewModel.RootNode.DocumentNode);
                    if (resourcesCollection != null && resourcesCollection.Resources != null && resourcesCollection.Resources.SupportsChildren)
                    {
                        index = resourcesCollection.Resources.Children.Count;
                    }
                    if (Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PasteResources(pastePackage, imageMap, ResourceConflictResolution.UseExisting | ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld, viewModel.RootNode, index, false))
                    {
                        ILayoutDesigner designerForParent = viewModel.GetLayoutDesignerForParent(insertionPoint.SceneElement, true);
                        List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater = new List <PasteCommand.DelayedElementTranslationInfo>(pastePackage.Elements.Count);
                        string copyElementToken = pastePackage.ClipboardCopyElementToken;
                        foreach (SceneElement element in pastePackage.Elements)
                        {
                            SceneElement sceneElement = PasteCommand.PasteElement(viewModel, element, elementsToTranslateLater, insertionPoint);
                            if (sceneElement != null)
                            {
                                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.UpdateImageReferences(sceneElement.DocumentNode, imageMap, pastePackage, viewModel);
                                list.Add((SceneNode)sceneElement);
                                sceneElement.ClearValue(DesignTimeProperties.CopyTokenProperty);
                            }
                        }
                        if (copyElementToken != null)
                        {
                            pastePackage.SetGlobalCopyElementToken(copyElementToken);
                            PastePackage.PasteSelectionChangePending = true;
                        }
                        foreach (SceneNode childProperty in pastePackage.ChildPropertyNodes)
                        {
                            PasteCommand.PasteChildProperty(viewModel, childProperty, (IList <SceneNode>)list);
                        }
                        foreach (StoryboardTimelineSceneNode storyboard in pastePackage.Storyboards)
                        {
                            PasteCommand.PasteStoryboard(viewModel, storyboard, (IList <SceneNode>)list);
                        }
                        viewModel.Document.OnUpdatedEditTransaction();
                        viewModel.DefaultView.UpdateLayout();
                        using (viewModel.ForceBaseValue())
                        {
                            Rect empty = Rect.Empty;
                            foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater)
                            {
                                empty.Union(elementTranslationInfo.Bounds);
                            }
                            foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater)
                            {
                                elementTranslationInfo.UpdateTranslation(designerForParent, empty);
                            }
                        }
                    }
                    else
                    {
                        canceledPasteOperation = true;
                    }
                }
            }
            else if (dataObject.GetDataPresent(DataFormats.FileDrop))
            {
                DesignerContext designerContext = viewModel.DesignerContext;
                string[]        supportedFiles  = FileDropToolBehavior.CreateImageOrMediaDrop(designerContext).GetSupportedFiles(ClipboardService.GetDataObject());
                if (supportedFiles.Length > 0)
                {
                    IEnumerable <IProjectItem> importedItems = designerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)supportedFiles, (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo()
                    {
                        SourcePath = file
                    })));
                    FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, importedItems, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint);
                }
                else
                {
                    viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage);
                }
            }
            else if (dataObject.GetDataPresent(DataFormats.Bitmap))
            {
                DesignerContext designerContext = viewModel.DesignerContext;
                IProjectItem    projectItem     = CutBuffer.AddImageDataFromClipboard(designerContext.ProjectManager, designerContext.ActiveProject);
                if (projectItem != null)
                {
                    FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, (IEnumerable <IProjectItem>) new List <IProjectItem>()
                    {
                        projectItem
                    }, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint);
                }
                else
                {
                    viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage);
                }
            }
            else
            {
                viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage);
            }
            return((ICollection <SceneNode>)list);
        }
Beispiel #6
0
 public static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject, ISceneInsertionPoint insertionPoint, out bool canceledPasteOperation)
 {
     return(PasteCommand.PasteData(viewModel, dataObject, insertionPoint, false, out canceledPasteOperation));
 }
Beispiel #7
0
        public static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject)
        {
            bool canceledPasteOperation;

            return(PasteCommand.PasteData(viewModel, dataObject, viewModel.ActiveSceneInsertionPoint, viewModel.LockedInsertionPoint == null, out canceledPasteOperation));
        }
        public override void Execute()
        {
            string               fileName           = "test";
            IProject             activeProject      = this.DesignerContext.ActiveProject;
            TemplateItemHelper   templateItemHelper = new TemplateItemHelper(activeProject, (IList <string>)null, (IServiceProvider)this.DesignerContext.Services);
            IProjectItemTemplate templateItem       = templateItemHelper.FindTemplateItem("UserControl");

            if (templateItem == null)
            {
                this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlTemplateNotFound);
            }
            else
            {
                SceneViewModel      activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel;
                List <SceneElement> elements             = new List <SceneElement>();
                elements.AddRange((IEnumerable <SceneElement>)activeSceneViewModel.ElementSelectionSet.Selection);
                elements.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(activeSceneViewModel.RootNode));
                if (this.ShowUI)
                {
                    string recommendedName = this.GetRecommendedName((IEnumerable <SceneElement>)elements);
                    MakeUserControlDialog userControlDialog = new MakeUserControlDialog(this.DesignerContext, this.DialogTitle, templateItemHelper, recommendedName);
                    bool?nullable = userControlDialog.ShowDialog();
                    if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                    {
                        return;
                    }
                    fileName = userControlDialog.ControlName;
                }
                List <IProjectItem>        itemsToOpen  = (List <IProjectItem>)null;
                IProjectItem               projectItem1 = (IProjectItem)null;
                IEnumerable <IProjectItem> source       = (IEnumerable <IProjectItem>)null;
                try
                {
                    source = templateItemHelper.AddProjectItemsForTemplateItem(templateItem, fileName, this.DesignerContext.ProjectManager.TargetFolderForProject(activeProject), CreationOptions.DoNotAllowOverwrites | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath, out itemsToOpen);
                }
                catch (Exception ex)
                {
                    if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex))
                    {
                        this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ProjectNewFileErrorDialogMessage, new object[2]
                        {
                            (object)fileName,
                            (object)ex.Message
                        }));
                    }
                    else
                    {
                        throw;
                    }
                }
                if (source == null || EnumerableExtensions.CountIsLessThan <IProjectItem>(source, 1))
                {
                    return;
                }
                if (itemsToOpen != null && itemsToOpen.Count > 0)
                {
                    projectItem1 = Enumerable.FirstOrDefault <IProjectItem>((IEnumerable <IProjectItem>)itemsToOpen);
                    projectItem1.OpenDocument(false, true);
                }
                if (projectItem1 != null && projectItem1.IsOpen && projectItem1.DocumentType.CanView)
                {
                    Rect empty = Rect.Empty;
                    for (int index = 0; index < elements.Count; ++index)
                    {
                        BaseFrameworkElement child = elements[index] as BaseFrameworkElement;
                        if (child != null)
                        {
                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                            empty.Union(childRect);
                        }
                    }
                    Rect         rect              = RoundingHelper.RoundRect(empty);
                    SceneElement parentElement     = elements[0].ParentElement;
                    bool         useLayoutRounding = LayoutRoundingHelper.GetUseLayoutRounding(parentElement);
                    DataObject   dataObject        = (DataObject)null;
                    using (activeSceneViewModel.ForceBaseValue())
                    {
                        PastePackage pastePackage = new PastePackage(activeSceneViewModel);
                        pastePackage.CopyStoryboardsReferencingElements = true;
                        pastePackage.AddElements(elements);
                        dataObject = pastePackage.GetPasteDataObject();
                    }
                    SceneView sceneView = projectItem1.OpenView(true) as SceneView;
                    if (sceneView != null)
                    {
                        SceneViewModel     viewModel           = sceneView.ViewModel;
                        ProjectXamlContext projectXamlContext  = ProjectXamlContext.FromProjectContext(viewModel.ViewRoot.ProjectContext);
                        ClassAttributes    rootClassAttributes = viewModel.DocumentRoot.RootClassAttributes;
                        ITypeId            typeId = (ITypeId)null;
                        if (projectXamlContext != null && rootClassAttributes != null)
                        {
                            projectXamlContext.RefreshUnbuiltTypeDescriptions();
                            if (rootClassAttributes != null)
                            {
                                typeId = (ITypeId)projectXamlContext.GetType(projectXamlContext.ProjectAssembly.Name, rootClassAttributes.QualifiedClassName);
                            }
                        }
                        if (typeId != null && this.CheckForCircularReference((IEnumerable <SceneElement>)elements, typeId))
                        {
                            this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlCircularReferenceFound);
                            this.CleanupAfterCancel(projectItem1);
                            return;
                        }
                        using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                        {
                            if (!rect.IsEmpty)
                            {
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignWidthProperty, (object)rect.Width);
                                viewModel.RootNode.SetValue(DesignTimeProperties.DesignHeightProperty, (object)rect.Height);
                                if (this.AddToApplicationFlow)
                                {
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.WidthProperty, (object)rect.Width);
                                    viewModel.RootNode.SetValue(BaseFrameworkElement.HeightProperty, (object)rect.Height);
                                }
                            }
                            IProperty property = LayoutRoundingHelper.ResolveUseLayoutRoundingProperty(viewModel.RootNode);
                            if (property != null)
                            {
                                viewModel.RootNode.SetValue((IPropertyId)property, (object)(bool)(useLayoutRounding ? true : false));
                            }
                            ILayoutDesigner         designerForParent = viewModel.GetLayoutDesignerForParent(viewModel.ActiveSceneInsertionPoint.SceneElement, true);
                            bool                    canceledPasteOperation;
                            ICollection <SceneNode> nodes = PasteCommand.PasteData(viewModel, new SafeDataObject((IDataObject)dataObject), viewModel.ActiveSceneInsertionPoint, out canceledPasteOperation);
                            if (canceledPasteOperation)
                            {
                                editTransaction.Cancel();
                                this.CleanupAfterCancel(projectItem1);
                                return;
                            }
                            editTransaction.Update();
                            if (nodes.Count > 0)
                            {
                                viewModel.DefaultView.UpdateLayout();
                                viewModel.SelectNodes(nodes);
                                if (designerForParent != null)
                                {
                                    foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)nodes)
                                    {
                                        BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                        if (child != null && child.IsViewObjectValid)
                                        {
                                            Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child);
                                            childRect.Location = (Point)(childRect.Location - rect.Location);
                                            designerForParent.SetChildRect(child, childRect);
                                        }
                                    }
                                }
                            }
                            editTransaction.Commit();
                        }
                        if (this.AddToApplicationFlow && this.DesignerContext.PrototypingService != null)
                        {
                            this.DesignerContext.PrototypingService.PromoteToCompositionScreen(projectItem1);
                        }
                        if (typeId != null)
                        {
                            using (activeSceneViewModel.ForceBaseValue())
                            {
                                using (activeSceneViewModel.DisableDrawIntoState())
                                {
                                    using (SceneEditTransaction editTransaction = activeSceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl))
                                    {
                                        using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove())
                                        {
                                            SceneElement primarySelection = activeSceneViewModel.ElementSelectionSet.PrimarySelection;
                                            IProperty    propertyForChild = parentElement.GetPropertyForChild((SceneNode)primarySelection);
                                            PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(parentElement, propertyForChild);
                                            SceneNode sceneNode = (SceneNode)null;
                                            if (sceneInsertionPoint.CanInsert(typeId))
                                            {
                                                foreach (SceneElement element in elements)
                                                {
                                                    if (element != primarySelection)
                                                    {
                                                        activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
                                                        element.Remove();
                                                    }
                                                }
                                                ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)propertyForChild);
                                                int index = collectionForProperty.IndexOf((SceneNode)primarySelection);
                                                activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection);
                                                primarySelection.Remove();
                                                sceneNode = activeSceneViewModel.CreateSceneNode(typeId);
                                                collectionForProperty.Insert(index, sceneNode);
                                                this.DesignerContext.ViewService.ActiveView = (IView)activeSceneViewModel.DefaultView;
                                                editTransaction.Update();
                                                activeSceneViewModel.DefaultView.UpdateLayout();
                                                BaseFrameworkElement child = sceneNode as BaseFrameworkElement;
                                                if (child != null && child.IsViewObjectValid)
                                                {
                                                    activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true).SetChildRect(child, rect);
                                                }
                                            }
                                            if (this.AddToApplicationFlow)
                                            {
                                                if (sceneNode != null)
                                                {
                                                    sceneNode.SetValue(DesignTimeProperties.IsPrototypingCompositionProperty, (object)true);
                                                }
                                            }
                                        }
                                        editTransaction.Commit();
                                    }
                                }
                            }
                            this.DesignerContext.ViewService.ActiveView = (IView)viewModel.DefaultView;
                        }
                    }
                }
                if (itemsToOpen == null || itemsToOpen.Count <= 1)
                {
                    return;
                }
                foreach (IProjectItem projectItem2 in itemsToOpen)
                {
                    if (projectItem1 != projectItem2)
                    {
                        projectItem2.OpenView(true);
                    }
                }
            }
        }