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))); }
public DocumentNode GetThemeResourceFromProject(IProject project, object resourceKey, out IList <DocumentCompositeNode> auxillaryResources) { auxillaryResources = (IList <DocumentCompositeNode>)null; IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project); if (projectContext == null) { return((DocumentNode)null); } string rootDirectory = Path.Combine(project.ProjectRoot.Path, "Themes"); foreach (string currentTheme in ThemeContentProvider.GetThemeNames(projectContext)) { DocumentReference fileThemeReference = ThemeContentProvider.GetFileThemeReference(rootDirectory, currentTheme); IProjectItem projectItem = project.FindItem(fileThemeReference); if (projectItem != null) { ResourceDictionaryContentProvider resourceDictionary = this.designerContext.ResourceManager.GetContentProviderForResourceDictionary(projectItem); if (resourceDictionary != null) { DocumentNode projectResource = this.FindProjectResource(project, resourceDictionary, projectItem.DocumentReference.Path, resourceKey, out auxillaryResources); if (projectResource != null) { return(projectResource); } } } } return((DocumentNode)null); }
public override bool CanAddToProject(IProject project) { if ((IProjectContext)ProjectXamlContext.GetProjectContext(project) == null) { return(false); } return(base.CanAddToProject(project)); }
private void ProjectManager_ProjectOpened(object sender, ProjectEventArgs e) { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(e.Project); if (projectContext == null) { return; } this.AddProjectContextHandlers(projectContext); }
public override bool CanAddToProject(IProject project) { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project); if (projectContext == null || !JoltHelper.TypeSupported((ITypeResolver)projectContext, PlatformTypes.ModelVisual3D)) { return(false); } return(base.CanAddToProject(project)); }
public override bool CanAddToProject(IProject project) { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project); if (projectContext == null || !projectContext.IsCapabilitySet(PlatformCapability.IsWpf)) { return(false); } return(base.CanAddToProject(project)); }
private bool AddReferences(IProjectContext projectContext, ReplaceStyleTemplateCommand.ExtraReferences references, string resourceKey) { ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(projectContext); if (projectXamlContext == null) { return(false); } if (references.Assemblies.Count > 0) { ISolution currentSolution = this.DesignerContext.ProjectManager.CurrentSolution; if (currentSolution != null) { List <IProject> list1 = new List <IProject>(); List <IProjectContext> list2 = new List <IProjectContext>(); foreach (IProject project in currentSolution.Projects) { ProjectXamlContext projectContext1 = ProjectXamlContext.GetProjectContext(project); if (projectContext1 != null && projectContext1.ProjectAssembly != null && references.Assemblies.Contains(projectContext1.ProjectAssembly)) { list1.Add(project); list2.Add((IProjectContext)projectContext1); } } for (int index = 0; index < list1.Count; ++index) { IProject source = list1[index]; IProjectContext projectContext1 = list2[index]; if (projectXamlContext != projectContext1 && ProjectHelper.DoesProjectReferenceHierarchyContainTarget(source, (IProjectContext)projectXamlContext)) { this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.DocumentRefersToUnresolvedTypesHeader, new object[1] { (object)resourceKey })); return(false); } } } foreach (IAssembly assembly in (IEnumerable <IAssembly>)references.Assemblies) { projectXamlContext.EnsureAssemblyReferenceMatches(this.SceneViewModel.ProjectContext, assembly); } } foreach (string assemblyPath in (IEnumerable <string>)references.PlatformAssemblies) { projectXamlContext.EnsureAssemblyReferenced(assemblyPath); } this.SceneViewModel.DesignerContext.ViewUpdateManager.RebuildPostponedViews(); return(true); }
protected override bool CreateProjectItem() { IProject project = this.targetedProject != null ? this.targetedProject : ProjectCommandExtensions.SelectedProjectOrNull((IProjectCommand)this); if (project == null) { return(false); } bool flag = false; string[] filesToImport = this.GetFilesToImport(this.importedPathFilter != null ? this.importedPathFilter : this.GetImportFolder()); if (filesToImport != null && filesToImport.Length > 0) { foreach (string str in filesToImport) { string withoutExtension = Path.GetFileNameWithoutExtension(str); ProjectAssembly projectAssembly = project.ReferencedAssemblies.Find(withoutExtension); if (projectAssembly != null && !projectAssembly.IsImplicitlyResolved) { ProjectCommandExtensions.DisplayCommandFailedMessage((IProjectCommand)this, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, StringTable.ReferenceExistsErrorDialogMessage, new object[2] { (object)str, (object)withoutExtension })); } else { IProjectItem projectItem = project.AddAssemblyReference(str, true); if (projectItem != null) { ProjectCommandExtensions.ProjectManager((IProjectCommand)this).DefaultImportPath = Path.GetDirectoryName(str); ProjectCommandExtensions.ProjectManager((IProjectCommand)this).ItemSelectionSet.Clear(); ProjectCommandExtensions.ProjectManager((IProjectCommand)this).ItemSelectionSet.ToggleSelection((IDocumentItem)projectItem); } ProjectXamlContext projectContext = ProjectXamlContext.GetProjectContext(project); if (projectContext != null) { projectContext.EnsureAssemblyReferenced(str); } if (projectItem != null) { flag = true; } } } } return(flag); }
private void TryAddItem(IProjectItem projectItem) { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(projectItem.Project); if (projectContext == null) { return; } IProjectDocument document1 = projectContext.GetDocument(DocumentReferenceLocator.GetDocumentLocator(projectItem.DocumentReference)); if (document1 != null && document1.DocumentType == ProjectDocumentType.ResourceDictionary && this.FindProvider(projectItem) == null) { IDocument document2 = projectItem.Document; this.ProjectResourceAssetAggregator.AddProvider((AssetProvider) new ResourceDictionaryAssetProvider(this.DesignerContext.ResourceManager.GetContentProviderForResourceDictionary(projectItem))); } this.ProjectAssetProvider.NeedsUpdate = true; }
public override bool IsValidStartupItem(IProjectItem projectItem) { if (this.IsControlLibrary) { return(base.IsValidStartupItem(projectItem)); } ProjectXamlContext projectContext = ProjectXamlContext.GetProjectContext((IProject)this); if (projectItem != null && projectContext != null) { IProjectDocument document = projectContext.GetDocument(DocumentReferenceLocator.GetDocumentLocator(projectItem.DocumentReference)); if (document != null && document.DocumentType == ProjectDocumentType.Page) { return(true); } } return(false); }
private void ProjectManager_ProjectClosing(object sender, ProjectEventArgs e) { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(e.Project); List <SceneDocument> list1 = (List <SceneDocument>)null; if (projectContext == null) { return; } this.MarkViewsForClosing(projectContext); this.RemoveProjectContextHandlers(projectContext); if (!this.watchedDocumentsForProjectContext.TryGetValue(projectContext, out list1)) { return; } foreach (SceneDocument sceneDocument in new List <SceneDocument>((IEnumerable <SceneDocument>)list1)) { List <SceneView> list2; if (this.primaryViewsForDocument.TryGetValue(sceneDocument, out list2)) { foreach (SceneView sceneView in list2) { this.UnregisterRelatedDocuments(sceneView); } this.primaryViewsForDocument.Remove(sceneDocument); } List <SceneView> list3; if (this.relatedViewsForDocument.TryGetValue(sceneDocument, out list3)) { foreach (SceneView sceneView in new List <SceneView>((IEnumerable <SceneView>)list3)) { if (sceneView.ProjectContext == projectContext) { sceneView.SuspendUpdatesForViewShutdown(); } this.UnregisterRelatedDocumentInternal(sceneView, sceneDocument); this.relatedDocumentsForView[sceneView].Remove(sceneDocument); } } this.RemoveHandlers(sceneDocument); } }
internal SceneDocument CreateDocument(IProject project, IProjectItem projectItem, ITextBuffer textBuffer, bool isReadOnly, Encoding encoding) { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project); DocumentReference documentReference = projectItem.DocumentReference; DocumentContext documentContext = DocumentContextHelper.CreateDocumentContext(project, projectContext, DocumentReferenceLocator.GetDocumentLocator(documentReference), projectItem.Properties["BuildAction"] == "Content"); SceneXamlDocument xamlDocument = new SceneXamlDocument((IDocumentContext)documentContext, (IUndoService) new UndoService(), PlatformTypes.Object, textBuffer, encoding); if (xamlDocument.ParseErrorsCount > 0) { IErrorService errorManager = this.designerContext.ErrorManager; if (errorManager != null) { errorManager.DisplayErrors(); } } SceneDocument sceneDocument = this.CreateSceneDocument(documentReference, xamlDocument, isReadOnly, this.designerContext); documentContext.DocumentLocator = (IDocumentLocator)sceneDocument; return(sceneDocument); }
protected virtual DocumentNode ResolveDefaultStyleAsDocumentNode(IType targetType, IPropertyId propertyKey) { DocumentNode node = (DocumentNode)null; IViewStyle viewStyle = (IViewStyle)null; if (this.IsViewObjectValid) { ReferenceStep referenceStep = propertyKey as ReferenceStep; if (referenceStep != null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf)) { viewStyle = this.Platform.ViewObjectFactory.Instantiate(referenceStep.GetCurrentValue(this.ViewObject.PlatformSpecificObject)) as IViewStyle; if (viewStyle != null && viewStyle.StyleTargetType != targetType.RuntimeType) { viewStyle = (IViewStyle)null; } if (viewStyle != null) { node = this.ViewModel.DefaultView.GetCorrespondingDocumentNode((IViewObject)viewStyle, true); if (node == null && this.DesignerContext.DesignerDefaultPlatformService.DefaultPlatform == this.Platform) { node = this.CreateNode(viewStyle.PlatformSpecificObject); } } } } for (IType type = this.ProjectContext.GetType(this.MetadataFactory.GetMetadata(targetType.RuntimeType).GetStylePropertyTargetType(propertyKey)); node == null && type != null && !PlatformTypes.Object.Equals((object)type); type = type.BaseType) { IList <DocumentCompositeNode> auxillaryResources = (IList <DocumentCompositeNode>)null; if (PlatformTypes.IsPlatformType((ITypeId)type)) { node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromPlatform(this.Platform, (object)type.RuntimeType, out auxillaryResources); } else { foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects) { IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project); if (projectContext != null && type.RuntimeAssembly.Equals((object)projectContext.ProjectAssembly)) { node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromProject(project, (object)type.RuntimeType, out auxillaryResources); if (node == null && !this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf)) { node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromAssembly(this.ProjectContext, type.RuntimeAssembly, type.RuntimeAssembly, (object)type.RuntimeType, out auxillaryResources); } } } } if (node != null) { node = node.Clone(this.DocumentContext); if (auxillaryResources != null && auxillaryResources.Count > 0) { StyleNode styleNode = (StyleNode)this.ViewModel.GetSceneNode(node); if (styleNode.AreResourcesSupported) { if (styleNode.Resources == null) { styleNode.Resources = (ResourceDictionaryNode)this.ViewModel.CreateSceneNode(PlatformTypes.ResourceDictionary); } for (int index = auxillaryResources.Count - 1; index >= 0; --index) { DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)this.ViewModel.GetSceneNode(auxillaryResources[index].Clone(this.DocumentContext)); styleNode.Resources.Insert(0, dictionaryEntryNode); } } } } } if (viewStyle == null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf)) { ReferenceStep referenceStep = propertyKey as ReferenceStep; if (referenceStep != null) { System.Windows.Style style = referenceStep.GetDefaultValue(targetType.RuntimeType) as System.Windows.Style; if (style != null) { node = this.CreateNode((object)style); } } } return(node); }
private void ResolveDefaultStyle(SceneElement targetElement, object defaultStyleKey, bool allowDefaultStyle, out DocumentNode currentStyle, out bool isThemeStyle, out IList <DocumentCompositeNode> auxillaryResources) { IProjectContext projectContext1 = this.SceneViewModel.ProjectContext; ThemeContentProvider themeContentProvider = this.DesignerContext.ThemeContentProvider; currentStyle = (DocumentNode)null; isThemeStyle = false; auxillaryResources = (IList <DocumentCompositeNode>)null; if (defaultStyleKey == null) { return; } IAssembly runtimeAssembly = targetElement.Type.RuntimeAssembly; IAssembly targetAssembly = PlatformTypeHelper.GetTargetAssembly(targetElement.Type); Type type1 = defaultStyleKey as Type; if (type1 != (Type)null) { ITypeId typeId = (ITypeId)projectContext1.GetType(type1); if (typeId != null) { IType type2 = projectContext1.ResolveType(typeId); runtimeAssembly = type2.RuntimeAssembly; targetAssembly = PlatformTypeHelper.GetTargetAssembly(type2); } } IAssembly designAssembly = projectContext1.GetDesignAssembly(runtimeAssembly); if (designAssembly != null) { currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, designAssembly, designAssembly, defaultStyleKey, out auxillaryResources); if (currentStyle != null) { return; } } if (!PlatformTypes.IsPlatformType((ITypeId)this.Type)) { foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects) { IProjectContext projectContext2 = (IProjectContext)ProjectXamlContext.GetProjectContext(project); if (projectContext2 != null && runtimeAssembly.Equals((object)projectContext2.ProjectAssembly)) { currentStyle = themeContentProvider.GetThemeResourceFromProject(project, defaultStyleKey, out auxillaryResources); if (currentStyle != null) { return; } } } } else if (!allowDefaultStyle || projectContext1.PlatformMetadata.TargetFramework.Identifier == ".NETFramework" && projectContext1.PlatformMetadata.TargetFramework.Version < projectContext1.PlatformMetadata.RuntimeFramework.Version) { currentStyle = themeContentProvider.GetThemeResourceFromPlatform(projectContext1.Platform, defaultStyleKey, out auxillaryResources); if (currentStyle != null) { isThemeStyle = true; return; } } if (!projectContext1.IsCapabilitySet(PlatformCapability.IsWpf)) { currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, runtimeAssembly, targetAssembly, defaultStyleKey, out auxillaryResources); isThemeStyle = currentStyle != null; } else { object resource = this.SceneViewModel.FindResource(defaultStyleKey); if (resource == null) { return; } if (projectContext1 != null && projectContext1.IsCapabilitySet(PlatformCapability.VsmInToolkit) && (projectContext1.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager) && projectContext1.PlatformMetadata.IsNullType((ITypeId)projectContext1.ResolveType(ProjectNeutralTypes.VisualStateManager)))) { IAssembly usingAssemblyName = projectContext1.Platform.Metadata.GetPlatformAssemblyUsingAssemblyName(targetElement.Type.RuntimeAssembly); if (usingAssemblyName == null || !AssemblyHelper.IsPlatformAssembly(usingAssemblyName)) { IDocumentContext documentContext = (IDocumentContext) new DocumentContext((IProjectContext) new ToolkitProjectContext(projectContext1), ((DocumentContext)this.SceneViewModel.Document.DocumentContext).DocumentLocator); DocumentNode node = documentContext.CreateNode(resource.GetType(), resource); if (ProjectAttributeHelper.GetDefaultStateRecords(this.Type, (ITypeResolver)(documentContext.TypeResolver as ProjectContext)).Count > 0 || (DocumentCompositeNode)node.FindFirst(new Predicate <DocumentNode>(this.SelectVisualStateGroupPredicate)) != null) { ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext1, this.DesignerContext.ViewUpdateManager); } } } SceneNode sceneNode = this.SceneViewModel.CreateSceneNode(resource); if (!PlatformTypes.Style.IsAssignableFrom((ITypeId)sceneNode.Type)) { return; } currentStyle = sceneNode.DocumentNode; } }
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); }
internal static bool DoesProjectReferencesContainTarget(IProject source, IProjectContext target) { return(Enumerable.Any <IProject>(source.ReferencedProjects, (Func <IProject, bool>)(project => ProjectXamlContext.GetProjectContext(project) == target))); }
internal static bool DoesProjectReferenceHierarchyContainTarget(IProject source, IProjectContext target) { IndexedHashSet <IProject> projects = new IndexedHashSet <IProject>(); ProjectHelper.BuildProjectReferences(source, projects); return(Enumerable.Any <IProject>((IEnumerable <IProject>)projects, (Func <IProject, bool>)(project => ProjectXamlContext.GetProjectContext(project) == target))); }
public override bool CanAddToProject(IProject project) { if ((IProjectContext) ProjectXamlContext.GetProjectContext(project) == null) return false; return base.CanAddToProject(project); }