protected override CreateResourceDialog CreateDialog(CreateResourceModel createResourceModel) { CreateResourceDialog createResourceDialog = new CreateResourceDialog(this.DesignerContext, createResourceModel); createResourceDialog.Title = StringTable.MakePartDialogTitle; return(createResourceDialog); }
protected virtual DocumentNode ProcessAsResource(BaseFrameworkElement originalElement, DocumentNode newValue) { if (!this.CreateResource) { return((DocumentNode)null); } CreateResourceModel model = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, this.SceneViewModel.ProjectContext.ResolveType(this.Type).RuntimeType, (System.Type)null, (string)null, (SceneElement)null, (SceneNode)originalElement, this.ResourceContextFlags); if (originalElement.IsNamed) { model.KeyString = model.CurrentResourceSite.GetUniqueResourceKey(originalElement.Name); if (model.KeyStringHasIssues) { model.ResetResourceKey(); } } if (this.ShowUI) { bool?nullable = new CreateResourceDialog(this.DesignerContext, model).ShowDialog(); if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0) { return((DocumentNode)null); } } return((DocumentNode)model.CreateResource(newValue, (IPropertyId)null, -1)); }
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); }