Browse Source

Worked on designer infrastructure.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2223 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
661dc93d6c
  1. 33
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  2. 44
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  3. 39
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DesignServiceContainer.cs
  4. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  5. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
  6. 45
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  7. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs
  8. 41
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignContext.cs
  9. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  10. 18
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/Extension.cs
  11. 45
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs
  12. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs
  13. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs
  14. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

33
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -26,14 +26,12 @@ namespace ICSharpCode.WpfDesign.Designer @@ -26,14 +26,12 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
DefaultServiceProvider _services;
DesignContext _context;
InnerDesignPanel _innerDesignPanel;
UIElement _designedElement;
public DesignPanel(DefaultServiceProvider services)
public DesignPanel()
{
this._services = services;
this.Focusable = true;
_innerDesignPanel = new InnerDesignPanel();
@ -50,6 +48,19 @@ namespace ICSharpCode.WpfDesign.Designer @@ -50,6 +48,19 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
/// <summary>
/// Gets/Sets the design context.
/// </summary>
public DesignContext Context {
get { return _context; }
set { _context = value; }
}
private IToolService ToolService {
[DebuggerStepThrough]
get { return _context.Services.Tool; }
}
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{
return new PointHitTestResult(this, hitTestParameters.HitPoint);
@ -69,7 +80,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -69,7 +80,7 @@ namespace ICSharpCode.WpfDesign.Designer
if (site != null) {
Debug.WriteLine(" Found designed element: " + site.Component.GetType().Name);
}
_services.Tool.CurrentTool.OnMouseDown(this, e);
ToolService.CurrentTool.OnMouseDown(this, e);
}
}
@ -77,7 +88,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -77,7 +88,7 @@ namespace ICSharpCode.WpfDesign.Designer
{
if (originalSource == null)
return null;
DesignItem site = _services.Component.GetDesignItem(originalSource);
DesignItem site = _context.Services.Component.GetDesignItem(originalSource);
if (site != null)
return site;
if (originalSource == _innerDesignPanel)
@ -104,16 +115,6 @@ namespace ICSharpCode.WpfDesign.Designer @@ -104,16 +115,6 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
#region IDesignPanel implementation
public UIElement DesignPanelUI {
get { return this; }
}
public DefaultServiceProvider Services {
get { return _services; }
}
#endregion
bool _isInInputAction;
void IDesignPanel.StartInputAction()

44
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -11,7 +11,6 @@ using System.Windows.Controls; @@ -11,7 +11,6 @@ using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Designer.Controls;
@ -22,36 +21,26 @@ namespace ICSharpCode.WpfDesign.Designer @@ -22,36 +21,26 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
public sealed class DesignSurface : SingleVisualChildElement
{
readonly DefaultServiceProvider _services;
readonly DefaultComponentService _componentService;
readonly ScrollViewer _scrollViewer;
readonly DesignPanel _designPanel;
DesignContext _designContext;
/// <summary>
/// Create a new DesignSurface instance.
/// </summary>
public DesignSurface()
{
DesignServiceContainer serviceContainer = new DesignServiceContainer();
_services = new DefaultServiceProvider(serviceContainer);
serviceContainer.AddService(typeof(IVisualDesignService), new DefaultVisualDesignService());
serviceContainer.AddService(typeof(ISelectionService), new DefaultSelectionService());
serviceContainer.AddService(typeof(IToolService), new DefaultToolService());
_componentService = new DefaultComponentService(this);
serviceContainer.AddService(typeof(IComponentService), _componentService);
_scrollViewer = new ScrollViewer();
_designPanel = new DesignPanel(_services);
_designPanel = new DesignPanel();
_scrollViewer.Content = _designPanel;
this.VisualChild = _scrollViewer;
}
/// <summary>
/// Gets the service provider.
/// Gets the active design context.
/// </summary>
public DefaultServiceProvider Services {
get { return _services; }
public DesignContext DesignContext {
get { return _designContext; }
}
/// <summary>
@ -69,7 +58,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -69,7 +58,7 @@ namespace ICSharpCode.WpfDesign.Designer
public void LoadDesigner(XmlReader xamlReader)
{
UnloadDesigner();
InitializeDesigner(XamlParser.Parse(xamlReader));
InitializeDesigner(new Xaml.XamlDesignContext(XamlDom.XamlParser.Parse(xamlReader)));
}
/// <summary>
@ -77,18 +66,14 @@ namespace ICSharpCode.WpfDesign.Designer @@ -77,18 +66,14 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
public void SaveDesigner(XmlWriter writer)
{
_currentDocument.Save(writer);
_designContext.Save(writer);
}
XamlDocument _currentDocument;
void InitializeDesigner(XamlDocument document)
void InitializeDesigner(DesignContext context)
{
_currentDocument = document;
XamlDesignItem rootSite = _componentService.RegisterXamlComponentRecursive(document.RootElement);
UIElement rootUI = DefaultVisualDesignService.CreateUIElementFor(rootSite);
rootSite.SetView(rootUI);
_designPanel.DesignedElement = rootUI;
_designContext = context;
_designPanel.Context = context;
_designPanel.DesignedElement = context.RootItem.View;
}
/// <summary>
@ -96,12 +81,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -96,12 +81,9 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
public void UnloadDesigner()
{
_currentDocument = null;
UIElement designedElement = this.DesignedElement;
if (designedElement != null) {
_componentService.UnregisterAllComponents();
_designContext = null;
_designPanel.Context = null;
_designPanel.DesignedElement = null;
}
}
}
}

39
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DesignServiceContainer.cs

@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.Designer.Services
{
sealed class DesignServiceContainer : IServiceContainer
{
public DesignServiceContainer()
{
AddService(typeof(IServiceContainer), this);
}
Dictionary<Type, object> _services = new Dictionary<Type, object>();
public void AddService(Type serviceInterface, object serviceInstance)
{
if (serviceInterface == null)
throw new ArgumentNullException("serviceInterface");
if (serviceInstance == null)
throw new ArgumentNullException("serviceInstance");
_services.Add(serviceInterface, serviceInstance);
}
public object GetService(Type serviceType)
{
object instance;
_services.TryGetValue(serviceType, out instance);
return instance;
}
}
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -61,17 +61,18 @@ @@ -61,17 +61,18 @@
<Compile Include="HashSet.cs" />
<Compile Include="Linq.cs" />
<Compile Include="ServiceRequiredException.cs" />
<Compile Include="Services\ComponentService.cs" />
<Compile Include="Services\DesignServiceContainer.cs" />
<Compile Include="Services\SelectionService.cs" />
<Compile Include="Services\ToolService.cs" />
<Compile Include="Services\VisualDesignService.cs" />
<Compile Include="XamlDesignItem.cs" />
<Compile Include="DesignSurface.cs" />
<Compile Include="Xaml\XamlComponentService.cs" />
<Compile Include="Xaml\XamlDesignContext.cs" />
<Compile Include="Xaml\XamlDesignItem.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Configuration" />
<Folder Include="Controls" />
<Folder Include="Xaml" />
<Folder Include="Services" />
<ProjectReference Include="..\..\WpfDesign.XamlDom\Project\WpfDesign.XamlDom.csproj">
<Project>{88DA149F-21B2-48AB-82C4-28FB6BDFD783}</Project>

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ComponentService.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs

@ -9,15 +9,15 @@ using System; @@ -9,15 +9,15 @@ using System;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer.Services
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
sealed class DefaultComponentService : IComponentService
sealed class XamlComponentService : IComponentService
{
readonly DesignSurface _surface;
readonly XamlDesignContext _context;
public DefaultComponentService(DesignSurface surface)
public XamlComponentService(XamlDesignContext context)
{
this._surface = surface;
this._context = context;
}
public event EventHandler<DesignItemEventArgs> ComponentRegistered;
@ -71,7 +71,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -71,7 +71,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
}
}
XamlDesignItem site = new XamlDesignItem(obj, _surface);
XamlDesignItem site = new XamlDesignItem(obj, _context);
_sites.Add(site.Component, site);
if (ComponentRegistered != null) {
ComponentRegistered(this, new DesignItemEventArgs(site));

45
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
sealed class XamlDesignContext : DesignContext
{
readonly XamlDocument _doc;
readonly XamlDesignItem _rootItem;
readonly XamlComponentService _componentService;
public XamlDesignContext(XamlDocument doc)
{
if (doc == null)
throw new ArgumentNullException("doc");
this._doc = doc;
this.Services.AddService(typeof(IVisualDesignService), new DefaultVisualDesignService());
this.Services.AddService(typeof(ISelectionService), new DefaultSelectionService());
this.Services.AddService(typeof(IToolService), new DefaultToolService());
_componentService = new XamlComponentService(this);
this.Services.AddService(typeof(IComponentService), _componentService);
_rootItem = _componentService.RegisterXamlComponentRecursive(doc.RootElement);
}
public override void Save(System.Xml.XmlWriter writer)
{
_doc.Save(writer);
}
public override DesignItem RootItem {
get { return _rootItem; }
}
}
}

19
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/XamlDesignItem.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

@ -9,23 +9,23 @@ using System; @@ -9,23 +9,23 @@ using System;
using System.Windows;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.WpfDesign.Designer
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
sealed class XamlDesignItem : DesignItem
{
readonly XamlObject xamlObject;
readonly DesignSurface designSurface;
readonly XamlObject _xamlObject;
readonly XamlDesignContext _designContext;
UIElement _view;
public XamlDesignItem(XamlObject xamlObject, DesignSurface designSurface)
public XamlDesignItem(XamlObject xamlObject, XamlDesignContext designContext)
{
this.xamlObject = xamlObject;
this.designSurface = designSurface;
this._xamlObject = xamlObject;
this._designContext = designContext;
}
public override object Component {
get {
return xamlObject.Instance;
return _xamlObject.Instance;
}
}
@ -43,9 +43,8 @@ namespace ICSharpCode.WpfDesign.Designer @@ -43,9 +43,8 @@ namespace ICSharpCode.WpfDesign.Designer
_view = newView;
}
public override object GetService(Type serviceType)
{
return designSurface.Services.GetService(serviceType);
public override DesignContext Context {
get { return _designContext; }
}
}
}

41
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignContext.cs

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using System.Xml;
namespace ICSharpCode.WpfDesign
{
/// <summary>
/// The context that the designer uses.
/// </summary>
public abstract class DesignContext
{
readonly ServiceContainer _services = new ServiceContainer();
/// <summary>
/// Gets the <see cref="ServiceContainer"/>.
/// </summary>
public ServiceContainer Services {
[DebuggerStepThrough]
get { return _services; }
}
/// <summary>
/// Gets the root design item.
/// </summary>
public abstract DesignItem RootItem {
get;
}
/// <summary>
/// Save the designed elements as XML.
/// </summary>
public abstract void Save(XmlWriter writer);
}
}

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
namespace ICSharpCode.WpfDesign
@ -20,7 +21,7 @@ namespace ICSharpCode.WpfDesign @@ -20,7 +21,7 @@ namespace ICSharpCode.WpfDesign
/// http://blogs.msdn.com/jnak/archive/2006/04/24/580393.aspx
/// http://blogs.msdn.com/jnak/archive/2006/08/04/687166.aspx
/// </remarks>
public abstract class DesignItem : IServiceProvider
public abstract class DesignItem
{
/// <summary>
/// Gets the component this DesignSite was created for.
@ -32,23 +33,17 @@ namespace ICSharpCode.WpfDesign @@ -32,23 +33,17 @@ namespace ICSharpCode.WpfDesign
/// </summary>
public abstract UIElement View { get; }
DefaultServiceProvider _defaultServiceProvider;
/// <summary>
/// Gets an instance that provides convenience properties for the most-used designers.
/// Gets the design context.
/// </summary>
public DefaultServiceProvider Services {
get {
if (_defaultServiceProvider == null) {
_defaultServiceProvider = new DefaultServiceProvider(this);
}
return _defaultServiceProvider;
}
}
public abstract DesignContext Context { get; }
/// <summary>
/// Gets the service with the specified type.
/// Gets an instance that provides convenience properties for the most-used designers.
/// </summary>
public abstract object GetService(Type serviceType);
public ServiceContainer Services {
[DebuggerStepThrough]
get { return this.Context.Services; }
}
}
}

18
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/Extension.cs

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.WpfDesign.Extensions
{
/// <summary>
/// Base class for all Extensions.
/// </summary>
public abstract class Extension
{
}
}

45
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DefaultServiceProvider.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs

@ -6,24 +6,37 @@ @@ -6,24 +6,37 @@
// </file>
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace ICSharpCode.WpfDesign
{
/// <summary>
/// Provides convenience methods for well-known service instances.
/// The <see cref="ServiceContainer"/> is a built-in service that manages the list of services.
/// You can only add services to it, removing or replacing services is not supported because
/// many designers depend on keeping their services available.
/// </summary>
public sealed class DefaultServiceProvider : IServiceProvider
public sealed class ServiceContainer : IServiceProvider
{
readonly IServiceProvider _serviceProvider;
Dictionary<Type, object> _services = new Dictionary<Type, object>();
/// <summary>
/// Creates a new DefaultServiceProvider that requests services from the specified service
/// provider.
/// Adds a new service to the container.
/// </summary>
public DefaultServiceProvider(IServiceProvider serviceProvider)
/// <param name="serviceInterface">
/// The type of the service interface to use as a key for the service.
/// </param>
/// <param name="serviceInstance">
/// The service instance implementing that interface.
/// </param>
public void AddService(Type serviceInterface, object serviceInstance)
{
this._serviceProvider = serviceProvider;
if (serviceInterface == null)
throw new ArgumentNullException("serviceInterface");
if (serviceInstance == null)
throw new ArgumentNullException("serviceInstance");
_services.Add(serviceInterface, serviceInstance);
}
/// <summary>
@ -31,7 +44,9 @@ namespace ICSharpCode.WpfDesign @@ -31,7 +44,9 @@ namespace ICSharpCode.WpfDesign
/// </summary>
public object GetService(Type serviceType)
{
return _serviceProvider.GetService(serviceType);
object instance;
_services.TryGetValue(serviceType, out instance);
return instance;
}
/// <summary>
@ -40,28 +55,18 @@ namespace ICSharpCode.WpfDesign @@ -40,28 +55,18 @@ namespace ICSharpCode.WpfDesign
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
public T GetService<T>() where T : class
{
return (T)_serviceProvider.GetService(typeof(T));
return (T)GetService(typeof(T));
}
T GetServiceChecked<T>() where T : class
{
T service = (T)_serviceProvider.GetService(typeof(T));
T service = (T)GetService(typeof(T));
if (service == null) {
throw new DesignerException("Could not find guaranteed service " + typeof(T).FullName);
}
return service;
}
/// <summary>
/// Gets the <see cref="IServiceContainer"/>.
/// This service is guaranteed to always exist -> this property will never return null.
/// </summary>
public IServiceContainer ServiceContainer {
get {
return GetServiceChecked<IServiceContainer>();
}
}
/// <summary>
/// Gets the <see cref="ISelectionService"/>.
/// This service is guaranteed to always exist -> this property will never return null.

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

@ -11,27 +11,6 @@ using System.Windows; @@ -11,27 +11,6 @@ using System.Windows;
namespace ICSharpCode.WpfDesign
{
#region IServiceContainer
/// <summary>
/// The <see cref="IServiceContainer"/> is a built-in service that manages the list of services.
/// You can only add services to it, removing or replacing services is not supported because
/// many designers depend on keeping their services available.
/// </summary>
public interface IServiceContainer : IServiceProvider
{
/// <summary>
/// Adds a new service to the container.
/// </summary>
/// <param name="serviceInterface">
/// The type of the service interface to use as a key for the service.
/// </param>
/// <param name="serviceInstance">
/// The service instance implementing that interface.
/// </param>
void AddService(Type serviceInterface, object serviceInstance);
}
#endregion
#region IVisualDesignService
/// <summary>
/// A service that can visualize non-UIElement objects on a design surface.

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs

@ -87,9 +87,9 @@ namespace ICSharpCode.WpfDesign @@ -87,9 +87,9 @@ namespace ICSharpCode.WpfDesign
public interface IDesignPanel : IInputElement
{
/// <summary>
/// Gets the service provider used by the DesignPanel.
/// Gets the design context used by the DesignPanel.
/// </summary>
DefaultServiceProvider Services { get; }
DesignContext Context { get; }
/// <summary>
/// Starts an input action. This prevents components and tools from getting input events,

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

@ -55,15 +55,18 @@ @@ -55,15 +55,18 @@
<Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="DesignContext.cs" />
<Compile Include="EventArgs.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="DesignerException.cs" />
<Compile Include="DefaultServiceProvider.cs" />
<Compile Include="Extensions\Extension.cs" />
<Compile Include="ServiceContainer.cs" />
<Compile Include="DesignItem.cs" />
<Compile Include="Services.cs" />
<Compile Include="Tools.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Configuration" />
<Folder Include="Extensions" />
</ItemGroup>
</Project>
Loading…
Cancel
Save