private SceneNode Move(SceneNode node, ref int index)
        {
            SceneElement sceneElement = node as SceneElement;
            ISceneNodeCollection <SceneNode> destinationCollection = this.DestinationCollection;
            bool flag = destinationCollection.Contains((SceneNode)sceneElement);
            BaseFrameworkElement element         = sceneElement as BaseFrameworkElement;
            ILayoutDesigner      layoutDesigner1 = element == null ? (ILayoutDesigner)null : this.ViewModel.GetLayoutDesignerForChild((SceneElement)element, false);

            if (sceneElement.IsAttached)
            {
                if (flag)
                {
                    if (destinationCollection.IndexOf((SceneNode)sceneElement) < index)
                    {
                        --index;
                    }
                    layoutDesigner1 = (ILayoutDesigner)null;
                }
                this.TargetNode.ViewModel.RemoveElement((SceneNode)sceneElement);
                this.ViewModel.Document.OnUpdatedEditTransaction();
            }
            SmartInsertionPoint.From(this.InsertionPoint, index).Insert((SceneNode)sceneElement);
            this.ViewModel.Document.OnUpdatedEditTransaction();
            ILayoutDesigner   layoutDesigner2 = element == null ? (ILayoutDesigner)null : this.ViewModel.GetLayoutDesignerForChild((SceneElement)element, false);
            LayoutCacheRecord layoutCacheRecord;

            if (layoutDesigner1 != null && layoutDesigner2 != null && (element != null && this.layoutCache.TryGetValue((SceneNode)element, out layoutCacheRecord)))
            {
                layoutDesigner2.SetLayoutFromCache(element, layoutCacheRecord, this.boundsOfAllElements);
            }
            if (index != -1)
            {
                ++index;
            }
            return((SceneNode)sceneElement);
        }
Example #2
0
        protected int ComputeIndexOffsetBeforeRemove(int index)
        {
            int num1 = 0;

            if (index >= 0)
            {
                ISceneNodeCollection <SceneNode> defaultContent = this.LayoutContainer.DefaultContent;
                if (defaultContent != null && defaultContent.Count > 0)
                {
                    foreach (BaseFrameworkElement frameworkElement in this.DraggedElements)
                    {
                        if (this.LayoutContainer == frameworkElement.Parent)
                        {
                            int num2 = defaultContent.IndexOf((SceneNode)frameworkElement);
                            if (num2 >= 0 && num2 < index)
                            {
                                --num1;
                            }
                        }
                    }
                }
            }
            return(num1);
        }
Example #3
0
        public static PathElement ConvertToPath(BaseFrameworkElement element)
        {
            SceneViewModel  viewModel        = element.ViewModel;
            PathGeometry    pathGeometry     = PathConversionHelper.ConvertToPathGeometry((SceneElement)element);
            PathElement     pathElement      = (PathElement)viewModel.CreateSceneNode(PlatformTypes.Path);
            ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)element, true);
            Rect            childRect        = designerForChild.GetChildRect(element);
            Transform       transform1       = Transform.Identity;

            if (element.IsSet(Base2DElement.RenderTransformProperty) == PropertyState.Set)
            {
                transform1 = (Transform)element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
            }
            Point point1 = new Point(0.5, 0.5);

            if (element.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Set)
            {
                point1 = (Point)element.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
            }
            bool flag = false;

            using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitConvertToPath, true))
            {
                using (viewModel.ForceBaseValue())
                {
                    pathElement.PathGeometry = pathGeometry;
                    pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill);
                    Brush textForeground = PathCommandHelper.GetTextForeground(element);
                    if (textForeground != null)
                    {
                        flag = true;
                        pathElement.SetValueAsWpf(ShapeElement.FillProperty, (object)textForeground);
                    }
                    viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)element);
                    Dictionary <IPropertyId, SceneNode> properties         = SceneElementHelper.StoreProperties((SceneNode)element);
                    ISceneNodeCollection <SceneNode>    collectionForChild = element.Parent.GetCollectionForChild((SceneNode)element);
                    int index = collectionForChild.IndexOf((SceneNode)element);
                    collectionForChild[index] = (SceneNode)pathElement;
                    if (flag)
                    {
                        List <IPropertyId> list = new List <IPropertyId>();
                        foreach (KeyValuePair <IPropertyId, SceneNode> keyValuePair in properties)
                        {
                            IPropertyId key = keyValuePair.Key;
                            DependencyPropertyReferenceStep propertyReferenceStep = key as DependencyPropertyReferenceStep;
                            if (propertyReferenceStep != null && !propertyReferenceStep.IsAttachable && (propertyReferenceStep.MemberType != MemberType.DesignTimeProperty && !PlatformTypeHelper.GetDeclaringType((IMember)propertyReferenceStep).IsAssignableFrom(typeof(Path))))
                            {
                                list.Add(key);
                            }
                        }
                        foreach (IPropertyId key in list)
                        {
                            properties.Remove(key);
                        }
                    }
                    SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties);
                }
                if (ProjectNeutralTypes.PrimitiveShape.IsAssignableFrom((ITypeId)element.Type))
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect   bounds          = pathGeometry.Bounds;
                        double halfStrokeWidth = PathCommandHelper.GetHalfStrokeWidth(pathElement);
                        bounds.Inflate(halfStrokeWidth / 2.0, halfStrokeWidth / 2.0);
                        if (transform1 != Transform.Identity && bounds.Size != childRect.Size)
                        {
                            Point point2 = (Point)pathElement.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty);
                            Point point3 = new Point(point2.X * childRect.Width, point2.Y * childRect.Height);
                            Point point4 = new Point((point3.X - bounds.X) / bounds.Width, (point3.Y - bounds.Y) / bounds.Height);
                            pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point4);
                        }
                        bounds.Offset(childRect.Left, childRect.Top);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, bounds);
                    }
                }
                if (flag && !pathGeometry.IsEmpty())
                {
                    using (viewModel.ForceBaseValue())
                    {
                        Rect bounds = pathGeometry.Bounds;
                        bounds.Offset(childRect.Left, childRect.Top);
                        Point point2 = new Point(bounds.Left + point1.X * bounds.Width, bounds.Top + point1.Y * bounds.Height);
                        Point point3 = new Point(childRect.Left + childRect.Width * point1.X, childRect.Top + childRect.Height * point1.Y);
                        Point point4 = new TransformGroup()
                        {
                            Children =
                            {
                                (Transform) new TranslateTransform(-point3.X, -point3.Y),
                                transform1,
                                (Transform) new TranslateTransform(point3.X,  point3.Y)
                            }
                        }.Transform(point2);
                        Transform transform2 = (Transform) new CanonicalTransform(transform1)
                        {
                            TranslationX = 0.0,
                            TranslationY = 0.0
                        }.TransformGroup;
                        Rect rect = new Rect(point4.X - bounds.Width * point1.X, point4.Y - bounds.Height * point1.Y, bounds.Width, bounds.Height);
                        pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point1);
                        editTransaction.Update();
                        designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect);
                        pathElement.RenderTransform = transform2;
                    }
                }
                editTransaction.Commit();
            }
            return(pathElement);
        }
        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();
                    }
                }
            }
        }
Example #5
0
        private void SetLightTypeOnSelection(Type lightType)
        {
            if (this.selectedLights.Count == 0 || this.lightType != null && this.lightType.Equals((object)lightType))
            {
                return;
            }
            this.lightType = (object)lightType;
            SceneViewModel           viewModel                     = this.selectedLights[0].ViewModel;
            SceneElementSelectionSet elementSelectionSet           = viewModel.ElementSelectionSet;
            List <KeyValuePair <LightElement, LightElement> > list = new List <KeyValuePair <LightElement, LightElement> >();

            foreach (LightElement key in (IEnumerable <LightElement>)elementSelectionSet.GetFilteredSelection <LightElement>())
            {
                if (!(key.TargetType == lightType))
                {
                    LightElement lightElement = (LightElement)key.ViewModel.CreateSceneNode(lightType);
                    DocumentNode documentNode = (DocumentNode)null;
                    if (typeof(SpotLight).Equals(lightType))
                    {
                        DocumentNodePath valueAsDocumentNode = key.GetLocalValueAsDocumentNode(SpotLightElement.DirectionProperty);
                        documentNode = valueAsDocumentNode != null ? valueAsDocumentNode.Node : (DocumentNode)null;
                    }
                    else if (typeof(DirectionalLight).Equals(lightType))
                    {
                        DocumentNodePath valueAsDocumentNode = key.GetLocalValueAsDocumentNode(DirectionalLightElement.DirectionProperty);
                        documentNode = valueAsDocumentNode != null ? valueAsDocumentNode.Node : (DocumentNode)null;
                    }
                    if (typeof(DirectionalLight).Equals(lightType))
                    {
                        if (documentNode != null)
                        {
                            lightElement.SetValue(DirectionalLightElement.DirectionProperty, (object)documentNode);
                        }
                    }
                    else if (typeof(PointLightBase).IsAssignableFrom(lightType))
                    {
                        if (!typeof(PointLightBase).IsAssignableFrom(key.TargetType))
                        {
                            lightElement.SetValue(LightElement.PositionProperty, (object)new Point3D(0.0, 0.0, 0.0));
                            lightElement.SetValue(LightElement.RangeProperty, (object)10.0);
                            lightElement.SetValue(LightElement.ConstantAttenuationProperty, (object)1.0);
                            lightElement.SetValue(LightElement.LinearAttenuationProperty, (object)0.0);
                            lightElement.SetValue(LightElement.QuadraticAttenuationProperty, (object)0.0);
                        }
                        if (typeof(SpotLight).Equals(lightType))
                        {
                            if (documentNode != null)
                            {
                                lightElement.SetValue(SpotLightElement.DirectionProperty, (object)documentNode);
                            }
                            lightElement.SetValue(SpotLightElement.OuterConeAngleProperty, (object)40.0);
                            lightElement.SetValue(SpotLightElement.InnerConeAngleProperty, (object)30.0);
                        }
                    }
                    list.Add(new KeyValuePair <LightElement, LightElement>(key, lightElement));
                }
            }
            if (list.Count != 0)
            {
                using (SceneEditTransaction editTransaction = viewModel.Document.CreateEditTransaction(StringTable.UndoUnitChangeLightType))
                {
                    foreach (KeyValuePair <LightElement, LightElement> keyValuePair in list)
                    {
                        LightElement key          = keyValuePair.Key;
                        LightElement lightElement = keyValuePair.Value;
                        viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)key);
                        Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)key);
                        elementSelectionSet.RemoveSelection((SceneElement)key);
                        SceneElement parentElement = key.ParentElement;
                        ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)parentElement.GetPropertyForChild((SceneNode)key));
                        int index = collectionForProperty.IndexOf((SceneNode)key);
                        collectionForProperty[index] = (SceneNode)lightElement;
                        SceneElementHelper.ApplyProperties((SceneNode)lightElement, properties);
                        elementSelectionSet.ExtendSelection((SceneElement)lightElement);
                    }
                    editTransaction.Commit();
                }
            }
            this.OnPropertyChanged("IsAmbientLight");
            this.OnPropertyChanged("IsPointLight");
            this.OnPropertyChanged("IsDirectionalLight");
            this.OnPropertyChanged("IsSpotLight");
        }
Example #6
0
        public virtual void PostProcessing(SceneNode oldElement, SceneNode newElement, DocumentCompositeNode styleNode)
        {
            SceneViewModel viewModel = newElement.ViewModel;

            if (!PlatformTypes.TextBox.IsAssignableFrom((ITypeId)newElement.Type) && !PlatformTypes.ContentControl.IsAssignableFrom((ITypeId)newElement.Type))
            {
                return;
            }
            StyleNode    styleElement;
            DocumentNode templateNode = MakeControlCommand.GetTemplateNode(newElement, styleNode, out styleElement);

            if (templateNode == null)
            {
                return;
            }
            DocumentCompositeNode documentCompositeNode1 = templateNode.FindFirst(new Predicate <DocumentNode>(this.SelectTextBlockPredicate)) as DocumentCompositeNode;

            if (documentCompositeNode1 == null)
            {
                return;
            }
            TextBlockElement      textBlockSceneNode     = styleElement.ViewModel.GetSceneNode((DocumentNode)documentCompositeNode1) as TextBlockElement;
            TextBoxElement        textBoxElement         = newElement as TextBoxElement;
            ContentControlElement contentControlElement1 = newElement as ContentControlElement;

            using (SceneEditTransaction editTransaction = styleElement.ViewModel.CreateEditTransaction(this.UndoString))
            {
                DocumentCompositeNode documentCompositeNode2 = templateNode.FindFirst(new Predicate <DocumentNode>(this.SelectContentPresenterPredicate)) as DocumentCompositeNode;
                if (textBoxElement != null)
                {
                    Dictionary <IPropertyId, IPropertyId> properties = new Dictionary <IPropertyId, IPropertyId>()
                    {
                        {
                            TextBlockElement.FontFamilyProperty,
                            ControlElement.FontFamilyProperty
                        },
                        {
                            TextBlockElement.FontWeightProperty,
                            ControlElement.FontWeightProperty
                        },
                        {
                            TextBlockElement.FontSizeProperty,
                            ControlElement.FontSizeProperty
                        },
                        {
                            TextBlockElement.FontStyleProperty,
                            ControlElement.FontStyleProperty
                        },
                        {
                            TextBlockElement.TextAlignmentProperty,
                            TextBoxElement.TextAlignmentProperty
                        },
                        {
                            TextBlockElement.PaddingProperty,
                            ControlElement.PaddingProperty
                        }
                    };
                    if (viewModel.ProjectContext.ResolveProperty(TextBoxElement.TextDecorationsProperty) != null && viewModel.ProjectContext.ResolveProperty(TextBlockElement.TextDecorationsProperty) != null)
                    {
                        properties.Add(TextBlockElement.TextDecorationsProperty, TextBoxElement.TextDecorationsProperty);
                    }
                    this.SetTextPropertiesOnStyle(viewModel, styleElement, textBlockSceneNode, properties);
                    ContentControlElement contentControlElement2 = (ContentControlElement)styleElement.ViewModel.CreateSceneNode(PlatformTypes.ScrollViewer);
                    if (viewModel.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                    {
                        contentControlElement2.Name = "PART_ContentHost";
                        DocumentNode documentNode = (DocumentNode)DocumentNodeUtilities.NewTemplateBindingNode((DocumentNode)documentCompositeNode1, Base2DElement.SnapsToDevicePixelsProperty);
                        contentControlElement2.SetValue(Base2DElement.SnapsToDevicePixelsProperty, (object)documentNode);
                    }
                    else
                    {
                        contentControlElement2.Name = "ContentElement";
                        DocumentNode documentNode = (DocumentNode)DocumentNodeUtilities.NewTemplateBindingNode((DocumentNode)documentCompositeNode1, ControlElement.PaddingProperty);
                        contentControlElement2.SetValue(ControlElement.PaddingProperty, (object)documentNode);
                        contentControlElement2.SetLocalValueAsWpf(ControlElement.BorderThicknessProperty, (object)new Thickness(0.0));
                        contentControlElement2.SetLocalValue(ControlElement.IsTabStopProperty, (object)false);
                    }
                    textBoxElement.SetValue(TextBoxElement.TextProperty, textBlockSceneNode.GetLocalOrDefaultValue(TextBlockElement.TextProperty));
                    if (PlatformTypes.TextBox.IsAssignableFrom((ITypeId)newElement.Type) && PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)oldElement.Type))
                    {
                        this.TransferLayoutProperties(MakeControlCommand.RenderTransformsProperties, (BaseFrameworkElement)textBlockSceneNode, (SceneElement)textBoxElement);
                        bool addRenderTransforms = true;
                        this.ClearLayoutProperties(this.GetLayoutProperties((SceneElement)textBlockSceneNode, addRenderTransforms), (SceneElement)contentControlElement2);
                    }
                    else
                    {
                        bool addRenderTransforms = true;
                        this.TransferLayoutProperties(this.GetLayoutProperties((SceneElement)textBlockSceneNode, addRenderTransforms), (BaseFrameworkElement)textBlockSceneNode, (SceneElement)contentControlElement2);
                    }
                    SceneNode parent           = textBlockSceneNode.Parent;
                    IProperty propertyForChild = parent.GetPropertyForChild((SceneNode)textBlockSceneNode);
                    ISceneNodeCollection <SceneNode> collectionForProperty = parent.GetCollectionForProperty((IPropertyId)propertyForChild);
                    int index = collectionForProperty.IndexOf((SceneNode)textBlockSceneNode);
                    collectionForProperty[index] = (SceneNode)contentControlElement2;
                    if (documentCompositeNode2 != null)
                    {
                        (styleElement.ViewModel.GetSceneNode((DocumentNode)documentCompositeNode2) as ContentPresenterElement).Remove();
                    }
                }
                else
                {
                    Dictionary <IPropertyId, IPropertyId> properties = new Dictionary <IPropertyId, IPropertyId>()
                    {
                        {
                            TextBlockElement.FontFamilyProperty,
                            ControlElement.FontFamilyProperty
                        },
                        {
                            TextBlockElement.FontWeightProperty,
                            ControlElement.FontWeightProperty
                        },
                        {
                            TextBlockElement.FontSizeProperty,
                            ControlElement.FontSizeProperty
                        },
                        {
                            TextBlockElement.FontStyleProperty,
                            ControlElement.FontStyleProperty
                        }
                    };
                    this.SetTextPropertiesOnStyle(viewModel, styleElement, textBlockSceneNode, properties);
                    contentControlElement1.SetValue((IPropertyId)contentControlElement1.DefaultContentProperty, textBlockSceneNode.GetLocalOrDefaultValue(TextBlockElement.TextProperty));
                    if (documentCompositeNode2 != null)
                    {
                        ContentPresenterElement presenterElement = (ContentPresenterElement)styleElement.ViewModel.GetSceneNode((DocumentNode)documentCompositeNode2);
                        if (PlatformTypes.ContentControl.IsAssignableFrom((ITypeId)newElement.Type) && PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)oldElement.Type))
                        {
                            this.TransferLayoutProperties(MakeControlCommand.RenderTransformsProperties, (BaseFrameworkElement)textBlockSceneNode, (SceneElement)newElement);
                            bool addRenderTransforms = true;
                            this.ClearLayoutProperties(this.GetLayoutProperties((SceneElement)textBlockSceneNode, addRenderTransforms), (SceneElement)presenterElement);
                        }
                        else
                        {
                            bool addRenderTransforms = true;
                            this.TransferLayoutProperties(this.GetLayoutProperties((SceneElement)textBlockSceneNode, addRenderTransforms), (BaseFrameworkElement)textBlockSceneNode, (SceneElement)presenterElement);
                        }
                    }
                    textBlockSceneNode.Remove();
                }
                if (textBlockSceneNode.IsSet(TextBlockElement.ForegroundProperty) == PropertyState.Set)
                {
                    styleElement.SetValue(ControlElement.ForegroundProperty, textBlockSceneNode.GetLocalValue(TextBlockElement.ForegroundProperty));
                }
                editTransaction.Commit();
            }
        }
Example #7
0
        public override void Execute()
        {
            BaseFrameworkElement selectedElement = this.SelectedElement;

            if (selectedElement == null)
            {
                return;
            }
            IType type1 = this.SceneViewModel.ProjectContext.ResolveType(PlatformTypes.Style);

            CreateResourceModel.ContextFlags contextFlags = this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles) ? CreateResourceModel.ContextFlags.CanApplyAutomatically : CreateResourceModel.ContextFlags.None;
            if (this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles))
            {
                contextFlags = CreateResourceModel.ContextFlags.CanApplyAutomatically;
            }
            CreateResourceModel createResourceModel = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, type1.RuntimeType, this.DefaultContainerType.RuntimeType, PlatformTypes.Style.Name, (SceneElement)null, (SceneNode)selectedElement, contextFlags);

            if (this.ShowUI)
            {
                bool?nullable = this.CreateDialog(createResourceModel).ShowDialog();
                if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                {
                    return;
                }
            }
            using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
            {
                using (SceneEditTransaction editTransaction1 = this.SceneViewModel.CreateEditTransaction(this.UndoString, false))
                {
                    using (this.SceneViewModel.ForceBaseValue())
                    {
                        using (this.SceneViewModel.DisableDrawIntoState())
                        {
                            this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)selectedElement);
                            this.SceneViewModel.ElementSelectionSet.Clear();
                            IDocumentContext documentContext = this.SceneViewModel.Document.DocumentContext;
                            IProjectContext  projectContext  = this.SceneViewModel.Document.ProjectContext;
                            Type             type2           = (Type)null;
                            if (createResourceModel.TargetTypeAsset != null && createResourceModel.TargetTypeAsset.EnsureTypeReferenced(this.SceneViewModel.ProjectContext as ProjectContext))
                            {
                                type2 = createResourceModel.TargetTypeAsset.Type.RuntimeType;
                            }
                            if (type2 == (Type)null)
                            {
                                type2 = createResourceModel.TargetType;
                            }
                            IType type3 = projectContext.GetType(type2);
                            DocumentCompositeNode documentCompositeNode1 = (DocumentCompositeNode)selectedElement.DocumentNode;
                            this.SceneViewModel.GetLayoutDesignerForChild((SceneElement)selectedElement, true).ClearUnusedLayoutProperties(selectedElement);
                            DocumentCompositeNode visualTreeNode            = documentContext.CreateNode((ITypeId)documentCompositeNode1.Type);
                            Dictionary <IProperty, DocumentNode> dictionary = new Dictionary <IProperty, DocumentNode>();
                            bool addRenderTransforms = false;
                            foreach (IPropertyId propertyId in this.GetLayoutProperties((SceneElement)selectedElement, addRenderTransforms))
                            {
                                IProperty property = this.DesignerContext.ActiveSceneViewModel.ProjectContext.ResolveProperty(propertyId);
                                if (property != null && documentCompositeNode1.Properties.Contains(property))
                                {
                                    dictionary.Add(property, documentCompositeNode1.Properties[(IPropertyId)property].Clone(documentContext));
                                    documentCompositeNode1.ClearValue((IPropertyId)property);
                                }
                            }
                            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode1.Properties)
                            {
                                IPropertyId index = (IPropertyId)keyValuePair.Key;
                                DependencyPropertyReferenceStep propertyReferenceStep = index as DependencyPropertyReferenceStep;
                                if ((propertyReferenceStep == null || !propertyReferenceStep.IsAttachable || propertyReferenceStep.MemberType == MemberType.DesignTimeProperty) && (!index.Equals((object)BaseFrameworkElement.WidthProperty) && !index.Equals((object)BaseFrameworkElement.HeightProperty)))
                                {
                                    visualTreeNode.Properties[index] = keyValuePair.Value.Clone(documentContext);
                                }
                            }
                            if (documentCompositeNode1.SupportsChildren)
                            {
                                foreach (DocumentNode documentNode in (IEnumerable <DocumentNode>)documentCompositeNode1.Children)
                                {
                                    visualTreeNode.Children.Add(documentNode.Clone(documentContext));
                                }
                            }
                            if (!PlatformTypes.Panel.IsAssignableFrom((ITypeId)documentCompositeNode1.Type))
                            {
                                GridElement gridElement = (GridElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Grid);
                                SceneNode   sceneNode   = this.SceneViewModel.GetSceneNode((DocumentNode)visualTreeNode);
                                gridElement.Children.Add(sceneNode);
                                visualTreeNode = (DocumentCompositeNode)gridElement.DocumentNode;
                            }
                            StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Style);
                            styleNode.StyleTargetTypeId = type3;
                            SetterSceneNode setterSceneNode = (SetterSceneNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Setter);
                            DependencyPropertyReferenceStep propertyReferenceStep1 = (DependencyPropertyReferenceStep)this.SceneViewModel.ProjectContext.ResolveProperty(ControlElement.TemplateProperty);
                            setterSceneNode.Property = propertyReferenceStep1;
                            BaseFrameworkElement  frameworkElement       = (BaseFrameworkElement)this.SceneViewModel.CreateSceneNode(type2);
                            DocumentCompositeNode documentCompositeNode2 = (DocumentCompositeNode)frameworkElement.DocumentNode;
                            this.AddPresenterIfNecessary(visualTreeNode, (SceneElement)frameworkElement);
                            ControlTemplateElement controlTemplateElement = (ControlTemplateElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.ControlTemplate);
                            controlTemplateElement.ControlTemplateTargetTypeId = (ITypeId)type3;
                            controlTemplateElement.DefaultInsertionPoint.Insert(this.SceneViewModel.GetSceneNode((DocumentNode)visualTreeNode));
                            if (PlatformTypes.Button.Equals((object)type3) && controlTemplateElement.CanEditTriggers && this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                            {
                                DocumentCompositeNode node = documentContext.CreateNode(typeof(TriggerCollection));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsFocusedProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsDefaultedProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, BaseFrameworkElement.IsMouseOverProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsPressedProperty, (object)true));
                                node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, BaseFrameworkElement.IsEnabledProperty, (object)false));
                                controlTemplateElement.SetLocalValue(ControlTemplateElement.ControlTemplateTriggersProperty, (DocumentNode)node);
                            }
                            setterSceneNode.SetValueAsSceneNode(SetterSceneNode.ValueProperty, (SceneNode)controlTemplateElement);
                            styleNode.Setters.Add((SceneNode)setterSceneNode);
                            bool useStaticResource = !JoltHelper.TypeSupported((ITypeResolver)this.SceneViewModel.ProjectContext, PlatformTypes.DynamicResource);
                            int  index1            = -1;
                            if (useStaticResource && selectedElement.DocumentContext == createResourceModel.CurrentResourceSite.DocumentContext)
                            {
                                index1 = createResourceModel.IndexInResourceSite(selectedElement.DocumentNode);
                            }
                            IList <DocumentCompositeNode> referencedResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources((DocumentNode)documentCompositeNode1);
                            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in dictionary)
                            {
                                documentCompositeNode2.Properties[(IPropertyId)keyValuePair.Key] = keyValuePair.Value;
                            }
                            IList <SceneNode> nodes = (IList <SceneNode>) new List <SceneNode>();
                            nodes.Add((SceneNode)frameworkElement);
                            SceneNode parent           = selectedElement.Parent;
                            IProperty propertyForChild = parent.GetPropertyForChild((SceneNode)selectedElement);
                            ISceneNodeCollection <SceneNode> collectionForProperty = parent.GetCollectionForProperty((IPropertyId)propertyForChild);
                            int index2 = collectionForProperty.IndexOf((SceneNode)selectedElement);
                            collectionForProperty[index2] = (SceneNode)frameworkElement;
                            if (createResourceModel.SelectedResourceDictionary != null)
                            {
                                ResourceContainer instance = createResourceModel.SelectedResourceDictionary.Instance;
                                if (instance != null && instance.DocumentNode == documentCompositeNode1)
                                {
                                    createResourceModel = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, type1.RuntimeType, type2, PlatformTypes.Style.Name, (SceneElement)frameworkElement, (SceneNode)null, contextFlags);
                                }
                            }
                            if (createResourceModel.CurrentResourceSite != null && !PlatformTypes.PlatformsCompatible(createResourceModel.CurrentResourceSite.DocumentContext.TypeResolver.PlatformMetadata, styleNode.DocumentNode.PlatformMetadata))
                            {
                                editTransaction1.Cancel();
                                return;
                            }
                            DocumentCompositeNode resource = createResourceModel.CreateResource(styleNode.DocumentNode, StyleNode.TargetTypeProperty, index1);
                            if (resource == null)
                            {
                                editTransaction1.Cancel();
                                return;
                            }
                            DocumentNode            resourceReference = createResourceModel.CreateResourceReference(this.SceneViewModel.Document.DocumentContext, resource, useStaticResource);
                            DefaultTypeInstantiator typeInstantiator  = new DefaultTypeInstantiator(this.SceneView);
                            if (resourceReference != null)
                            {
                                documentCompositeNode2.Properties[BaseFrameworkElement.StyleProperty] = resourceReference;
                            }
                            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode1.Properties)
                            {
                                IPropertyId index3 = (IPropertyId)keyValuePair.Key;
                                DependencyPropertyReferenceStep propertyReferenceStep2 = index3 as DependencyPropertyReferenceStep;
                                if (propertyReferenceStep2 != null && propertyReferenceStep2.IsAttachable && propertyReferenceStep2.MemberType != MemberType.DesignTimeProperty)
                                {
                                    documentCompositeNode2.Properties[index3] = keyValuePair.Value.Clone(documentContext);
                                }
                            }
                            DocumentCompositeNode hostNode  = createResourceModel.CurrentResourceSite.HostNode;
                            SceneViewModel        viewModel = this.SceneViewModel.GetViewModel(hostNode.DocumentRoot, false);
                            using (SceneEditTransaction editTransaction2 = viewModel.CreateEditTransaction(this.UndoString))
                            {
                                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CopyResourcesToNewResourceSite(referencedResources, viewModel, hostNode, resource, createResourceModel.IndexInResourceSite((DocumentNode)resource));
                                editTransaction2.Commit();
                            }
                            editTransaction1.Update();
                            if (this.SceneView.IsValid)
                            {
                                typeInstantiator.ApplyAfterInsertionDefaultsToElements(nodes, (SceneNode)null);
                            }
                            this.SceneView.CandidateEditingContainer = frameworkElement.DocumentNodePath;
                            editTransaction1.Update();
                            this.SceneViewModel.ElementSelectionSet.ExtendSelection((SceneElement)frameworkElement);
                            this.PostProcessing((SceneNode)selectedElement, (SceneNode)frameworkElement, resource);
                            if (frameworkElement.GetComputedValue(ControlElement.TemplateProperty) != null)
                            {
                                this.ActivateTemplateEditingMode((SceneElement)frameworkElement);
                            }
                            else
                            {
                                UIThreadDispatcherHelper.BeginInvoke(DispatcherPriority.ApplicationIdle, (Delegate) new Action <SceneElement>(this.ActivateTemplateEditingMode), (object)frameworkElement);
                            }
                            this.SceneView.CandidateEditingContainer = (DocumentNodePath)null;
                        }
                        editTransaction1.Commit();
                    }
                }
            }
        }
        private void Rebuild()
        {
            if (this.TriggerNodeView == null)
            {
                return;
            }
            int currentPosition = this.TriggerNodeView.CurrentPosition;

            this.ClearTriggerPropertiesList();
            ISceneNodeCollection <SceneNode> collectionForProperty = this.behaviorNode.GetCollectionForProperty(BehaviorHelper.BehaviorTriggersProperty);

            foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)collectionForProperty)
            {
                BehaviorTriggerBaseNode behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)sceneNode;
                foreach (BehaviorTriggerActionNode triggerActionNode in (IEnumerable <SceneNode>)behaviorTriggerBaseNode.Actions)
                {
                    InvokeCommandActionNode commandActionNode = triggerActionNode as InvokeCommandActionNode;
                    if (commandActionNode != null && commandActionNode.IsAttached && string.Compare(commandActionNode.CommandName, this.CategoryName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        PropertyReference propertyReference = new PropertyReference(new List <ReferenceStep>()
                        {
                            this.behaviorNode.GetPropertyForChild((SceneNode)behaviorTriggerBaseNode) as ReferenceStep,
                            (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)sceneNode.ProjectContext, ProjectNeutralTypes.BehaviorTriggerCollection, collectionForProperty.IndexOf((SceneNode)behaviorTriggerBaseNode))
                        });
                        if (!Enumerable.Any <PropertyEntry>((IEnumerable <PropertyEntry>) this.TriggerNodes, (Func <PropertyEntry, bool>)(existingProperty => ((PropertyReferenceProperty)existingProperty).Reference.Equals((object)propertyReference))))
                        {
                            this.TriggerNodes.Add((PropertyEntry)this.CreateProperty(propertyReference));
                        }
                    }
                }
            }
            if (currentPosition >= this.TriggerNodes.Count)
            {
                return;
            }
            this.TriggerNodeView.MoveCurrentToPosition(currentPosition);
        }
        private PropertyEntry CreatePropertyEntryForCondition(SceneNode condition)
        {
            List <ReferenceStep> steps     = new List <ReferenceStep>();
            IProperty            property1 = condition.ProjectContext.ResolveProperty(BehaviorHelper.BehaviorsProperty);

            steps.Add(property1 as ReferenceStep);
            ISceneNodeCollection <SceneNode> collectionForProperty = this.behaviorTriggerBaseNode.GetCollectionForProperty(BehaviorHelper.BehaviorsProperty);

            steps.Add((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)condition.ProjectContext, ProjectNeutralTypes.BehaviorCollection, collectionForProperty.IndexOf((SceneNode)this.conditionBehaviorNode)));
            IProperty property2 = condition.ProjectContext.ResolveProperty(ConditionBehaviorNode.ConditionProperty);

            steps.Add(property2 as ReferenceStep);
            IProperty property3 = condition.ProjectContext.ResolveProperty(ConditionalExpressionNode.ConditionsProperty);

            steps.Add(property3 as ReferenceStep);
            steps.Add((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)condition.ProjectContext, ProjectNeutralTypes.ConditionCollection, this.conditions.IndexOf(condition)));
            return((PropertyEntry)this.objectSet.CreateProperty(new PropertyReference(steps), (AttributeCollection)null));
        }
Example #10
0
        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);
                }
            }
        }
        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);
                    }
                }
            }
        }
Example #12
0
 public override void Execute()
 {
     using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.undoDescription))
     {
         this.ConvertSelectedElementsToPathIfNecessary();
         editTransaction.Update();
         this.SceneViewModel.DefaultView.UpdateLayout();
         SceneElementSelectionSet      elementSelectionSet   = this.SceneViewModel.ElementSelectionSet;
         SceneElement                  primarySelection      = elementSelectionSet.PrimarySelection;
         System.Windows.Media.Geometry renderedGeometryAsWpf = this.SceneView.GetRenderedGeometryAsWpf(primarySelection);
         if (renderedGeometryAsWpf == null)
         {
             return;
         }
         this.Initialize(renderedGeometryAsWpf);
         SceneElementCollection elementCollection = new SceneElementCollection();
         foreach (SceneElement shapeElement in elementSelectionSet.Selection)
         {
             if (shapeElement != primarySelection)
             {
                 elementCollection.Add(shapeElement);
                 System.Windows.Media.Geometry secondaryGeometry = this.SceneView.GetRenderedGeometryAsWpf(shapeElement);
                 if (secondaryGeometry == null)
                 {
                     return;
                 }
                 Matrix transformToElement = shapeElement.GetComputedTransformToElement(primarySelection);
                 if (!transformToElement.IsIdentity)
                 {
                     MatrixTransform matrixTransform = new MatrixTransform(transformToElement);
                     matrixTransform.Freeze();
                     GeometryGroup geometryGroup = new GeometryGroup();
                     geometryGroup.Children.Add(secondaryGeometry);
                     geometryGroup.Transform = (Transform)matrixTransform;
                     secondaryGeometry       = (System.Windows.Media.Geometry)geometryGroup;
                 }
                 this.Combine(secondaryGeometry);
             }
         }
         PathGeometry result = this.GetResult();
         BooleanCommand.CleanUpPathGeometry(ref result);
         PathGeometry pathGeometry = PathConversionHelper.RemoveDegeneratePoints((System.Windows.Media.Geometry)result);
         elementSelectionSet.Clear();
         PathGeometryUtilities.CollapseSingleSegmentsToPolySegments(pathGeometry);
         PathElement pathElement = (PathElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Path);
         Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null;
         using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
         {
             this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection);
             properties = SceneElementHelper.StoreProperties((SceneNode)primarySelection);
             ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer();
             int index = collectionContainer.IndexOf((SceneNode)primarySelection);
             collectionContainer[index] = (SceneNode)pathElement;
         }
         foreach (SceneElement element in elementCollection)
         {
             this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
             element.Remove();
         }
         using (this.SceneViewModel.ForceBaseValue())
         {
             if (properties != null)
             {
                 SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties);
             }
             pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill);
             PathCommandHelper.ReplacePathGeometry(pathElement, pathGeometry, editTransaction);
         }
         elementSelectionSet.SetSelection((SceneElement)pathElement);
         editTransaction.Commit();
     }
 }