Esempio n. 1
0
        public static IType GetStyleType(DocumentCompositeNode valueNode)
        {
            DocumentPrimitiveNode documentPrimitiveNode = valueNode.Properties[StyleNode.TargetTypeProperty] as DocumentPrimitiveNode;

            if (documentPrimitiveNode != null)
            {
                return(DocumentPrimitiveNode.GetValueAsType((DocumentNode)documentPrimitiveNode));
            }
            return((IType)null);
        }
Esempio n. 2
0
        public static IType GetDataTemplateType(DocumentCompositeNode dataTemplateNode)
        {
            IType     type     = (IType)null;
            IProperty property = dataTemplateNode.TypeResolver.ResolveProperty(DataTemplateElement.DataTypeProperty);

            if (property != null)
            {
                type = DocumentPrimitiveNode.GetValueAsType(dataTemplateNode.Properties[(IPropertyId)property]);
            }
            return(type);
        }
Esempio n. 3
0
        public static IType GetDataType(DocumentNode dataNode)
        {
            if (dataNode == null)
            {
                return((IType)null);
            }
            IType type1 = dataNode.Type;
            IType type2;

            if (dataNode is DocumentPrimitiveNode)
            {
                type2 = DocumentPrimitiveNode.GetValueAsType(dataNode) ?? dataNode.Type;
            }
            else
            {
                DocumentCompositeNode documentCompositeNode = (DocumentCompositeNode)dataNode;
                if (PlatformTypes.ObjectDataProvider.IsAssignableFrom((ITypeId)dataNode.Type))
                {
                    type2 = DataContextHelper.GetObjectDataProviderType(documentCompositeNode);
                }
                else if (PlatformTypes.CollectionViewSource.IsAssignableFrom((ITypeId)dataNode.Type))
                {
                    type2 = DataContextHelper.GetCollectionViewSourceType(documentCompositeNode);
                }
                else if (dataNode.Type.IsBinding)
                {
                    type2 = DataContextHelper.GetBindingType(documentCompositeNode);
                }
                else if (dataNode.Type.RuntimeType == typeof(DesignInstanceExtension))
                {
                    type2 = DataContextHelper.GetDesignInstanceType(documentCompositeNode);
                }
                else if (dataNode.Type.RuntimeType == typeof(DesignDataExtension))
                {
                    type2 = DataContextHelper.GetDesignDataType(documentCompositeNode);
                }
                else
                {
                    if (!PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)dataNode.Type))
                    {
                        return(dataNode.Type);
                    }
                    type2 = DataContextHelper.GetDataTemplateType(documentCompositeNode);
                }
                if (type2 == null || type2.RuntimeType == (Type)null)
                {
                    type2 = dataNode.TypeResolver.ResolveType(PlatformTypes.Object);
                }
            }
            return(type2);
        }
Esempio n. 4
0
        private IType GetTargetType(DocumentCompositeNode documentNode, IPropertyId typeProperty)
        {
            IProperty property = documentNode.TypeResolver.ResolveProperty(typeProperty);

            if (property == null)
            {
                return((IType)null);
            }
            IType        type = (IType)null;
            DocumentNode node = documentNode.Properties[(IPropertyId)property];

            if (node != null)
            {
                type = DocumentPrimitiveNode.GetValueAsType(node);
            }
            return(type);
        }
Esempio n. 5
0
        private DataContextInfo GetTypedTemplateDataContext(DocumentCompositeNode documentNode, RawDataSourceInfoBase localSource)
        {
            if (!PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)documentNode.Type))
            {
                return((DataContextInfo)null);
            }
            IProperty dataContextProperty = documentNode.TypeResolver.ResolveProperty(DataTemplateElement.DataTypeProperty);

            if (dataContextProperty == null)
            {
                return((DataContextInfo)null);
            }
            if (DocumentPrimitiveNode.GetValueAsType(documentNode.Properties[(IPropertyId)dataContextProperty]) == null)
            {
                return((DataContextInfo)null);
            }
            DataContextInfo dataContextInfo = new DataContextInfo();

            dataContextInfo.RawDataSource = new RawDataSourceInfo((DocumentNode)documentNode, (string)null).CombineWith(localSource);
            dataContextInfo.SetDataContextOwner(documentNode, dataContextProperty);
            return(dataContextInfo);
        }
Esempio n. 6
0
        public static DocumentNode GetShadowPropertyNode(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
        {
            IType valueAsType;
            DocumentNodeMemberValue value;
            ReferenceStep           member;

            if (!context.UseShadowProperties || propertyKey == null || !KnownProperties.SetterPropertyProperty.Equals(propertyKey))
            {
                return(null);
            }
            if (context.ContainerRoot == null || !PlatformTypes.Style.IsAssignableFrom(context.ContainerRoot.Type))
            {
                return(null);
            }
            DocumentCompositeNode documentNode = (DocumentCompositeNode)context.ContainerRoot.DocumentNode;
            DocumentPrimitiveNode item         = documentNode.Properties[KnownProperties.StyleTargetTypeProperty] as DocumentPrimitiveNode;

            if (item != null)
            {
                valueAsType = DocumentPrimitiveNode.GetValueAsType(item);
            }
            else
            {
                valueAsType = null;
            }
            IType type = valueAsType;

            if (type == null)
            {
                return(null);
            }
            DocumentPrimitiveNode documentPrimitiveNode = valueNode as DocumentPrimitiveNode;

            if (documentPrimitiveNode != null)
            {
                value = documentPrimitiveNode.Value as DocumentNodeMemberValue;
            }
            else
            {
                value = null;
            }
            DocumentNodeMemberValue documentNodeMemberValue = value;

            if (documentNodeMemberValue != null)
            {
                member = documentNodeMemberValue.Member as ReferenceStep;
            }
            else
            {
                member = null;
            }
            ReferenceStep referenceStep = member;

            if (referenceStep == null)
            {
                return(null);
            }
            if (context.RootTargetTypeReplacement != null)
            {
                ViewNode viewNode1 = StyleControlTemplateHelper.FindStyleTemplateOwningViewNode(viewNode);
                if (viewNode1 == null || viewNode1 == viewNode.ViewNodeManager.Root)
                {
                    IProperty replacementProperty = context.RootTargetTypeReplacement.GetReplacementProperty(referenceStep);
                    if (replacementProperty != null && replacementProperty != referenceStep)
                    {
                        return(context.DocumentContext.CreateNode(valueNode.Type, new DocumentNodeMemberValue(replacementProperty)));
                    }
                }
            }
            IProperty shadowProperty = DesignTimeProperties.GetShadowProperty(referenceStep, type);

            if (shadowProperty == null)
            {
                return(null);
            }
            if (!DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, shadowProperty))
            {
                return(null);
            }
            DocumentPrimitiveNode documentPrimitiveNode1 = context.DocumentContext.CreateNode(valueNode.Type, new DocumentNodeMemberValue(shadowProperty));

            return(documentPrimitiveNode1);
        }
 public override void Execute()
 {
     PerformanceUtility.StartPerformanceSequence(PerformanceEvent.EditStyleOrTemplate);
     if (this.IsEnabled)
     {
         SceneElement     targetElement                = this.TargetElement;
         IDocumentContext documentContext              = this.SceneViewModel.Document.DocumentContext;
         Type             propertyTargetType           = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty);
         CreateResourceModel.ContextFlags contextFlags = !PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)this.TargetProperty.PropertyType) ? (this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles) ? CreateResourceModel.ContextFlags.CanApplyAutomatically : CreateResourceModel.ContextFlags.None) : CreateResourceModel.ContextFlags.None;
         CreateResourceModel           model           = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, PlatformTypeHelper.GetPropertyType((IProperty)this.TargetProperty), propertyTargetType, this.TargetProperty.Name, (SceneElement)null, (SceneNode)(targetElement as BaseFrameworkElement), contextFlags);
         IList <DocumentCompositeNode> auxillaryResources;
         DocumentNode node1 = this.ProvideValue(out auxillaryResources);
         if (node1 != null)
         {
             IPropertyId           targetTypeProperty    = this.GetTargetTypeProperty((ITypeId)this.TargetProperty.PropertyType);
             DocumentCompositeNode documentCompositeNode = node1 as DocumentCompositeNode;
             if (targetTypeProperty != null && documentCompositeNode != null)
             {
                 IType valueAsType = DocumentPrimitiveNode.GetValueAsType(documentCompositeNode.Properties[targetTypeProperty]);
                 if (valueAsType != null && valueAsType.RuntimeType != (Type)null)
                 {
                     model.TargetType = valueAsType.RuntimeType;
                 }
             }
             else
             {
                 model.TargetType = (Type)null;
             }
             ReplaceStyleTemplateCommand.ExtraReferences references = new ReplaceStyleTemplateCommand.ExtraReferences();
             this.CollectExtraReferences(node1, references);
             if (auxillaryResources != null)
             {
                 foreach (DocumentNode node2 in (IEnumerable <DocumentCompositeNode>)auxillaryResources)
                 {
                     this.CollectExtraReferences(node2, references);
                 }
             }
             if (references.UnresolvedTypes.Count > 0)
             {
                 string message = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.CopyStyleTemplateTypesNotInDocumentMessage, new object[2]
                 {
                     (object)this.TargetProperty.Name,
                     (object)SceneView.GetUnresolvedTypesList(references.UnresolvedTypes)
                 });
                 if (!this.ShowUI)
                 {
                     return;
                 }
                 this.DesignerContext.MessageDisplayService.ShowError(message);
                 return;
             }
             if (this.ShowUI)
             {
                 bool?nullable = new CreateResourceDialog(this.DesignerContext, model).ShowDialog();
                 if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                 {
                     return;
                 }
             }
             bool flag = model.CurrentResourceSite != null;
             if (!flag || targetElement.DocumentNode.DocumentRoot == null)
             {
                 return;
             }
             SceneViewModel viewModel = this.SceneViewModel.GetViewModel(model.CurrentResourceSite.HostNode.DocumentRoot, false);
             if (viewModel == null || !PlatformTypes.PlatformsCompatible(node1.PlatformMetadata, viewModel.ProjectContext.PlatformMetadata) || !this.AddReferences(viewModel.ProjectContext, references, model.KeyString))
             {
                 return;
             }
             using (SceneEditTransaction editTransaction1 = this.SceneViewModel.CreateEditTransaction(this.UndoString))
             {
                 DocumentNode          documentNode1 = (DocumentNode)null;
                 DocumentCompositeNode resource;
                 using (SceneEditTransaction editTransaction2 = viewModel.CreateEditTransaction(this.UndoString))
                 {
                     DocumentNode newResourceNode;
                     try
                     {
                         newResourceNode = node1.Clone(viewModel.Document.DocumentContext);
                     }
                     catch
                     {
                         editTransaction2.Cancel();
                         editTransaction1.Cancel();
                         this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.CommandFailedDialogMessage, new object[1]
                         {
                             (object)this.UndoString
                         }));
                         return;
                     }
                     newResourceNode.Name = (string)null;
                     bool useStaticResource = !(this.TargetProperty is DependencyPropertyReferenceStep) || !JoltHelper.TypeSupported((ITypeResolver)this.SceneViewModel.ProjectContext, PlatformTypes.DynamicResource);
                     int  index             = useStaticResource ? model.IndexInResourceSite(targetElement.DocumentNode) : -1;
                     resource = model.CreateResource(newResourceNode, targetTypeProperty, index);
                     flag     = resource != null;
                     if (flag)
                     {
                         documentNode1 = model.CreateResourceReference(this.SceneViewModel.Document.DocumentContext, resource, useStaticResource);
                         flag          = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CopyResourcesToNewResourceSite(auxillaryResources, viewModel, model.CurrentResourceSite.HostNode, resource, model.IndexInResourceSite((DocumentNode)resource));
                     }
                     if (flag)
                     {
                         editTransaction2.Commit();
                         if (this.SceneViewModel == viewModel)
                         {
                             editTransaction1.Update();
                             this.DesignerContext.ViewUpdateManager.UpdateRelatedViews(this.SceneViewModel.Document, false);
                         }
                         this.DesignerContext.ViewUpdateManager.RefreshActiveViewApplicationResources();
                     }
                     else
                     {
                         editTransaction2.Cancel();
                     }
                 }
                 if (flag && resource != null)
                 {
                     DocumentNode     documentNode2 = resource.Properties[DictionaryEntryNode.ValueProperty];
                     DocumentNodePath documentNodePath;
                     if (targetElement.IsAttached)
                     {
                         if (documentNode1 != null)
                         {
                             targetElement.SetValue(this.TargetPropertyReference, (object)documentNode1);
                         }
                         else
                         {
                             targetElement.ClearValue(this.TargetPropertyReference);
                         }
                         this.SceneView.CandidateEditingContainer = targetElement.DocumentNodePath;
                         editTransaction1.Update();
                         this.SceneView.CandidateEditingContainer = (DocumentNodePath)null;
                         documentNodePath = this.ProvideEditingContainer(targetElement, this.TargetPropertyReference, documentNode2);
                     }
                     else
                     {
                         documentNodePath = (DocumentNodePath)null;
                     }
                     if (this.SceneView.IsValid)
                     {
                         if (documentNodePath != null && documentNodePath.Node != null && (!DocumentNodeUtilities.IsDynamicResource(documentNodePath.Node) && !DocumentNodeUtilities.IsStaticResource(documentNodePath.Node)))
                         {
                             DocumentNode node2             = documentNodePath.Node;
                             bool         preferInPlaceEdit = ControlStylingOperations.CanEditInPlace(targetElement, this.TargetProperty, documentNodePath);
                             ControlStylingOperations.SetActiveEditingContainer(targetElement, this.TargetProperty, node2, documentNodePath, preferInPlaceEdit, editTransaction1);
                         }
                         else
                         {
                             ControlStylingOperations.SetActiveEditingContainer(targetElement, this.TargetProperty, documentNode2, (DocumentNodePath)null, false, editTransaction1);
                         }
                     }
                     editTransaction1.Commit();
                 }
                 else
                 {
                     editTransaction1.Cancel();
                 }
             }
         }
     }
     PerformanceUtility.EndPerformanceSequence(PerformanceEvent.EditStyleOrTemplate);
 }