Ejemplo n.º 1
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");
        }
Ejemplo n.º 2
0
        private ContextMenu BuildResourceContextMenu(ReadOnlyCollection <ResourceEntryBase> selection)
        {
            ContextMenu contextMenu = new ContextMenu();

            if (selection.Count == 1)
            {
                ResourceEntryBase resourceEntryBase = selection[0];
                ResourceEntryItem resourceEntryItem = resourceEntryBase as ResourceEntryItem;
                if (resourceEntryItem != null)
                {
                    TypedResourceItem typedResourceItem = resourceEntryItem as TypedResourceItem;
                    if (typedResourceItem != null)
                    {
                        contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemEdit, "ResourceEntryItem_Edit", typedResourceItem.EditCommand));
                    }
                }
                ResourceDictionaryItem resourceDictionaryItem = resourceEntryBase as ResourceDictionaryItem;
                if (resourceDictionaryItem != null)
                {
                    contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemEdit, "ResourceDictionaryItem_Edit", resourceDictionaryItem.EditCommand));
                }
                ResourceContainer targetContainer = resourceEntryBase as ResourceContainer;
                if (resourceEntryBase == this.activeDocumentWrapper)
                {
                    targetContainer = this.resourceManager.ActiveRootContainer;
                }
                if (targetContainer != null && targetContainer.DocumentContext != null && resourceEntryBase.DocumentNode != null && (targetContainer is DocumentResourceContainer || targetContainer is NodeResourceContainer))
                {
                    IProject project = ProjectHelper.GetProject(this.DesignerContext.ProjectManager, targetContainer.DocumentContext);
                    if (project != null)
                    {
                        if (project.FindItem(targetContainer.DocumentReference).ContainsDesignTimeResources)
                        {
                            MenuItem menuItem = this.CreateItem(StringTable.DesignTimeResourcesAddDictionary, "ResourceContainer_LinkToDesignTimeResources", (ICommand) new ResourcePane.LinkToDesignTimeResourceCommand(this.DesignerContext, targetContainer));
                            contextMenu.Items.Add((object)menuItem);
                        }
                        else
                        {
                            IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
                            if (projectContext != null)
                            {
                                MenuItem menuItem1 = this.CreateItem(StringTable.UndoUnitLinkToResourceDictionary, "ResourceContainer_LinkToResources", (ICommand)null);
                                foreach (DocumentResourceContainer resourceContainer in (Collection <DocumentResourceContainer>) this.resourceManager.DocumentResourceContainers)
                                {
                                    if (resourceContainer.DocumentReference != targetContainer.DocumentReference && resourceContainer.Document != null && (resourceContainer.Document.DocumentRoot != null && resourceContainer.Document.DocumentRoot.RootNode != null) && (resourceContainer.ProjectContext != null && !resourceContainer.ProjectItem.ContainsDesignTimeResources && PlatformTypes.ResourceDictionary.IsAssignableFrom((ITypeId)resourceContainer.Document.DocumentRoot.RootNode.Type)) && (resourceContainer.ProjectContext == projectContext || ProjectHelper.DoesProjectReferencesContainTarget(project, resourceContainer.ProjectContext)))
                                    {
                                        ResourcePane.LinkToResourcesCommand resourcesCommand = new ResourcePane.LinkToResourcesCommand(this.resourceManager, targetContainer, resourceContainer.ProjectItem);
                                        MenuItem menuItem2 = this.CreateItem(resourceContainer.Name, resourceContainer.Name, (ICommand)resourcesCommand);
                                        menuItem2.IsCheckable = true;
                                        menuItem2.SetBinding(MenuItem.IsCheckedProperty, (BindingBase) new Binding("IsChecked")
                                        {
                                            Source = (object)resourcesCommand,
                                            Mode   = BindingMode.OneTime
                                        });
                                        menuItem1.Items.Add((object)menuItem2);
                                    }
                                }
                                if (menuItem1.Items.Count == 0)
                                {
                                    MenuItem menuItem2 = this.CreateItem(StringTable.ResourcePaneNoDictionaries, (string)null, (ICommand)null);
                                    menuItem2.IsEnabled = false;
                                    menuItem1.Items.Add((object)menuItem2);
                                }
                                contextMenu.Items.Add((object)menuItem1);
                            }
                        }
                    }
                }
                if (contextMenu.Items.Count > 0)
                {
                    contextMenu.Items.Add((object)new Separator());
                }
            }
            contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemCut, "ResourcePane_Cut", this.CutCommand));
            contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemCopy, "ResourcePane_Copy", this.CopyCommand));
            contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemPaste, "ResourcePane_Paste", this.PasteCommand));
            contextMenu.Items.Add((object)this.CreateItem(StringTable.ResourceItemDelete, "ResourcePane_Delete", this.DeleteCommand));
            contextMenu.Items.Add((object)new Separator());
            contextMenu.Items.Add((object)this.CreateItem(StringTable.ViewXamlCommandName, "ResourcePane_ViewXaml", this.ViewXamlCommand));
            return(contextMenu);
        }
Ejemplo n.º 3
0
        public virtual bool CanInsertTo(IProjectItem projectItem, IView view, ISceneInsertionPoint insertionPoint)
        {
            if (projectItem.Project == null)
            {
                return(false);
            }
            SceneView sceneView = view as SceneView;

            if (sceneView == null || !sceneView.IsDesignSurfaceEnabled || insertionPoint == null)
            {
                return(false);
            }
            ViewState viewState = ViewState.ElementValid | ViewState.AncestorValid;

            if ((sceneView.GetViewState(insertionPoint.SceneNode) & viewState) != viewState)
            {
                return(false);
            }
            ProjectContext projectContext = (ProjectContext)ProjectXamlContext.GetProjectContext(projectItem.Project);

            if (projectContext == null)
            {
                return(false);
            }
            IProject project = ProjectHelper.GetProject(this.designerContext.ProjectManager, sceneView.Document.DocumentContext);

            return(project != null && (projectContext == sceneView.Document.ProjectContext || ProjectHelper.DoesProjectReferencesContainTarget(project, (IProjectContext)projectContext)) && ((!this.IsContentOrNoneBuildItem(projectItem) || projectItem.Project == project) && this.CanAddToProject(project)));
        }