Esempio n. 1
0
        public static DocumentCompositeNode CreateDataTemplateResource(SceneNode targetElement, IPropertyId templateProperty, string resourceNameBase, IList <DataSchemaNodePath> entries, DataViewCategory category, ITypeId dataTemplateType)
        {
            SceneViewModel        viewModel             = targetElement.ViewModel;
            IPlatform             platform              = targetElement.Platform;
            IDocumentContext      documentContext       = viewModel.Document.DocumentContext;
            DocumentCompositeNode documentCompositeNode = DataViewFactory.GenerateDataView(platform, documentContext, entries, category);

            if (documentCompositeNode == null)
            {
                return((DocumentCompositeNode)null);
            }
            DocumentCompositeNode node = documentContext.CreateNode(dataTemplateType);

            node.Properties[(IPropertyId)node.Type.Metadata.DefaultContentProperty] = (DocumentNode)documentCompositeNode;
            CreateResourceModel createResourceModel = new CreateResourceModel(viewModel, viewModel.DesignerContext.ResourceManager, node.Type.RuntimeType, (Type)null, (string)null, (SceneElement)null, (SceneNode)null, CreateResourceModel.ContextFlags.None);

            createResourceModel.KeyString = resourceNameBase;
            bool useStaticResource = !JoltHelper.TypeSupported((ITypeResolver)viewModel.ProjectContext, PlatformTypes.DynamicResource);

            if (!useStaticResource && !PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)targetElement.Type))
            {
                useStaticResource = true;
            }
            int index = useStaticResource ? createResourceModel.IndexInResourceSite(targetElement.DocumentNode) : -1;
            DocumentCompositeNode resource = createResourceModel.CreateResource((DocumentNode)node, (IPropertyId)null, index);

            if (templateProperty != null)
            {
                DocumentNode resourceReference = createResourceModel.CreateResourceReference(documentContext, resource, useStaticResource);
                using (viewModel.AnimationEditor.DeferKeyFraming())
                    targetElement.SetValue(templateProperty, (object)resourceReference);
            }
            return((DocumentCompositeNode)resource.Properties[DictionaryEntryNode.ValueProperty]);
        }
Esempio n. 2
0
 public PropertyReferenceProperty(ObjectSetBase objectSet, PropertyReference propertyReference, AttributeCollection attributes, PropertyValue parentValue, Type proxyType)
     : base(parentValue)
 {
     if (attributes == null)
     {
         DependencyPropertyReferenceStep propertyReferenceStep = propertyReference.LastStep as DependencyPropertyReferenceStep;
         if (propertyReferenceStep != null)
         {
             attributes = propertyReferenceStep.Attributes;
         }
     }
     this.proxyType         = proxyType;
     this.attributes        = attributes;
     this.objectSet         = objectSet;
     this.propertyReference = propertyReference;
     if (propertyReference.LastStep.IsAttachable)
     {
         this.SetName(propertyReference.LastStep.DeclaringType.Name + "." + propertyReference.LastStep.Name);
     }
     else
     {
         this.SetName(propertyReference.LastStep.Name);
     }
     this.InitializeConverter(base.get_PropertyName());
     this.InitializeValueEditorParameters();
     if (!JoltHelper.TypeHasEnumValues(this.PropertyTypeId))
     {
         return;
     }
     this.objectSet.DesignerContext.ProjectManager.ProjectOpened += new EventHandler <ProjectEventArgs>(this.ProjectManager_ProjectOpened);
 }
        private static DataBindingDragDropModel UpdateDragModel(DataBindingDragDropModel dragModel)
        {
            if (!JoltHelper.DatabindingSupported(dragModel.TargetNode.ProjectContext))
            {
                dragModel.DropFlags = DataBindingDragDropFlags.None;
                return(dragModel);
            }
            DataBindingDragDropHandler bindingDragDropHandler = (DataBindingDragDropHandler)null;

            for (int index = 0; index < DataBindingDragDropManager.handlers.Length; ++index)
            {
                bindingDragDropHandler = DataBindingDragDropManager.handlers[index];
                using (bindingDragDropHandler.InitDragModel(dragModel))
                {
                    if (bindingDragDropHandler.CanHandle())
                    {
                        dragModel = bindingDragDropHandler.DragModel;
                        break;
                    }
                    bindingDragDropHandler = (DataBindingDragDropHandler)null;
                }
            }
            DataBindingDragDropManager.targetHandler = bindingDragDropHandler;
            if (bindingDragDropHandler == null)
            {
                dragModel.DropFlags = DataBindingDragDropFlags.None;
            }
            else
            {
                dragModel.DropFlags &= dragModel.DragFlags;
            }
            return(dragModel);
        }
Esempio n. 4
0
 protected override object GetComputedValueInternal(PropertyReference propertyReference)
 {
     if (this.ProjectContext.IsCapabilitySet(PlatformCapability.WorkaroundSL23187) && PlatformTypes.DiscreteObjectKeyFrame.IsAssignableFrom((ITypeId)this.Type))
     {
         return(JoltHelper.GetComputedValueFromLocalSceneNode((SceneNode)this, propertyReference));
     }
     return(base.GetComputedValueInternal(propertyReference));
 }
Esempio n. 5
0
 public override void OnRemoveFromCategory()
 {
     if (!JoltHelper.TypeHasEnumValues(this.PropertyTypeId) || this.objectSet.DesignerContext.ProjectManager == null)
     {
         return;
     }
     this.objectSet.DesignerContext.ProjectManager.ProjectOpened -= new EventHandler <ProjectEventArgs>(this.ProjectManager_ProjectOpened);
 }
        public override bool CanAddToProject(IProject project)
        {
            IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project);

            if (projectContext == null || !JoltHelper.TypeSupported((ITypeResolver)projectContext, PlatformTypes.ModelVisual3D))
            {
                return(false);
            }
            return(base.CanAddToProject(project));
        }
        private static bool IsBindableSceneNode(SceneNode sceneNode)
        {
            if (!JoltHelper.DatabindingSupported(sceneNode.ProjectContext))
            {
                return(false);
            }
            Type type = sceneNode.GetType();

            return(!typeof(KeyFrameSceneNode).IsAssignableFrom(type) && !typeof(TimelineSceneNode).IsAssignableFrom(type) && (!(sceneNode is StyleNode) || sceneNode.Platform.Metadata.IsCapabilitySet(PlatformCapability.SupportBindingsInStyleSetters)));
        }
        protected void SetBrushTransform(CanonicalTransform transform)
        {
            this.EnsureEditTransaction();
            transform.CenterX       = RoundingHelper.RoundLength(transform.CenterX);
            transform.CenterY       = RoundingHelper.RoundLength(transform.CenterY);
            transform.ScaleX        = RoundingHelper.RoundScale(transform.ScaleX);
            transform.ScaleY        = RoundingHelper.RoundScale(transform.ScaleY);
            transform.SkewX         = RoundingHelper.RoundAngle(transform.SkewX);
            transform.SkewY         = RoundingHelper.RoundAngle(transform.SkewY);
            transform.RotationAngle = RoundingHelper.RoundAngle(transform.RotationAngle);
            transform.TranslationX  = RoundingHelper.RoundLength(transform.TranslationX);
            transform.TranslationY  = RoundingHelper.RoundLength(transform.TranslationY);
            IProjectContext    projectContext     = this.ActiveDocument.ProjectContext;
            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.GetBrushValue(BrushNode.RelativeTransformProperty));

            if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterX, transform.CenterX) != 0 || JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterY, transform.CenterY) != 0)
            {
                this.SetBrushValue(BrushNode.RelativeTransformProperty, transform.GetPlatformTransform(this.RootNode.Platform.GeometryHelper));
            }
            else
            {
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleX, transform.ScaleX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleXReference, transform.ScaleX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleY, transform.ScaleY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleYReference, transform.ScaleY);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewX, transform.SkewX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewXReference, transform.SkewX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewY, transform.SkewY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewYReference, transform.SkewY);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.RotationAngle, transform.RotationAngle) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushRotationAngleReference, transform.RotationAngle);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationX, transform.TranslationX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationXReference, transform.TranslationX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationY, transform.TranslationY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationYReference, transform.TranslationY);
                }
            }
            this.UpdateEditTransaction();
        }
Esempio n. 9
0
        public override void SetValueToLocalResource(SceneNodeProperty propertyKey, LocalResourceModel localResource)
        {
            DocumentNode resourceKey = localResource.ResourceKey;

            PerformanceUtility.StartPerformanceSequence(PerformanceEvent.ApplyResource, "Apply resource.");
            SceneViewModel viewModel = this.ViewModel;

            if (viewModel != null)
            {
                IDocumentContext documentContext = viewModel.Document.DocumentContext;
                IProjectContext  projectContext  = viewModel.ProjectContext;
                DocumentNode     keyNode         = resourceKey.Clone(documentContext);
                bool             flag            = this.CanSetDynamicExpression && JoltHelper.TypeSupported((ITypeResolver)projectContext, PlatformTypes.DynamicResource);
                if (flag && this.ShouldAllowAnimation && (propertyKey.IsEnabledRecordCurrentValue && this.ViewModel.AnimationEditor.IsRecording))
                {
                    flag = false;
                }
                DocumentNode documentNode = !flag ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode);
                using (this.ShouldAllowAnimation ? (IDisposable)null : viewModel.AnimationEditor.DeferKeyFraming())
                {
                    string description = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertyChangeUndoDescription, new object[1]
                    {
                        (object)((PropertyEntry)propertyKey).get_PropertyName()
                    });
                    if (viewModel.Document.IsEditable)
                    {
                        using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(description))
                        {
                            this.SetValue((PropertyReferenceProperty)propertyKey, (object)documentNode);
                            bool         isMixed;
                            DocumentNode valueAsDocumentNode = this.GetLocalValueAsDocumentNode(propertyKey, GetLocalValueFlags.CheckKeyframes, out isMixed);
                            if (!isMixed && valueAsDocumentNode != null)
                            {
                                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EnsureReferencedResourcesAreReachable(localResource.ResourceNode, valueAsDocumentNode);
                            }
                            editTransaction.Commit();
                        }
                    }
                }
            }
            PerformanceUtility.EndPerformanceSequence(PerformanceEvent.ApplyResource, "Apply resource.");
        }
Esempio n. 10
0
        public bool ApplyStyle(SceneNode node)
        {
            BaseFrameworkElement frameworkElement = node as BaseFrameworkElement;

            if (frameworkElement == null || !this.StyleType.IsAssignableFrom((ITypeId)frameworkElement.Type))
            {
                return(false);
            }
            ResourceDictionaryAssetProvider dictionaryAssetProvider = this.Provider as ResourceDictionaryAssetProvider;

            if (dictionaryAssetProvider != null && dictionaryAssetProvider.ContentProvider != null && !dictionaryAssetProvider.ContentProvider.EnsureLinked(frameworkElement.ViewModel) || frameworkElement.DocumentNodePath.Contains(this.ResourceModel.ValueNode))
            {
                return(false);
            }
            IDocumentContext context   = frameworkElement.DocumentNode.Context;
            DocumentNode     valueNode = !JoltHelper.TypeSupported((ITypeResolver)frameworkElement.ProjectContext, PlatformTypes.DynamicResource) ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(context, this.ResourceModel.KeyNode.Clone(context)) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(context, this.ResourceModel.KeyNode.Clone(context));

            frameworkElement.SetLocalValue(BaseFrameworkElement.StyleProperty, valueNode);
            return(true);
        }
Esempio n. 11
0
 private void Rebuild()
 {
     if (!this.editingProperty.IsMixedValue)
     {
         object obj = this.editingProperty.GetValue();
         if (PlatformTypes.IsInstance(obj, PlatformTypes.GridLength, (ITypeResolver)((SceneNodeProperty)this.editingProperty).SceneNodeObjectSet.ProjectContext))
         {
             SceneNodeObjectSet sceneNodeObjectSet = ((SceneNodeProperty)this.editingProperty).SceneNodeObjectSet;
             GridLength         gridLength         = (GridLength)sceneNodeObjectSet.DesignerContext.PlatformConverter.ConvertToWpf(((SceneNodeProperty)this.editingProperty).SceneNodeObjectSet.DocumentContext, obj);
             this.value        = JoltHelper.RoundDouble(sceneNodeObjectSet.ProjectContext, gridLength.Value);
             this.gridUnitType = gridLength.GridUnitType;
             this.OnPropertyChanged("Value");
         }
     }
     else
     {
         this.gridUnitType = GridUnitType.Star;
     }
     this.OnPropertyChanged("GridUnitType");
 }
Esempio n. 12
0
        private void UpdatePaneVisibility()
        {
            SceneViewModel activeSceneViewModel = this.designerContext.ActiveSceneViewModel;

            if (activeSceneViewModel == null)
            {
                return;
            }
            bool       flag            = JoltHelper.TriggersSupported(activeSceneViewModel.ProjectContext);
            IWorkspace activeWorkspace = this.designerContext.WorkspaceService.ActiveWorkspace;

            if (activeWorkspace == null)
            {
                return;
            }
            ExpressionView expressionView = activeWorkspace.FindPalette("Designer_TriggersPane") as ExpressionView;

            if (expressionView == null)
            {
                return;
            }
            expressionView.IsForcedInvisible = !flag;
        }
Esempio n. 13
0
        private void StripUnsupportedElements(DocumentCompositeNode compositeNode)
        {
            IProjectContext projectContext = this.TextSource.ViewModel.ProjectContext;

            if (compositeNode.SupportsChildren)
            {
                for (int index = compositeNode.Children.Count - 1; index >= 0; --index)
                {
                    if (!JoltHelper.TypeSupported((ITypeResolver)projectContext, (ITypeId)compositeNode.Children[index].Type))
                    {
                        compositeNode.Children.RemoveAt(index);
                    }
                }
            }
            foreach (Microsoft.Expression.DesignModel.DocumentModel.DocumentNode documentNode in compositeNode.ChildNodes)
            {
                DocumentCompositeNode compositeNode1 = documentNode as DocumentCompositeNode;
                if (compositeNode1 != null)
                {
                    this.StripUnsupportedElements(compositeNode1);
                }
            }
        }
Esempio n. 14
0
        protected override IList <SceneElement> AddToDocumentInternal(string importedFilePath, SceneElement element, ISceneInsertionPoint insertionPoint, SceneViewModel sceneViewModel, SceneEditTransaction editTransaction)
        {
            MediaSceneElement    mediaSceneElement = element as MediaSceneElement;
            IList <SceneElement> list = (IList <SceneElement>) new List <SceneElement>();

            if (mediaSceneElement != null)
            {
                double num = (double)mediaSceneElement.GetLocalOrDefaultValueAsWpf(DesignTimeProperties.DesignTimeNaturalDurationProperty);
                mediaSceneElement.ClearLocalValue(DesignTimeProperties.DesignTimeNaturalDurationProperty);
                if (insertionPoint.CanInsert((ITypeId)mediaSceneElement.Type))
                {
                    if (!JoltHelper.TypeSupported((ITypeResolver)element.ProjectContext, PlatformTypes.MediaTimeline))
                    {
                        Uri uri = new Uri(importedFilePath, UriKind.RelativeOrAbsolute);
                        mediaSceneElement.SetLocalValueAsWpf(MediaSceneElement.SourceProperty, (object)uri);
                    }
                    else
                    {
                        IStoryboardContainer        mediaStoryboardContainer = insertionPoint.SceneNode.StoryboardContainer;
                        StoryboardTimelineSceneNode targetStoryboard         = (StoryboardTimelineSceneNode)null;
                        sceneViewModel.EditContextManager.SingleViewModelEditContextWalker.Walk(false, (SingleHistoryCallback)((context, isGhosted) =>
                        {
                            if (context.StoryboardContainer != mediaStoryboardContainer)
                            {
                                return(false);
                            }
                            targetStoryboard = context.Timeline;
                            return(true);
                        }));
                        if (targetStoryboard == null)
                        {
                            foreach (TriggerBaseNode triggerBaseNode in (IEnumerable <TriggerBaseNode>)mediaStoryboardContainer.VisualTriggers)
                            {
                                EventTriggerNode eventTriggerNode = triggerBaseNode as EventTriggerNode;
                                if (eventTriggerNode != null && eventTriggerNode.RoutedEvent == FrameworkElement.LoadedEvent)
                                {
                                    foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)eventTriggerNode.Actions)
                                    {
                                        TimelineActionNode timelineActionNode = sceneNode as TimelineActionNode;
                                        if (timelineActionNode != null && timelineActionNode.TimelineOperation == TimelineOperation.Begin)
                                        {
                                            targetStoryboard = timelineActionNode.TargetTimeline;
                                            if (!TimelinePane.ShouldExposeStoryboardToUser((SceneNode)targetStoryboard))
                                            {
                                                targetStoryboard = (StoryboardTimelineSceneNode)null;
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (targetStoryboard != null)
                                {
                                    break;
                                }
                            }
                            if (targetStoryboard != null)
                            {
                                sceneViewModel.SetActiveStoryboardTimeline(mediaStoryboardContainer, targetStoryboard, (TriggerBaseNode)null);
                            }
                        }
                        if (targetStoryboard == null)
                        {
                            targetStoryboard = sceneViewModel.AnimationEditor.CreateNewTimeline(sceneViewModel.ActiveStoryboardContainer, element.Name, TriggerCreateBehavior.Default, true);
                            sceneViewModel.AnimationEditor.IsRecording = false;
                        }
                        IType type = this.DesignerContext.ActiveDocument.ProjectContext.ResolveType(PlatformTypes.MediaTimeline);
                        MediaTimelineSceneNode timelineSceneNode = (MediaTimelineSceneNode)sceneViewModel.CreateSceneNode(type.RuntimeType);
                        timelineSceneNode.SetLocalValue(DesignTimeProperties.DesignTimeNaturalDurationProperty, (object)num);
                        Uri uri = new Uri(importedFilePath, UriKind.RelativeOrAbsolute);
                        timelineSceneNode.Source     = uri;
                        timelineSceneNode.TargetName = element.Name;
                        double animationTime = sceneViewModel.AnimationEditor.AnimationTime;
                        timelineSceneNode.Begin = animationTime;
                        targetStoryboard.Children.Add((TimelineSceneNode)timelineSceneNode);
                        editTransaction.Update();
                    }
                    list.Add(element);
                    insertionPoint.Insert((SceneNode)mediaSceneElement);
                }
            }
            return(list);
        }
 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);
 }
Esempio n. 16
0
 protected void SetToResourceInternal(PropertyReference propertyReference, LocalResourceModel resourceModel)
 {
     using (SceneEditTransaction editTransaction = this.ViewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertySetUndo, new object[1]
     {
         (object)this.TargetProperty.Name
     })))
     {
         IDocumentContext documentContext       = this.ViewModel.Document.DocumentContext;
         DocumentNode     keyNode               = resourceModel.ResourceKey.Clone(documentContext);
         DocumentNode     resourceExtensionNode = !(propertyReference[0] is DependencyPropertyReferenceStep) || !JoltHelper.TypeSupported((ITypeResolver)this.ViewModel.ProjectContext, PlatformTypes.DynamicResource) ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode);
         this.TargetElement.SetValue(propertyReference, (object)resourceExtensionNode);
         Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EnsureReferencedResourcesAreReachable(resourceModel.ResourceNode, resourceExtensionNode);
         editTransaction.Commit();
     }
 }
Esempio n. 17
0
        private void ApplyResourceOnExistingElement(SceneElement targetElement, IPropertyId targetProperty, ResourceEntryItem resource)
        {
            if (resource.Resource.KeyNode != null || targetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
            {
                using (SceneEditTransaction editTransaction = this.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertySetUndo, new object[1]
                {
                    (object)targetProperty.Name
                })))
                {
                    if (resource.Resource.KeyNode != null)
                    {
                        IDocumentContext documentContext = this.ActiveSceneViewModel.Document.DocumentContext;
                        IProjectContext  projectContext  = this.ActiveSceneViewModel.Document.ProjectContext;
                        DocumentNode     keyNode         = resource.Resource.KeyNode.Clone(documentContext);
                        DocumentNode     documentNode    = !(projectContext.ResolveProperty(targetProperty) is DependencyPropertyReferenceStep) || !JoltHelper.TypeSupported((ITypeResolver)projectContext, PlatformTypes.DynamicResource) ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode);
                        targetElement.SetValue(targetProperty, (object)documentNode);
                    }
                    else if (targetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
                    {
                        targetElement.ClearValue(targetProperty);
                    }
                    editTransaction.Commit();
                }
            }
            ResourceManager   resourceManager   = this.ActiveSceneViewModel.DesignerContext.ResourceManager;
            DocumentReference documentReference = resource.Container.DocumentReference;

            if (resource.Resource.IsResourceReachable((SceneNode)targetElement) || !(documentReference != resourceManager.ActiveRootContainer.DocumentReference) || !(documentReference != resourceManager.TopLevelResourceContainer.DocumentReference))
            {
                return;
            }
            resourceManager.LinkToResource(resourceManager.TopLevelResourceContainer, documentReference);
        }
Esempio n. 18
0
        private IEnumerable <IType> AllXamlRelevantTypesInAssembly(IAssembly assembly)
        {
            IProjectContext project         = this.ProjectContext;
            bool            supportInternal = assembly.Equals((object)project.ProjectAssembly);

            Type[] assemblyTypes = Type.EmptyTypes;
            try
            {
                assemblyTypes = AssemblyHelper.GetTypes(assembly);
            }
            catch (ReflectionTypeLoadException ex)
            {
                assemblyTypes = Type.EmptyTypes;
            }
            IAttachedPropertiesProvider attachedPropertiesProvider = this.AttachedPropertiesProvider;

            if (attachedPropertiesProvider == null)
            {
                throw new NotSupportedException();
            }
            Type[] allTypesWithAttachedProperties = (Type[])null;
            using (IAttachedPropertiesAccessToken token = attachedPropertiesProvider.AttachedProperties.Access())
            {
                CodeAidProvider.EnsurePreloadKnownAttachedProperties(token, project);
                allTypesWithAttachedProperties = Enumerable.ToArray <Type>(Enumerable.Select <IGrouping <Type, IAttachedPropertyMetadata>, Type>(Enumerable.GroupBy <IAttachedPropertyMetadata, Type>((IEnumerable <IAttachedPropertyMetadata>)token.AttachedPropertiesForAssembly(assembly.Name), (Func <IAttachedPropertyMetadata, Type>)(property => property.OwnerType)), (Func <IGrouping <Type, IAttachedPropertyMetadata>, Type>)(type => type.Key)));
            }
            foreach (Type type3 in assemblyTypes)
            {
                IType yieldedTypeId = (IType)null;
                try
                {
                    if (!type3.IsGenericType)
                    {
                        if (type3.IsVisible)
                        {
                            if (!type3.IsNested)
                            {
                                if (!typeof(Attribute).IsAssignableFrom(type3))
                                {
                                    if (!typeof(Exception).IsAssignableFrom(type3))
                                    {
                                        if (type3.IsPublic)
                                        {
                                            if (TypeUtilities.HasDefaultConstructor(type3, supportInternal) && TypeUtilities.CanCreateTypeInXaml((ITypeResolver)project, type3))
                                            {
                                                IType type1 = project.GetType(type3);
                                                if (JoltHelper.TypeSupported((ITypeResolver)project, (ITypeId)type1))
                                                {
                                                    yieldedTypeId = type1;
                                                }
                                            }
                                            else if (allTypesWithAttachedProperties != null)
                                            {
                                                if (OrderedListExtensions.GenericBinarySearch <Type, Type>(allTypesWithAttachedProperties, type3, (Func <Type, Type, int>)((type1, type2) => type1.Name.CompareTo(type2.Name))) >= 0)
                                                {
                                                    yieldedTypeId = project.GetType(type3);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (FileNotFoundException ex)
                {
                }
                if (yieldedTypeId != null)
                {
                    yield return(yieldedTypeId);
                }
            }
        }
Esempio n. 19
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();
                    }
                }
            }
        }