Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
157 src/AddIns/DisplayBindings/FormsDesigner/FormsDesigner.AddIn/FormsDesignerViewContent.cs
@@ -26,6 +26,7 @@
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
+using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.FormsDesigner
{
@@ -169,6 +170,7 @@ void LoadAppDomain()
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 @@ protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
LoadAppDomain();
- propertyContainer.PropertyGridReplacementContent = FrameworkElementAdapters.ContractToViewAdapter(appDomainHost.CreatePropertyGrid());
+ propertyContainer.PropertyGridReplacementContent = WrapInCustomHost(appDomainHost.CreatePropertyGrid());
// TODO : init PropertyGrid
if (inMasterLoadOperation) {
@@ -266,6 +268,14 @@ protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
}
}
+ CustomWindowsFormsHost WrapInCustomHost(Control control, bool enableFontInheritance = true)
+ {
+ var host = new CustomWindowsFormsHost(appDomain);
+ host.EnableFontInheritance = enableFontInheritance;
+ host.Child = control;
+ return host;
+ }
+
protected override void SaveInternal(OpenedFile file, System.IO.Stream stream)
{
LoggingService.Debug("Forms designer: Save " + file.FileName);
@@ -287,7 +297,7 @@ internal void AddResourceFile(OpenedFile file)
#region Proxies
class ViewContentIFormsDesignerProxy : MarshalByRefObject, IFormsDesigner
{
- FormsDesignerViewContent vc;
+ IFormsDesigner vc;
public ViewContentIFormsDesignerProxy(FormsDesignerViewContent vc)
{
@@ -296,7 +306,7 @@ public ViewContentIFormsDesignerProxy(FormsDesignerViewContent vc)
public IDesignerGenerator Generator {
get {
- return vc.generator;
+ return vc.Generator;
}
}
@@ -330,6 +340,11 @@ public void MakeDirty()
{
vc.MakeDirty();
}
+
+ public void InvalidateRequerySuggested()
+ {
+ vc.InvalidateRequerySuggested();
+ }
}
#endregion
@@ -364,11 +379,6 @@ void LoadDesigner()
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.SelectionChanged += new EventHandlerProxy(SelectionChangedHandler);
if (IsTabOrderMode) { // fixes SD2-1015
@@ -376,7 +386,7 @@ void LoadDesigner()
ShowTabOrder();
}
- UpdatePropertyPad();
+ appDomainHost.UpdatePropertyPad();
hasUnmergedChanges = false;
@@ -417,6 +427,7 @@ SharpDevelopDesignerOptions LoadOptions()
options.EnableInSituEditing = PropertyService.Get("FormsDesigner.DesignerOptions.EnableInSituEditing", true);
options.ObjectBoundSmartTagAutoShow = GeneralOptionsPanel.SmartTagAutoShow;
options.UseOptimizedCodeGeneration = PropertyService.Get("FormsDesigner.DesignerOptions.UseOptimizedCodeGeneration", true);
+ options.EventHandlerNameFormat = "{0}{1}";
return options;
}
@@ -431,31 +442,14 @@ void MakeDirty()
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,47 +469,40 @@ void UnloadDesigner()
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.SelectionChanged -= new EventHandlerProxy(SelectionChangedHandler);
- appDomainHost.DesignSurfaceUnloaded += delegate {
- ServiceContainer serviceContainer = appDomainHost.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.
- // Thus we would get the confusing "InvalidOperationException: The container cannot be disposed at design time"
- // when any component throws an exception.
-
- // See http://community.sharpdevelop.net/forums/p/10928/35288.aspx
- // Reproducible with a custom control that has a designer that crashes on unloading
- // e.g. http://www.codeproject.com/KB/toolbars/WinFormsRibbon.aspx
-
- // We work around this problem by unregistering the designer host manually.
- try {
- var services = (Dictionary<Type, object>)typeof(ServiceContainer).InvokeMember(
- "Services",
- BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic,
- null, serviceContainer, null);
- foreach (var pair in services.ToArray()) {
- if (pair.Value is IDesignerHost) {
- serviceContainer.GetType().InvokeMember(
- "RemoveFixedService",
- BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic,
- null, serviceContainer, new object[] { pair.Key });
+ appDomainHost.DesignSurfaceUnloaded += new EventHandlerProxy(
+ delegate {
+ ServiceContainer serviceContainer = appDomainHost.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.
+ // Thus we would get the confusing "InvalidOperationException: The container cannot be disposed at design time"
+ // when any component throws an exception.
+
+ // See http://community.sharpdevelop.net/forums/p/10928/35288.aspx
+ // Reproducible with a custom control that has a designer that crashes on unloading
+ // e.g. http://www.codeproject.com/KB/toolbars/WinFormsRibbon.aspx
+
+ // We work around this problem by unregistering the designer host manually.
+ try {
+ var services = (Dictionary<Type, object>)typeof(ServiceContainer).InvokeMember(
+ "Services",
+ BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic,
+ null, serviceContainer, null);
+ foreach (var pair in services.ToArray()) {
+ if (pair.Value is IDesignerHost) {
+ serviceContainer.GetType().InvokeMember(
+ "RemoveFixedService",
+ BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic,
+ null, serviceContainer, new object[] { pair.Key });
+ }
}
+ } catch (Exception ex) {
+ LoggingService.Error(ex);
}
- } catch (Exception ex) {
- LoggingService.Error(ex);
}
- }
- };
+ });
try {
appDomainHost.DisposeDesignSurface();
} catch (ExceptionCollection exceptions) {
@@ -579,45 +566,38 @@ void DesignerLoading(object sender, EventArgs e)
{
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);
-// designView.BackColor = Color.White;
-// designView.RightToLeft = RightToLeft.No;
- // Make sure auto-scaling is based on the correct font.
+ // 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.Font = System.Windows.Forms.Control.DefaultFont;
+ CustomWindowsFormsHost designView = WrapInCustomHost(appDomainHost.DesignSurfaceView, enableFontInheritance: false);
this.UserContent = designView;
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 +728,7 @@ public override void Dispose()
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 +888,7 @@ protected void ReloadDesignerFromMemory()
this.Load(this.DesignerCodeFile, ms);
}
- UpdatePropertyPad();
+ appDomainHost.UpdatePropertyPad();
}
public virtual object ToolsContent {
View
26 src/AddIns/DisplayBindings/FormsDesigner/Project/FormsDesigner.csproj
@@ -45,35 +45,16 @@
<DefineConstants>DEBUG, FORMSDESIGNER_DLL</DefineConstants>
</PropertyGroup>
<ItemGroup>
- <Reference Include="PresentationCore">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
- <Reference Include="PresentationFramework">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
<Reference Include="System" />
- <Reference Include="System.AddIn" />
- <Reference Include="System.AddIn.Contract">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
<Reference Include="System.Core" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Design" />
<Reference Include="System.Windows.Forms" />
- <Reference Include="System.Windows.Presentation">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.XML" />
- <Reference Include="WindowsBase">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
- <Reference Include="WindowsFormsIntegration">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\Src\EasyCodeDom.cs">
@@ -119,5 +100,12 @@
<EmbeddedResource Include="Resources\WindowsFormsGeneralOptions.xfrm" />
<Compile Include="Src\Services\DesignerSerializationService.cs" />
</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
98 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.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 @@ void ComponentChanged(object sender, ComponentChangedEventArgs e)
}
}
+ 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 @@ void InitializeEvents()
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 @@ void InitializeEvents()
selectionService.SelectionChanged += selectionService_SelectionChanged;
}
- Host.TransactionClosed += Host_TransactionClosed;
+ Host.TransactionClosed += TransactionClose;
}
void selectionService_SelectionChanged(object sender, EventArgs e)
@@ -357,16 +375,17 @@ public void FlushDesignSurface()
designSurface.Flush();
}
- WindowsFormsHost host;
+ bool isDesignSurfaceViewInitialized = false;
- public INativeHandleContract DesignSurfaceView {
+ public Control DesignSurfaceView {
get {
- if (host == null) {
- host = new WindowsFormsHost();
- host.Child = (Control)designSurface.View;
+ var designView = (Control)designSurface.View;
+ if (!isDesignSurfaceViewInitialized) {
+ designView.BackColor = Color.White;
+ designView.RightToLeft = RightToLeft.No;
+ isDesignSurfaceViewInitialized = true;
}
-
- return FrameworkElementAdapters.ViewToContractAdapter(host);
+ return designView;
}
}
@@ -375,13 +394,44 @@ public void DisposeDesignSurface()
designSurface.Dispose();
}
- public INativeHandleContract CreatePropertyGrid()
+ PropertyGrid grid;
+
+ public PropertyGrid CreatePropertyGrid()
{
- var grid = new PropertyGrid() { Dock = DockStyle.Fill };
- var host = new WindowsFormsHost();
- host.Child = grid;
+ grid = new PropertyGrid() { Dock = DockStyle.Fill };
- return FrameworkElementAdapters.ViewToContractAdapter(host);
+ return grid;
+ }
+
+ public void UpdatePropertyPad()
+ {
+ if (HasDesignerHost) {
+ UpdateDesignerHost(); // TODO reuse code from PropertyPad!
+// propertyContainer.SelectableObjects = appDomainHost.Host.Container.Components;
+ ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
+ if (selectionService != null) {
+ UpdatePropertyPadSelection(selectionService);
+ }
+ }
+ }
+
+ void UpdateDesignerHost()
+ {
+// if (grid. == Host)
+// return;
+// if (instance.host != null)
+// instance.RemoveHost(instance.host);
+// if (container.Host != null)
+// instance.SetDesignerHost(container.Host);
+ }
+
+ public void UpdatePropertyPadSelection(ISelectionService selectionService)
+ {
+ var selection = selectionService.GetSelectedComponents();
+ object[] selArray = new object[selection.Count];
+ selection.CopyTo(selArray, 0);
+// propertyContainer.SelectedObjects = selArray;
+ properties.FormsDesignerProxy.InvalidateRequerySuggested();
}
public IFormsDesignerLoggingService LoggingService {
@@ -444,6 +494,16 @@ public void InitializeUndoEngine()
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
View
1 src/AddIns/DisplayBindings/FormsDesigner/Project/Src/IFormsDesigner.cs
@@ -28,6 +28,7 @@ public interface IFormsDesigner
SharpDevelopDesignerOptions DesignerOptions { get; }
void MakeDirty();
+ void InvalidateRequerySuggested();
}
public enum ResourceType

No commit comments for this range

Something went wrong with that request. Please try again.