private static void UpdateItemsSourceOnItemsChanged(SceneElement itemsControl) { if (PropertyState.Unset == itemsControl.IsSet(ItemsControlElement.ItemsSourceProperty)) { return; } itemsControl.ClearValue(ItemsControlElement.ItemTemplateProperty); itemsControl.ClearValue(ItemsControlElement.ItemsSourceProperty); }
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); }
public override void Execute() { SceneElement primarySelection = this.DesignerContext.SelectionManager.ElementSelectionSet.PrimarySelection; using (SceneEditTransaction editTransaction = this.DesignerContext.ActiveSceneViewModel.CreateEditTransaction(StringTable.UndoClearPartAssignment)) { primarySelection.ClearValue(primarySelection.NameProperty); editTransaction.Commit(); } }
public static void SetLayoutOverrides(SceneElement element, LayoutOverrides flags) { if (flags == LayoutOverrides.None) { element.ClearValue(DesignTimeProperties.LayoutOverridesProperty); } else { element.SetValue(DesignTimeProperties.LayoutOverridesProperty, (object)flags); } }
private static void SetAutoLayoutRounding(SceneElement element, bool auto) { if (auto) { element.SetValue(DesignTimeProperties.LayoutRoundingProperty, (object)LayoutRoundingHelper.AutoLayoutRoundingValue); } else { element.ClearValue(DesignTimeProperties.LayoutRoundingProperty); } }
private static void SetAnnotationReferences(SceneElement element, IEnumerable <string> ids) { ExceptionChecks.CheckNullArgument <SceneElement>(element, "element"); ExceptionChecks.CheckNullArgument <IEnumerable <string> >(ids, "ids"); if (!Enumerable.Any <string>(ids)) { element.ClearValue(AnnotationSceneNode.ReferencesProperty); } else { element.SetValue(AnnotationSceneNode.ReferencesProperty, (object)string.Join(", ", Enumerable.ToArray <string>(ids))); } }
public static void ClearMutuallyExclusivePropertyIfNeeded(SceneElement itemsControl, PropertyReference propertyReference) { ReferenceStep firstStep = propertyReference.FirstStep; if (ItemsControlElement.ItemsSourceProperty.Equals((object)firstStep)) { ISceneNodeCollection <SceneNode> collectionForProperty = itemsControl.GetCollectionForProperty((IPropertyId)itemsControl.DefaultContentProperty); if (collectionForProperty != null) { foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)collectionForProperty) { SceneElement element = sceneNode as SceneElement; if (element != null) { itemsControl.ViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element); } } collectionForProperty.Clear(); } itemsControl.ClearValue(ItemsControlElement.ItemsProperty); } else if (ItemsControlElement.ItemsProperty.Equals((object)firstStep)) { ItemsControlElement.UpdateItemsSourceOnItemsChanged(itemsControl); } else if (ItemsControlElement.ItemTemplateProperty.Equals((object)firstStep)) { itemsControl.ClearValue(ItemsControlElement.DisplayMemberPathProperty); } else { if (!ItemsControlElement.DisplayMemberPathProperty.Equals((object)firstStep)) { return; } itemsControl.ClearValue(ItemsControlElement.ItemTemplateProperty); } }
public static bool UpdateLayoutRounding(SceneElement element) { if (!LayoutRoundingHelper.ShouldConsiderLayoutRoundingAdjustment(element)) { return(false); } IPropertyId propertyKey = (IPropertyId)LayoutRoundingHelper.ResolveUseLayoutRoundingProperty((SceneNode)element); if (propertyKey == null) { return(false); } bool flag1 = element.IsSet(propertyKey) == PropertyState.Set; if (PlatformTypes.Path.IsAssignableFrom((ITypeId)element.Type)) { if (!flag1 && (bool)element.GetComputedValue(propertyKey)) { element.SetLocalValue(Base2DElement.UseLayoutRoundingProperty, (object)false); LayoutRoundingHelper.SetAutoLayoutRounding(element, false); return(true); } } else if (!flag1 || LayoutRoundingHelper.GetAutoLayoutRounding(element)) { bool flag2 = (bool)element.GetComputedValue(propertyKey); if (LayoutRoundingHelper.IsAxisAligned(element)) { if (!flag2) { element.ClearValue(propertyKey); LayoutRoundingHelper.SetAutoLayoutRounding(element, false); return(true); } } else if (flag2) { element.SetValue(propertyKey, (object)false); LayoutRoundingHelper.SetAutoLayoutRounding(element, true); return(true); } } return(false); }
public static void DeleteBehavior(BehaviorBaseNode node) { Stack <ReferenceStep> input = new Stack <ReferenceStep>(); SceneNode parent1 = node.Parent; SceneNode child1 = (SceneNode)node; while (true) { ReferenceStep referenceStep = (ReferenceStep)parent1.GetPropertyForChild(child1); if (parent1.IsCollectionProperty((IPropertyId)referenceStep)) { int index = parent1.GetCollectionForProperty((IPropertyId)referenceStep).IndexOf(child1); input.Push((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((ITypeResolver)node.ProjectContext, (ITypeId)referenceStep.PropertyType, index)); } input.Push(referenceStep); if (!(parent1 is SceneElement)) { child1 = parent1; parent1 = parent1.Parent; } else { break; } } SceneElement sceneElement = (SceneElement)parent1; SceneNode parent2 = node.Parent; PropertyReference propertyReference = new PropertyReference(input); node.ViewModel.AnimationEditor.DeleteAllAnimations((SceneNode)sceneElement, propertyReference.ToString()); SceneNode child2 = (SceneNode)node; int num = propertyReference.Count - 1; ISceneNodeCollection <SceneNode> collectionForChild; int endIndex; while (true) { SceneNode parent3 = child2.Parent; if (sceneElement != child2 && parent3 != null) { ReferenceStep referenceStep = (ReferenceStep)parent3.GetPropertyForChild(child2); collectionForChild = parent3.GetCollectionForChild(child2); DocumentNodeHelper.PreserveFormatting(child2.DocumentNode); endIndex = propertyReference.ReferenceSteps.IndexOf(referenceStep); if (collectionForChild.Count == 1) { child2.Remove(); child2 = parent3; } else { goto label_10; } } else { break; } } sceneElement.ClearValue((IPropertyId)propertyReference.FirstStep); goto label_11; label_10: int index1 = collectionForChild.IndexOf(child2); child2.ViewModel.AnimationEditor.ValidateAnimations((SceneNode)sceneElement, propertyReference.Subreference(0, endIndex), index1, false); child2.Remove(); label_11: node.ViewModel.Document.OnUpdatedEditTransaction(); }
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); }
private static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject, ISceneInsertionPoint insertionPoint, bool allowInsertionPointChange, out bool canceledPasteOperation) { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.PasteElements); canceledPasteOperation = false; List <SceneNode> list = new List <SceneNode>(); PastePackage pastePackage = PastePackage.FromData(viewModel, dataObject); if (pastePackage != null) { if (allowInsertionPointChange) { insertionPoint = PasteCommand.ComputeNewInsertionPoint(viewModel, insertionPoint, pastePackage); } if (!PasteCommand.CanAddMultipleElements(insertionPoint.SceneElement, pastePackage.Elements.Count)) { string name = insertionPoint.SceneElement.TargetType.Name; viewModel.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PasteMultipleInSingleContainerError, new object[1] { (object)name })); } else if (pastePackage.Elements.Count == 0 && pastePackage.Storyboards.Count == 0 && pastePackage.Resources.Count > 0) { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedNoElementsDialogMessage); } else { IDictionary <DocumentNode, string> imageMap = (IDictionary <DocumentNode, string>) new Dictionary <DocumentNode, string>(); foreach (SceneNode sceneNode in pastePackage.Elements) { foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel)) { imageMap.Add(keyValuePair); } } foreach (SceneNode sceneNode in pastePackage.Resources) { foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel)) { imageMap.Add(keyValuePair); } } int index = 0; ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(viewModel.RootNode.DocumentNode); if (resourcesCollection != null && resourcesCollection.Resources != null && resourcesCollection.Resources.SupportsChildren) { index = resourcesCollection.Resources.Children.Count; } if (Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PasteResources(pastePackage, imageMap, ResourceConflictResolution.UseExisting | ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld, viewModel.RootNode, index, false)) { ILayoutDesigner designerForParent = viewModel.GetLayoutDesignerForParent(insertionPoint.SceneElement, true); List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater = new List <PasteCommand.DelayedElementTranslationInfo>(pastePackage.Elements.Count); string copyElementToken = pastePackage.ClipboardCopyElementToken; foreach (SceneElement element in pastePackage.Elements) { SceneElement sceneElement = PasteCommand.PasteElement(viewModel, element, elementsToTranslateLater, insertionPoint); if (sceneElement != null) { Microsoft.Expression.DesignSurface.Utility.ResourceHelper.UpdateImageReferences(sceneElement.DocumentNode, imageMap, pastePackage, viewModel); list.Add((SceneNode)sceneElement); sceneElement.ClearValue(DesignTimeProperties.CopyTokenProperty); } } if (copyElementToken != null) { pastePackage.SetGlobalCopyElementToken(copyElementToken); PastePackage.PasteSelectionChangePending = true; } foreach (SceneNode childProperty in pastePackage.ChildPropertyNodes) { PasteCommand.PasteChildProperty(viewModel, childProperty, (IList <SceneNode>)list); } foreach (StoryboardTimelineSceneNode storyboard in pastePackage.Storyboards) { PasteCommand.PasteStoryboard(viewModel, storyboard, (IList <SceneNode>)list); } viewModel.Document.OnUpdatedEditTransaction(); viewModel.DefaultView.UpdateLayout(); using (viewModel.ForceBaseValue()) { Rect empty = Rect.Empty; foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater) { empty.Union(elementTranslationInfo.Bounds); } foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater) { elementTranslationInfo.UpdateTranslation(designerForParent, empty); } } } else { canceledPasteOperation = true; } } } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { DesignerContext designerContext = viewModel.DesignerContext; string[] supportedFiles = FileDropToolBehavior.CreateImageOrMediaDrop(designerContext).GetSupportedFiles(ClipboardService.GetDataObject()); if (supportedFiles.Length > 0) { IEnumerable <IProjectItem> importedItems = designerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)supportedFiles, (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo() { SourcePath = file }))); FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, importedItems, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint); } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else if (dataObject.GetDataPresent(DataFormats.Bitmap)) { DesignerContext designerContext = viewModel.DesignerContext; IProjectItem projectItem = CutBuffer.AddImageDataFromClipboard(designerContext.ProjectManager, designerContext.ActiveProject); if (projectItem != null) { FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, (IEnumerable <IProjectItem>) new List <IProjectItem>() { projectItem }, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint); } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } return((ICollection <SceneNode>)list); }