Browse Source

Overworked form designer assembly loading a bit. Showing the custom components in the tools pad no longer causes the assembly to be loaded, it is loaded only when the component in the toolbox is activated.

TypeResolutionService now searches for types using the code completion cache and loads the correct assembly when it is required by the designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@964 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
4ac89b6905
  1. 2
      src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj
  2. 2
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs
  3. 31
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs
  4. 20
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs
  5. 198
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs
  6. BIN
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.FormDesigner.Gui.AssemblyList.resources
  7. BIN
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ControlLibrariesPanel.resources
  8. 17
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabDesigner.cs
  9. 14
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabItemDesigner.cs
  10. 9
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs
  11. 161
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs
  12. 11
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs
  13. 12
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToCSharpConvertVisitor.cs
  14. 12
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToVBNetConvertVisitor.cs
  15. 2
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs
  16. 16
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  17. 20
      src/Main/Base/Project/Src/Services/ParserService/ProjectContentRegistry.cs
  18. 13
      src/Main/Base/Project/Src/Services/ParserService/ReflectionProjectContent.cs
  19. 12
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerationForm.cs

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

@ -90,8 +90,6 @@
<Compile Include="Src\Services\TypeResolutionService.cs" /> <Compile Include="Src\Services\TypeResolutionService.cs" />
<Compile Include="Src\Services\UIService.cs" /> <Compile Include="Src\Services\UIService.cs" />
<Compile Include="Src\ToolboxProvider.cs" /> <Compile Include="Src\ToolboxProvider.cs" />
<EmbeddedResource Include="Src\Gui\ICSharpCode.SharpDevelop.FormDesigner.Gui.AssemblyList.resources" />
<EmbeddedResource Include="Src\Gui\ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ControlLibrariesPanel.resources" />
<None Include="FormsDesigner.addin"> <None Include="FormsDesigner.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>

2
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs

@ -115,7 +115,7 @@ namespace ICSharpCode.FormsDesigner
if (pd.Name == "Name" && nameInserted) { if (pd.Name == "Name" && nameInserted) {
continue; continue;
} }
if (pd.Name == "DataBindings" || if (pd.Name == "DataBindings" || pd.Name == "FlatAppearance" ||
// TabControl duplicate TabPages Workaround (TabPages got inserted twice : In Controls and in TabPages) // TabControl duplicate TabPages Workaround (TabPages got inserted twice : In Controls and in TabPages)
(o.GetType().FullName == "System.Windows.Forms.TabControl" && pd.Name == "Controls")) { (o.GetType().FullName == "System.Windows.Forms.TabControl" && pd.Name == "Controls")) {
continue; continue;

31
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs

@ -134,6 +134,8 @@ namespace ICSharpCode.FormsDesigner
} }
} }
if (lastAssembly != null) { if (lastAssembly != null) {
if (!TypeResolutionService.DesignerAssemblies.Contains(lastAssembly))
TypeResolutionService.DesignerAssemblies.Add(lastAssembly);
LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name); LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name);
return lastAssembly; return lastAssembly;
} }
@ -156,7 +158,7 @@ namespace ICSharpCode.FormsDesigner
serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), designerResourceService); serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), designerResourceService);
AmbientProperties ambientProperties = new AmbientProperties(); AmbientProperties ambientProperties = new AmbientProperties();
serviceContainer.AddService(typeof(AmbientProperties), ambientProperties); serviceContainer.AddService(typeof(AmbientProperties), ambientProperties);
serviceContainer.AddService(typeof(ITypeResolutionService), ToolboxProvider.TypeResolutionService); serviceContainer.AddService(typeof(ITypeResolutionService), new TypeResolutionService(viewContent.FileName));
serviceContainer.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService()); serviceContainer.AddService(typeof(System.ComponentModel.Design.IDesignerEventService), new DesignerEventService());
serviceContainer.AddService(typeof(System.ComponentModel.Design.DesignerOptionService), new ICSharpCode.FormsDesigner.Services.DesignerOptionService()); serviceContainer.AddService(typeof(System.ComponentModel.Design.DesignerOptionService), new ICSharpCode.FormsDesigner.Services.DesignerOptionService());
serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService()); serviceContainer.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
@ -264,29 +266,24 @@ namespace ICSharpCode.FormsDesigner
failedDesignerInitialize = true; failedDesignerInitialize = true;
TextBox errorText = new TextBox(); TextBox errorText = new TextBox();
errorText.Multiline = true; errorText.Multiline = true;
if (e.InnerException is FormsDesignerLoadException) if (e.InnerException is FormsDesignerLoadException) {
errorText.Text = e.InnerException.Message; errorText.Text = e.InnerException.Message;
else if (e is FormsDesignerLoadException) } else if (e is FormsDesignerLoadException) {
errorText.Text = e.Message; errorText.Text = e.Message;
else } else if (!designSurface.IsLoaded && designSurface.LoadErrors != null) {
errorText.Text = e.ToString(); errorText.Text = "Error loading designer:\r\n\r\n";
//output loaderrors too foreach(Exception le in designSurface.LoadErrors) {
if(!designSurface.IsLoaded) { errorText.Text += le.ToString();
errorText.Text += "\r\nDesignSurface not loaded :"; errorText.Text += "\r\n";
if(designSurface.LoadErrors != null) {
foreach(Exception le in designSurface.LoadErrors) {
errorText.Text += "\r\n";
errorText.Text += le.ToString();
errorText.Text += "\r\n";
errorText.Text += le.StackTrace;
}
} }
} else {
errorText.Text = e.ToString();
} }
errorText.Dock = DockStyle.Fill; errorText.Dock = DockStyle.Fill;
p.Controls.Add(errorText); p.Controls.Add(errorText);
Control title = new Label(); Control title = new Label();
title.Text = "Failed to load designer. Check the source code for syntax errors."; title.Text = "Failed to load designer. Check the source code for syntax errors and check if all references are available.";
title.Dock = DockStyle.Top; title.Dock = DockStyle.Top;
p.Controls.Add(title); p.Controls.Add(title);
} }
@ -577,6 +574,8 @@ namespace ICSharpCode.FormsDesigner
/// </summary> /// </summary>
void PropertyValueChanged(object source, PropertyValueChangedEventArgs e) void PropertyValueChanged(object source, PropertyValueChangedEventArgs e)
{ {
if (e.ChangedItem == null || e.OldValue == null)
return;
if (e.ChangedItem.GridItemType == GridItemType.Property) { if (e.ChangedItem.GridItemType == GridItemType.Property) {
if (e.ChangedItem.PropertyDescriptor.Name == "Language") { if (e.ChangedItem.PropertyDescriptor.Name == "Language") {
if (!e.OldValue.Equals(e.ChangedItem.Value)) { if (!e.OldValue.Equals(e.ChangedItem.Value)) {

20
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs

@ -104,10 +104,16 @@ namespace ICSharpCode.FormsDesigner.Gui
public Assembly LoadAssembly() public Assembly LoadAssembly()
{ {
//ICSharpCode.Core.LoggingService.Debug("ToolComponent.LoadAssembly(): " + AssemblyName);
Assembly assembly;
if (HintPath != null) { if (HintPath != null) {
return Assembly.LoadFrom(FileName); assembly = Assembly.LoadFrom(FileName);
} else {
assembly = Assembly.Load(AssemblyName);
} }
return Assembly.Load(AssemblyName); if (!ICSharpCode.FormsDesigner.Services.TypeResolutionService.DesignerAssemblies.Contains(assembly))
ICSharpCode.FormsDesigner.Services.TypeResolutionService.DesignerAssemblies.Add(assembly);
return assembly;
} }
public object Clone() public object Clone()
@ -266,7 +272,7 @@ namespace ICSharpCode.FormsDesigner.Gui
string name = node.Attributes["name"].InnerText; string name = node.Attributes["name"].InnerText;
Category newCategory = new Category(name); Category newCategory = new Category(name);
foreach (XmlNode componentNode in node.ChildNodes) { foreach (XmlNode componentNode in node.ChildNodes) {
ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText, ToolComponent newToolComponent = new ToolComponent(componentNode.Attributes["class"].InnerText,
(ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)]); (ComponentAssembly)assemblies[Int32.Parse(componentNode.Attributes["assembly"].InnerText)]);
newCategory.ToolComponents.Add(newToolComponent); newCategory.ToolComponents.Add(newToolComponent);
} }
@ -298,11 +304,11 @@ namespace ICSharpCode.FormsDesigner.Gui
} }
if (b == null) { if (b == null) {
try { try {
Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp"); Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp");
if (imageStream != null) { if (imageStream != null) {
b = new Bitmap(Image.FromStream(imageStream)); b = new Bitmap(Image.FromStream(imageStream));
b.MakeTransparent(); b.MakeTransparent();
} }
} catch (Exception e) { } catch (Exception e) {
ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.GetIcon: " + e.Message); ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.GetIcon: " + e.Message);
} }

198
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs

@ -1,30 +1,23 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt"/> // <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/> // <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> // <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System; using System;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Design; using System.Drawing.Design;
using System.Reflection;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.Design; using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Security.Policy;
using System.Runtime.Remoting;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Threading;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.FormsDesigner.Services; using ICSharpCode.FormsDesigner.Services;
@ -32,13 +25,6 @@ namespace ICSharpCode.FormsDesigner.Gui
{ {
public class CustomComponentsSideTab : SideTabDesigner public class CustomComponentsSideTab : SideTabDesigner
{ {
ArrayList projectAssemblies = new ArrayList();
ArrayList referencedAssemblies = new ArrayList();
Dictionary<string, Assembly> loadedFiles = new Dictionary<string, Assembly>();
List<string> loadedProjects = new List<string>();
static bool loadReferencedAssemblies = true;
///<summary>Load an assembly's controls</summary> ///<summary>Load an assembly's controls</summary>
public CustomComponentsSideTab(AxSideBar sideTab, string name, IToolboxService toolboxService) : base(sideTab,name, toolboxService) public CustomComponentsSideTab(AxSideBar sideTab, string name, IToolboxService toolboxService) : base(sideTab,name, toolboxService)
{ {
@ -47,142 +33,88 @@ namespace ICSharpCode.FormsDesigner.Gui
ProjectService.SolutionLoaded += RescanProjectAssemblies; ProjectService.SolutionLoaded += RescanProjectAssemblies;
} }
public static bool LoadReferencedAssemblies { void RescanProjectAssemblies(object sender, EventArgs e)
get {
return loadReferencedAssemblies;
}
set {
loadReferencedAssemblies = value;
}
}
string loadingPath = String.Empty;
byte[] GetBytes(string fileName)
{ {
FileStream fs = File.OpenRead(fileName); Items.Clear();
long size = fs.Length; AddDefaultItem();
byte[] outArray = new byte[size]; ScanProjectAssemblies();
fs.Read(outArray, 0, (int)size); SharpDevelopSideBar.SideBar.Refresh();
fs.Close();
return outArray;
} }
Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) void ScanProjectAssemblies()
{ {
LoggingService.Debug("Form Designer: MyResolve: " + args.Name); // custom user controls don't need custom images
string file = args.Name; loadImages = false;
int idx = file.IndexOf(','); foreach (IProjectContent pc in ParserService.AllProjectContentsWithReferences) {
if (idx >= 0) { if (pc.Project == null) {
file = file.Substring(0, idx); ReflectionProjectContent rpc = pc as ReflectionProjectContent;
} if (rpc == null || rpc.IsGacAssembly)
//search in other assemblies, this also help to avoid doubling of loaded assms continue;
if (ProjectService.OpenSolution != null) {
foreach (IProject project in ProjectService.OpenSolution.Projects) {
if (project.AssemblyName == file)
return LoadAssemblyFile(project.OutputAssemblyFullPath, true);
} }
} foreach (IClass c in pc.Classes) {
foreach (IClass subClass in c.ClassInheritanceTree) {
//skip already loaded if (subClass.FullyQualifiedName == "System.Windows.Forms.Form") {
Assembly lastAssembly = null; break; // is not a design component
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { }
//LoggingService.Info("Assembly..." + asm.FullName); if (subClass.FullyQualifiedName == "System.ComponentModel.IComponent") {
if (asm.FullName == args.Name) { goto isDesignComponent;
lastAssembly = asm; }
foreach (IAttribute attr in subClass.Attributes) {
if (attr.Name == "DesignTimeVisibleAttribute"
|| attr.Name == "System.ComponentModel.DesignTimeVisibleAttribute")
{
// TODO: Check value of attribute (make IAttribute store at least simple values like bool's and typeof's)
goto isDesignComponent;
}
}
}
// is not a design component
continue;
isDesignComponent:
this.Items.Add(new SideTabItemDesigner(c.Name, new CustomComponentToolBoxItem(c)));
} }
} }
if (lastAssembly != null) {
LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name);
return lastAssembly;
}
return null;
} }
}
Assembly LoadAssemblyFile(string assemblyName, bool nonLocking) public class CustomComponentToolBoxItem : ToolboxItem
{ {
assemblyName = assemblyName.ToLower(); string className;
//skip already loaded over MyResolveEventHandler IProjectContent assemblyLocation;
if(loadedFiles.ContainsKey(assemblyName)) bool initialized;
return loadedFiles[assemblyName];
if ((assemblyName.EndsWith("exe") || assemblyName.EndsWith("dll")) && File.Exists(assemblyName)) {
string fileAsmName = AssemblyName.GetAssemblyName(assemblyName).ToString();
Assembly asm;
//skip already loaded public CustomComponentToolBoxItem(IClass c)
Assembly lastAssembly = null; {
foreach (Assembly asmLoaded in AppDomain.CurrentDomain.GetAssemblies()) { className = c.FullyQualifiedName;
if (asmLoaded.FullName == fileAsmName) { assemblyLocation = c.ProjectContent;
lastAssembly = asmLoaded; this.Bitmap = new ToolboxItem(typeof(Component)).Bitmap;
} this.IsTransient = true;
}
if (lastAssembly != null) {
asm = lastAssembly;
} else {
asm = nonLocking ? Assembly.Load(GetBytes(assemblyName)) : Assembly.LoadFrom(assemblyName); //Assembly.LoadFrom(assemblyName);
}
if (asm != null) {
loadedFiles[assemblyName] = asm;
BuildToolboxFromAssembly(asm);
}
return asm;
}
return null;
} }
void LoadProject(IProject project) void Init()
{ {
string assemblyName = project.OutputAssemblyFullPath; if (initialized)
if(loadedProjects.Contains(assemblyName))
return; return;
loadedProjects.Add(assemblyName); initialized = true;
LoggingService.Debug("Initializing MyToolBoxItem: " + className);
foreach (ProjectItem projectItem in project.Items) { if (assemblyLocation != null) {
ProjectReferenceProjectItem projectReferenceProjectItem = projectItem as ProjectReferenceProjectItem; Assembly asm = TypeResolutionService.LoadAssembly(assemblyLocation);
if(projectReferenceProjectItem != null) if (asm != null) {
LoadProject(projectReferenceProjectItem.ReferencedProject); Initialize(asm.GetType(className));
}
} }
loadingPath = Path.GetDirectoryName(assemblyName) + Path.DirectorySeparatorChar;
LoadAssemblyFile(assemblyName, true);
} }
void ScanProjectAssemblies() protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{ {
projectAssemblies.Clear(); Init();
referencedAssemblies.Clear(); return base.CreateComponentsCore(host);
loadedFiles.Clear();
loadedProjects.Clear();
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
try {
// custom user controls don't need custom images
loadImages = false;
ITypeResolutionService typeResolutionService = ToolboxProvider.TypeResolutionService;
if (ProjectService.OpenSolution != null) {
foreach (IProject project in ProjectService.OpenSolution.Projects) {
LoadProject(project);
projectAssemblies.Add(project.OutputAssemblyFullPath);
}
}
} catch (Exception e) {
LoggingService.Warn("Form Designer: ScanProjectAssemblies", e);
} finally {
AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(MyResolveEventHandler);
}
} }
void RescanProjectAssemblies(object sender, EventArgs e) protected override IComponent[] CreateComponentsCore(IDesignerHost host, System.Collections.IDictionary defaultValues)
{ {
projectAssemblies.Clear(); Init();
referencedAssemblies.Clear(); return base.CreateComponentsCore(host, defaultValues);
Items.Clear();
AddDefaultItem();
ScanProjectAssemblies();
SharpDevelopSideBar.SideBar.Refresh();
} }
} }
} }

BIN
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.FormDesigner.Gui.AssemblyList.resources

Binary file not shown.

BIN
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ControlLibrariesPanel.resources

Binary file not shown.

17
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabDesigner.cs

@ -26,28 +26,18 @@ namespace ICSharpCode.FormsDesigner.Gui
protected bool loadImages = true; protected bool loadImages = true;
IToolboxService toolboxService; IToolboxService toolboxService;
public void CreatedUserControl()
{
InitializeComponents();
}
void InitializeComponents()
{
}
protected SideTabDesigner(AxSideBar sideBar, string name, IToolboxService toolboxService) : base(sideBar, name) protected SideTabDesigner(AxSideBar sideBar, string name, IToolboxService toolboxService) : base(sideBar, name)
{ {
this.toolboxService = toolboxService; this.toolboxService = toolboxService;
this.CanSaved = false; this.CanSaved = false;
AddDefaultItem(); AddDefaultItem();
this.ChoosedItemChanged += SelectedTabItemChanged;
} }
protected void AddDefaultItem() protected void AddDefaultItem()
{ {
this.Items.Add(new SideTabItemDesigner()); this.Items.Add(new SideTabItemDesigner());
//Event the user click on an another "control" itemin the current tab
this.ChoosedItemChanged += new EventHandler(SelectedTabItemChanged);
} }
///<summary>Load an assembly's controls</summary> ///<summary>Load an assembly's controls</summary>
@ -67,6 +57,7 @@ namespace ICSharpCode.FormsDesigner.Gui
} }
} }
/*
protected void LoadAssembly(string assemblyName) protected void LoadAssembly(string assemblyName)
{ {
Assembly assembly = FindAssembly(assemblyName); Assembly assembly = FindAssembly(assemblyName);
@ -202,12 +193,14 @@ namespace ICSharpCode.FormsDesigner.Gui
} }
if (lastAssembly != null) { if (lastAssembly != null) {
LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name); LoggingService.Info("ICSharpAssemblyResolver found..." + args.Name);
if (!TypeResolutionService.DesignerAssemblies.Contains(lastAssembly))
TypeResolutionService.DesignerAssemblies.Add(lastAssembly);
return lastAssembly; return lastAssembly;
} }
return null; return null;
} }
*/
void SelectedTabItemChanged(object sender, EventArgs e) void SelectedTabItemChanged(object sender, EventArgs e)
{ {

14
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/SideTabItemDesigner.cs

@ -35,27 +35,17 @@ namespace ICSharpCode.FormsDesigner.Gui
{ {
public class SideTabItemDesigner : SharpDevelopSideTabItem public class SideTabItemDesigner : SharpDevelopSideTabItem
{ {
public void CreatedUserControl()
{
InitializeComponents();
}
void InitializeComponents()
{
}
///<summary>create a tabitem from a toolboxitem. It init Icon and name from the tag</summary> ///<summary>create a tabitem from a toolboxitem. It init Icon and name from the tag</summary>
public SideTabItemDesigner(ToolboxItem tag) : base(tag.DisplayName, tag) public SideTabItemDesigner(ToolboxItem tag) : base(tag.DisplayName, tag)
{ {
this.Icon = tag.Bitmap; this.Icon = tag.Bitmap;
ReloadToolBox(); ReloadToolBox();
} }
///<summary>create a tabitem from a toolboxitem. It init Icon from the tag</summary> ///<summary>create a tabitem from a toolboxitem. It init Icon from the tag</summary>
public SideTabItemDesigner(string name, ToolboxItem tag) : base(name, tag) public SideTabItemDesigner(string name, ToolboxItem tag) : base(name, tag)
{ {
this.Icon = tag.Bitmap; this.Icon = tag.Bitmap;
ReloadToolBox(); ReloadToolBox();
} }

9
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs

@ -35,13 +35,14 @@ namespace ICSharpCode.FormsDesigner.Services
{ {
List<Type> types = new List<Type>(); List<Type> types = new List<Type>();
if (baseType != null) { if (baseType != null) {
LoggingService.Debug("TypeDiscoveryService.GetTypes baseType=" + baseType.FullName); LoggingService.Debug("TypeDiscoveryService.GetTypes for " + baseType.FullName
LoggingService.Debug("TypeDiscoveryService.GetTypes excludeGlobalTypes=" + excludeGlobalTypes.ToString()); + "excludeGlobalTypes=" + excludeGlobalTypes.ToString());
//seek in all assemblies //seek in all assemblies
//allow to work designers like columns editor in datagridview //allow to work designers like columns editor in datagridview
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Assembly asm in TypeResolutionService.DesignerAssemblies) {
AddDerivedTypes(baseType, asm, types); AddDerivedTypes(baseType, asm, types);
} }
LoggingService.Debug("TypeDiscoveryService returns " + types.Count + " types");
// TODO - Don't look in all assemblies. // TODO - Don't look in all assemblies.
// Should use the current project and its referenced assemblies // Should use the current project and its referenced assemblies
@ -58,7 +59,7 @@ namespace ICSharpCode.FormsDesigner.Services
{ {
foreach (Type t in assembly.GetExportedTypes()) { foreach (Type t in assembly.GetExportedTypes()) {
if (t.IsSubclassOf(baseType)) { if (t.IsSubclassOf(baseType)) {
LoggingService.Debug("TypeDiscoveryService. Adding type=" + t.FullName); //LoggingService.Debug("TypeDiscoveryService. Adding type=" + t.FullName);
list.Add(t); list.Add(t);
} }
} }

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

@ -1,23 +1,119 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt"/> // <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/> // <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> // <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System; using System;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Collections; using System.Collections;
using System.Collections.Specialized; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.Design; using System.ComponentModel.Design;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.Core; using ICSharpCode.Core;
using HashFunction = System.Security.Cryptography.SHA1Managed;
namespace ICSharpCode.FormsDesigner.Services namespace ICSharpCode.FormsDesigner.Services
{ {
public class TypeResolutionService : ITypeResolutionService public class TypeResolutionService : ITypeResolutionService
{ {
readonly static List<Assembly> designerAssemblies = new List<Assembly>();
// hash of file content -> Assembly
readonly static Dictionary<string, Assembly> assemblyDict = new Dictionary<string, Assembly>();
/// <summary>
/// List of assemblies used by the form designer. This static list is not an optimal solution,
/// but better than using AppDomain.CurrentDomain.GetAssemblies(). See SD2-630.
/// </summary>
public static List<Assembly> DesignerAssemblies {
get {
return designerAssemblies;
}
}
static TypeResolutionService()
{
DesignerAssemblies.Add(ProjectContentRegistry.MscorlibAssembly);
DesignerAssemblies.Add(ProjectContentRegistry.SystemAssembly);
DesignerAssemblies.Add(typeof(System.Drawing.Point).Assembly);
}
string formSourceFileName;
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(string formSourceFileName)
{
this.formSourceFileName = formSourceFileName;
}
/// <summary>
/// Loads the assembly represented by the project content. Returns null on failure.
/// </summary>
public static Assembly LoadAssembly(IProjectContent pc)
{
if (pc.Project != null) {
return LoadAssembly(pc.Project.OutputAssemblyFullPath);
} else if (pc is ReflectionProjectContent) {
return LoadAssembly((pc as ReflectionProjectContent).AssemblyLocation);
} else {
return null;
}
}
/// <summary>
/// Loads the file in none-locking mode. Returns null on failure.
/// </summary>
public static Assembly LoadAssembly(string fileName)
{
if (!File.Exists(fileName))
return null;
byte[] data = File.ReadAllBytes(fileName);
string hash;
using (HashFunction hashFunction = new HashFunction()) {
hash = Convert.ToBase64String(hashFunction.ComputeHash(data));
}
lock (assemblyDict) {
Assembly asm;
if (assemblyDict.TryGetValue(hash, out asm))
return asm;
asm = Assembly.Load(data);
lock (designerAssemblies) {
if (!designerAssemblies.Contains(asm))
designerAssemblies.Add(asm);
}
assemblyDict[hash] = asm;
return asm;
}
}
public Assembly GetAssembly(AssemblyName name) public Assembly GetAssembly(AssemblyName name)
{ {
return GetAssembly(name, false); return GetAssembly(name, false);
@ -25,7 +121,18 @@ namespace ICSharpCode.FormsDesigner.Services
public Assembly GetAssembly(AssemblyName name, bool throwOnError) public Assembly GetAssembly(AssemblyName name, bool throwOnError)
{ {
return Assembly.Load(name); try {
Assembly asm = Assembly.Load(name);
lock (designerAssemblies) {
if (!designerAssemblies.Contains(asm))
designerAssemblies.Add(asm);
}
return asm;
} catch (System.IO.FileLoadException) {
if (throwOnError)
throw;
return null;
}
} }
public string GetPathOfAssembly(AssemblyName name) public string GetPathOfAssembly(AssemblyName name)
@ -39,7 +146,7 @@ namespace ICSharpCode.FormsDesigner.Services
public Type GetType(string name) public Type GetType(string name)
{ {
return GetType(name, false); return GetType(name, false, false);
} }
public Type GetType(string name, bool throwOnError) public Type GetType(string name, bool throwOnError)
@ -56,18 +163,29 @@ namespace ICSharpCode.FormsDesigner.Services
return null; return null;
} }
try { try {
Assembly lastAssembly = null; lock (designerAssemblies) {
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Assembly asm in DesignerAssemblies) {
Type t = asm.GetType(name, throwOnError); Type t = asm.GetType(name, false);
if (t != null) { if (t != null) {
lastAssembly = asm; return t;
}
} }
} }
if (lastAssembly != null) {
return lastAssembly.GetType(name, throwOnError, ignoreCase);
}
Type type = Type.GetType(name, throwOnError, ignoreCase); Type type = Type.GetType(name, false, ignoreCase);
if (type == null) {
IProjectContent pc = this.CallingProject;
if (pc != null) {
IClass foundClass = pc.GetClass(name);
if (foundClass != null) {
Assembly assembly = LoadAssembly(foundClass.ProjectContent);
if (assembly != null) {
type = assembly.GetType(name, false, ignoreCase);
}
}
}
}
// type lookup for typename, assembly, xyz style lookups // type lookup for typename, assembly, xyz style lookups
if (type == null) { if (type == null) {
@ -80,19 +198,26 @@ namespace ICSharpCode.FormsDesigner.Services
try { try {
assembly = Assembly.Load(assemblyName); assembly = Assembly.Load(assemblyName);
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine(e); LoggingService.Error(e);
} }
if (assembly != null) { if (assembly != null) {
type = assembly.GetType(typeName, throwOnError, ignoreCase); lock (designerAssemblies) {
if (!designerAssemblies.Contains(assembly))
designerAssemblies.Add(assembly);
}
type = assembly.GetType(typeName, false, ignoreCase);
} else { } else {
type = Type.GetType(typeName, throwOnError, ignoreCase); type = Type.GetType(typeName, false, ignoreCase);
} }
} }
} }
if (throwOnError && type == null)
throw new TypeLoadException(name + " not found by TypeResolutionService");
return type; return type;
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine(e); LoggingService.Error(e);
} }
return null; return null;
} }

11
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs

@ -40,17 +40,10 @@ namespace ICSharpCode.FormsDesigner
public class ToolboxProvider public class ToolboxProvider
{ {
static ICSharpCode.FormsDesigner.Services.ToolboxService toolboxService = null; static ICSharpCode.FormsDesigner.Services.ToolboxService toolboxService = null;
static ITypeResolutionService typeResolutionService = new TypeResolutionService();
public static ArrayList SideTabs = new ArrayList(); public static ArrayList SideTabs = new ArrayList();
static ComponentLibraryLoader componentLibraryLoader = new ComponentLibraryLoader(); static ComponentLibraryLoader componentLibraryLoader = new ComponentLibraryLoader();
public static ITypeResolutionService TypeResolutionService {
get {
return typeResolutionService;
}
}
public static ComponentLibraryLoader ComponentLibraryLoader { public static ComponentLibraryLoader ComponentLibraryLoader {
get { get {
return componentLibraryLoader; return componentLibraryLoader;
@ -210,7 +203,7 @@ namespace ICSharpCode.FormsDesigner
static void AddReferenceToProject(IProject project, AssemblyName referenceName) static void AddReferenceToProject(IProject project, AssemblyName referenceName)
{ {
LoggingService.Debug("Adding reference to project: " + referenceName.FullName); LoggingService.Warn("Adding reference to project: " + referenceName.FullName);
ReferenceProjectItem reference = new ReferenceProjectItem(project, "Reference"); ReferenceProjectItem reference = new ReferenceProjectItem(project, "Reference");
ToolComponent toolComponent = ToolboxProvider.ComponentLibraryLoader.GetToolComponent(referenceName.FullName); ToolComponent toolComponent = ToolboxProvider.ComponentLibraryLoader.GetToolComponent(referenceName.FullName);
if (toolComponent == null || toolComponent.HintPath == null) { if (toolComponent == null || toolComponent.HintPath == null) {
@ -250,7 +243,7 @@ namespace ICSharpCode.FormsDesigner
static void AddProjectReferenceToProject(IProject project, IProject referenceTo) static void AddProjectReferenceToProject(IProject project, IProject referenceTo)
{ {
LoggingService.Debug("Adding project reference to project."); LoggingService.Warn("Adding project reference to project.");
ProjectReferenceProjectItem reference = new ProjectReferenceProjectItem(project, referenceTo); ProjectReferenceProjectItem reference = new ProjectReferenceProjectItem(project, referenceTo);
ProjectService.AddProjectItem(project, reference); ProjectService.AddProjectItem(project, reference);
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView(); ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();

12
src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToCSharpConvertVisitor.cs

@ -1,9 +1,9 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: Daniel Grunwald // <license see="prj:///doc/license.txt"/>
* Date: 02.01.2006 // <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
* Time: 18:15 // <version>$Revision$</version>
*/ // </file>
using System; using System;
using System.Text; using System.Text;

12
src/Libraries/NRefactory/Project/Src/Parser/Visitors/ToVBNetConvertVisitor.cs

@ -1,9 +1,9 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: Daniel Grunwald // <license see="prj:///doc/license.txt"/>
* Date: 02.01.2006 // <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
* Time: 18:18 // <version>$Revision$</version>
*/ // </file>
using System; using System;
using System.Text; using System.Text;

2
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageView.cs

@ -331,7 +331,7 @@ namespace ICSharpCode.SharpDevelop.Gui
// find start of current line // find start of current line
while (--start > 0 && fullText[start - 1] != '\n'); while (--start > 0 && fullText[start - 1] != '\n');
// find end of current line // find end of current line
while (++index < fullText.Length && fullText[index] != '\r'); while (++index < fullText.Length && fullText[index] != '\n');
string textLine = fullText.Substring(start, index - start); string textLine = fullText.Substring(start, index - start);

16
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -57,12 +57,28 @@ namespace ICSharpCode.Core
forcedContent = content; forcedContent = content;
} }
/// <summary>
/// Gets the list of project contents of all open projects.
/// </summary>
public static IEnumerable<IProjectContent> AllProjectContents { public static IEnumerable<IProjectContent> AllProjectContents {
get { get {
return projectContents.Values; return projectContents.Values;
} }
} }
/// <summary>
/// Gets the list of project contents of all open projects plus the referenced project contents.
/// </summary>
public static IEnumerable<IProjectContent> AllProjectContentsWithReferences {
get {
foreach (IProjectContent pc in AllProjectContents) {
yield return pc;
}
foreach (IProjectContent pc in ProjectContentRegistry.LoadedProjectContents) {
yield return pc;
}
}
}
static ParserService() static ParserService()
{ {

20
src/Main/Base/Project/Src/Services/ParserService/ProjectContentRegistry.cs

@ -57,6 +57,12 @@ namespace ICSharpCode.Core
} }
} }
public static IEnumerable<IProjectContent> LoadedProjectContents {
get {
return contents.Values;
}
}
public static IProjectContent WinForms { public static IProjectContent WinForms {
get { get {
lock (contents) { lock (contents) {
@ -173,13 +179,25 @@ namespace ICSharpCode.Core
} }
} }
public static Assembly MscorlibAssembly {
get {
return typeof(object).Assembly;
}
}
public static Assembly SystemAssembly {
get {
return typeof(Uri).Assembly;
}
}
static Assembly GetDefaultAssembly(string shortName) static Assembly GetDefaultAssembly(string shortName)
{ {
// These assemblies are already loaded by SharpDevelop, so we don't need to load // These assemblies are already loaded by SharpDevelop, so we don't need to load
// them in a separate AppDomain. // them in a separate AppDomain.
switch (shortName) { switch (shortName) {
case "System": // System != mscorlib !!! case "System": // System != mscorlib !!!
return typeof(Uri).Assembly; return SystemAssembly;
case "System.Data": case "System.Data":
return typeof(System.Data.DataException).Assembly; return typeof(System.Data.DataException).Assembly;
case "System.Design": case "System.Design":

13
src/Main/Base/Project/Src/Services/ParserService/ReflectionProjectContent.cs

@ -32,6 +32,19 @@ namespace ICSharpCode.SharpDevelop.Dom
} }
} }
public bool IsGacAssembly {
get {
return assemblyLocation == typeof(object).Assembly.Location
|| FileUtility.IsBaseDirectory(GacRootPath, assemblyLocation);
}
}
public static string GacRootPath {
get {
return Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ProjectContentRegistry.SystemAssembly.Location), "..\\..\\.."));
}
}
public string AssemblyFullName { public string AssemblyFullName {
get { get {
return assemblyFullName; return assemblyFullName;

12
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerationForm.cs

@ -1,9 +1,9 @@
/* // <file>
* Created by SharpDevelop. // <copyright see="prj:///doc/copyright.txt"/>
* User: Daniel Grunwald // <license see="prj:///doc/license.txt"/>
* Date: 29.12.2005 // <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
* Time: 14:34 // <version>$Revision$</version>
*/ // </file>
using System; using System;
using System.Collections; using System.Collections;

Loading…
Cancel
Save