Ejemplo n.º 1
0
 public CreateResourceModel(SceneViewModel viewModel, ResourceManager resourceManager, Type resourceType, Type targetType, string targetPropertyName, SceneElement explicitResourcesHost, SceneNode nearestResourceScopeElement, CreateResourceModel.ContextFlags contextFlags)
 {
     this.viewModel                   = viewModel;
     this.targetPropertyName          = targetPropertyName;
     this.nearestResourceScopeElement = nearestResourceScopeElement;
     this.contextFlags                = contextFlags;
     this.resourceType                = resourceType;
     this.targetType                  = targetType;
     this.applicationDocument         = this.viewModel.Document.ApplicationSceneDocument;
     this.selectedLocation            = (object)this.thisDocumentResourceDictionaries;
     this.UpdateResourceList(resourceManager);
     if (explicitResourcesHost != null)
     {
         bool flag = false;
         foreach (Named <ResourceContainer> named in (Collection <Named <ResourceContainer> >) this.thisDocumentResourceDictionaries)
         {
             if (named.Instance.DocumentNode == explicitResourcesHost.DocumentNode)
             {
                 this.SelectedResourceDictionary = named;
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             this.explicitResourcesHost = this.CreateNamedResourceContainer(new NodeResourceContainer(resourceManager, (SceneNode)explicitResourcesHost));
             this.thisDocumentResourceDictionaries.Add(this.explicitResourcesHost);
             this.SelectedLocation           = (object)this.ThisDocumentResourceDictionaries;
             this.SelectedResourceDictionary = this.explicitResourcesHost;
         }
     }
     if (this.thisDocumentResourceDictionaries.Count == 0)
     {
         bool flag = false;
         foreach (ResourceContainer resourceContainer in (Collection <ResourceContainer>) this.externalResourceDictionaries)
         {
             if (resourceContainer.Document == this.viewModel.Document)
             {
                 this.SelectedLocation = (object)this.OtherDocuments;
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             this.SelectedLocation = (object)this.applicationDocument;
         }
     }
     if (this.keyString != null)
     {
         return;
     }
     this.RegenerateUniqueResourceKey();
 }
Ejemplo n.º 2
0
        internal void UpdateResourceList(ResourceManager resourceManager)
        {
            ResourceContainer resourceContainer1 = this.selectedExternalResourceDictionaryFile;
            ResourceContainer resourceContainer2 = this.selectedResourceDictionary != null ? this.selectedResourceDictionary.Instance : resourceManager.ActiveRootContainer;

            this.externalResourceDictionaries.Clear();
            this.thisDocumentResourceDictionaries.Clear();
            this.selectedExternalResourceDictionaryFile = (ResourceContainer)null;
            this.selectedResourceDictionary             = (Named <ResourceContainer>)null;
            ResourceContainer resourceContainer3 = resourceManager.TopLevelResourceContainer;

            if (resourceManager.ActiveSceneViewModel == this.viewModel && resourceManager.ActiveRootContainer is NodeResourceContainer)
            {
                foreach (ResourceContainer resourceContainer4 in resourceManager.ActiveResourceContainers)
                {
                    if (resourceContainer4.IsInScope)
                    {
                        if (resourceContainer4 == resourceContainer3)
                        {
                            resourceContainer3 = (ResourceContainer)null;
                        }
                        NodeResourceContainer nodeResourceContainer;
                        this.thisDocumentResourceDictionaries.Add((nodeResourceContainer = resourceContainer4 as NodeResourceContainer) == null ? new Named <ResourceContainer>(resourceContainer4.Name, resourceContainer4, resourceContainer4.DocumentReference.Path) : this.CreateNamedResourceContainer(nodeResourceContainer));
                        this.AddExternalDictionaries(resourceManager, resourceContainer4);
                    }
                }
            }
            IProject currentProject = ProjectHelper.GetProject(this.viewModel.DesignerContext.ProjectManager, this.viewModel.Document.DocumentContext);

            foreach (DocumentResourceContainer resourceContainer4 in Enumerable.Where <DocumentResourceContainer>((IEnumerable <DocumentResourceContainer>)resourceManager.DocumentResourceContainers, (Func <DocumentResourceContainer, bool>)(documentContainer =>
            {
                if (!documentContainer.ProjectItem.ContainsDesignTimeResources)
                {
                    return(false);
                }
                if (documentContainer.ProjectItem.Project != currentProject)
                {
                    return(ProjectHelper.DoesProjectReferencesContainTarget(currentProject, documentContainer.ProjectContext));
                }
                return(true);
            })))
            {
                this.AddExternalDictionaries(resourceManager, (ResourceContainer)resourceContainer4);
            }
            if (resourceContainer3 != null)
            {
                if (resourceContainer3 is DocumentResourceContainer && resourceContainer3.Document != this.applicationDocument)
                {
                    this.externalResourceDictionaries.Add(resourceContainer3);
                }
                this.AddExternalDictionaries(resourceManager, resourceContainer3);
            }
            if (this.explicitResourcesHost != null)
            {
                this.thisDocumentResourceDictionaries.Add(this.explicitResourcesHost);
            }
            foreach (Named <ResourceContainer> named in (Collection <Named <ResourceContainer> >) this.thisDocumentResourceDictionaries)
            {
                if (named.Instance == resourceContainer2)
                {
                    this.SelectedResourceDictionary = named;
                    break;
                }
            }
            if (this.externalResourceDictionaries.Contains(resourceContainer1))
            {
                this.SelectedExternalResourceDictionaryFile = resourceContainer1;
            }
            this.OnPropertyChanged("CanDefineInOtherDocument");
        }