Exemple #1
0
        private static IList <ResourceEvaluation> EvaluateResourcesInternal(IList <DictionaryEntryNode> resources, SceneNode destination)
        {
            SceneViewModel            viewModel = destination.ViewModel;
            List <ResourceEvaluation> list      = new List <ResourceEvaluation>();

            foreach (DictionaryEntryNode originalResource in (IEnumerable <DictionaryEntryNode>)resources)
            {
                DocumentNode documentNode = (DocumentNode)null;
                SceneNode    keyNode      = originalResource.KeyNode;
                if (keyNode != null)
                {
                    documentNode = new ExpressionEvaluator(viewModel.DocumentRootResolver).EvaluateResource(destination.DocumentNodePath, keyNode.DocumentNode);
                }
                if (documentNode == null)
                {
                    list.Add(new ResourceEvaluation(originalResource, (DocumentNode)null, ResourceEvaluationResult.NoExistingResource));
                }
                else
                {
                    ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(destination.DocumentNode);
                    bool flag = resourcesCollection != null && resourcesCollection.Resources == documentNode.Parent.Parent;
                    if (ResourceHelper.NodeTreesAreEquivalent(viewModel, originalResource.Value.DocumentNode, documentNode))
                    {
                        list.Add(new ResourceEvaluation(originalResource, documentNode, flag ? ResourceEvaluationResult.IdenticalResourceExists : ResourceEvaluationResult.IdenticalResourceIsMasked));
                    }
                    else
                    {
                        list.Add(new ResourceEvaluation(originalResource, documentNode, flag ? ResourceEvaluationResult.ConflictingResourceExists : ResourceEvaluationResult.ConflictingResourceIsMasked));
                    }
                }
            }
            return((IList <ResourceEvaluation>)list);
        }
Exemple #2
0
 private void OnViewUpdated(SceneUpdatePhaseEventArgs args)
 {
     if (this.view != null && this.Document != null && this.Document.IsEditable)
     {
         ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(this.Document.RootNode);
         if (resourcesCollection != null)
         {
             DocumentNode node = (DocumentNode)resourcesCollection.Resources;
             if (node != null)
             {
                 this.resourceSubscription.SetBasisNodes(this.ViewModel, (IEnumerable <SceneNode>) new List <SceneNode>()
                 {
                     this.ViewModel.GetSceneNode(node)
                 });
                 this.resourceSubscription.Update(this.ViewModel, args.DocumentChanges, args.DocumentChangeStamp);
             }
         }
     }
     else
     {
         this.needsRebuild = true;
         this.resourceSubscription.SetBasisNodes(this.ViewModel, (IEnumerable <SceneNode>) new List <SceneNode>());
     }
     if (!this.needsRebuild)
     {
         return;
     }
     this.OnItemsChanged();
 }
Exemple #3
0
        private void UpdateAsync()
        {
            SelectedElementsResourceObserver.UpdateState updateState = this.updateState;
            this.updateState = SelectedElementsResourceObserver.UpdateState.None;
            List <DocumentNode> list1 = this.oldNodesAsync;
            List <DocumentNode> list2 = this.newNodesAsync;

            this.oldNodesAsync = new List <DocumentNode>();
            this.newNodesAsync = new List <DocumentNode>();
            if (updateState == SelectedElementsResourceObserver.UpdateState.Catastrophic)
            {
                this.Update(this.ViewModel, SceneViewModel.ViewStateBits.EntireScene);
            }
            foreach (DocumentNode documentNode in list2)
            {
                foreach (ResourceContainer resourceContainer in this.ResourceManager.ActiveSceneViewModel == null || documentNode.DocumentRoot != this.ResourceManager.ActiveSceneViewModel.DocumentRoot ? (IEnumerable)this.ResourceManager.DocumentResourceContainers : (IEnumerable)this.ResourceManager.LocalResourceContainers)
                {
                    if (resourceContainer.DocumentNode != null && ResourceNodeHelper.GetResourcesCollection(resourceContainer.DocumentNode).Resources == documentNode.Parent)
                    {
                        foreach (ResourceItem resourceItem in (Collection <ResourceItem>)resourceContainer.ResourceItems)
                        {
                            if (resourceItem.DocumentNode == documentNode)
                            {
                                this.AddRefItem(resourceItem);
                                break;
                            }
                        }
                    }
                }
            }
            foreach (DocumentNode documentNode in list1)
            {
                foreach (ResourceItem resourceItem in (Collection <ResourceItem>) this.ResourceItems)
                {
                    if (resourceItem.DocumentNode == documentNode)
                    {
                        this.RemoveItem(resourceItem);
                        break;
                    }
                }
            }
        }
Exemple #4
0
        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);
        }