Example #1
0
 protected override DocumentNodePath ProvideEditingContainer(SceneElement targetElement, PropertyReference targetProperty, DocumentNode resourceNode)
 {
     if (this.UseStyle)
     {
         if (this.SceneView.IsEditable && targetElement.IsViewObjectValid && (this.SceneView.GetViewState((SceneNode)targetElement) & this.RequiredSelectionViewState) == this.RequiredSelectionViewState)
         {
             Type runtimeType = this.SceneViewModel.ProjectContext.ResolveType(PlatformTypes.FrameworkTemplate).RuntimeType;
             return(this.SceneView.GetCorrespondingNodePath(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(targetElement.GetComputedValue((IPropertyId)this.ProvideTemplateProperty(SingleTargetCommandBase.GetTypeOfElement(targetElement)))), true));
         }
         SceneNode sceneNode = targetElement.GetLocalValueAsSceneNode(targetProperty);
         if (sceneNode == null && resourceNode != null && resourceNode.IsInDocument)
         {
             SceneViewModel viewModel = SceneViewModel.GetViewModel(this.ViewHost, resourceNode.DocumentRoot, false);
             if (viewModel != null)
             {
                 sceneNode = viewModel.GetSceneNode(resourceNode);
             }
         }
         if (sceneNode != null)
         {
             return(sceneNode.GetLocalValueAsDocumentNode((IPropertyId)this.ProvideTemplateProperty(SingleTargetCommandBase.GetTypeOfElement(targetElement))));
         }
     }
     return(targetElement.GetLocalValueAsDocumentNode(targetProperty));
 }
Example #2
0
        private void UpdateAmbientValueFromSceneElement(SceneElement element, PropertyReference propertyReference)
        {
            bool strictTypeCheck = true;
            PropertyReference propertyReference1 = SceneNodeObjectSet.FilterProperty((SceneNode)element, propertyReference, strictTypeCheck);

            if (!element.IsViewObjectValid || propertyReference1 == null || propertyReference1.PlatformMetadata != element.Platform.Metadata)
            {
                return;
            }
            AmbientPropertyManager.AmbientPropertyValue ambientPropertyValue = this.GetAmbientPropertyValue(propertyReference1.FirstStep);
            if (ambientPropertyValue == null)
            {
                return;
            }
            using (element.ViewModel.ForceBaseValue())
            {
                if (element.IsSet(propertyReference1) == PropertyState.Unset)
                {
                    ambientPropertyValue.Value = null;
                }
                else
                {
                    DocumentNodePath valueAsDocumentNode = element.GetLocalValueAsDocumentNode(propertyReference1);
                    if (!this.HasValidValue(element.ViewModel, valueAsDocumentNode))
                    {
                        return;
                    }
                    ambientPropertyValue.Value = valueAsDocumentNode.Node;
                }
            }
        }
Example #3
0
        protected override DocumentNodePath ProvideEditingContainer(SceneElement targetElement, PropertyReference targetProperty, DocumentNode resourceNode)
        {
            SceneViewModel   viewModel        = targetElement.ViewModel.GetViewModel(resourceNode.DocumentRoot, false);
            DocumentNodePath documentNodePath = targetElement.GetLocalValueAsDocumentNode(targetProperty) ?? new DocumentNodePath(resourceNode.DocumentRoot.RootNode, resourceNode);
            DocumentNode     documentNode     = (viewModel.GetSceneNode(resourceNode) as StyleNode).GetLocalValueAsSceneNode(ControlElement.TemplateProperty).DocumentNode;

            return(documentNodePath.GetPathInContainer((DocumentNode)documentNode.Parent).GetPathInSubContainer(documentNode.SitePropertyKey, documentNode));
        }
        public static DocumentNodePath ProvideStyleOrTemplateNodePath(SceneElement targetElement, PropertyReference targetPropertyReference)
        {
            DocumentNodePath documentNodePath = (DocumentNodePath)null;
            ReferenceStep    targetProperty   = targetPropertyReference[0];
            StyleNode        styleNode        = targetElement as StyleNode;

            if (targetPropertyReference.TargetType.IsAssignableFrom(targetElement.TargetType) || styleNode != null && targetPropertyReference.TargetType.IsAssignableFrom(styleNode.StyleTargetType))
            {
                IViewObjectFactory viewObjectFactory = targetElement.Platform.ViewObjectFactory;
                object             computedValue     = targetElement.GetComputedValue(targetPropertyReference);
                DocumentNodePath   valuePath         = (DocumentNodePath)null;
                if (computedValue != null)
                {
                    IViewObject instance = viewObjectFactory.Instantiate(computedValue);
                    valuePath = targetElement.ViewModel.DefaultView.GetCorrespondingNodePath(instance, true);
                }
                if (valuePath == null && !BaseFrameworkElement.StyleProperty.Equals((object)targetProperty))
                {
                    BaseFrameworkElement frameworkElement = targetElement as BaseFrameworkElement;
                    if (frameworkElement != null)
                    {
                        frameworkElement.FindMissingImplicitStyle();
                    }
                    if (computedValue != null)
                    {
                        IViewObject      instance = viewObjectFactory.Instantiate(computedValue);
                        DocumentNodePath correspondingNodePath = targetElement.ViewModel.DefaultView.GetCorrespondingNodePath(instance, true);
                        if (correspondingNodePath != null)
                        {
                            valuePath = ControlStylingOperations.FindTemplateWithinStyle(correspondingNodePath, targetElement, (IPropertyId)targetProperty, (IPropertyId)targetProperty);
                        }
                    }
                }
                if (ControlStylingOperations.ShouldSetEditingContextToNodePath(valuePath, targetElement, targetProperty))
                {
                    documentNodePath = valuePath;
                }
            }
            if (documentNodePath == null && styleNode != null && targetElement.IsSet(targetPropertyReference) == PropertyState.Set)
            {
                DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference);
                if (ControlStylingOperations.ShouldSetEditingContextToNodePath(valueAsDocumentNode, targetElement, targetProperty))
                {
                    documentNodePath = valueAsDocumentNode;
                }
            }
            return(documentNodePath);
        }
Example #5
0
        public bool IsSynchronizedWithArtboard()
        {
            bool isMixed;

            this.BasisProperty.GetLocalValueAsDocumentNode(true, out isMixed);
            if (isMixed)
            {
                return(false);
            }
            SceneElement primarySelection = this.BasisProperty.SceneNodeObjectSet.DesignerContext.ActiveView.ElementSelectionSet.PrimarySelection;

            if (primarySelection == null || this.BasisProperty.Reference.PlatformMetadata != primarySelection.ProjectContext.PlatformMetadata)
            {
                return(false);
            }
            DocumentNodePath valueAsDocumentNode = primarySelection.GetLocalValueAsDocumentNode(this.BasisProperty.Reference);

            if (valueAsDocumentNode != null)
            {
                return(this.BasisProperty.SceneNodeObjectSet.DesignerContext.GradientToolSelectionService.AdornedBrush == valueAsDocumentNode.Node);
            }
            return(false);
        }
Example #6
0
        public static bool ShouldApplyRectangleGeometryAdornerTo(SceneElement adornedElement)
        {
            DocumentNodePath valueAsDocumentNode = adornedElement.GetLocalValueAsDocumentNode(Base2DElement.ClipProperty);

            return(valueAsDocumentNode != null && valueAsDocumentNode.Node != null && PlatformTypes.RectangleGeometry.IsAssignableFrom((ITypeId)valueAsDocumentNode.Node.Type));
        }
Example #7
0
        public override void Execute()
        {
            SceneElement targetElement = this.TargetElement;

            if (targetElement is StyleNode)
            {
                this.useStyle = new bool?(false);
            }
            else
            {
                IList <DocumentCompositeNode> auxillaryResources1;
                DocumentNode documentNode1 = this.ProvideCurrentStyle(targetElement, this.Type, new PropertyReference((ReferenceStep)targetElement.ProjectContext.ResolveProperty(BaseFrameworkElement.StyleProperty)), false, out auxillaryResources1);
                IList <DocumentCompositeNode> auxillaryResources2;
                DocumentNode other = this.ProvideCurrentTemplate(targetElement, new PropertyReference(this.ActiveTemplateProperty), out auxillaryResources2);
                bool         flag  = false;
                if ((other == null || other.DocumentRoot == null) && documentNode1 != null)
                {
                    using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitEditCopyStyle, true))
                    {
                        if (auxillaryResources1 != null && auxillaryResources1.Count > 0)
                        {
                            ResourceSite resourceSite = new ResourceSite(targetElement.DocumentNode);
                            resourceSite.EnsureResourceCollection();
                            foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources1)
                            {
                                DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(entryNode);
                                DocumentNode documentNode2    = entryNode.Properties[DictionaryEntryNode.ValueProperty];
                                if (resourceEntryKey != null && documentNode2 != null)
                                {
                                    DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.DictionaryEntry);
                                    dictionaryEntryNode.KeyNode = this.SceneViewModel.GetSceneNode(resourceEntryKey.Clone(this.SceneViewModel.Document.DocumentContext));
                                    dictionaryEntryNode.Value   = this.SceneViewModel.GetSceneNode(documentNode2.Clone(this.SceneViewModel.Document.DocumentContext));
                                    resourceSite.ResourcesDictionary.Children.Add(dictionaryEntryNode.DocumentNode);
                                }
                            }
                        }
                        documentNode1 = documentNode1.Clone(this.SceneViewModel.Document.DocumentContext);
                        DocumentCompositeNode documentCompositeNode = documentNode1 as DocumentCompositeNode;
                        if (documentCompositeNode != null && documentCompositeNode.NameProperty != null && documentCompositeNode.Properties.Contains(documentCompositeNode.NameProperty))
                        {
                            documentCompositeNode.ClearValue((IPropertyId)documentCompositeNode.NameProperty);
                        }
                        targetElement.SetValue(this.TargetPropertyReference, (object)documentNode1);
                        DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(this.TargetPropertyReference);
                        documentNode1 = valueAsDocumentNode != null ? valueAsDocumentNode.Node : (DocumentNode)null;
                        editTransaction.Update();
                        object computedValue = targetElement.GetComputedValue(new PropertyReference(this.ActiveTemplateProperty));
                        if (computedValue != null)
                        {
                            DocumentNodePath correspondingNodePath = this.SceneView.GetCorrespondingNodePath(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(computedValue), true);
                            if (correspondingNodePath != null)
                            {
                                flag  = valueAsDocumentNode.IsAncestorOf(correspondingNodePath);
                                other = correspondingNodePath != null ? correspondingNodePath.Node : other;
                            }
                        }
                        editTransaction.Cancel();
                    }
                }
                this.useStyle = new bool?(flag || other != null && documentNode1 != null && documentNode1.IsAncestorOf(other));
            }
            base.Execute();
            this.useStyle = new bool?();
        }
        protected DocumentNode ProvideCurrentStyle(SceneElement targetElement, IType targetType, PropertyReference targetPropertyReference, bool allowDefaultStyle, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            DocumentNode currentStyle = (DocumentNode)null;
            bool         isThemeStyle = false;
            IType        targetType1  = targetType;

            if (!this.TargetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
            {
                IDocumentContext documentContext    = this.SceneViewModel.Document.DocumentContext;
                Type             propertyTargetType = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty);
                targetType1 = propertyTargetType == (Type)null ? (IType)null : this.SceneViewModel.ProjectContext.GetType(propertyTargetType);
            }
            if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set)
            {
                DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference);
                if (valueAsDocumentNode != null && valueAsDocumentNode.Node is DocumentCompositeNode && PlatformTypes.Style.IsAssignableFrom((ITypeId)valueAsDocumentNode.Node.Type) && (!StyleNode.IsDefaultValue(valueAsDocumentNode.Node) || allowDefaultStyle))
                {
                    StyleNode styleNode = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as StyleNode;
                    if (styleNode != null)
                    {
                        currentStyle       = styleNode.DocumentNode;
                        auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(valueAsDocumentNode.Node);
                    }
                }
            }
            if (currentStyle == null)
            {
                object obj = this.ResolveCurrentStyle(targetElement, targetPropertyReference, allowDefaultStyle);
                if (obj != null)
                {
                    DocumentNode correspondingDocumentNode = this.SceneView.GetCorrespondingDocumentNode(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(obj), true);
                    if (correspondingDocumentNode != null && PlatformTypes.Style.IsAssignableFrom((ITypeId)correspondingDocumentNode.Type))
                    {
                        currentStyle = correspondingDocumentNode;
                    }
                    else if (obj is Style)
                    {
                        StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(obj);
                        if (targetType1 != null)
                        {
                            styleNode.StyleTargetTypeId = targetType1;
                        }
                        currentStyle = styleNode.DocumentNode;
                    }
                }
                if (currentStyle != null && !allowDefaultStyle && StyleNode.IsDefaultValue(currentStyle))
                {
                    currentStyle = (DocumentNode)null;
                }
            }
            if (currentStyle == null)
            {
                object defaultStyleKey = this.GetDefaultStyleKey(targetElement, (ITypeId)targetType1, (IPropertyId)this.TargetProperty);
                if (defaultStyleKey != null)
                {
                    this.ResolveDefaultStyle(targetElement, defaultStyleKey, allowDefaultStyle, out currentStyle, out isThemeStyle, out auxillaryResources);
                }
            }
            if (currentStyle != null && !allowDefaultStyle)
            {
                List <DocumentCompositeNode> list = new List <DocumentCompositeNode>();
                DocumentCompositeNode        node = currentStyle as DocumentCompositeNode;
                IProperty property = this.SceneViewModel.ProjectContext.ResolveProperty(StyleNode.BasedOnProperty);
                while (node != null && property != null && (node.Type.Equals((object)PlatformTypes.Style) && node.Properties.Count == 2) && (node.Properties[(IPropertyId)property] != null && node.Properties[StyleNode.TargetTypeProperty] != null))
                {
                    node = node.Properties[StyleNode.BasedOnProperty] as DocumentCompositeNode;
                    if (node != null)
                    {
                        if (DocumentNodeUtilities.IsDynamicResource((DocumentNode)node) || DocumentNodeUtilities.IsStaticResource((DocumentNode)node))
                        {
                            DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                            if (resourceKey != null && auxillaryResources != null)
                            {
                                foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources)
                                {
                                    if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode)))
                                    {
                                        node = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                                        break;
                                    }
                                }
                            }
                        }
                        if (PlatformTypes.Style.IsAssignableFrom((ITypeId)node.Type))
                        {
                            currentStyle = (DocumentNode)node;
                            list.Add(node);
                        }
                    }
                }
                if (auxillaryResources != null)
                {
                    foreach (DocumentNode documentNode in list)
                    {
                        DocumentCompositeNode parent = documentNode.Parent;
                        if (parent != null && parent.Type.Equals((object)PlatformTypes.DictionaryEntry))
                        {
                            auxillaryResources.Remove(parent);
                        }
                    }
                }
                if (currentStyle != null && (list.Count > 0 || currentStyle.DocumentRoot != null))
                {
                    currentStyle = currentStyle.Clone(targetElement.DocumentContext);
                }
                if (auxillaryResources != null)
                {
                    for (int index = 0; index < auxillaryResources.Count; ++index)
                    {
                        if (auxillaryResources[index].DocumentRoot != null)
                        {
                            auxillaryResources[index] = (DocumentCompositeNode)auxillaryResources[index].Clone(targetElement.DocumentContext);
                        }
                    }
                }
                if (isThemeStyle)
                {
                    ReplaceStyleTemplateCommand.StripFormatting(currentStyle);
                    if (auxillaryResources != null)
                    {
                        for (int index = 0; index < auxillaryResources.Count; ++index)
                        {
                            ReplaceStyleTemplateCommand.StripFormatting((DocumentNode)auxillaryResources[index]);
                        }
                    }
                }
                DocumentCompositeNode documentCompositeNode = currentStyle as DocumentCompositeNode;
                if (documentCompositeNode != null && targetType1 != null)
                {
                    documentCompositeNode.Properties[StyleNode.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType1));
                }
                if (targetType1 != null)
                {
                    ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(currentStyle, auxillaryResources, targetType1);
                }
            }
            return(currentStyle);
        }
 protected virtual DocumentNodePath ProvideEditingContainer(SceneElement targetElement, PropertyReference targetProperty, DocumentNode resourceNode)
 {
     return(targetElement.GetLocalValueAsDocumentNode(targetProperty));
 }