Skip to content
Browse files

WIP: add DesignerAppDomainHost and use only one AD

  • Loading branch information...
1 parent aedf2a7 commit 5047c6aac99fbb454a69d8d49432d2584c9cfcb6 @siegfriedpammer siegfriedpammer committed Sep 19, 2011
Showing with 416 additions and 323 deletions.
  1. +7 −7 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Commands/FormsCommands.cs
  2. +57 −0 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/DesignerAppDomainHost.cs
  3. +12 −6 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormKeyHandler.cs
  4. +1 −1 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesigner.AddIn.csproj
  5. +0 −23 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerAppDomainServer.cs
  6. +233 −223 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerViewContent.cs
  7. +2 −2 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/ProjectResourceService.cs
  8. +1 −1 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/SharpDevelopCommandProvider.cs
  9. +2 −0 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Toolbox/ToolboxProvider.cs
  10. +2 −8 src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj
  11. +35 −0 src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesignerCreationProperties.cs
  12. +36 −44 ...s/DisplayBindings/FormsDesigner/Project/{FormsDesignerAppDomainHost.cs → FormsDesignerManager.cs}
  13. +21 −1 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerAppDomainManager.cs
  14. +2 −2 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs
  15. +2 −2 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/IDEContainer.cs
  16. +1 −1 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/PropertyPadContent.cs
  17. +2 −2 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/DesignerResourceService.cs
View
14 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Commands/FormsCommands.cs
@@ -24,7 +24,7 @@ public abstract class AbstractFormsDesignerCommand : AbstractMenuCommand
get;
}
- protected virtual bool CanExecuteCommand(FormsDesignerAppDomainHost host)
+ protected virtual bool CanExecuteCommand(FormsDesignerManager host)
{
return true;
}
@@ -42,8 +42,8 @@ public override void Run()
{
try {
FormsDesignerViewContent formsDesigner = FormsDesigner;
- if (formsDesigner != null && CanExecuteCommand(formsDesigner.AppDomainHost)) {
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)formsDesigner.AppDomainHost.MenuCommandService;
+ if (formsDesigner != null && CanExecuteCommand(formsDesigner.AppDomainManager)) {
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)formsDesigner.AppDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandID);
}
} catch (Exception e) {
@@ -100,7 +100,7 @@ public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
{
List<ToolStripItem> items = new List<ToolStripItem>();
- foreach (IDesignerVerbProxy verb in ((FormsDesignerAppDomainHost)owner).CommandVerbs) {
+ foreach (IDesignerVerbProxy verb in ((FormsDesignerManager)owner).CommandVerbs) {
items.Add(new ContextMenuCommand(verb));
}
@@ -248,7 +248,7 @@ public class HorizSpaceMakeEqual : AbstractFormsDesignerCommand
}
}
- protected override bool CanExecuteCommand(FormsDesignerAppDomainHost host)
+ protected override bool CanExecuteCommand(FormsDesignerManager host)
{
ISelectionService selectionService = (ISelectionService)host.GetService(typeof(ISelectionService));
return selectionService.SelectionCount > 1;
@@ -292,7 +292,7 @@ public class VertSpaceMakeEqual : AbstractFormsDesignerCommand
}
}
- protected override bool CanExecuteCommand(FormsDesignerAppDomainHost host)
+ protected override bool CanExecuteCommand(FormsDesignerManager host)
{
ISelectionService selectionService = (ISelectionService)host.GetService(typeof(ISelectionService));
return selectionService.SelectionCount > 1;
@@ -408,7 +408,7 @@ public class ShowLargeIcons : AbstractCheckableMenuCommand
get {
FormsDesignerViewContent formDesigner = FormDesigner;
if (formDesigner != null) {
- return formDesigner.AppDomainHost.GetService(typeof(ComponentTray)) as ComponentTray;
+ return formDesigner.AppDomainManager.GetService(typeof(ComponentTray)) as ComponentTray;
}
return null;
View
57 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/DesignerAppDomainHost.cs
@@ -0,0 +1,57 @@
+// 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.IO;
+
+namespace ICSharpCode.FormsDesigner
+{
+ /// <summary>
+ /// Description of DesignerAppDomainHost.
+ /// </summary>
+ public class DesignerAppDomainHost
+ {
+ static DesignerAppDomainHost instance;
+ DesignerAppDomainManager manager;
+ AppDomain appDomain;
+
+ public AppDomain DesignerAppDomain {
+ get { return appDomain; }
+ }
+
+ public static DesignerAppDomainHost Instance {
+ get { Initialize(); return instance; }
+ }
+
+ public DesignerAppDomainHost(DesignerAppDomainManager manager, AppDomain appDomain)
+ {
+ this.manager = manager;
+ this.appDomain = appDomain;
+ }
+
+ static void Initialize()
+ {
+ if (instance != null && instance.appDomain != null)
+ return;
+
+ // Construct and initialize settings for a second AppDomain.
+ AppDomainSetup formsDesignerAppDomainSetup = new AppDomainSetup();
+ formsDesignerAppDomainSetup.ApplicationBase = Path.GetDirectoryName(typeof(DesignerAppDomainManager).Assembly.Location);
+ formsDesignerAppDomainSetup.DisallowBindingRedirects = false;
+ formsDesignerAppDomainSetup.DisallowCodeDownload = true;
+ formsDesignerAppDomainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
+
+ // Create the second AppDomain.
+ AppDomain appDomain = AppDomain.CreateDomain("FormsDesigner AD", null, formsDesignerAppDomainSetup);
+
+ var manager = (DesignerAppDomainManager)appDomain.CreateInstanceAndUnwrap(typeof(DesignerAppDomainManager).Assembly.FullName, typeof(DesignerAppDomainManager).FullName);
+
+ instance = new DesignerAppDomainHost(manager, appDomain);
+ }
+
+ public FormsDesignerManager CreateFormsDesignerInAppDomain(FormsDesignerCreationProperties creationProperties)
+ {
+ return manager.CreateFormsDesignerInAppDomain(creationProperties);
+ }
+ }
+}
View
18 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormKeyHandler.cs
@@ -22,13 +22,19 @@ public sealed class FormKeyHandler : MarshalByRefObject, IMessageFilter
readonly Dictionary<Keys, CommandWrapper> keyTable = new Dictionary<Keys, CommandWrapper>();
FormsDesignerViewContent formsDesigner;
- public static bool inserted = false;
- public static void Insert(FormsDesignerViewContent formsDesigner)
+ public static FormKeyHandler Insert(FormsDesignerViewContent formsDesigner)
{
Debug.Assert(!DesignerAppDomainManager.IsDesignerDomain);
- inserted = true;
- Application.AddMessageFilter(new FormKeyHandler(formsDesigner));
+ var filter = new FormKeyHandler(formsDesigner);
+ Application.AddMessageFilter(filter);
+ return filter;
+ }
+
+ public void Remove()
+ {
+ Debug.Assert(!DesignerAppDomainManager.IsDesignerDomain);
+ Application.RemoveMessageFilter(this);
}
public FormKeyHandler(FormsDesignerViewContent formsDesigner)
@@ -102,7 +108,7 @@ public bool PreFilterMessage(ref Message m)
return false;
}
}
- var host = formsDesigner.AppDomainHost;
+ var host = formsDesigner.AppDomainManager;
LoggingService.Debug("Run menu command: " + commandWrapper.CommandID);
IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)host.MenuCommandService;
@@ -131,7 +137,7 @@ bool HandleMenuCommand(IComponent activeComponent, Keys keyPressed)
Assembly asm = typeof(WindowsFormsDesignerOptionService).Assembly;
// Microsoft made ToolStripKeyboardHandlingService internal, so we need Reflection
Type keyboardType = asm.GetType("System.Windows.Forms.Design.ToolStripKeyboardHandlingService");
- object keyboardService = formsDesigner.AppDomainHost.GetService(keyboardType);
+ object keyboardService = formsDesigner.AppDomainManager.GetService(keyboardType);
if (keyboardService == null) {
LoggingService.Debug("no ToolStripKeyboardHandlingService found");
return false; // handle command normally
View
2 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesigner.AddIn.csproj
@@ -79,6 +79,7 @@
<Compile Include="Commands\FormsCommands.cs" />
<Compile Include="Commands\SideBarCommands.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
+ <Compile Include="DesignerAppDomainHost.cs" />
<Compile Include="DesignerGenerator\AbstractDesignerGenerator.cs" />
<Compile Include="DesignerGenerator\CodeDOMGenerator.cs" />
<Compile Include="DesignerGenerator\CSharpDesignerGenerator.cs" />
@@ -89,7 +90,6 @@
<Compile Include="DesignerLoader\NRefactoryDesignerLoader.cs" />
<Compile Include="DesignerSourceCodeStorage.cs" />
<Compile Include="FormKeyHandler.cs" />
- <Compile Include="FormsDesignerAppDomainServer.cs" />
<Compile Include="FormsDesignerLoggingServiceImpl.cs" />
<Compile Include="FormsDesignerViewContent.cs" />
<Compile Include="ImageResourceEditorDialogWrapper.cs" />
View
23 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerAppDomainServer.cs
@@ -1,23 +0,0 @@
-// 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.Runtime.Remoting.Lifetime;
-
-namespace ICSharpCode.FormsDesigner
-{
- /// <summary>
- /// Description of FormsDesignerAppDomainServer.
- /// </summary>
- public class FormsDesignerAppDomainServer : MarshalByRefObject, ISponsor
- {
- public FormsDesignerAppDomainServer()
- {
- }
-
- public TimeSpan Renewal(ILease lease)
- {
- throw new NotImplementedException();
- }
- }
-}
View
456 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerViewContent.cs
@@ -33,26 +33,33 @@ namespace ICSharpCode.FormsDesigner
{
public class FormsDesignerViewContent : AbstractViewContentHandlingLoadErrors, IClipboardHandler, IUndoHandler, IHasPropertyContainer, IContextHelpProvider, IToolsHost, IFileDocumentProvider, IFormsDesigner
{
+ #region Fields
readonly Control pleaseWaitLabel = new Label() { Text = StringParser.Parse("${res:Global.PleaseWait}"), TextAlign=ContentAlignment.MiddleCenter };
- bool disposing;
-
readonly IViewContent primaryViewContent;
readonly IDesignerLoaderProviderWithViewContent loaderProvider;
readonly IDesignerGenerator generator;
readonly IDesignerSourceProvider sourceProvider;
readonly ResourceStore resourceStore;
+ readonly DesignerSourceCodeStorage sourceCodeStorage;
+ readonly PropertyContainer propertyContainer = new PropertyContainer();
+
+ bool disposing;
IFormsDesignerUndoEngine undoEngine;
- FormsDesignerAppDomainHost appDomainHost;
+ FormsDesignerManager appDomainManager;
ToolboxProvider toolbox;
+ bool inMasterLoadOperation;
+ bool hasUnmergedChanges;
+ bool reloadPending;
+ CustomWindowsFormsHost designView;
+ SharpDevelopDesignerOptions options;
+ FormKeyHandler keyHandler;
+ #endregion
- public FormsDesignerAppDomainHost AppDomainHost {
- get { return appDomainHost; }
+ #region Properties
+ public FormsDesignerManager AppDomainManager {
+ get { return appDomainManager; }
}
- AppDomain appDomain;
-
- readonly DesignerSourceCodeStorage sourceCodeStorage;
-
public OpenedFile DesignerCodeFile {
get { return this.sourceCodeStorage.DesignerCodeFile; }
}
@@ -80,11 +87,6 @@ public class FormsDesignerViewContent : AbstractViewContentHandlingLoadErrors, I
set { this.DesignerCodeFileDocument.Text = value; }
}
- public ICSharpCode.SharpDevelop.Editor.IDocument GetDocumentForFile(OpenedFile file)
- {
- return this.sourceCodeStorage[file];
- }
-
public IEnumerable<KeyValuePair<OpenedFile, IDocument>> SourceFiles {
get { return this.sourceCodeStorage; }
}
@@ -101,6 +103,41 @@ public ICSharpCode.SharpDevelop.Editor.IDocument GetDocumentForFile(OpenedFile f
get { return StringParser.Parse("${res:ICSharpCode.SharpDevelop.FormDesigner.LoadErrorCheckSourceCodeForErrors}") + Environment.NewLine + Environment.NewLine; }
}
+ public virtual object ToolsContent {
+ get {
+ LoadAppDomainManager();
+ return toolbox.FormsDesignerSideBar;
+ }
+ }
+
+ public PropertyContainer PropertyContainer {
+ get {
+ return propertyContainer;
+ }
+ }
+
+ public IDesignerGenerator Generator {
+ get {
+ return generator;
+ }
+ }
+
+ public Control DesignerContent {
+ get {
+ if (designView == null)
+ return null;
+ return designView.Child;
+ }
+ }
+
+ public SharpDevelopDesignerOptions DesignerOptions {
+ get {
+ return options;
+ }
+ }
+ #endregion
+
+ #region Constructors
FormsDesignerViewContent(IViewContent primaryViewContent)
: base()
{
@@ -134,6 +171,8 @@ public FormsDesignerViewContent(IViewContent primaryViewContent, IDesignerLoader
this.sourceProvider.Attach(this);
this.Files.Add(this.primaryViewContent.PrimaryFile);
+
+ LoadAppDomainManager();
}
/// <summary>
@@ -145,13 +184,101 @@ public FormsDesignerViewContent(IViewContent primaryViewContent, OpenedFile mock
this.sourceCodeStorage.AddFile(mockFile, Encoding.UTF8);
this.sourceCodeStorage.DesignerCodeFile = mockFile;
this.Files.Add(primaryViewContent.PrimaryFile);
+
+ LoadAppDomainManager();
}
+ #endregion
- void LoadAppDomain()
+ #region Proxies
+ class ViewContentIFormsDesignerProxy : MarshalByRefObject, IFormsDesigner
{
+ FormsDesignerViewContent vc;
+
+ public ViewContentIFormsDesignerProxy(FormsDesignerViewContent vc)
+ {
+ this.vc = vc;
+ }
+
+ public IDesignerGenerator Generator {
+ get {
+ return vc.Generator;
+ }
+ }
+
+ public SharpDevelopDesignerOptions DesignerOptions {
+ get {
+ return vc.DesignerOptions;
+ }
+ }
+
+ public IntPtr GetDialogOwnerWindowHandle()
+ {
+ return vc.GetDialogOwnerWindowHandle();
+ }
+
+ public void ShowSourceCode()
+ {
+ vc.ShowSourceCode();
+ }
+
+ public void ShowSourceCode(int lineNumber)
+ {
+ vc.ShowSourceCode(lineNumber);
+ }
+
+ public void ShowSourceCode(IComponent component, EventDescriptorProxy edesc, string methodName)
+ {
+ vc.ShowSourceCode(component, edesc, methodName);
+ }
+
+ public void MakeDirty()
+ {
+ vc.MakeDirty();
+ }
+
+ public void InvalidateRequerySuggested()
+ {
+ ((IFormsDesigner)vc).InvalidateRequerySuggested();
+ }
+
+ public bool IsTabOrderMode {
+ get {
+ return vc.IsTabOrderMode;
+ }
+ }
+
+ public bool EnableDelete {
+ get {
+ return vc.EnableDelete;
+ }
+ }
+
+ public void HideTabOrder()
+ {
+ vc.HideTabOrder();
+ }
+
+ public Control DesignerContent {
+ get {
+ return vc.DesignerContent;
+ }
+ }
+ }
+ #endregion
+
+ public ICSharpCode.SharpDevelop.Editor.IDocument GetDocumentForFile(OpenedFile file)
+ {
+ return this.sourceCodeStorage[file];
+ }
+
+ void LoadAppDomainManager()
+ {
+ if (appDomainManager != null)
+ return;
+
options = LoadOptions();
- var creationProperties = new FormsDesignerAppDomainCreationProperties {
+ var creationProperties = new FormsDesignerCreationProperties {
FileName = PrimaryFileName,
TypeLocator = new DomTypeLocator(PrimaryFileName),
GacWrapper = new DomGacWrapper(),
@@ -162,30 +289,29 @@ void LoadAppDomain()
ResourceStore = resourceStore
};
- appDomain = null;
- appDomainHost = FormsDesignerAppDomainHost.CreateFormsDesignerInAppDomain(ref appDomain, creationProperties);
- toolbox = new ToolboxProvider(appDomainHost);
- appDomainHost.UseSDAssembly(typeof(CustomWindowsFormsHost).Assembly.FullName, typeof(CustomWindowsFormsHost).Assembly.Location);
+ appDomainManager = DesignerAppDomainHost.Instance.CreateFormsDesignerInAppDomain(creationProperties);
+ toolbox = new ToolboxProvider(appDomainManager);
+ appDomainManager.UseSDAssembly(typeof(CustomWindowsFormsHost).Assembly.FullName, typeof(CustomWindowsFormsHost).Assembly.Location);
- if (!FormKeyHandler.inserted) {
- FormKeyHandler.Insert(this);
- }
+ keyHandler = FormKeyHandler.Insert(this);
Application.Idle += ApplicationIdle;
}
- bool inMasterLoadOperation;
+ void UnloadAppDomainManager()
+ {
+ if (appDomainManager == null)
+ return;
+ Application.Idle -= ApplicationIdle;
+ keyHandler.Remove();
+ appDomainManager.Dispose();
+ appDomainManager = null;
+ }
protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
{
LoggingService.Debug("Forms designer: Load " + file.FileName + "; inMasterLoadOperation=" + this.inMasterLoadOperation);
- if (appDomain == null) {
- LoadAppDomain();
- }
-
- propertyContainer.PropertyGridReplacementContent = WrapInCustomHost(appDomainHost.CreatePropertyPad());
-
if (inMasterLoadOperation) {
if (this.sourceCodeStorage.ContainsFile(file)) {
@@ -198,13 +324,15 @@ protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
} else if (file == this.PrimaryFile || this.sourceCodeStorage.ContainsFile(file)) {
- if (appDomainHost.IsLoaderLoading) {
+ if (appDomainManager != null && appDomainManager.IsLoaderLoading) {
throw new InvalidOperationException("Designer loading a source code file while DesignerLoader is loading and the view is not in a master load operation. This must not happen.");
}
-// if (appDomainHost.DesignSurfaceName != null) {
-// this.UnloadDesigner();
-// }
+ if (appDomainManager != null) {
+ UnloadDesigner();
+ UnloadAppDomainManager();
+ LoadAppDomainManager();
+ }
this.inMasterLoadOperation = true;
@@ -248,7 +376,7 @@ protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
// Loading a resource file
bool mustReload;
- if (appDomainHost.IsLoaderLoading) {
+ if (appDomainManager.IsLoaderLoading) {
LoggingService.Debug("Forms designer: Reloading designer because of LoadInternal on resource file");
this.UnloadDesigner();
mustReload = true;
@@ -272,7 +400,7 @@ protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
CustomWindowsFormsHost WrapInCustomHost(Control control, bool enableFontInheritance = true)
{
- var host = new SDWindowsFormsHost(appDomain, true);
+ var host = new SDWindowsFormsHost(DesignerAppDomainHost.Instance.DesignerAppDomain, true);
host.DisposeChild = false;
host.ServiceObject = this;
host.EnableFontInheritance = enableFontInheritance;
@@ -295,119 +423,46 @@ protected override void SaveInternal(OpenedFile file, System.IO.Stream stream)
internal void AddResourceFile(OpenedFile file)
{
- this.Files.Add(file);
- }
-
- #region Proxies
- class ViewContentIFormsDesignerProxy : MarshalByRefObject, IFormsDesigner
- {
- FormsDesignerViewContent vc;
-
- public ViewContentIFormsDesignerProxy(FormsDesignerViewContent vc)
- {
- this.vc = vc;
- }
-
- public IDesignerGenerator Generator {
- get {
- return vc.Generator;
- }
- }
-
- public SharpDevelopDesignerOptions DesignerOptions {
- get {
- return vc.DesignerOptions;
- }
- }
-
- public IntPtr GetDialogOwnerWindowHandle()
- {
- return vc.GetDialogOwnerWindowHandle();
- }
-
- public void ShowSourceCode()
- {
- vc.ShowSourceCode();
- }
-
- public void ShowSourceCode(int lineNumber)
- {
- vc.ShowSourceCode(lineNumber);
- }
-
- public void ShowSourceCode(IComponent component, EventDescriptorProxy edesc, string methodName)
- {
- vc.ShowSourceCode(component, edesc, methodName);
- }
-
- public void MakeDirty()
- {
- vc.MakeDirty();
- }
-
- public void InvalidateRequerySuggested()
- {
- ((IFormsDesigner)vc).InvalidateRequerySuggested();
- }
-
- public bool IsTabOrderMode {
- get {
- return vc.IsTabOrderMode;
- }
- }
-
- public bool EnableDelete {
- get {
- return vc.EnableDelete;
- }
- }
-
- public void HideTabOrder()
- {
- vc.HideTabOrder();
- }
-
- public Control DesignerContent {
- get {
- return vc.DesignerContent;
- }
- }
+ if (!this.Files.Contains(file))
+ this.Files.Add(file);
}
- #endregion
void LoadDesigner()
{
LoggingService.Info("Form Designer: BEGIN INITIALIZE");
- appDomainHost.AddService(typeof(ISharpDevelopIDEService), new FormsMessageService());
- appDomainHost.AddService(typeof(System.Windows.Forms.Design.IUIService), new UIService(this, appDomainHost));
+ appDomainManager.ResetServiceContainer();
- appDomainHost.AddService(typeof(IHelpService), new HelpService());
+ appDomainManager.AddService(typeof(ISharpDevelopIDEService), new FormsMessageService());
+ appDomainManager.AddService(typeof(System.Windows.Forms.Design.IUIService), new UIService(this, appDomainManager));
- appDomainHost.AddService(typeof(IProjectResourceService), CreateProjectResourceService());
- appDomainHost.AddService(typeof(IImageResourceEditorDialogWrapper), new ImageResourceEditorDialogWrapper(ParserService.GetParseInformation(this.DesignerCodeFile.FileName).CompilationUnit.ProjectContent.Project as IProject));
+ appDomainManager.AddService(typeof(IHelpService), new HelpService());
- appDomainHost.DesignSurfaceLoading += new EventHandlerProxy(DesignerLoading);
- appDomainHost.DesignSurfaceLoaded += new LoadedEventHandlerProxy(DesignerLoaded);
- appDomainHost.DesignSurfaceFlushed += new EventHandlerProxy(DesignerFlushed);
- appDomainHost.DesignSurfaceUnloading += new EventHandlerProxy(DesignerUnloading);
-
- appDomainHost.BeginDesignSurfaceLoad(generator, loaderProvider);
+ appDomainManager.AddService(typeof(IProjectResourceService), CreateProjectResourceService());
+ appDomainManager.AddService(typeof(IImageResourceEditorDialogWrapper), new ImageResourceEditorDialogWrapper(ParserService.GetParseInformation(this.DesignerCodeFile.FileName).CompilationUnit.ProjectContent.Project as IProject));
+
+ appDomainManager.DesignSurfaceLoading += new EventHandlerProxy(DesignerLoading);
+ appDomainManager.DesignSurfaceLoaded += new LoadedEventHandlerProxy(DesignerLoaded);
+ appDomainManager.DesignSurfaceFlushed += new EventHandlerProxy(DesignerFlushed);
+ appDomainManager.DesignSurfaceUnloading += new EventHandlerProxy(DesignerUnloading);
+
+ appDomainManager.BeginDesignSurfaceLoad(generator, loaderProvider);
- if (!appDomainHost.IsDesignSurfaceLoaded) {
- throw new FormsDesignerLoadException(appDomainHost.LoadErrors);
+ if (!appDomainManager.IsDesignSurfaceLoaded) {
+ throw new FormsDesignerLoadException(appDomainManager.LoadErrors);
}
- appDomainHost.InitializeRemainingServices();
+ appDomainManager.InitializeRemainingServices();
- undoEngine = (IFormsDesignerUndoEngine)appDomainHost.GetService(typeof(IFormsDesignerUndoEngine));
+ undoEngine = (IFormsDesignerUndoEngine)appDomainManager.GetService(typeof(IFormsDesignerUndoEngine));
if (IsTabOrderMode) { // fixes SD2-1015
tabOrderMode = false; // let ShowTabOrder call the designer command again
ShowTabOrder();
}
- appDomainHost.UpdatePropertyPad();
+ propertyContainer.PropertyGridReplacementContent = WrapInCustomHost(appDomainManager.CreatePropertyPad());
+ appDomainManager.UpdatePropertyPad();
hasUnmergedChanges = false;
@@ -416,13 +471,13 @@ void LoadDesigner()
void ApplicationIdle(object sender, EventArgs e)
{
- appDomainHost.RaiseApplicationIdle();
+ appDomainManager.RaiseApplicationIdle();
}
ProjectResourceService CreateProjectResourceService()
{
IProjectContent projectContent = GetProjectContentForFile();
- return new ProjectResourceService(appDomainHost, projectContent);
+ return new ProjectResourceService(appDomainManager, projectContent);
}
IProjectContent GetProjectContentForFile()
@@ -458,8 +513,6 @@ SharpDevelopDesignerOptions LoadOptions()
return options;
}
- bool hasUnmergedChanges;
-
void MakeDirty()
{
hasUnmergedChanges = true;
@@ -481,23 +534,23 @@ void IFormsDesigner.MakeDirty()
void UnloadDesigner()
{
LoggingService.Debug("FormsDesigner unloading, setting ActiveDesignSurface to null");
- FormsDesignerAppDomainHost.DeactivateDesignSurface();
+ FormsDesignerManager.DeactivateDesignSurface();
bool savedIsDirty = (this.DesignerCodeFile == null) ? false : this.DesignerCodeFile.IsDirty;
this.UserContent = this.pleaseWaitLabel;
if (this.DesignerCodeFile != null) {
this.DesignerCodeFile.IsDirty = savedIsDirty;
}
- if (appDomainHost != null && appDomainHost.DesignSurfaceName != null) {
- appDomainHost.DesignSurfaceLoading -= new EventHandlerProxy(DesignerLoading);
- appDomainHost.DesignSurfaceLoaded -= new LoadedEventHandlerProxy(DesignerLoaded);
- appDomainHost.DesignSurfaceFlushed -= new EventHandlerProxy(DesignerFlushed);
- appDomainHost.DesignSurfaceUnloading -= new EventHandlerProxy(DesignerUnloading);
+ if (appDomainManager != null && appDomainManager.DesignSurfaceName != null) {
+ appDomainManager.DesignSurfaceLoading -= new EventHandlerProxy(DesignerLoading);
+ appDomainManager.DesignSurfaceLoaded -= new LoadedEventHandlerProxy(DesignerLoaded);
+ appDomainManager.DesignSurfaceFlushed -= new EventHandlerProxy(DesignerFlushed);
+ appDomainManager.DesignSurfaceUnloading -= new EventHandlerProxy(DesignerUnloading);
- appDomainHost.DesignSurfaceUnloaded += new EventHandlerProxy(
+ appDomainManager.DesignSurfaceUnloaded += new EventHandlerProxy(
delegate {
- ServiceContainer serviceContainer = appDomainHost.GetService(typeof(ServiceContainer)) as ServiceContainer;
+ ServiceContainer serviceContainer = appDomainManager.GetService(typeof(ServiceContainer)) as ServiceContainer;
if (serviceContainer != null) {
// Workaround for .NET bug: .NET unregisters the designer host only if no component throws an exception,
// but then in a finally block assumes that the designer host is already unloaded.
@@ -528,32 +581,24 @@ void UnloadDesigner()
}
});
try {
- appDomainHost.DisposeDesignSurface();
+ appDomainManager.DisposeDesignSurface();
} catch (ExceptionCollection exceptions) {
foreach (Exception ex in exceptions.Exceptions) {
LoggingService.Error(ex);
}
}
- }
-
- appDomainHost.UnregisterTypeProviders();
- }
-
- readonly PropertyContainer propertyContainer = new PropertyContainer();
-
- public PropertyContainer PropertyContainer {
- get {
- return propertyContainer;
+
+ appDomainManager.UnregisterTypeProviders();
}
}
public void ShowHelp()
{
- if (appDomainHost == null) {
+ if (appDomainManager == null) {
return;
}
- ISelectionService selectionService = (ISelectionService)appDomainHost.GetService(typeof(ISelectionService));
+ ISelectionService selectionService = (ISelectionService)appDomainManager.GetService(typeof(ISelectionService));
if (selectionService != null) {
Control ctl = selectionService.PrimarySelection as Control;
if (ctl != null) {
@@ -565,21 +610,18 @@ public void ShowHelp()
void LoadAndDisplayDesigner()
{
try {
-
+ LoadAppDomainManager();
LoadDesigner();
-
} catch (Exception e) {
-
if (e.InnerException is FormsDesignerLoadException) {
throw new FormsDesignerLoadException(e.InnerException.Message, e);
} else if (e is FormsDesignerLoadException) {
throw;
- } else if (appDomainHost.DesignSurfaceName != null && !appDomainHost.IsDesignSurfaceLoaded && appDomainHost.LoadErrors != null) {
- throw new FormsDesignerLoadException(appDomainHost.LoadErrors, e);
+ } else if (appDomainManager != null && appDomainManager.DesignSurfaceName != null && !appDomainManager.IsDesignSurfaceLoaded && appDomainManager.LoadErrors != null) {
+ throw new FormsDesignerLoadException(appDomainManager.LoadErrors, e);
} else {
throw;
}
-
}
}
@@ -598,10 +640,6 @@ void DesignerUnloading(object sender, EventArgs e)
}
}
- bool reloadPending;
-
- CustomWindowsFormsHost designView;
-
void DesignerLoaded(object sender, LoadedEventArgsProxy e)
{
// This method is called when the designer has loaded.
@@ -614,21 +652,22 @@ void DesignerLoaded(object sender, LoadedEventArgsProxy e)
// enableFontInheritance: Make sure auto-scaling is based on the correct font.
// This is required on Vista, I don't know why it works correctly in XP
- designView = WrapInCustomHost(appDomainHost.DesignSurfaceView, enableFontInheritance: false);
+ designView = WrapInCustomHost(appDomainManager.DesignSurfaceView, enableFontInheritance: false);
+ propertyContainer.PropertyGridReplacementContent = WrapInCustomHost(appDomainManager.CreatePropertyPad());
this.UserContent = designView;
- LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + appDomainHost.DesignSurfaceName);
- appDomainHost.ActivateDesignSurface();
+ LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + appDomainManager.DesignSurfaceName);
+ appDomainManager.ActivateDesignSurface();
this.DesignerCodeFile.IsDirty = savedIsDirty;
- appDomainHost.UpdatePropertyPad();
+ appDomainManager.UpdatePropertyPad();
} else {
// This method can not only be called during initialization,
// but also when the designer reloads itself because of
// a language change.
// When a load error occurs there, we are not somewhere
// below the Load method which handles load errors.
// That is why we create an error text box here anyway.
- ShowError(new Exception(appDomainHost.LoadErrors));
+ ShowError(new Exception(appDomainManager.LoadErrors));
}
}
@@ -640,15 +679,15 @@ void DesignerFlushed(object sender, EventArgs e)
public virtual void MergeFormChanges()
{
- if (this.HasLoadError || appDomainHost.DesignSurfaceName == null) {
+ if (this.HasLoadError || appDomainManager.DesignSurfaceName == null) {
LoggingService.Debug("Forms designer: Cannot merge form changes because the designer is not loaded successfully or not loaded at all");
return;
} else if (this.DesignerCodeFile == null) {
throw new InvalidOperationException("Cannot merge form changes without a designer code file.");
}
bool isDirty = this.DesignerCodeFile.IsDirty;
LoggingService.Info("Merging form changes...");
- appDomainHost.FlushDesignSurface();
+ appDomainManager.FlushDesignSurface();
this.resourceStore.CommitAllResourceChanges();
LoggingService.Info("Finished merging form changes");
hasUnmergedChanges = false;
@@ -690,18 +729,17 @@ public void ShowSourceCode(IComponent component, EventDescriptorProxy edesc, str
void IsActiveViewContentChangedHandler(object sender, EventArgs e)
{
- if (this.IsActiveViewContent && appDomainHost != null) {
+ if (this.IsActiveViewContent) {
+ LoggingService.Debug("FormsDesigner view content activated, setting ActiveDesignSurface to " + appDomainManager.DesignSurfaceName);
+ appDomainManager.ActivateDesignSurface();
- LoggingService.Debug("FormsDesigner view content activated, setting ActiveDesignSurface to " + appDomainHost.DesignSurfaceName);
- appDomainHost.ActivateDesignSurface();
-
- if (appDomainHost.DesignSurfaceName != null) {
+ if (appDomainManager.DesignSurfaceName != null) {
// Reload designer when a referenced assembly has changed
// (the default Load/Save logic using OpenedFile cannot catch this case)
- if (appDomainHost.ReferencedAssemblyChanged) {
- IDesignerLoaderService loaderService = appDomainHost.GetService(typeof(IDesignerLoaderService)) as IDesignerLoaderService;
+ if (appDomainManager.ReferencedAssemblyChanged) {
+ IDesignerLoaderService loaderService = appDomainManager.GetService(typeof(IDesignerLoaderService)) as IDesignerLoaderService;
if (loaderService != null) {
- if (!appDomainHost.Host.Loading) {
+ if (!appDomainManager.Host.Loading) {
LoggingService.Info("Forms designer reloading due to change in referenced assembly");
this.reloadPending = true;
if (!loaderService.Reload()) {
@@ -719,7 +757,7 @@ void IsActiveViewContentChangedHandler(object sender, EventArgs e)
} else {
LoggingService.Debug("FormsDesigner view content deactivated, setting ActiveDesignSurface to null");
- FormsDesignerAppDomainHost.DeactivateDesignSurface();
+ FormsDesignerManager.DeactivateDesignSurface();
}
}
@@ -759,7 +797,7 @@ public override void Dispose()
void SelectionChangedHandler(object sender, EventArgs args)
{
- appDomainHost.UpdatePropertyPadSelection((ISelectionService)sender);
+ appDomainManager.UpdatePropertyPadSelection((ISelectionService)sender);
}
#region IUndoHandler implementation
@@ -797,11 +835,11 @@ public virtual void Redo()
#region IClipboardHandler implementation
bool IsMenuCommandEnabled(CommandIDEnum commandID)
{
- if (appDomainHost.DesignSurfaceName == null) {
+ if (appDomainManager == null || appDomainManager.DesignSurfaceName == null) {
return false;
}
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
if (menuCommandService == null) {
return false;
}
@@ -836,43 +874,44 @@ bool IsMenuCommandEnabled(CommandIDEnum commandID)
public bool EnableSelectAll {
get {
- return appDomainHost.DesignSurfaceName != null;
+ return appDomainManager.DesignSurfaceName != null;
}
}
public void Cut()
{
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandIDEnum.Cut);
}
public void Copy()
{
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandIDEnum.Copy);
}
public void Paste()
{
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandIDEnum.Paste);
}
public void Delete()
{
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandIDEnum.Delete);
}
public void SelectAll()
{
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandIDEnum.SelectAll);
}
#endregion
#region Tab Order Handling
bool tabOrderMode = false;
+
public virtual bool IsTabOrderMode {
get {
return tabOrderMode;
@@ -882,7 +921,7 @@ public void SelectAll()
public virtual void ShowTabOrder()
{
if (!IsTabOrderMode) {
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandIDEnum.TabOrder);
tabOrderMode = true;
}
@@ -891,7 +930,7 @@ public virtual void ShowTabOrder()
public virtual void HideTabOrder()
{
if (IsTabOrderMode) {
- IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainHost.MenuCommandService;
+ IMenuCommandServiceProxy menuCommandService = (IMenuCommandServiceProxy)appDomainManager.MenuCommandService;
menuCommandService.GlobalInvoke(CommandIDEnum.TabOrder);
tabOrderMode = false;
}
@@ -913,16 +952,7 @@ protected void ReloadDesignerFromMemory()
this.Load(this.DesignerCodeFile, ms);
}
- appDomainHost.UpdatePropertyPad();
- }
-
- public virtual object ToolsContent {
- get {
- if (appDomain == null) {
- LoadAppDomain();
- }
- return toolbox.FormsDesignerSideBar;
- }
+ appDomainManager.UpdatePropertyPad();
}
void FileServiceFileRemoving(object sender, FileCancelEventArgs e)
@@ -971,7 +1001,7 @@ void CheckForDesignerCodeFileDeletion(FileCancelEventArgs e)
void DebugStarting(object sender, EventArgs e)
{
- if (appDomainHost.IsActiveDesignSurface ||
+ if (appDomainManager == null || appDomainManager.IsActiveDesignSurface ||
!this.reloadPending)
return;
@@ -994,29 +1024,9 @@ void DebugStarting(object sender, EventArgs e)
#endregion
- SharpDevelopDesignerOptions options;
-
- public SharpDevelopDesignerOptions DesignerOptions {
- get {
- return options;
- }
- }
-
public IntPtr GetDialogOwnerWindowHandle()
{
return WorkbenchSingleton.MainWin32Window.Handle;
}
-
- public IDesignerGenerator Generator {
- get {
- return generator;
- }
- }
-
- public Control DesignerContent {
- get {
- return designView.Child;
- }
- }
}
}
View
4 ...dIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/ProjectResourceService.cs
@@ -22,11 +22,11 @@ namespace ICSharpCode.FormsDesigner.Services
public sealed class ProjectResourceService : MarshalByRefObject, IProjectResourceService
{
IProjectContent projectContent;
- FormsDesignerAppDomainHost host;
+ FormsDesignerManager host;
string stringLiteralDelimiter;
bool designerSupportsProjectResources = true;
- public ProjectResourceService(FormsDesignerAppDomainHost host, IProjectContent projectContent)
+ public ProjectResourceService(FormsDesignerManager host, IProjectContent projectContent)
{
if (host == null)
throw new ArgumentNullException("host");
View
2 ...DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Services/SharpDevelopCommandProvider.cs
@@ -46,7 +46,7 @@ public void ShowContextMenu(CommandIDEnum menuID, int x, int y)
if (panel != null) {
Point p = panel.PointToClient(new Point(x, y));
- MenuService.ShowContextMenu(vc.AppDomainHost, contextMenuPath, panel, p.X, p.Y);
+ MenuService.ShowContextMenu(vc.AppDomainManager, contextMenuPath, panel, p.X, p.Y);
}
}
}
View
2 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/Toolbox/ToolboxProvider.cs
@@ -58,6 +58,8 @@ void CreateToolboxService()
sideBar = new FormsDesignerSideBar();
LoadToolbox();
toolboxService = (SharpDevelopToolboxService)services.GetService(typeof(IToolboxService));
+ if (toolboxService == null)
+ throw new NullReferenceException("toolboxService not found!");
ReloadSideTabs(false);
toolboxService.SelectedItemUsed += new EventHandlerProxy(SelectedToolUsedHandler);
sideBar.SideTabDeleted += SideTabDeleted;
View
10 src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj
@@ -62,7 +62,8 @@
</Compile>
<EmbeddedResource Include="Resources\WindowsFormsGridOptions.xfrm" />
<Compile Include="Configuration\AssemblyInfo.cs" />
- <Compile Include="FormsDesignerAppDomainHost.cs" />
+ <Compile Include="FormsDesignerCreationProperties.cs" />
+ <Compile Include="FormsDesignerManager.cs" />
<Compile Include="Src\DesignerAppDomainManager.cs" />
<Compile Include="Src\DesignerLoader\SharpDevelopDesignerLoader.cs" />
<Compile Include="Src\DesignerLoader\IDesignerLoader.cs" />
@@ -110,12 +111,5 @@
<DependentUpon>ImageResourceEditorDialog.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
- <Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
- <Name>ICSharpCode.SharpDevelop.Widgets</Name>
- <Private>False</Private>
- </ProjectReference>
- </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>
View
35 src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesignerCreationProperties.cs
@@ -0,0 +1,35 @@
+// 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 System.ComponentModel;
+using System.ComponentModel.Design;
+using System.ComponentModel.Design.Serialization;
+using System.Drawing;
+using System.Drawing.Design;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.Remoting.Lifetime;
+using System.Text;
+using System.Windows.Forms;
+
+using ICSharpCode.FormsDesigner.Gui;
+using ICSharpCode.FormsDesigner.Services;
+using ICSharpCode.FormsDesigner.UndoRedo;
+
+namespace ICSharpCode.FormsDesigner
+{
+ public class FormsDesignerCreationProperties : MarshalByRefObject
+ {
+ public string FileName { get; set; }
+ public ITypeLocator TypeLocator { get; set; }
+ public IGacWrapper GacWrapper { get; set; }
+ public ICommandProvider Commands { get; set; }
+ public IFormsDesigner FormsDesignerProxy { get; set; }
+ public IFormsDesignerLoggingService Logger { get; set; }
+ public SharpDevelopDesignerOptions Options { get; set; }
+ public IResourceStore ResourceStore { get; set; }
+ }
+}
View
80 ...ner/Project/FormsDesignerAppDomainHost.cs → ...sDesigner/Project/FormsDesignerManager.cs
@@ -24,7 +24,7 @@ namespace ICSharpCode.FormsDesigner
/// <summary>
/// Description of FormsDesignerAppDomainHost.
/// </summary>
- public class FormsDesignerAppDomainHost : MarshalByRefObject, IServiceProvider
+ public class FormsDesignerManager : MarshalByRefObject, IServiceProvider, IDisposable
{
DesignSurface designSurface;
ServiceContainer container;
@@ -33,7 +33,7 @@ public class FormsDesignerAppDomainHost : MarshalByRefObject, IServiceProvider
Services.MenuCommandService menuCommandService;
IDesignerGenerator generator;
bool unloading;
- FormsDesignerAppDomainCreationProperties properties;
+ FormsDesignerCreationProperties properties;
readonly Dictionary<Type, TypeDescriptionProvider> addedTypeDescriptionProviders = new Dictionary<Type, TypeDescriptionProvider>();
public string DesignSurfaceName {
@@ -68,29 +68,17 @@ public class FormsDesignerAppDomainHost : MarshalByRefObject, IServiceProvider
static readonly DesignSurfaceManager designSurfaceManager = new DesignSurfaceManager();
- public static FormsDesignerAppDomainHost CreateFormsDesignerInAppDomain(ref AppDomain appDomain, FormsDesignerAppDomainCreationProperties properties)
+ public FormsDesignerManager(FormsDesignerCreationProperties properties)
{
- if (appDomain == null) {
- // Construct and initialize settings for a second AppDomain.
- AppDomainSetup formsDesignerAppDomainSetup = new AppDomainSetup();
- formsDesignerAppDomainSetup.ApplicationBase = Path.GetDirectoryName(typeof(FormsDesignerAppDomainHost).Assembly.Location);
- formsDesignerAppDomainSetup.DisallowBindingRedirects = false;
- formsDesignerAppDomainSetup.DisallowCodeDownload = true;
- formsDesignerAppDomainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
-
- // Create the second AppDomain.
- appDomain = AppDomain.CreateDomain("FormsDesigner AD", null, formsDesignerAppDomainSetup);
- }
- var host = (FormsDesignerAppDomainHost)appDomain.CreateInstanceAndUnwrap(typeof(FormsDesignerAppDomainHost).Assembly.FullName, typeof(FormsDesignerAppDomainHost).FullName);
- host.Initialize(properties);
- return host;
+ this.properties = properties;
+ InitializeServices();
+ InitializeEvents();
}
- void Initialize(FormsDesignerAppDomainCreationProperties properties)
+ void InitializeServices()
{
- this.properties = properties;
this.container = new DefaultServiceContainer();
- container.AddService(typeof(FormsDesignerAppDomainHost), this);
+ container.AddService(typeof(FormsDesignerManager), this);
container.AddService(typeof(IFormsDesignerLoggingService), logger = new FormsDesignerLoggingServiceProxy(properties.Logger));
container.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService());
container.AddService(typeof(ITypeResolutionService), new TypeResolutionService(properties.FileName, container, properties.TypeLocator));
@@ -113,8 +101,6 @@ void Initialize(FormsDesignerAppDomainCreationProperties properties)
// Provide the ImageResourceEditor for all Image and Icon properties
addedTypeDescriptionProviders.Add(typeof(Image), TypeDescriptor.AddAttributes(typeof(Image), new EditorAttribute(typeof(ImageResourceEditor), typeof(System.Drawing.Design.UITypeEditor))));
addedTypeDescriptionProviders.Add(typeof(Icon), TypeDescriptor.AddAttributes(typeof(Icon), new EditorAttribute(typeof(ImageResourceEditor), typeof(System.Drawing.Design.UITypeEditor))));
-
- InitializeEvents();
}
#region Events
@@ -145,7 +131,7 @@ protected virtual void OnDesignSurfaceFlushed(EventArgs e)
DesignSurfaceFlushed(this, e);
}
}
-
+
public event EventHandler DesignSurfaceUnloading;
protected virtual void OnDesignSurfaceUnloading(EventArgs e)
@@ -262,27 +248,27 @@ void InitializeEvents()
Host.TransactionClosed += TransactionClose;
}
-
+
void SelectionServiceSelectionChanged(object sender, EventArgs e)
{
UpdatePropertyPadSelection((ISelectionService)sender);
}
-
+
void Host_TransactionClosed(object sender, DesignerTransactionCloseEventArgs e)
{
OnHostTransactionClosed(e);
}
-
+
void componentChangeService_ComponentRename(object sender, ComponentRenameEventArgs e)
{
OnComponentRename(new ComponentRenameEventArgsProxy { Component = e.Component, NewName = e.NewName, OldName = e.OldName });
}
-
+
void componentChangeService_ComponentRemoved(object sender, ComponentEventArgs e)
{
OnComponentRemoved(new ComponentEventArgsProxy { Component = e.Component });
}
-
+
void componentChangeService_ComponentAdded(object sender, ComponentEventArgs e)
{
OnComponentAdded(new ComponentEventArgsProxy { Component = e.Component });
@@ -292,24 +278,24 @@ void designSurface_Unloaded(object sender, EventArgs e)
{
OnDesignSurfaceUnloaded(e);
}
-
+
void designSurface_Unloading(object sender, EventArgs e)
{
unloading = true;
OnDesignSurfaceUnloading(e);
}
-
+
void designSurface_Flushed(object sender, EventArgs e)
{
OnDesignSurfaceFlushed(e);
}
-
+
void designSurface_Loaded(object sender, LoadedEventArgs e)
{
unloading = false;
OnDesignSurfaceLoaded(e);
}
-
+
void designSurface_Loading(object sender, EventArgs e)
{
unloading = false;
@@ -555,17 +541,23 @@ public IProjectResourceInfo CreateProjectResourceInfo(string resourceFile, strin
{
return ProjectResourceInfo.Create((IResourceStore)GetService(typeof(IResourceStore)), resourceFile, resourceKey);
}
- }
-
- public class FormsDesignerAppDomainCreationProperties : MarshalByRefObject
- {
- public string FileName { get; set; }
- public ITypeLocator TypeLocator { get; set; }
- public IGacWrapper GacWrapper { get; set; }
- public ICommandProvider Commands { get; set; }
- public IFormsDesigner FormsDesignerProxy { get; set; }
- public IFormsDesignerLoggingService Logger { get; set; }
- public SharpDevelopDesignerOptions Options { get; set; }
- public IResourceStore ResourceStore { get; set; }
+
+ bool disposed;
+
+ public void Dispose()
+ {
+ if (!disposed) {
+ DisposeDesignSurface();
+ UnregisterTypeProviders();
+ Services.Dispose();
+ disposed = true;
+ }
+ }
+
+ public void ResetServiceContainer()
+ {
+ UnregisterTypeProviders();
+ InitializeServices();
+ }
}
}
View
22 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerAppDomainManager.cs
@@ -2,19 +2,39 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.Remoting.Lifetime;
+using System.Windows.Forms;
namespace ICSharpCode.FormsDesigner
{
/// <summary>
/// Description of DesignerAppDomainManager.
/// </summary>
- public class DesignerAppDomainManager
+ public class DesignerAppDomainManager : MarshalByRefObject, ISponsor, IDisposable
{
/// <summary>
/// Gets whether this is a designer domain (and not the SharpDevelop domain)
/// </summary>
public static bool IsDesignerDomain {
get { return AppDomain.CurrentDomain.FriendlyName == "FormsDesigner AD"; }
}
+
+ public TimeSpan Renewal(ILease lease)
+ {
+ throw new NotImplementedException();
+ }
+
+ public FormsDesignerManager CreateFormsDesignerInAppDomain(FormsDesignerCreationProperties creationProperties)
+ {
+ Debug.Assert(IsDesignerDomain);
+ return new FormsDesignerManager(creationProperties);
+ }
+
+ public void Dispose()
+ {
+ throw new NotImplementedException();
+ }
}
}
View
4 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ComponentLibraryLoader.cs
@@ -226,13 +226,13 @@ public class ComponentLibraryLoader
IServiceProvider provider;
IFormsDesignerLoggingService logger;
- FormsDesignerAppDomainHost appDomainHost;
+ FormsDesignerManager appDomainHost;
public ComponentLibraryLoader(IServiceProvider provider)
{
this.provider = provider;
logger = (IFormsDesignerLoggingService)provider.GetService(typeof(IFormsDesignerLoggingService));
- appDomainHost = (FormsDesignerAppDomainHost)provider.GetService(typeof(FormsDesignerAppDomainHost));
+ appDomainHost = (FormsDesignerManager)provider.GetService(typeof(FormsDesignerManager));
Categories = new List<Category>();
}
View
4 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/IDEContainer.cs
@@ -12,9 +12,9 @@ class IDEContainer : Container
{
IServiceProvider serviceProvider;
IComponent grid;
- FormsDesignerAppDomainHost appDomainHost;
+ FormsDesignerManager appDomainHost;
- public IDEContainer(FormsDesignerAppDomainHost appDomainHost)
+ public IDEContainer(FormsDesignerManager appDomainHost)
{
this.appDomainHost = appDomainHost;
}
View
2 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/PropertyPadContent.cs
@@ -70,7 +70,7 @@ public class PropertyPadContent : Control
public event EventHandler SelectedObjectChanged;
public event SelectedGridItemChangedEventHandler SelectedGridItemChanged;
- public PropertyPadContent(IDesignerHost host, IFormsDesigner designer, FormsDesignerAppDomainHost appDomainHost)
+ public PropertyPadContent(IDesignerHost host, IFormsDesigner designer, FormsDesignerManager appDomainHost)
{
ideContainer = new IDEContainer(appDomainHost);
View
4 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/DesignerResourceService.cs
@@ -12,9 +12,9 @@ namespace ICSharpCode.FormsDesigner.Services
sealed class DesignerResourceService : System.ComponentModel.Design.IResourceService
{
readonly IResourceStore store;
- FormsDesignerAppDomainHost host;
+ FormsDesignerManager host;
- public DesignerResourceService(IResourceStore store, FormsDesignerAppDomainHost host)
+ public DesignerResourceService(IResourceStore store, FormsDesignerManager host)
{
if (store == null)
throw new ArgumentNullException("store");

0 comments on commit 5047c6a

Please sign in to comment.
Something went wrong with that request. Please try again.