Browse Source

- split ProjectResourceService

- split TypeResolutionService
- wrap ICSharpCode.Core utilities in IMessageService
formsdesignerappdomain
Siegfried Pammer 15 years ago
parent
commit
629b89e42a
  1. 5
      src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/DesignerViewContent.cs
  2. 8
      src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesigner.AddIn.csproj
  3. 126
      src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/DomTypeLocator.cs
  4. 29
      src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/FormsMessageService.cs
  5. 61
      src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/ProjectResourceService.cs
  6. 0
      src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/UIService.cs
  7. 3
      src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj
  8. 1
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/IDesignerGenerator.cs
  9. 10
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/LoggingService.cs
  10. 24
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/IProjectResourceService.cs
  11. 25
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ITypeLocator.cs
  12. 10
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ImageResourceEditor.cs
  13. 5
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesComponentCodeDomSerializer.cs
  14. 126
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs

5
src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/DesignerViewContent.cs

@ -263,6 +263,7 @@ namespace ICSharpCode.FormsDesigner
LoggingService.Info("Form Designer: BEGIN INITIALIZE"); LoggingService.Info("Form Designer: BEGIN INITIALIZE");
DefaultServiceContainer serviceContainer = new DefaultServiceContainer(); DefaultServiceContainer serviceContainer = new DefaultServiceContainer();
serviceContainer.AddService(typeof(IMessageService), new FormsMessageService());
serviceContainer.AddService(typeof(System.Windows.Forms.Design.IUIService), new UIService()); serviceContainer.AddService(typeof(System.Windows.Forms.Design.IUIService), new UIService());
serviceContainer.AddService(typeof(System.Drawing.Design.IToolboxService), ToolboxProvider.ToolboxService); serviceContainer.AddService(typeof(System.Drawing.Design.IToolboxService), ToolboxProvider.ToolboxService);
@ -272,12 +273,12 @@ namespace ICSharpCode.FormsDesigner
serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), new DesignerResourceService(this.resourceStore)); serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), new DesignerResourceService(this.resourceStore));
AmbientProperties ambientProperties = new AmbientProperties(); AmbientProperties ambientProperties = new AmbientProperties();
serviceContainer.AddService(typeof(AmbientProperties), ambientProperties); serviceContainer.AddService(typeof(AmbientProperties), ambientProperties);
this.typeResolutionService = new TypeResolutionService(this.PrimaryFileName); this.typeResolutionService = new TypeResolutionService(this.PrimaryFileName, serviceContainer, new DomTypeLocator(this.PrimaryFileName));
serviceContainer.AddService(typeof(ITypeResolutionService), this.typeResolutionService); serviceContainer.AddService(typeof(ITypeResolutionService), this.typeResolutionService);
serviceContainer.AddService(typeof(DesignerOptionService), new SharpDevelopDesignerOptionService()); serviceContainer.AddService(typeof(DesignerOptionService), new SharpDevelopDesignerOptionService());
serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService()); serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
serviceContainer.AddService(typeof(MemberRelationshipService), new DefaultMemberRelationshipService()); serviceContainer.AddService(typeof(MemberRelationshipService), new DefaultMemberRelationshipService());
serviceContainer.AddService(typeof(ProjectResourceService), new ProjectResourceService(ParserService.GetParseInformation(this.DesignerCodeFile.FileName).CompilationUnit.ProjectContent)); serviceContainer.AddService(typeof(IProjectResourceService), new ProjectResourceService(ParserService.GetParseInformation(this.DesignerCodeFile.FileName).CompilationUnit.ProjectContent));
// Provide the ImageResourceEditor for all Image and Icon properties // Provide the ImageResourceEditor for all Image and Icon properties
this.addedTypeDescriptionProviders.Add(typeof(Image), TypeDescriptor.AddAttributes(typeof(Image), new EditorAttribute(typeof(ImageResourceEditor), typeof(System.Drawing.Design.UITypeEditor)))); this.addedTypeDescriptionProviders.Add(typeof(Image), TypeDescriptor.AddAttributes(typeof(Image), new EditorAttribute(typeof(ImageResourceEditor), typeof(System.Drawing.Design.UITypeEditor))));

8
src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesigner.AddIn.csproj

@ -79,9 +79,12 @@
<Compile Include="OptionPanels\LocalizationModelOptionsPanel.cs" /> <Compile Include="OptionPanels\LocalizationModelOptionsPanel.cs" />
<Compile Include="SecondaryDisplayBinding.cs" /> <Compile Include="SecondaryDisplayBinding.cs" />
<Compile Include="Services\DesignerResourceService.cs" /> <Compile Include="Services\DesignerResourceService.cs" />
<Compile Include="Services\DomTypeLocator.cs" />
<Compile Include="Services\HelpService.cs" /> <Compile Include="Services\HelpService.cs" />
<Compile Include="Services\FormsMessageService.cs" />
<Compile Include="Services\ProjectResourceService.cs" /> <Compile Include="Services\ProjectResourceService.cs" />
<Compile Include="Services\ResourceStore.cs" /> <Compile Include="Services\ResourceStore.cs" />
<Compile Include="Services\UIService.cs" />
<Compile Include="Toolbox\AddComponentsDialog.cs"> <Compile Include="Toolbox\AddComponentsDialog.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -107,6 +110,11 @@
<Name>ICSharpCode.Core</Name> <Name>ICSharpCode.Core</Name>
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\Project\FormsDesigner.csproj"> <ProjectReference Include="..\Project\FormsDesigner.csproj">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project> <Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name> <Name>FormsDesigner</Name>

126
src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/DomTypeLocator.cs

@ -0,0 +1,126 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.FormsDesigner.Services
{
public class DomTypeLocator : ITypeLocator
{
string formSourceFileName;
IProjectContent callingProject;
public System.ComponentModel.Design.ITypeResolutionService ParentService { get; set; }
/// <summary>
/// Gets the project content of the project that created this TypeResolutionService.
/// Returns null when no calling project was specified.
/// </summary>
public IProjectContent CallingProject {
get {
if (formSourceFileName != null) {
if (ProjectService.OpenSolution != null) {
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(formSourceFileName);
if (p != null) {
callingProject = ParserService.GetProjectContent(p);
}
}
formSourceFileName = null;
}
return callingProject;
}
}
public DomTypeLocator(string formSourceFileName)
{
this.formSourceFileName = formSourceFileName;
}
static readonly Dictionary<IProjectContent, object> projectContentsCurrentlyLoadingAssembly = new Dictionary<IProjectContent, object>();
public string LocateType(string name, out string[] referencedAssemblies)
{
IProjectContent pc = CallingProject;
if (pc != null) {
// find assembly containing type by using SharpDevelop.Dom
IClass foundClass;
if (name.Contains("`")) {
int typeParameterCount;
int.TryParse(name.Substring(name.IndexOf('`') + 1), out typeParameterCount);
foundClass = pc.GetClass(name.Substring(0, name.IndexOf('`')).Replace('+', '.'), typeParameterCount);
} else {
foundClass = pc.GetClass(name.Replace('+', '.'), 0);
}
if (foundClass != null) {
string path = GetPathToAssembly(pc);
if (string.IsNullOrEmpty(path)) {
referencedAssemblies = new string[0];
return "";
}
List<string> assemblies = new List<string>();
FindReferencedAssemblies(assemblies, pc);
if (assemblies.Contains(path))
assemblies.Remove(path);
referencedAssemblies = assemblies.ToArray();
return path;
}
}
referencedAssemblies = new string[0];
return "";
}
void FindReferencedAssemblies(List<string> assemblies, IProjectContent pc)
{
// prevent StackOverflow when project contents have cyclic dependencies
// Very popular example of cyclic dependency: System <-> System.Xml (yes, really!)
if (projectContentsCurrentlyLoadingAssembly.ContainsKey(pc))
return;
projectContentsCurrentlyLoadingAssembly.Add(pc, null);
string path = GetPathToAssembly(assemblies, pc);
if (!string.IsNullOrEmpty(path) && !assemblies.Contains(path))
assemblies.Add(path);
try {
// load dependencies of current assembly
foreach (IProjectContent rpc in pc.ReferencedContents) {
if (rpc is ParseProjectContent) {
FindReferencedAssemblies(assemblies, rpc);
} else if (rpc is ReflectionProjectContent) {
ReflectionProjectContent rrpc = (ReflectionProjectContent)rpc;
if (!GacInterop.IsWithinGac(rrpc.AssemblyLocation))
FindReferencedAssemblies(assemblies, rpc);
}
}
} finally {
projectContentsCurrentlyLoadingAssembly.Remove(pc);
}
}
string GetPathToAssembly(IProjectContent pc)
{
if (pc.Project != null)
return ((IProject)pc.Project).OutputAssemblyFullPath;
else if (pc is ReflectionProjectContent)
return ((ReflectionProjectContent)pc).AssemblyLocation;
return null;
}
public bool IsGacAssembly(string path)
{
return GacInterop.IsWithinGac(path);
}
}
}

29
src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/FormsMessageService.cs

@ -0,0 +1,29 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.Core;
namespace ICSharpCode.FormsDesigner.Services
{
/// <summary>
/// Description of MessageService.
/// </summary>
public class FormsMessageService : IMessageService
{
public void ShowOutputPad()
{
WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).BringPadToFront();
}
public void AppendTextToBuildMessages(string text)
{
TaskService.BuildMessageViewCategory.AppendText(StringParser.Parse(text));
}
public void ShowException(Exception ex, string message)
{
MessageService.ShowException(ex, message);
}
}
}

61
src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/ProjectResourceService.cs

@ -16,21 +16,19 @@ namespace ICSharpCode.FormsDesigner.Services
/// <summary> /// <summary>
/// Supports project-level resources in the Windows.Forms designer. /// Supports project-level resources in the Windows.Forms designer.
/// </summary> /// </summary>
public sealed class ProjectResourceService public sealed class ProjectResourceService : IProjectResourceService
{ {
public const string ProjectResourceKey = "SDProjectResource_";
IProjectContent projectContent; IProjectContent projectContent;
string stringLiteralDelimiter; string stringLiteralDelimiter;
bool designerSupportsProjectResources = true; bool designerSupportsProjectResources = true;
public ProjectResourceService(IProjectContent projectContent) public ProjectResourceService(IProjectContent projectContent)
{ {
if (projectContent == null) if (projectContent == null)
throw new ArgumentNullException("projectContent"); throw new ArgumentNullException("projectContent");
this.projectContent = projectContent; this.projectContent = projectContent;
} }
public IProjectContent ProjectContent { public IProjectContent ProjectContent {
get { return projectContent; } get { return projectContent; }
set { set {
@ -42,12 +40,16 @@ namespace ICSharpCode.FormsDesigner.Services
} }
} }
} }
public bool DesignerSupportsProjectResources { public bool DesignerSupportsProjectResources {
get { return designerSupportsProjectResources; } get { return designerSupportsProjectResources; }
set { designerSupportsProjectResources = value; } set { designerSupportsProjectResources = value; }
} }
public string ProjectResourceKey {
get { return "SDProjectResource_"; }
}
/// <summary> /// <summary>
/// Gets the string literal delimiter for the current language /// Gets the string literal delimiter for the current language
/// by generating code for a known literal. /// by generating code for a known literal.
@ -62,7 +64,7 @@ namespace ICSharpCode.FormsDesigner.Services
return stringLiteralDelimiter; return stringLiteralDelimiter;
} }
} }
/// <summary> /// <summary>
/// Gets the project resource from the specified expression. /// Gets the project resource from the specified expression.
/// </summary> /// </summary>
@ -73,22 +75,22 @@ namespace ICSharpCode.FormsDesigner.Services
LoggingService.Info("Target of possible project resources property reference is not a type reference, but " + propRef.TargetObject.ToString() + "."); LoggingService.Info("Target of possible project resources property reference is not a type reference, but " + propRef.TargetObject.ToString() + ".");
return null; return null;
} }
// Get the (generated) class where the resource is defined. // Get the (generated) class where the resource is defined.
IClass resourceClass = this.projectContent.GetClassByReflectionName(typeRef.Type.BaseType, true); IClass resourceClass = this.projectContent.GetClassByReflectionName(typeRef.Type.BaseType, true);
if (resourceClass == null) { if (resourceClass == null) {
throw new InvalidOperationException("Could not find class for project resources: '" + typeRef.Type.BaseType + "'."); throw new InvalidOperationException("Could not find class for project resources: '" + typeRef.Type.BaseType + "'.");
} }
if (resourceClass.CompilationUnit == null || resourceClass.CompilationUnit.FileName == null) { if (resourceClass.CompilationUnit == null || resourceClass.CompilationUnit.FileName == null) {
return null; return null;
} }
// Make sure the class we have found is a generated resource class. // Make sure the class we have found is a generated resource class.
if (!IsGeneratedResourceClass(resourceClass)) { if (!IsGeneratedResourceClass(resourceClass)) {
return null; return null;
} }
// Get the name of the resource file based on the file that contains the generated class. // Get the name of the resource file based on the file that contains the generated class.
string resourceFileName = Path.GetFileNameWithoutExtension(resourceClass.CompilationUnit.FileName); string resourceFileName = Path.GetFileNameWithoutExtension(resourceClass.CompilationUnit.FileName);
if (resourceFileName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase)) { if (resourceFileName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase)) {
@ -102,59 +104,59 @@ namespace ICSharpCode.FormsDesigner.Services
} else { } else {
throw new FileNotFoundException("Could not find the resource file for type '" + resourceClass.FullyQualifiedName + "'. Tried these file names: '" + resourceFileName + ".(resources|resx)'."); throw new FileNotFoundException("Could not find the resource file for type '" + resourceClass.FullyQualifiedName + "'. Tried these file names: '" + resourceFileName + ".(resources|resx)'.");
} }
// Get the property for the resource. // Get the property for the resource.
IProperty prop = resourceClass.Properties.SingleOrDefault(p => p.Name == propRef.PropertyName); IProperty prop = resourceClass.Properties.SingleOrDefault(p => p.Name == propRef.PropertyName);
if (prop == null) { if (prop == null) {
throw new InvalidOperationException("Property '" + propRef.PropertyName + "' not found in type '" + resourceClass.FullyQualifiedName + "'."); throw new InvalidOperationException("Property '" + propRef.PropertyName + "' not found in type '" + resourceClass.FullyQualifiedName + "'.");
} }
if (!prop.CanGet) { if (!prop.CanGet) {
throw new InvalidOperationException("Property '" + propRef.PropertyName + "' in type '" + resourceClass.FullyQualifiedName + "' does not have a getter."); throw new InvalidOperationException("Property '" + propRef.PropertyName + "' in type '" + resourceClass.FullyQualifiedName + "' does not have a getter.");
} }
// Get the code of the resource class and // Get the code of the resource class and
// extract the resource key from the property. // extract the resource key from the property.
// This is necessary because the key may differ from the property name // This is necessary because the key may differ from the property name
// if special characters are used. // if special characters are used.
// It would be better if we could use a real code parser for this, but // It would be better if we could use a real code parser for this, but
// that is not possible without getting dependent on the programming language. // that is not possible without getting dependent on the programming language.
IDocument doc = new ICSharpCode.SharpDevelop.Editor.AvalonEdit.AvalonEditDocumentAdapter(); IDocument doc = new ICSharpCode.SharpDevelop.Editor.AvalonEdit.AvalonEditDocumentAdapter();
doc.Text = ParserService.GetParseableFileContent(resourceClass.CompilationUnit.FileName).Text; doc.Text = ParserService.GetParseableFileContent(resourceClass.CompilationUnit.FileName).Text;
int startOffset = doc.PositionToOffset(prop.GetterRegion.BeginLine, prop.GetterRegion.BeginColumn); int startOffset = doc.PositionToOffset(prop.GetterRegion.BeginLine, prop.GetterRegion.BeginColumn);
int endOffset = doc.PositionToOffset(prop.GetterRegion.EndLine, prop.GetterRegion.EndColumn); int endOffset = doc.PositionToOffset(prop.GetterRegion.EndLine, prop.GetterRegion.EndColumn);
string code = doc.GetText(startOffset, endOffset - startOffset + 1); string code = doc.GetText(startOffset, endOffset - startOffset + 1);
int index = code.IndexOf("ResourceManager", StringComparison.Ordinal); int index = code.IndexOf("ResourceManager", StringComparison.Ordinal);
if (index == -1) { if (index == -1) {
throw new InvalidOperationException("No reference to ResourceManager found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'"); throw new InvalidOperationException("No reference to ResourceManager found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
} }
index = code.IndexOf("Get", index, StringComparison.Ordinal); index = code.IndexOf("Get", index, StringComparison.Ordinal);
if (index == -1) { if (index == -1) {
throw new InvalidOperationException("No call to Get... found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'"); throw new InvalidOperationException("No call to Get... found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
} }
index = code.IndexOf(this.StringLiteralDelimiter, index + 1, StringComparison.Ordinal); index = code.IndexOf(this.StringLiteralDelimiter, index + 1, StringComparison.Ordinal);
if (index == -1) { if (index == -1) {
throw new InvalidOperationException("No string delimiter ('" + this.StringLiteralDelimiter + "') found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'"); throw new InvalidOperationException("No string delimiter ('" + this.StringLiteralDelimiter + "') found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
} }
index += this.StringLiteralDelimiter.Length; index += this.StringLiteralDelimiter.Length;
int endIndex = code.LastIndexOf(this.StringLiteralDelimiter, StringComparison.Ordinal); int endIndex = code.LastIndexOf(this.StringLiteralDelimiter, StringComparison.Ordinal);
if (endIndex == -1) { if (endIndex == -1) {
throw new InvalidOperationException("No string terminator ('" + this.StringLiteralDelimiter + "') found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'"); throw new InvalidOperationException("No string terminator ('" + this.StringLiteralDelimiter + "') found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
} }
string resourceKey = code.Substring(index, endIndex - index); string resourceKey = code.Substring(index, endIndex - index);
LoggingService.Debug("-> Decoded resource: In: " + resourceFileName + ". Key: " + resourceKey); LoggingService.Debug("-> Decoded resource: In: " + resourceFileName + ". Key: " + resourceKey);
return new ProjectResourceInfo(resourceFileName, resourceKey); return new ProjectResourceInfo(resourceFileName, resourceKey);
} }
/// <summary> /// <summary>
/// Determines whether the specified class is a generated resource /// Determines whether the specified class is a generated resource
/// class, based on the attached attributes. /// class, based on the attached attributes.
@ -167,12 +169,7 @@ namespace ICSharpCode.FormsDesigner.Services
return false; return false;
} }
IReturnType generatedCodeAttribute = generatedCodeAttributeClass.DefaultReturnType; IReturnType generatedCodeAttribute = generatedCodeAttributeClass.DefaultReturnType;
return @class.Attributes.Any( return @class.Attributes.Any(att => att.AttributeType.Equals(generatedCodeAttribute) && att.PositionalArguments.Count == 2 && String.Equals("System.Resources.Tools.StronglyTypedResourceBuilder", att.PositionalArguments[0] as string, StringComparison.Ordinal));
att =>
att.AttributeType.Equals(generatedCodeAttribute) &&
att.PositionalArguments.Count == 2 &&
String.Equals("System.Resources.Tools.StronglyTypedResourceBuilder", att.PositionalArguments[0] as string, StringComparison.Ordinal)
);
} }
} }
} }

0
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/UIService.cs → src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/UIService.cs

3
src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj

@ -70,6 +70,8 @@
<Compile Include="Src\Services\DesignerOptionService.cs" /> <Compile Include="Src\Services\DesignerOptionService.cs" />
<Compile Include="Src\Services\EventBindingService.cs" /> <Compile Include="Src\Services\EventBindingService.cs" />
<Compile Include="Src\Services\ImageResourceEditor.cs" /> <Compile Include="Src\Services\ImageResourceEditor.cs" />
<Compile Include="Src\Services\IProjectResourceService.cs" />
<Compile Include="Src\Services\ITypeLocator.cs" />
<Compile Include="Src\Services\MenuCommandService.cs" /> <Compile Include="Src\Services\MenuCommandService.cs" />
<Compile Include="Src\Services\ProjectResourceInfo.cs" /> <Compile Include="Src\Services\ProjectResourceInfo.cs" />
<Compile Include="Src\Services\ProjectResourcesComponentCodeDomSerializer.cs" /> <Compile Include="Src\Services\ProjectResourcesComponentCodeDomSerializer.cs" />
@ -78,7 +80,6 @@
<Compile Include="Src\Services\SharpDevelopSerializationProvider.cs" /> <Compile Include="Src\Services\SharpDevelopSerializationProvider.cs" />
<Compile Include="Src\Services\ToolboxService.cs" /> <Compile Include="Src\Services\ToolboxService.cs" />
<Compile Include="Src\Services\TypeResolutionService.cs" /> <Compile Include="Src\Services\TypeResolutionService.cs" />
<Compile Include="Src\Services\UIService.cs" />
<Compile Include="Src\Services\XmlDesignerNameCreationService.cs" /> <Compile Include="Src\Services\XmlDesignerNameCreationService.cs" />
<Compile Include="Src\DesignerLoader\DesignerLoaderProvider.cs" /> <Compile Include="Src\DesignerLoader\DesignerLoaderProvider.cs" />
<Compile Include="Src\DesignerLoader\FormsDesignerLoadException.cs" /> <Compile Include="Src\DesignerLoader\FormsDesignerLoadException.cs" />

1
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/IDesignerGenerator.cs

@ -32,5 +32,6 @@ namespace ICSharpCode.FormsDesigner
bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out string file, out int position); bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out string file, out int position);
ICollection GetCompatibleMethods(EventDescriptor edesc); ICollection GetCompatibleMethods(EventDescriptor edesc);
void NotifyFormRenamed(string newName); void NotifyFormRenamed(string newName);
CodeDomProvider CodeDomProvider { get; }
} }
} }

10
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/LoggingService.cs

@ -31,5 +31,15 @@ namespace ICSharpCode.FormsDesigner
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public static void DebugFormatted(string format, params object[] args)
{
throw new NotImplementedException();
}
public static void WarnFormatted(string format, params object[] args)
{
throw new NotImplementedException();
}
} }
} }

24
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/IProjectResourceService.cs

@ -0,0 +1,24 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.CodeDom;
using System.IO;
using System.Linq;
namespace ICSharpCode.FormsDesigner.Services
{
public interface IProjectResourceService
{
ProjectResourceInfo GetProjectResource(CodePropertyReferenceExpression propRef);
bool DesignerSupportsProjectResources { get; set; }
string ProjectResourceKey { get; set; }
}
public interface IMessageService
{
void ShowOutputPad();
void AppendTextToBuildMessages(string text);
void ShowException(Exception ex, string message);
}
}

25
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ITypeLocator.cs

@ -0,0 +1,25 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.FormsDesigner.Services
{
public struct AssemblyInfo
{
public readonly string FullNameOrPath;
public readonly bool IsInGac;
public AssemblyInfo(string fullNameOrPath, bool isInGac)
{
this.FullNameOrPath = fullNameOrPath;
this.IsInGac = isInGac;
}
}
public interface ITypeLocator
{
AssemblyInfo LocateType(string name, out AssemblyInfo[] referencedAssemblies);
bool IsWithinGac(string path);
}
}

10
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ImageResourceEditor.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.FormsDesigner.Services
if (typeof(Image).IsAssignableFrom(context.PropertyDescriptor.PropertyType) || if (typeof(Image).IsAssignableFrom(context.PropertyDescriptor.PropertyType) ||
typeof(Icon).IsAssignableFrom(context.PropertyDescriptor.PropertyType)) { typeof(Icon).IsAssignableFrom(context.PropertyDescriptor.PropertyType)) {
if (context.GetService(typeof(ProjectResourceService)) is ProjectResourceService) { if (context.GetService(typeof(IProjectResourceService)) is IProjectResourceService) {
return UITypeEditorEditStyle.Modal; return UITypeEditorEditStyle.Modal;
} }
@ -59,7 +59,7 @@ namespace ICSharpCode.FormsDesigner.Services
} }
} }
var prs = provider.GetService(typeof(ProjectResourceService)) as ProjectResourceService; var prs = provider.GetService(typeof(IProjectResourceService)) as IProjectResourceService;
if (prs == null) { if (prs == null) {
return value; return value;
} }
@ -74,7 +74,7 @@ namespace ICSharpCode.FormsDesigner.Services
throw new InvalidOperationException("The required IDictionaryService is not available."); throw new InvalidOperationException("The required IDictionaryService is not available.");
} }
var projectResource = dictService.GetValue(ProjectResourceService.ProjectResourceKey + context.PropertyDescriptor.Name) as ProjectResourceInfo; var projectResource = dictService.GetValue(prs.ProjectResourceKey + context.PropertyDescriptor.Name) as ProjectResourceInfo;
IProject project = prs.ProjectContent.Project as IProject; IProject project = prs.ProjectContent.Project as IProject;
ImageResourceEditorDialog dialog; ImageResourceEditorDialog dialog;
@ -95,7 +95,7 @@ namespace ICSharpCode.FormsDesigner.Services
if (edsvc.ShowDialog(dialog) == DialogResult.OK) { if (edsvc.ShowDialog(dialog) == DialogResult.OK) {
projectResource = dialog.SelectedProjectResource; projectResource = dialog.SelectedProjectResource;
if (projectResource != null) { if (projectResource != null) {
dictService.SetValue(ProjectResourceService.ProjectResourceKey + context.PropertyDescriptor.Name, projectResource); dictService.SetValue(prs.ProjectResourceKey + context.PropertyDescriptor.Name, projectResource);
// Ensure the resource generator is turned on for the selected resource file. // Ensure the resource generator is turned on for the selected resource file.
if (project != null) { if (project != null) {
@ -114,7 +114,7 @@ namespace ICSharpCode.FormsDesigner.Services
return projectResource.OriginalValue; return projectResource.OriginalValue;
} else { } else {
dictService.SetValue(ProjectResourceService.ProjectResourceKey + context.PropertyDescriptor.Name, null); dictService.SetValue(prs.ProjectResourceKey + context.PropertyDescriptor.Name, null);
return dialog.SelectedResourceValue; return dialog.SelectedResourceValue;
} }
} }

5
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/ProjectResourcesComponentCodeDomSerializer.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.FormsDesigner.Services
static ProjectResourceInfo GetProjectResourceFromPropertyReference(IDesignerSerializationManager manager, CodePropertyReferenceExpression propRefSource) static ProjectResourceInfo GetProjectResourceFromPropertyReference(IDesignerSerializationManager manager, CodePropertyReferenceExpression propRefSource)
{ {
ProjectResourceService prs = manager.GetService(typeof(ProjectResourceService)) as ProjectResourceService; IProjectResourceService prs = manager.GetService(typeof(IProjectResourceService)) as IProjectResourceService;
if (prs == null) { if (prs == null) {
throw new InvalidOperationException("The required ProjectResourceService is not available."); throw new InvalidOperationException("The required ProjectResourceService is not available.");
} }
@ -195,11 +195,12 @@ namespace ICSharpCode.FormsDesigner.Services
static void StoreResourceInfo(IComponent component, string propertyName, ProjectResourceInfo resourceInfo) static void StoreResourceInfo(IComponent component, string propertyName, ProjectResourceInfo resourceInfo)
{ {
IProjectResourceService prs = manager.GetService(typeof(IProjectResourceService)) as IProjectResourceService;
var dictService = component.Site.GetService(typeof(IDictionaryService)) as IDictionaryService; var dictService = component.Site.GetService(typeof(IDictionaryService)) as IDictionaryService;
if (dictService == null) { if (dictService == null) {
throw new InvalidOperationException("The required IDictionaryService is not available on component '" + component.ToString() + "'."); throw new InvalidOperationException("The required IDictionaryService is not available on component '" + component.ToString() + "'.");
} }
dictService.SetValue(ProjectResourceService.ProjectResourceKey + propertyName, resourceInfo); dictService.SetValue(prs.ProjectResourceKey + propertyName, resourceInfo);
} }
#region Default overrides redirecting to baseSerializer #region Default overrides redirecting to baseSerializer

126
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs

@ -32,13 +32,12 @@ namespace ICSharpCode.FormsDesigner.Services
static TypeResolutionService() static TypeResolutionService()
{ {
ClearMixedAssembliesTemporaryFiles(); ClearMixedAssembliesTemporaryFiles();
DesignerAssemblies.Add(ProjectContentRegistry.MscorlibAssembly); DesignerAssemblies.Add(typeof(object).Assembly);
DesignerAssemblies.Add(ProjectContentRegistry.SystemAssembly); DesignerAssemblies.Add(typeof(System.Uri).Assembly);
DesignerAssemblies.Add(typeof(System.Drawing.Point).Assembly); DesignerAssemblies.Add(typeof(System.Drawing.Point).Assembly);
DesignerAssemblies.Add(typeof(System.Windows.Forms.Design.AnchorEditor).Assembly); DesignerAssemblies.Add(typeof(System.Windows.Forms.Design.AnchorEditor).Assembly);
RegisterVSDesignerWorkaround(); RegisterVSDesignerWorkaround();
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveEventHandler; AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveEventHandler;
} }
[System.Runtime.InteropServices.DllImport("kernel32.dll")] [System.Runtime.InteropServices.DllImport("kernel32.dll")]
@ -69,89 +68,26 @@ namespace ICSharpCode.FormsDesigner.Services
string formSourceFileName; string formSourceFileName;
ServiceContainer serviceContainer;
ITypeLocator typeLocator;
/// <summary> /// <summary>
/// Dictionary of file name -> hash of loaded assemblies for the currently designed document. /// Dictionary of file name -> hash of loaded assemblies for the currently designed document.
/// Used to detect changes in references assemblies. /// Used to detect changes in references assemblies.
/// </summary> /// </summary>
readonly Dictionary<string, string> loadedAssembliesForCurrentDocument = new Dictionary<string, string>(StringComparer.Ordinal); readonly Dictionary<string, string> loadedAssembliesForCurrentDocument = new Dictionary<string, string>(StringComparer.Ordinal);
/*
IProjectContent callingProject;
/// <summary>
/// Gets the project content of the project that created this TypeResolutionService.
/// Returns null when no calling project was specified.
/// </summary>
public IProjectContent CallingProject {
get {
if (formSourceFileName != null) {
if (ProjectService.OpenSolution != null) {
IProject p = ProjectService.OpenSolution.FindProjectContainingFile(formSourceFileName);
if (p != null) {
callingProject = ParserService.GetProjectContent(p);
}
}
formSourceFileName = null;
}
return callingProject;
}
}*/
public TypeResolutionService() public TypeResolutionService()
{ {
} }
public TypeResolutionService(string formSourceFileName) public TypeResolutionService(string formSourceFileName, ServiceContainer serviceContainer, ITypeLocator typeLocator)
{ {
this.formSourceFileName = formSourceFileName; this.formSourceFileName = formSourceFileName;
this.serviceContainer = serviceContainer;
this.typeLocator = typeLocator;
} }
/*
static readonly Dictionary<IProjectContent, object> projectContentsCurrentlyLoadingAssembly = new Dictionary<IProjectContent, object>();
/// <summary>
/// Loads the assembly represented by the project content. Returns null on failure.
/// </summary>
public Assembly LoadAssembly(IProjectContent pc)
{
// prevent StackOverflow when project contents have cyclic dependencies
// Very popular example of cyclic dependency: System <-> System.Xml (yes, really!)
if (projectContentsCurrentlyLoadingAssembly.ContainsKey(pc))
return null;
projectContentsCurrentlyLoadingAssembly.Add(pc, null);
try {
// load dependencies of current assembly
foreach (IProjectContent rpc in pc.ReferencedContents) {
if (rpc is ParseProjectContent) {
LoadAssembly(rpc);
} else if (rpc is ReflectionProjectContent) {
ReflectionProjectContent rrpc = (ReflectionProjectContent)rpc;
if (rrpc.AssemblyFullName != typeof(object).FullName
&& !GacInterop.IsWithinGac(rrpc.AssemblyLocation))
{
LoadAssembly(rpc);
}
}
}
} finally {
projectContentsCurrentlyLoadingAssembly.Remove(pc);
}
if (pc.Project != null) {
return LoadAssembly(((IProject)pc.Project).OutputAssemblyFullPath);
} else if (pc is ReflectionProjectContent) {
ReflectionProjectContent rpc = (ReflectionProjectContent)pc;
if (GacInterop.IsWithinGac(rpc.AssemblyLocation))
return LoadAssembly(new AssemblyName(rpc.AssemblyFullName), false);
else
return LoadAssembly(rpc.AssemblyLocation);
} else {
return null;
}
}
*/
static string GetHash(string fileName) static string GetHash(string fileName)
{ {
return Path.GetFileName(fileName).ToLowerInvariant() + File.GetLastWriteTimeUtc(fileName).Ticks.ToString(); return Path.GetFileName(fileName).ToLowerInvariant() + File.GetLastWriteTimeUtc(fileName).Ticks.ToString();
@ -191,6 +127,8 @@ namespace ICSharpCode.FormsDesigner.Services
} }
} }
IMessageService messenger = serviceContainer.GetService(typeof(IMessageService)) as IMessageService;
string hash = GetHash(fileName); string hash = GetHash(fileName);
lock (assemblyDict) { lock (assemblyDict) {
Assembly asm; Assembly asm;
@ -223,7 +161,7 @@ namespace ICSharpCode.FormsDesigner.Services
asm.LoadModule(Path.GetFileName(fileName), File.ReadAllBytes(fileName)); asm.LoadModule(Path.GetFileName(fileName), File.ReadAllBytes(fileName));
} }
} catch (Exception ex) { } catch (Exception ex) {
MessageService.ShowException(ex, "Error calling linker for netmodule"); messenger.ShowException(ex, "Error calling linker for netmodule");
} }
try { try {
File.Delete(tempPath); File.Delete(tempPath);
@ -234,11 +172,8 @@ namespace ICSharpCode.FormsDesigner.Services
// The error might be caused by an assembly that is // The error might be caused by an assembly that is
// not even needed for the designer to load. // not even needed for the designer to load.
LoggingService.Error("Error loading assembly " + fileName, e); LoggingService.Error("Error loading assembly " + fileName, e);
WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).BringPadToFront(); messenger.ShowOutputPad();
TaskService.BuildMessageViewCategory.AppendText( messenger.AppendTextToBuildMessages("${res:FileUtilityService.ErrorWhileLoading}\r\n" + fileName + "\r\n" + e.Message + "\r\n");
StringParser.Parse("${res:FileUtilityService.ErrorWhileLoading}")
+ "\r\n" + fileName + "\r\n" + e.Message + "\r\n"
);
return null; return null;
} }
} catch (FileLoadException e) { } catch (FileLoadException e) {
@ -354,28 +289,27 @@ namespace ICSharpCode.FormsDesigner.Services
} }
#endif #endif
try { try {
Type type = Type.GetType(name, false, ignoreCase); Type type = Type.GetType(name, false, ignoreCase);
if (type == null) { if (type == null) {
IProjectContent pc = this.CallingProject; AssemblyInfo[] assemblies;
if (pc != null) { AssemblyInfo assemblyInfo = typeLocator.LocateType(name, out assemblies);
// find assembly containing type by using SharpDevelop.Dom
IClass foundClass; foreach (AssemblyInfo a in assemblies) {
if (name.Contains("`")) { if (a.IsInGac)
int typeParameterCount; LoadAssembly(new AssemblyName(a.FullNameOrPath), false);
int.TryParse(name.Substring(name.IndexOf('`') + 1), out typeParameterCount); else
foundClass = pc.GetClass(name.Substring(0, name.IndexOf('`')).Replace('+', '.'), typeParameterCount); LoadAssembly(a.FullNameOrPath);
} else {
foundClass = pc.GetClass(name.Replace('+', '.'), 0);
}
if (foundClass != null) {
Assembly assembly = LoadAssembly(foundClass.ProjectContent);
if (assembly != null) {
type = assembly.GetType(name, false, ignoreCase);
}
}
} }
Assembly assembly;
if (assemblyInfo.IsInGac)
assembly = LoadAssembly(new AssemblyName(assemblyInfo.FullNameOrPath), false);
else
assembly = LoadAssembly(assemblyInfo.FullNameOrPath);
if (assembly != null)
type = assembly.GetType(name, throwOnError, ignoreCase);
} }
// type lookup for typename, assembly, xyz style lookups // type lookup for typename, assembly, xyz style lookups

Loading…
Cancel
Save