public override void Execute(object arg) { DesignerContext designerContext = this.DesignerContext; SceneViewModel activeSceneViewModel = designerContext.ActiveSceneViewModel; ITypeId type = this.Type; if (type is ProjectNeutralTypeId) { bool flag = activeSceneViewModel.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)this.DesignerContext.ActiveSceneViewModel.ProjectContext, type); if (!flag && this.IsDragDropContainer) { IMessageDisplayService messageDisplayService = activeSceneViewModel.DesignerContext.MessageDisplayService; flag = ToolkitHelper.EnsureSilverlightToolkitTypeAvailable((ITypeResolver)activeSceneViewModel.ProjectContext, type, messageDisplayService, StringTable.SilverlightToolkitDragDropNotInstalled, StringTable.SilverlightToolkitDragDropIncorrectVersion); } if (!flag) { return; } } using (SceneEditTransaction editTransaction = designerContext.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitGroupIntoLayoutType, new object[1] { (object)this.Type.Name }))) { List <SceneElement> list1 = new List <SceneElement>(); List <SceneNode> elements = new List <SceneNode>(); list1.AddRange((IEnumerable <SceneElement>)designerContext.SelectionManager.ElementSelectionSet.Selection); GroupIntoLayoutTypeCommand.OrientationHelper orientationHelper = new GroupIntoLayoutTypeCommand.OrientationHelper(); list1.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(this.SceneViewModel.RootNode)); List <LayoutCacheRecord> list2 = new List <LayoutCacheRecord>(list1.Count); Rect empty = Rect.Empty; for (int index = 0; index < list1.Count; ++index) { list2.Add((LayoutCacheRecord)null); BaseFrameworkElement element = list1[index] as BaseFrameworkElement; if (element != null) { ILayoutDesigner designerForChild = element.ViewModel.GetLayoutDesignerForChild((SceneElement)element, true); Rect roundedUpChildRect = LayoutRoundingHelper.GetRoundedUpChildRect(designerForChild, element); empty.Union(roundedUpChildRect); orientationHelper.AddChildRect((SceneNode)element, roundedUpChildRect); LayoutCacheRecord layoutCacheRecord = designerForChild.CacheLayout(element); list2[index] = layoutCacheRecord; elements.Add((SceneNode)element); } } Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null; using (this.SceneViewModel.ForceBaseValue()) { using (this.SceneViewModel.DisableDrawIntoState()) { SceneElement sceneElement1 = (SceneElement)null; SceneElement sceneElement2 = (SceneElement)activeSceneViewModel.CreateSceneNode(type); Orientation? nullable = orientationHelper.ApplyOrientation(sceneElement2); if (nullable.HasValue) { orientationHelper.SortElements(elements, nullable.Value); } int num; if (list1.Count == 1 && list1[0] is BaseFrameworkElement) { int?fixedCapacity = sceneElement2.DefaultContent.FixedCapacity; num = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false); } else { num = 0; } bool flag = num != 0; if (sceneElement2 != null) { activeSceneViewModel.GetLayoutDesignerForParent(sceneElement2, true); } foreach (SceneElement sceneElement3 in list1) { if (sceneElement3 != null) { BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement; ILayoutDesigner layoutDesigner = frameworkElement == null ? (ILayoutDesigner)null : sceneElement3.ViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true); if (flag) { properties = SceneElementHelper.StoreProperties((SceneNode)sceneElement3, layoutDesigner.GetLayoutProperties(), true); } if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == sceneElement3) { sceneElement1 = sceneElement3; } } } if (list1.Count == 1) { VisualStateManagerSceneNode.MoveStates(list1[0], sceneElement2); } using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { SceneElement primarySelection = designerContext.SelectionManager.ElementSelectionSet.PrimarySelection; designerContext.SelectionManager.ElementSelectionSet.Clear(); Dictionary <IPropertyId, List <SceneNode> > storedChildren = new Dictionary <IPropertyId, List <SceneNode> >(); storedChildren.Add((IPropertyId)sceneElement2.DefaultContentProperty, elements); ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer(); foreach (SceneElement sceneElement3 in list1) { if (sceneElement3 != primarySelection) { sceneElement3.Remove(); } } int index1 = collectionContainer.IndexOf((SceneNode)primarySelection); primarySelection.Remove(); collectionContainer.Insert(index1, (SceneNode)sceneElement2); ChangeLayoutTypeCommand.ApplyChildren(sceneElement2, storedChildren, empty.Size); if (flag) { SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)list1[0], (SceneNode)sceneElement2, properties); SceneElementHelper.ApplyProperties((SceneNode)sceneElement2, properties); } else { ILayoutDesigner designerForChild = sceneElement2.ViewModel.GetLayoutDesignerForChild(sceneElement2, true); if (sceneElement2.IsViewObjectValid) { LayoutOverrides layoutOverrides = LayoutOverrides.None; LayoutOverrides overridesToIgnore = LayoutOverrides.None; if (nullable.HasValue && nullable.Value == Orientation.Horizontal) { layoutOverrides |= LayoutOverrides.Width; } else { overridesToIgnore |= LayoutOverrides.Width; } if (nullable.HasValue && nullable.Value == Orientation.Vertical) { layoutOverrides |= LayoutOverrides.Height; } else { overridesToIgnore |= LayoutOverrides.Height; } designerForChild.SetChildRect((BaseFrameworkElement)sceneElement2, empty, layoutOverrides, overridesToIgnore, LayoutOverrides.None); } } editTransaction.Update(); if (sceneElement2.IsViewObjectValid) { this.SceneViewModel.DefaultView.UpdateLayout(); SceneElement parentElement = primarySelection.ParentElement; ILayoutDesigner designerForParent = activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true); for (int index2 = 0; index2 < list1.Count; ++index2) { SceneElement sceneElement3 = list1[index2]; BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement; if (frameworkElement != null) { LayoutCacheRecord layoutCacheRecord = list2[index2]; Rect rect = LayoutRoundingHelper.RoundUpLayoutRect(frameworkElement, layoutCacheRecord.Rect); rect.Location = (Point)(rect.Location - empty.Location); designerForParent.ClearUnusedLayoutProperties(frameworkElement); designerForParent.SetChildRect(frameworkElement, rect, flag ? LayoutOverrides.None : layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None); if (this.IsDragDropContainer) { sceneElement3.SetValue(Base2DElement.AllowDropProperty, (object)true); } } } } if (sceneElement1 != null) { this.SceneViewModel.SetLockedInsertionPoint(sceneElement1); } } designerContext.SelectionManager.ElementSelectionSet.SetSelection(sceneElement2); editTransaction.Commit(); } } } }
private SceneNode[] Ungroup(SceneEditTransaction transaction, BaseFrameworkElement group) { SceneElement parentElement = group.ParentElement; if (parentElement == null) { return(new SceneNode[0]); } transaction.Update(); ILayoutDesigner designerForParent1 = this.SceneViewModel.GetLayoutDesignerForParent(parentElement, true); Rect childRect = designerForParent1.GetChildRect(group); Matrix effectiveRenderTransform = group.GetEffectiveRenderTransform(false); SceneNode[] array = new SceneNode[group.DefaultContent.Count]; group.DefaultContent.CopyTo(array, 0); using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { Transform[] transformArray = new Transform[array.Length]; Point[] pointArray = new Point[array.Length]; LayoutCacheRecord[] layoutCacheRecordArray = new LayoutCacheRecord[array.Length]; ILayoutDesigner designerForParent2 = group.ViewModel.GetLayoutDesignerForParent((SceneElement)group, true); for (int index = 0; index < array.Length; ++index) { BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement; if (frameworkElement != null) { transformArray[index] = (Transform)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty); pointArray[index] = frameworkElement.RenderTransformOrigin; designerForParent2.GetChildRect(frameworkElement); LayoutCacheRecord layoutCacheRecord = designerForParent2.CacheLayout(frameworkElement); layoutCacheRecordArray[index] = layoutCacheRecord; } } int num1; if (array.Length == 1 && array[0] is BaseFrameworkElement) { int?fixedCapacity = group.DefaultContent.FixedCapacity; num1 = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false); } else { num1 = 0; } bool flag = num1 != 0; if (flag) { Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)group, designerForParent1.GetLayoutProperties(), true); SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)group, array[0], properties); if (!SceneElementHelper.ApplyProperties(array[0], properties)) { flag = false; } } if (array.Length == 1 && array[0] is SceneElement) { VisualStateManagerSceneNode.MoveStates((SceneElement)group, (SceneElement)array[0]); } using (this.SceneViewModel.ForceBaseValue()) { SceneElement sceneElement = (SceneElement)null; for (int index = 0; index < array.Length; ++index) { BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement; if (frameworkElement != null) { if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == frameworkElement) { sceneElement = (SceneElement)frameworkElement; } DocumentNodeHelper.PreserveFormatting(frameworkElement.DocumentNode); frameworkElement.Remove(); } } ISceneNodeCollection <SceneNode> collectionContainer = group.GetCollectionContainer(); int index1 = collectionContainer.IndexOf((SceneNode)group); this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)group); this.SceneViewModel.RemoveElement((SceneNode)group); Matrix matrix1 = effectiveRenderTransform; matrix1.OffsetX = 0.0; matrix1.OffsetY = 0.0; for (int index2 = array.Length - 1; index2 >= 0; --index2) { BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement; if (frameworkElement != null) { Matrix matrix2 = (transformArray[index2] ?? Transform.Identity).Value; collectionContainer.Insert(index1, (SceneNode)frameworkElement); CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix2 * matrix1)); if (frameworkElement.GetLocalValue(Base2DElement.RenderTransformProperty) != null || !canonicalTransform.TransformGroup.Value.IsIdentity) { frameworkElement.SetValue(Base2DElement.RenderTransformProperty, canonicalTransform.GetPlatformTransform(frameworkElement.Platform.GeometryHelper)); if (frameworkElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset) { frameworkElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5)); } } } } transaction.Update(); if (sceneElement != null) { this.SceneViewModel.SetLockedInsertionPoint(sceneElement); } bool[] flagArray = new bool[array.Length]; int length = 0; for (int index2 = 0; index2 < array.Length; ++index2) { BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement; if (frameworkElement != null && array[index2].Parent != null) { if (!flag) { LayoutCacheRecord layoutCacheRecord = layoutCacheRecordArray[index2]; Rect rect1 = layoutCacheRecord.Rect; Point point1 = new Point(rect1.X + rect1.Width * pointArray[index2].X, rect1.Y + rect1.Height * pointArray[index2].Y); Point point2 = effectiveRenderTransform.Transform(point1); Rect rect2 = new Rect(rect1.TopLeft + point2 - point1 + (Vector)childRect.TopLeft, rect1.Size); designerForParent1.ClearUnusedLayoutProperties(frameworkElement); designerForParent1.SetChildRect(frameworkElement, rect2, layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None); } flagArray[index2] = true; ++length; } } SceneNode[] sceneNodeArray = new SceneNode[length]; int num2 = 0; for (int index2 = 0; index2 < array.Length; ++index2) { if (flagArray[index2]) { sceneNodeArray[num2++] = array[index2]; } } return(sceneNodeArray); } } }