private static bool CanMoveInside(MoveStrategyContext context, BaseFrameworkElement candidateContainer) { if (context.PrimarySelection == null) { return(false); } IProperty contentProperty = MoveStrategyFactory.GetContentProperty(context, (SceneNode)candidateContainer); if (contentProperty == null) { return(false); } PropertySceneInsertionPoint insertionPoint = new PropertySceneInsertionPoint((SceneElement)candidateContainer, contentProperty); ControlTemplateElement controlTemplateElement; if (candidateContainer.IsLockedOrAncestorLocked || candidateContainer.IsHiddenOrCollapsedOrAncestorHiddenOrCollapsed || (context.SelectedElements.Count == 0 || Enumerable.Any <SceneElement>((IEnumerable <SceneElement>)context.SelectedElements, (Func <SceneElement, bool>)(element => !insertionPoint.CanInsert((ITypeId)element.TrueTargetTypeId)))) || ProjectNeutralTypes.TabItem.IsAssignableFrom((ITypeId)candidateContainer.Type) || (candidateContainer.Name == "PART_ContentHost" && typeof(ScrollViewer).IsAssignableFrom(candidateContainer.TargetType) && ((controlTemplateElement = context.RootNode as ControlTemplateElement) != null && typeof(TextBoxBase).IsAssignableFrom(controlTemplateElement.TargetElementType)) || candidateContainer.IsPlaceholder)) { return(false); } foreach (SceneNode sceneNode in context.DraggedElements) { if (sceneNode.IsAncestorOf((SceneNode)candidateContainer)) { return(false); } } return(true); }
public bool CanInsert(ITypeId typeToInsert) { if (this.SceneElement != null) { IType typeToInsert1 = this.SceneNode.ProjectContext.ResolveType(typeToInsert); IProperty defaultContentProperty = this.SceneNode.DefaultContentProperty; if (typeToInsert1 != null && defaultContentProperty != null) { return(PropertySceneInsertionPoint.IsTypeCompatible(this.SceneNode, typeToInsert1, defaultContentProperty)); } } return(false); }
public void Insert(SceneNode nodeToInsert) { if (this.ShouldNestContents(nodeToInsert)) { this.NestContents(nodeToInsert); } else { ISceneNodeCollection <SceneNode> destinationCollection = this.DestinationCollection; if (destinationCollection.FixedCapacity.HasValue && destinationCollection.Count >= destinationCollection.FixedCapacity.Value) { PropertySceneInsertionPoint.Cleanup(destinationCollection[destinationCollection.Count - 1]); } if (this.index >= 0 && this.index < destinationCollection.Count) { destinationCollection.Insert(this.index, nodeToInsert); } else { destinationCollection.Add(nodeToInsert); } } }
private static void PasteChildProperty(SceneViewModel viewModel, SceneNode childProperty, IList <SceneNode> pastedNodes) { IList <SceneElement> list = (IList <SceneElement>)null; DocumentNodeHelper.StripExtraNamespaces(childProperty.DocumentNode); if (viewModel.ElementSelectionSet.Selection.Count != 0) { list = (IList <SceneElement>)viewModel.ElementSelectionSet.Selection; } else if (viewModel.ChildPropertySelectionSet.Selection.Count != 0 && !(childProperty is BehaviorBaseNode) && !(childProperty is BehaviorTriggerBaseNode)) { list = (IList <SceneElement>) new List <SceneElement>(); foreach (SceneNode sceneNode in viewModel.ChildPropertySelectionSet.Selection) { SceneElement sceneElement = sceneNode.Parent as SceneElement; list.Add(sceneElement); } } if (list == null) { return; } IProperty targetProperty = viewModel.ProjectContext.ResolveProperty(PasteCommand.ChildSceneNodeToPropertyId(childProperty)); foreach (SceneElement sceneElement in (IEnumerable <SceneElement>)list) { PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(sceneElement, targetProperty); if (sceneInsertionPoint.CanInsert((ITypeId)childProperty.Type)) { if (ProjectNeutralTypes.BehaviorTriggerBase.IsAssignableFrom((ITypeId)childProperty.Type)) { BehaviorTriggerBaseNode behaviorTriggerBaseNode1 = (BehaviorTriggerBaseNode)childProperty; bool flag = true; foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)behaviorTriggerBaseNode1.Actions) { if (!sceneInsertionPoint.CanInsert((ITypeId)sceneNode.Type)) { flag = false; break; } } if (flag) { ISceneNodeCollection <SceneNode> collectionForProperty = sceneElement.GetCollectionForProperty((IPropertyId)targetProperty); BehaviorTriggerBaseNode behaviorTriggerBaseNode2 = BehaviorHelper.FindMatchingTriggerNode(behaviorTriggerBaseNode1.DocumentNode, collectionForProperty); if (behaviorTriggerBaseNode2 == null) { DocumentNode node = behaviorTriggerBaseNode1.DocumentNode.Clone(behaviorTriggerBaseNode1.DocumentContext); behaviorTriggerBaseNode2 = (BehaviorTriggerBaseNode)viewModel.GetSceneNode(node); collectionForProperty.Add((SceneNode)behaviorTriggerBaseNode2); } else { DocumentNode node = behaviorTriggerBaseNode1.Actions[0].DocumentNode.Clone(behaviorTriggerBaseNode1.Actions[0].DocumentNode.Context); BehaviorTriggerActionNode triggerActionNode = (BehaviorTriggerActionNode)viewModel.GetSceneNode(node); behaviorTriggerBaseNode2.Actions.Add((SceneNode)triggerActionNode); } BehaviorEventTriggerNode eventTriggerNode = behaviorTriggerBaseNode2 as BehaviorEventTriggerNode; if (eventTriggerNode != null) { BehaviorEventTriggerNode.FixUpEventName(eventTriggerNode); } } else { continue; } } else { DocumentNode node = childProperty.DocumentNode.Clone(childProperty.DocumentNode.Context); SceneNode sceneNode = viewModel.GetSceneNode(node); sceneInsertionPoint.Insert(sceneNode); if (sceneNode is EffectNode) { pastedNodes.Add(sceneNode); } } TimelineItem timelineItem = viewModel.TimelineItemManager.FindTimelineItem((SceneNode)sceneElement); if (timelineItem != null) { timelineItem.IsExpanded = true; } } } }
public override void Execute() { string fileName = "test"; IProject activeProject = this.DesignerContext.ActiveProject; TemplateItemHelper templateItemHelper = new TemplateItemHelper(activeProject, (IList <string>)null, (IServiceProvider)this.DesignerContext.Services); IProjectItemTemplate templateItem = templateItemHelper.FindTemplateItem("UserControl"); if (templateItem == null) { this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlTemplateNotFound); } else { SceneViewModel activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel; List <SceneElement> elements = new List <SceneElement>(); elements.AddRange((IEnumerable <SceneElement>)activeSceneViewModel.ElementSelectionSet.Selection); elements.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(activeSceneViewModel.RootNode)); if (this.ShowUI) { string recommendedName = this.GetRecommendedName((IEnumerable <SceneElement>)elements); MakeUserControlDialog userControlDialog = new MakeUserControlDialog(this.DesignerContext, this.DialogTitle, templateItemHelper, recommendedName); bool?nullable = userControlDialog.ShowDialog(); if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0) { return; } fileName = userControlDialog.ControlName; } List <IProjectItem> itemsToOpen = (List <IProjectItem>)null; IProjectItem projectItem1 = (IProjectItem)null; IEnumerable <IProjectItem> source = (IEnumerable <IProjectItem>)null; try { source = templateItemHelper.AddProjectItemsForTemplateItem(templateItem, fileName, this.DesignerContext.ProjectManager.TargetFolderForProject(activeProject), CreationOptions.DoNotAllowOverwrites | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath, out itemsToOpen); } catch (Exception ex) { if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex)) { this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ProjectNewFileErrorDialogMessage, new object[2] { (object)fileName, (object)ex.Message })); } else { throw; } } if (source == null || EnumerableExtensions.CountIsLessThan <IProjectItem>(source, 1)) { return; } if (itemsToOpen != null && itemsToOpen.Count > 0) { projectItem1 = Enumerable.FirstOrDefault <IProjectItem>((IEnumerable <IProjectItem>)itemsToOpen); projectItem1.OpenDocument(false, true); } if (projectItem1 != null && projectItem1.IsOpen && projectItem1.DocumentType.CanView) { Rect empty = Rect.Empty; for (int index = 0; index < elements.Count; ++index) { BaseFrameworkElement child = elements[index] as BaseFrameworkElement; if (child != null) { Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child); empty.Union(childRect); } } Rect rect = RoundingHelper.RoundRect(empty); SceneElement parentElement = elements[0].ParentElement; bool useLayoutRounding = LayoutRoundingHelper.GetUseLayoutRounding(parentElement); DataObject dataObject = (DataObject)null; using (activeSceneViewModel.ForceBaseValue()) { PastePackage pastePackage = new PastePackage(activeSceneViewModel); pastePackage.CopyStoryboardsReferencingElements = true; pastePackage.AddElements(elements); dataObject = pastePackage.GetPasteDataObject(); } SceneView sceneView = projectItem1.OpenView(true) as SceneView; if (sceneView != null) { SceneViewModel viewModel = sceneView.ViewModel; ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(viewModel.ViewRoot.ProjectContext); ClassAttributes rootClassAttributes = viewModel.DocumentRoot.RootClassAttributes; ITypeId typeId = (ITypeId)null; if (projectXamlContext != null && rootClassAttributes != null) { projectXamlContext.RefreshUnbuiltTypeDescriptions(); if (rootClassAttributes != null) { typeId = (ITypeId)projectXamlContext.GetType(projectXamlContext.ProjectAssembly.Name, rootClassAttributes.QualifiedClassName); } } if (typeId != null && this.CheckForCircularReference((IEnumerable <SceneElement>)elements, typeId)) { this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlCircularReferenceFound); this.CleanupAfterCancel(projectItem1); return; } using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl)) { if (!rect.IsEmpty) { viewModel.RootNode.SetValue(DesignTimeProperties.DesignWidthProperty, (object)rect.Width); viewModel.RootNode.SetValue(DesignTimeProperties.DesignHeightProperty, (object)rect.Height); if (this.AddToApplicationFlow) { viewModel.RootNode.SetValue(BaseFrameworkElement.WidthProperty, (object)rect.Width); viewModel.RootNode.SetValue(BaseFrameworkElement.HeightProperty, (object)rect.Height); } } IProperty property = LayoutRoundingHelper.ResolveUseLayoutRoundingProperty(viewModel.RootNode); if (property != null) { viewModel.RootNode.SetValue((IPropertyId)property, (object)(bool)(useLayoutRounding ? true : false)); } ILayoutDesigner designerForParent = viewModel.GetLayoutDesignerForParent(viewModel.ActiveSceneInsertionPoint.SceneElement, true); bool canceledPasteOperation; ICollection <SceneNode> nodes = PasteCommand.PasteData(viewModel, new SafeDataObject((IDataObject)dataObject), viewModel.ActiveSceneInsertionPoint, out canceledPasteOperation); if (canceledPasteOperation) { editTransaction.Cancel(); this.CleanupAfterCancel(projectItem1); return; } editTransaction.Update(); if (nodes.Count > 0) { viewModel.DefaultView.UpdateLayout(); viewModel.SelectNodes(nodes); if (designerForParent != null) { foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)nodes) { BaseFrameworkElement child = sceneNode as BaseFrameworkElement; if (child != null && child.IsViewObjectValid) { Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child); childRect.Location = (Point)(childRect.Location - rect.Location); designerForParent.SetChildRect(child, childRect); } } } } editTransaction.Commit(); } if (this.AddToApplicationFlow && this.DesignerContext.PrototypingService != null) { this.DesignerContext.PrototypingService.PromoteToCompositionScreen(projectItem1); } if (typeId != null) { using (activeSceneViewModel.ForceBaseValue()) { using (activeSceneViewModel.DisableDrawIntoState()) { using (SceneEditTransaction editTransaction = activeSceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl)) { using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { SceneElement primarySelection = activeSceneViewModel.ElementSelectionSet.PrimarySelection; IProperty propertyForChild = parentElement.GetPropertyForChild((SceneNode)primarySelection); PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(parentElement, propertyForChild); SceneNode sceneNode = (SceneNode)null; if (sceneInsertionPoint.CanInsert(typeId)) { foreach (SceneElement element in elements) { if (element != primarySelection) { activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element); element.Remove(); } } ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)propertyForChild); int index = collectionForProperty.IndexOf((SceneNode)primarySelection); activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection); primarySelection.Remove(); sceneNode = activeSceneViewModel.CreateSceneNode(typeId); collectionForProperty.Insert(index, sceneNode); this.DesignerContext.ViewService.ActiveView = (IView)activeSceneViewModel.DefaultView; editTransaction.Update(); activeSceneViewModel.DefaultView.UpdateLayout(); BaseFrameworkElement child = sceneNode as BaseFrameworkElement; if (child != null && child.IsViewObjectValid) { activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true).SetChildRect(child, rect); } } if (this.AddToApplicationFlow) { if (sceneNode != null) { sceneNode.SetValue(DesignTimeProperties.IsPrototypingCompositionProperty, (object)true); } } } editTransaction.Commit(); } } } this.DesignerContext.ViewService.ActiveView = (IView)viewModel.DefaultView; } } } if (itemsToOpen == null || itemsToOpen.Count <= 1) { return; } foreach (IProjectItem projectItem2 in itemsToOpen) { if (projectItem1 != projectItem2) { projectItem2.OpenView(true); } } } }