From f02d5cae10c8dbf0bdc43e5791a2c39436bd9019 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 30 Aug 2011 18:33:59 +0200 Subject: [PATCH] migrate some Component-related events into the AD use our CustomWindowsFormsHost --- .../FormsDesignerViewContent.cs | 98 +++++++------------ .../Project/FormsDesigner.csproj | 26 ++--- .../Project/FormsDesignerAppDomainHost.cs | 80 +++++++++++---- .../Project/Src/IFormsDesigner.cs | 1 + 4 files changed, 101 insertions(+), 104 deletions(-) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerViewContent.cs b/src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerViewContent.cs index 988fdf4363..2fa8155cbe 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerViewContent.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerViewContent.cs @@ -26,6 +26,7 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.SharpDevelop.Widgets; namespace ICSharpCode.FormsDesigner { @@ -169,6 +170,7 @@ namespace ICSharpCode.FormsDesigner appDomain = null; appDomainHost = FormsDesignerAppDomainHost.CreateFormsDesignerInAppDomain(ref appDomain, creationProperties); toolbox = new ToolboxProvider(appDomainHost); + appDomainHost.UseSDAssembly(typeof(CustomWindowsFormsHost).Assembly.FullName, typeof(CustomWindowsFormsHost).Assembly.Location); } bool inMasterLoadOperation; @@ -179,7 +181,7 @@ namespace ICSharpCode.FormsDesigner LoadAppDomain(); - propertyContainer.PropertyGridReplacementContent = FrameworkElementAdapters.ContractToViewAdapter(appDomainHost.CreatePropertyGrid()); + propertyContainer.PropertyGridReplacementContent = WrapInCustomHost(appDomainHost.CreatePropertyGrid()); // TODO : init PropertyGrid if (inMasterLoadOperation) { @@ -266,6 +268,13 @@ namespace ICSharpCode.FormsDesigner } } + CustomWindowsFormsHost WrapInCustomHost(Control control) + { + var host = new CustomWindowsFormsHost(appDomain); + host.Child = control; + return host; + } + protected override void SaveInternal(OpenedFile file, System.IO.Stream stream) { LoggingService.Debug("Forms designer: Save " + file.FileName); @@ -287,7 +296,7 @@ namespace ICSharpCode.FormsDesigner #region Proxies class ViewContentIFormsDesignerProxy : MarshalByRefObject, IFormsDesigner { - FormsDesignerViewContent vc; + IFormsDesigner vc; public ViewContentIFormsDesignerProxy(FormsDesignerViewContent vc) { @@ -296,7 +305,7 @@ namespace ICSharpCode.FormsDesigner public IDesignerGenerator Generator { get { - return vc.generator; + return vc.Generator; } } @@ -330,6 +339,11 @@ namespace ICSharpCode.FormsDesigner { vc.MakeDirty(); } + + public void InvalidateRequerySuggested() + { + vc.InvalidateRequerySuggested(); + } } #endregion @@ -364,10 +378,10 @@ namespace ICSharpCode.FormsDesigner undoEngine = (IFormsDesignerUndoEngine)appDomainHost.GetService(typeof(IFormsDesignerUndoEngine)); - appDomainHost.ComponentAdded += new ComponentEventHandlerProxy(ComponentListChanged); - appDomainHost.ComponentRemoved += new ComponentEventHandlerProxy(ComponentListChanged); - appDomainHost.ComponentRename += new ComponentRenameEventHandlerProxy(ComponentListChanged); - appDomainHost.HostTransactionClosed += new DesignerTransactionCloseEventHandlerProxy(TransactionClose); +// appDomainHost.ComponentAdded += new ComponentEventHandlerProxy(ComponentListChanged); +// appDomainHost.ComponentRemoved += new ComponentEventHandlerProxy(ComponentListChanged); +// appDomainHost.ComponentRename += new ComponentRenameEventHandlerProxy(ComponentListChanged); +// appDomainHost.HostTransactionClosed += new DesignerTransactionCloseEventHandlerProxy(TransactionClose); appDomainHost.SelectionChanged += new EventHandlerProxy(SelectionChangedHandler); @@ -376,7 +390,7 @@ namespace ICSharpCode.FormsDesigner ShowTabOrder(); } - UpdatePropertyPad(); + appDomainHost.UpdatePropertyPad(); hasUnmergedChanges = false; @@ -431,31 +445,14 @@ namespace ICSharpCode.FormsDesigner System.Windows.Input.CommandManager.InvalidateRequerySuggested(); } - void IFormsDesigner.MakeDirty() - { - MakeDirty(); - } - - bool shouldUpdateSelectableObjects = false; - - void TransactionClose(object sender, DesignerTransactionCloseEventArgs e) + void IFormsDesigner.InvalidateRequerySuggested() { - if (shouldUpdateSelectableObjects) { - // update the property pad after the transaction is *really* finished - // (including updating the selection) - WorkbenchSingleton.SafeThreadAsyncCall(UpdatePropertyPad); - shouldUpdateSelectableObjects = false; - } + System.Windows.Input.CommandManager.InvalidateRequerySuggested(); } - void ComponentListChanged(object sender, EventArgs e) + void IFormsDesigner.MakeDirty() { - bool loading = appDomainHost.IsLoaderLoading; - LoggingService.Debug("Forms designer: Component added/removed/renamed, Loading=" + loading + ", Unloading=" + this.unloading); - if (!loading && !unloading) { - shouldUpdateSelectableObjects = true; - this.MakeDirty(); - } + MakeDirty(); } void UnloadDesigner() @@ -475,13 +472,9 @@ namespace ICSharpCode.FormsDesigner appDomainHost.DesignSurfaceFlushed -= new EventHandlerProxy(DesignerFlushed); appDomainHost.DesignSurfaceUnloading -= new EventHandlerProxy(DesignerUnloading); - appDomainHost.ComponentAdded -= new ComponentEventHandlerProxy(ComponentListChanged); - appDomainHost.ComponentRemoved -= new ComponentEventHandlerProxy(ComponentListChanged); - appDomainHost.ComponentRename -= new ComponentRenameEventHandlerProxy(ComponentListChanged); - - if (appDomainHost.HasDesignerHost) { - appDomainHost.HostTransactionClosed -= new DesignerTransactionCloseEventHandlerProxy(TransactionClose); - } +// appDomainHost.ComponentAdded -= new ComponentEventHandlerProxy(ComponentListChanged); +// appDomainHost.ComponentRemoved -= new ComponentEventHandlerProxy(ComponentListChanged); +// appDomainHost.ComponentRename -= new ComponentRenameEventHandlerProxy(ComponentListChanged); appDomainHost.SelectionChanged -= new EventHandlerProxy(SelectionChangedHandler); @@ -579,33 +572,29 @@ namespace ICSharpCode.FormsDesigner { LoggingService.Debug("Forms designer: DesignerLoader loading..."); this.reloadPending = false; - this.unloading = false; this.UserContent = this.pleaseWaitLabel; } void DesignerUnloading(object sender, EventArgs e) { LoggingService.Debug("Forms designer: DesignerLoader unloading..."); - this.unloading = true; if (!this.disposing) { this.UserContent = this.pleaseWaitLabel; } } bool reloadPending; - bool unloading; void DesignerLoaded(object sender, LoadedEventArgsProxy e) { // This method is called when the designer has loaded. LoggingService.Debug("Forms designer: DesignerLoader loaded, HasSucceeded=" + e.HasSucceeded.ToString()); this.reloadPending = false; - this.unloading = false; if (e.HasSucceeded) { // Display the designer on the view content bool savedIsDirty = this.DesignerCodeFile.IsDirty; - System.Windows.FrameworkElement designView = FrameworkElementAdapters.ContractToViewAdapter(appDomainHost.DesignSurfaceView); + CustomWindowsFormsHost designView = WrapInCustomHost(appDomainHost.DesignSurfaceView); // designView.BackColor = Color.White; // designView.RightToLeft = RightToLeft.No; @@ -617,7 +606,7 @@ namespace ICSharpCode.FormsDesigner LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + appDomainHost.DesignSurfaceName); appDomainHost.ActivateDesignSurface(); this.DesignerCodeFile.IsDirty = savedIsDirty; - this.UpdatePropertyPad(); + appDomainHost.UpdatePropertyPad(); } else { // This method can not only be called during initialization, // but also when the designer reloads itself because of @@ -748,28 +737,7 @@ namespace ICSharpCode.FormsDesigner void SelectionChangedHandler(object sender, EventArgs args) { - UpdatePropertyPadSelection((ISelectionService)sender); - } - - void UpdatePropertyPadSelection(ISelectionService selectionService) - { - ICollection selection = selectionService.GetSelectedComponents(); - object[] selArray = new object[selection.Count]; - selection.CopyTo(selArray, 0); - propertyContainer.SelectedObjects = selArray; - System.Windows.Input.CommandManager.InvalidateRequerySuggested(); - } - - protected void UpdatePropertyPad() - { - if (appDomainHost.HasDesignerHost) { -// propertyContainer.Host = appDomainHost.Host; -// propertyContainer.SelectableObjects = appDomainHost.Host.Container.Components; -// ISelectionService selectionService = (ISelectionService)appDomainHost.GetService(typeof(ISelectionService)); -// if (selectionService != null) { -// UpdatePropertyPadSelection(selectionService); -// } - } + appDomainHost.UpdatePropertyPadSelection((ISelectionService)sender); } #region IUndoHandler implementation @@ -929,7 +897,7 @@ namespace ICSharpCode.FormsDesigner this.Load(this.DesignerCodeFile, ms); } - UpdatePropertyPad(); + appDomainHost.UpdatePropertyPad(); } public virtual object ToolsContent { diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj b/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj index b336529f32..9531822aaf 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj @@ -45,35 +45,16 @@ DEBUG, FORMSDESIGNER_DLL - - 3.0 - - - 3.0 - - - - 3.5 - - - 3.5 - 4.0 - - 3.0 - - - 3.0 - @@ -119,5 +100,12 @@ + + + {8035765F-D51F-4A0C-A746-2FD100E19419} + ICSharpCode.SharpDevelop.Widgets + False + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesignerAppDomainHost.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesignerAppDomainHost.cs index e78a3bafa5..30a95c3a26 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesignerAppDomainHost.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesignerAppDomainHost.cs @@ -1,8 +1,6 @@ // 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.AddIn.Contract; -using System.AddIn.Pipeline; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Drawing; @@ -12,7 +10,6 @@ using System.Reflection; using System.Runtime.Remoting.Lifetime; using System.Text; using System.Windows.Forms; -using System.Windows.Forms.Integration; using ICSharpCode.FormsDesigner.Gui; using ICSharpCode.FormsDesigner.Services; @@ -217,6 +214,27 @@ namespace ICSharpCode.FormsDesigner } } + bool shouldUpdateSelectableObjects = false; + + void TransactionClose(object sender, DesignerTransactionCloseEventArgs e) + { + if (shouldUpdateSelectableObjects) { + // update the property pad after the transaction is *really* finished + // (including updating the selection) + DesignSurfaceView.BeginInvoke((Action)UpdatePropertyPad); + shouldUpdateSelectableObjects = false; + } + } + + void ComponentListChanged(object sender, EventArgs e) + { + LoggingService.Debug("Forms designer: Component added/removed/renamed, Loading=" + IsLoaderLoading + ", Unloading=" + this.unloading); + if (!IsLoaderLoading && !unloading) { + shouldUpdateSelectableObjects = true; + properties.FormsDesignerProxy.MakeDirty(); + } + } + void InitializeEvents() { designSurface.Loading += designSurface_Loading; @@ -228,9 +246,9 @@ namespace ICSharpCode.FormsDesigner IComponentChangeService componentChangeService = (IComponentChangeService)GetService(typeof(IComponentChangeService)); if (componentChangeService != null) { componentChangeService.ComponentChanged += ComponentChanged; - componentChangeService.ComponentAdded += componentChangeService_ComponentAdded; - componentChangeService.ComponentRemoved += componentChangeService_ComponentRemoved; - componentChangeService.ComponentRename += componentChangeService_ComponentRename; + componentChangeService.ComponentAdded += ComponentListChanged; + componentChangeService.ComponentRemoved += ComponentListChanged; + componentChangeService.ComponentRename += ComponentListChanged; } ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService; @@ -238,7 +256,7 @@ namespace ICSharpCode.FormsDesigner selectionService.SelectionChanged += selectionService_SelectionChanged; } - Host.TransactionClosed += Host_TransactionClosed; + Host.TransactionClosed += TransactionClose; } void selectionService_SelectionChanged(object sender, EventArgs e) @@ -357,16 +375,9 @@ namespace ICSharpCode.FormsDesigner designSurface.Flush(); } - WindowsFormsHost host; - - public INativeHandleContract DesignSurfaceView { + public Control DesignSurfaceView { get { - if (host == null) { - host = new WindowsFormsHost(); - host.Child = (Control)designSurface.View; - } - - return FrameworkElementAdapters.ViewToContractAdapter(host); + return (Control)designSurface.View; } } @@ -375,13 +386,32 @@ namespace ICSharpCode.FormsDesigner designSurface.Dispose(); } - public INativeHandleContract CreatePropertyGrid() + public PropertyGrid CreatePropertyGrid() { var grid = new PropertyGrid() { Dock = DockStyle.Fill }; - var host = new WindowsFormsHost(); - host.Child = grid; - return FrameworkElementAdapters.ViewToContractAdapter(host); + return grid; + } + + public void UpdatePropertyPad() + { + if (HasDesignerHost) { +// propertyContainer.Host = appDomainHost.Host; +// propertyContainer.SelectableObjects = appDomainHost.Host.Container.Components; +// ISelectionService selectionService = (ISelectionService)appDomainHost.GetService(typeof(ISelectionService)); +// if (selectionService != null) { +// UpdatePropertyPadSelection(selectionService); +// } + } + } + + public void UpdatePropertyPadSelection(ISelectionService selectionService) + { +// ICollection selection = selectionService.GetSelectedComponents(); +// object[] selArray = new object[selection.Count]; +// selection.CopyTo(selArray, 0); +// propertyContainer.SelectedObjects = selArray; + properties.FormsDesignerProxy.InvalidateRequerySuggested(); } public IFormsDesignerLoggingService LoggingService { @@ -444,6 +474,16 @@ namespace ICSharpCode.FormsDesigner container.AddService(typeof(UndoEngine), undoEngine); container.AddService(typeof(IFormsDesignerUndoEngine), new FormsDesignerUndoEngineProxy(undoEngine)); } + + public void UseSDAssembly(string name, string location) + { + AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs args) { + LoggingService.DebugFormatted("Looking for: {0} in {1} {2}", args.Name, name, location); + if (args.Name == name) + return Assembly.LoadFile(location); + return null; + }; + } } public class FormsDesignerAppDomainCreationProperties : MarshalByRefObject diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/IFormsDesigner.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/IFormsDesigner.cs index db0e8104de..d732c3d087 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/IFormsDesigner.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/IFormsDesigner.cs @@ -28,6 +28,7 @@ namespace ICSharpCode.FormsDesigner SharpDevelopDesignerOptions DesignerOptions { get; } void MakeDirty(); + void InvalidateRequerySuggested(); } public enum ResourceType