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 static List <TargetedReferenceStep> GetPropertiesFromSelection(IEnumerable <SceneNode> selectedSceneNodes) { List <TargetedReferenceStep> properties = new List <TargetedReferenceStep>(); ProjectXamlContext projectXamlContext = (ProjectXamlContext)Enumerable.First <SceneNode>(selectedSceneNodes).ProjectContext; PropertyMerger.GetMergedPropertiesForSelection(selectedSceneNodes, properties); PropertyMerger.ReferenceStepComparer referenceStepComparer = new PropertyMerger.ReferenceStepComparer(); int count = properties.Count; using (IAttachedPropertiesAccessToken propertiesAccessToken = projectXamlContext.AttachedProperties.Access()) { if (!projectXamlContext.AttachedProperties.IsFinished) { projectXamlContext.AttachedProperties.FinishedScanning += new EventHandler(PropertyMerger.OnAttachedPropertiesFinishedScanning); } foreach (IAttachedPropertyMetadata propertyMetadata in propertiesAccessToken.AllAttachedProperties()) { IType type = projectXamlContext.GetType(propertyMetadata.OwnerType); if (type != null) { DependencyPropertyReferenceStep propertyReferenceStep = type.GetMember(MemberType.AttachedProperty, propertyMetadata.Name, MemberAccessTypes.Public) as DependencyPropertyReferenceStep; if (propertyReferenceStep != null) { TargetedReferenceStep targetedReferenceStep = new TargetedReferenceStep((ReferenceStep)propertyReferenceStep, propertyReferenceStep.DeclaringType); if (properties.BinarySearch(0, count, targetedReferenceStep, (IComparer <TargetedReferenceStep>)referenceStepComparer) < 0) { properties.Add(targetedReferenceStep); } } } } } return(properties); }
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)); }
internal static void EnsureSystemWindowsInteractivityReferenced(ITypeResolver typeResolver) { IType type = typeResolver.ResolveType(BehaviorHelper.BehaviorsProperty.DeclaringTypeId); ProjectXamlContext projectXamlContext = typeResolver as ProjectXamlContext; Uri result; if (typeResolver.PlatformMetadata.IsNullType((ITypeId)type) || projectXamlContext == null || !Uri.TryCreate(type.RuntimeType.Assembly.CodeBase, UriKind.Absolute, out result)) { return; } projectXamlContext.EnsureAssemblyReferenced(result.LocalPath); }
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); }
public static bool IsSubsetFontTargetInstalled(ITypeResolver context) { ProjectXamlContext projectXamlContext = (ProjectXamlContext)context; FrameworkName targetFramework = projectXamlContext.TargetFramework; bool flag; if (!FontEmbedder.isSubsettingTaskInstalledForPlatform.TryGetValue(targetFramework, out flag)) { string buildExtensionsPath = projectXamlContext.MSBuildExtensionsPath; flag = Microsoft.Expression.Framework.Documents.PathHelper.FileExists(FontEmbedder.GetSubsetFontTargetFileName(targetFramework).Replace("$(MSBuildExtensionsPath)", buildExtensionsPath)); FontEmbedder.isSubsettingTaskInstalledForPlatform.Add(targetFramework, flag); } return(flag); }
private void RefreshAssemblies(SceneView view) { if (view == null || view.IsClosing) { return; } ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(view.ProjectContext); if (projectXamlContext == null) { return; } projectXamlContext.RefreshAssemblies(); }
public SchemaManager(ProjectXamlContext projectContext) { this.projectContext = projectContext; this.designDataManager = new DesignDataSchemaManager((IProjectContext)projectContext); this.schemaCache = new SchemaManager.WeakDocumentNodeStore <ISchema>(); this.projectContext.TypesChanged += new EventHandler <TypesChangedEventArgs>(this.ProjectContext_TypesChanged); this.projectContext.DocumentClosing += new EventHandler <ProjectDocumentEventArgs>(this.ProjectContext_DocumentClosing); this.projectContext.SampleData.SampleDataAdded += new EventHandler <SampleDataEventArgs>(this.SampleData_Added); this.projectContext.SampleData.SampleDataRemoving += new EventHandler <SampleDataEventArgs>(this.SampleData_Removing); foreach (SampleDataSet sampleDataSet in this.projectContext.SampleData.SampleDataSetCollection) { sampleDataSet.SampleTypesChanged += new SampleDataChangedEventHandler(this.SampleDataSet_TypesChanged); sampleDataSet.SampleTypesChanging += new SampleDataChangedEventHandler(this.SampleDataSet_TypesChanging); } }
public void UpdatePlatformOnSolutionChanged(IProjectContext projectContext) { if (!this.allowsInitialRestart) { return; } ProjectXamlContext projectXamlContext = projectContext as ProjectXamlContext; IPlatform platform = projectXamlContext != null ? projectXamlContext.Platform : (IPlatform)null; if (this.viewService.Views.Count == 0 && platform != null && platform.NeedsContextUpdate) { platform.ActivatePlatformContext(); } this.allowsInitialRestart = false; }
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 bool EnsureTreeControlTypeAssembly() { if (this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf)) { return(true); } ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(this.ProjectContext); if (projectXamlContext == null) { return(false); } projectXamlContext.EnsureAssemblyReferenced(DataBindingDragDropDefaultHandler.SilverlightTreeControlAssemblyName); this.DragModel.TargetNode.DesignerContext.ViewUpdateManager.RebuildPostponedViews(); return(!this.ProjectContext.PlatformMetadata.IsNullType((ITypeId)this.ProjectContext.ResolveType(DataBindingDragDropDefaultHandler.TreeControlType))); }
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 void Dispose() { if (this.projectContext != null) { this.projectContext.TypesChanged -= new EventHandler <TypesChangedEventArgs>(this.ProjectContext_TypesChanged); this.projectContext.DocumentClosing -= new EventHandler <ProjectDocumentEventArgs>(this.ProjectContext_DocumentClosing); this.projectContext.SampleData.SampleDataAdded -= new EventHandler <SampleDataEventArgs>(this.SampleData_Added); this.projectContext.SampleData.SampleDataRemoving -= new EventHandler <SampleDataEventArgs>(this.SampleData_Removing); foreach (SampleDataSet sampleDataSet in this.projectContext.SampleData.SampleDataSetCollection) { sampleDataSet.SampleTypesChanged -= new SampleDataChangedEventHandler(this.SampleDataSet_TypesChanged); sampleDataSet.SampleTypesChanging -= new SampleDataChangedEventHandler(this.SampleDataSet_TypesChanging); } this.projectContext = (ProjectXamlContext)null; this.designDataManager.Dispose(); } GC.SuppressFinalize((object)this); }
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); }
public static IType GetSourceType(IType type, ITypeResolver typeResolver) { if (typeResolver.PlatformMetadata.IsNullType((ITypeId)type)) { return(type); } DesignTypeResult designTypeResult = DesignTypeGenerator.LookupGetDesignTypeResult(type.RuntimeType); if (designTypeResult != null && !designTypeResult.IsFailed && designTypeResult.SourceType != type.RuntimeType) { ITypeResolver typeResolver1 = (ITypeResolver)ProjectXamlContext.FromProjectContext(typeResolver as IProjectContext) ?? typeResolver; IType type1 = typeResolver1.GetType(designTypeResult.SourceType); if (!typeResolver1.PlatformMetadata.IsNullType((ITypeId)type1)) { return(type1); } } return(type); }
public static ISchema GetSchemaForDataSourceInfo(DataSourceInfo dataSource) { if (dataSource == null || !dataSource.IsValidWithSource) { return((ISchema) new EmptySchema()); } string errorMessage; ISchema schema = ProjectXamlContext.FromDocumentNode(dataSource.SourceNode).SchemaManager.GetSchemaForDataSourceInternal(dataSource.SourceNode, out errorMessage); if (schema != null && !string.IsNullOrEmpty(dataSource.Path)) { DataSchemaNodePath nodePathFromPath = schema.GetNodePathFromPath(dataSource.Path); if (nodePathFromPath != null) { schema = nodePathFromPath.RelativeSchema; } } return(schema); }
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); } }
public void Rebuild() { if (this.SceneNodeProperty == null) { return; } ProjectXamlContext projectXamlContext = this.ProjectXamlContext; if (this.ProjectXamlContext != null) { SampleDataCollection sampleData = projectXamlContext.SampleData; IEnumerable <DataStoreReferenceEntry> dataStoreDataSet = this.FindDataStoreDataSet((Predicate <SampleDataSet>)(dataSet => true)); HashSet <string> hashSet = new HashSet <string>(); List <DataStorePropertyEntry> list = new List <DataStorePropertyEntry>(); list.Add(new DataStorePropertyEntry((SampleDataSet)null, StringTable.CreateNewPropertyItem, true)); this.properties = list; if (dataStoreDataSet != null) { foreach (DataStoreReferenceEntry storeReferenceEntry in dataStoreDataSet) { SampleDataSet dataStore = storeReferenceEntry.DataStore; if (!hashSet.Contains(dataStore.Name)) { hashSet.Add(dataStore.Name); for (int index = 0; index < storeReferenceEntry.DataStore.RootType.Properties.Count; ++index) { list.Add(new DataStorePropertyEntry(storeReferenceEntry.DataStore, storeReferenceEntry.DataStore.RootType.Properties[index].Name, false)); } } } if (this.editingProperty != null) { this.editingProperty = Enumerable.FirstOrDefault <DataStorePropertyEntry>(Enumerable.Where <DataStorePropertyEntry>((IEnumerable <DataStorePropertyEntry>) this.properties, (Func <DataStorePropertyEntry, bool>)(entry => entry.Name == this.SelectedProperty.Name))); } } } if (this.Rebuilt == null) { return; } this.Rebuilt((object)this, (EventArgs)null); }
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); }
private static StringComparison GetMethodNameComparison(ITypeResolver typeResolver) { StringComparison stringComparison = StringComparison.Ordinal; ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(typeResolver as IProjectContext); if (projectXamlContext == null) { return(stringComparison); } IProject project = (IProject)projectXamlContext.GetService(typeof(IProject)); if (project == null || project.CodeDocumentType == null) { return(stringComparison); } ICodeGeneratorHost codeGeneratorHost = project.CodeDocumentType as ICodeGeneratorHost; if (codeGeneratorHost == null || (codeGeneratorHost.CodeDomProvider.LanguageOptions & LanguageOptions.CaseInsensitive) != LanguageOptions.CaseInsensitive) { return(stringComparison); } stringComparison = StringComparison.OrdinalIgnoreCase; return(stringComparison); }
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 static void GoToXaml(SceneView sceneView, SceneXamlDocument document, List <DocumentNode> targetNodes, bool selectElementNameOnly, bool setFocusToXamlEditor) { ITextRange selectionSpan = TextRange.Null; bool flag = false; ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(document.ProjectContext); if (projectXamlContext == null) { return; } DocumentNode rootNode = document.RootNode; if (rootNode != null && targetNodes != null) { foreach (DocumentNode documentNode in targetNodes) { DocumentNode node = GoToXamlCommand.GetCorrespondingDocumentNode(documentNode, rootNode); if (node != null) { ITextRange nodeSpan; for (nodeSpan = DocumentNodeHelper.GetNodeSpan(node); TextRange.IsNull(nodeSpan) && node != null && node != rootNode; nodeSpan = DocumentNodeHelper.GetNodeSpan(node)) { node = (DocumentNode)node.Parent; } if (!TextRange.IsNull(nodeSpan)) { if (!flag) { flag = true; selectionSpan = nodeSpan; } else { selectionSpan = TextRange.Union(selectionSpan, nodeSpan); } } } } } if (sceneView == null) { sceneView = projectXamlContext.OpenView((IDocumentRoot)document, true); } using (sceneView.DisableSelectionSynchronization()) { sceneView.EnsureXamlEditorVisible(); if (!flag || sceneView.CodeEditor == null) { return; } ITextEditor textEditor = sceneView.CodeEditor; textEditor.ClearSelection(); if (selectElementNameOnly) { selectionSpan = GoToXamlCommand.GetElementNameSelectionSpan((IReadableSelectableTextBuffer)document.TextBuffer, selectionSpan); } textEditor.Select(selectionSpan.Offset, selectionSpan.Length); textEditor.CaretPosition = selectionSpan.Offset + selectionSpan.Length; Action action = (Action)(() => { textEditor.EnsureSpanVisible(selectionSpan.Offset, selectionSpan.Length); textEditor.EnsureCaretVisible(); textEditor.MoveLineToCenterOfView(textEditor.GetLineNumberFromPosition(selectionSpan.Offset)); if (!setFocusToXamlEditor) { return; } textEditor.Focus(); }); if (SceneViewUpdateScheduleTask.Synchronous) { action(); } else { UIThreadDispatcher.Instance.BeginInvoke(DispatcherPriority.Render, action); } } }
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; } }
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 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))); }