private void DeleteLeftoverElements(HashSet <SceneElement> elementsWithDeletedParts) { List <SceneElement> elements = new List <SceneElement>(); foreach (SceneElement sceneElement in this.SceneViewModel.ElementSelectionSet.Selection) { if (!elementsWithDeletedParts.Contains(sceneElement)) { elements.Add(sceneElement); } } ElementUtilities.SortElementsByDepth(elements); foreach (SceneElement sceneElement in elements) { this.SceneViewModel.ElementSelectionSet.RemoveSelection(sceneElement); this.SceneViewModel.DeleteElementTree(sceneElement); } }
public override void Execute(object arg) { ITypeId type = this.Type; if (type is ProjectNeutralTypeId && !this.SceneViewModel.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)this.SceneViewModel.ProjectContext, type)) { return; } using (SceneEditTransaction editTransaction = this.DesignerContext.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitLayoutPaneChangeLayoutType, new object[1] { (object)this.Type.Name }))) { bool flag1 = false; SceneViewModel activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel; ReadOnlyCollection <SceneElement> selection = this.DesignerContext.SelectionManager.ElementSelectionSet.Selection; SceneElement primarySelection1 = this.DesignerContext.SelectionManager.ElementSelectionSet.PrimarySelection; List <SceneElement> list = new List <SceneElement>(); bool flag2 = false; bool flag3 = false; bool flag4 = false; SceneElement sceneElement1 = (SceneElement)null; IStoryboardContainer storyboardContainer = (IStoryboardContainer)null; SceneElement primarySelection2 = (SceneElement)null; this.DesignerContext.SelectionManager.ElementSelectionSet.Clear(); List <SceneElement> elements = new List <SceneElement>(); elements.AddRange((IEnumerable <SceneElement>)selection); ElementUtilities.SortElementsByDepth(elements); foreach (SceneElement sceneElement2 in elements) { ITypeId typeId1 = (ITypeId)null; foreach (ITypeId typeId2 in ChangeLayoutTypeFlyoutCommand.LayoutTypes) { if (typeId2.IsAssignableFrom((ITypeId)sceneElement2.Type)) { typeId1 = typeId2; break; } } if (typeId1 == null) { list.Add(sceneElement2); } else { if (activeSceneViewModel.LockedInsertionPoint != null) { if (activeSceneViewModel.LockedInsertionPoint.SceneElement == sceneElement2) { flag2 = true; } else if (sceneElement2.IsAncestorOf((SceneNode)activeSceneViewModel.ActiveSceneInsertionPoint.SceneElement)) { sceneElement1 = activeSceneViewModel.ActiveSceneInsertionPoint.SceneElement; flag2 = true; } } if (primarySelection1 == sceneElement2) { flag4 = true; } if (!flag3 && activeSceneViewModel.ActiveStoryboardContainer == sceneElement2) { activeSceneViewModel.SetActiveStoryboardTimeline((IStoryboardContainer)null, (StoryboardTimelineSceneNode)null, (TriggerBaseNode)null); flag3 = true; } using (sceneElement2.ViewModel.ForceBaseValue()) { BaseFrameworkElement parent1 = sceneElement2 as BaseFrameworkElement; List <LayoutCacheRecord> layoutCache = (List <LayoutCacheRecord>)null; ILayoutDesigner designerForParent = activeSceneViewModel.GetLayoutDesignerForParent(sceneElement2, true); if (parent1 != null) { layoutCache = designerForParent.GetCurrentRects(parent1); } SceneElement elementContainingChildren = (SceneElement)null; SceneElement sceneElement3 = ChangeLayoutTypeCommand.ChangeLayoutType(sceneElement2, type, ref elementContainingChildren); editTransaction.Update(); if (sceneElement3.IsViewObjectValid) { this.SceneViewModel.DefaultView.UpdateLayout(); BaseFrameworkElement parent2 = elementContainingChildren as BaseFrameworkElement; if (parent2 != null && parent2.IsViewObjectValid && layoutCache != null) { activeSceneViewModel.GetLayoutDesignerForParent(elementContainingChildren, true).SetCurrentRects(parent2, layoutCache); } if (flag2 && sceneElement1 == null) { sceneElement1 = elementContainingChildren; } if (flag3 && storyboardContainer == null) { storyboardContainer = (IStoryboardContainer)sceneElement3; } if (flag4 && primarySelection2 == null) { primarySelection2 = sceneElement3; } list.Add(sceneElement3); } flag1 = true; } } } if (flag2 && sceneElement1 != null) { activeSceneViewModel.SetLockedInsertionPoint(sceneElement1); } if (flag3 && storyboardContainer != null) { activeSceneViewModel.SetActiveStoryboardTimeline(storyboardContainer, (StoryboardTimelineSceneNode)null, (TriggerBaseNode)null); } this.DesignerContext.SelectionManager.ElementSelectionSet.SetSelection((ICollection <SceneElement>)list, primarySelection2); if (flag1) { editTransaction.Commit(); } else { editTransaction.Cancel(); } } }