Browse Source

Documented AppBuilder.

And made `Start` method private: clients should use
`SetupWithoutStarting`.
pull/537/head
Steven Kirk 10 years ago
parent
commit
b1988af4e7
  1. 56
      src/Avalonia.Controls/AppBuilder.cs
  2. 2
      src/Avalonia.DesignerSupport/DesignerAssist.cs

56
src/Avalonia.Controls/AppBuilder.cs

@ -1,27 +1,51 @@
// Copyright (c) The Avalonia Project. All rights reserved. // Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Input;
using System; using System;
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
/// <summary>
/// Initializes up platform-specific services for an <see cref="Application"/>.
/// </summary>
public class AppBuilder public class AppBuilder
{ {
/// <summary>
/// Gets or sets the <see cref="Application"/> instance being initialized.
/// </summary>
public Application Instance { get; set; } public Application Instance { get; set; }
/// <summary>
/// Gets or sets a method to call the initialize the windowing subsystem.
/// </summary>
public Action WindowingSubsystem { get; set; } public Action WindowingSubsystem { get; set; }
/// <summary>
/// Gets or sets a method to call the initialize the windowing subsystem.
/// </summary>
public Action RenderingSubsystem { get; set; } public Action RenderingSubsystem { get; set; }
/// <summary>
/// Gets or sets a method to call before <see cref="Start{TMainWindow}"/> is called on the
/// <see cref="Application"/>.
/// </summary>
public Action<AppBuilder> BeforeStartCallback { get; set; } public Action<AppBuilder> BeforeStartCallback { get; set; }
/// <summary>
/// Begin configuring an <see cref="Application"/>.
/// </summary>
/// <typeparam name="TApp">The subclass of <see cref="Application"/> to configure.</typeparam>
/// <returns>An <see cref="AppBuilder"/> instance.</returns>
public static AppBuilder Configure<TApp>() public static AppBuilder Configure<TApp>()
where TApp : Application, new() where TApp : Application, new()
{ {
return Configure(new TApp()); return Configure(new TApp());
} }
/// <summary>
/// Begin configuring an <see cref="Application"/>.
/// </summary>
/// <returns>An <see cref="AppBuilder"/> instance.</returns>
public static AppBuilder Configure(Application app) public static AppBuilder Configure(Application app)
{ {
AvaloniaLocator.CurrentMutable.BindToSelf(app); AvaloniaLocator.CurrentMutable.BindToSelf(app);
@ -32,12 +56,22 @@ namespace Avalonia.Controls
}; };
} }
/// <summary>
/// Registers a callback to call before <see cref="Start{TMainWindow}"/> is called on the
/// <see cref="Application"/>.
/// </summary>
/// <param name="callback">The callback.</param>
/// <returns>An <see cref="AppBuilder"/> instance.</returns>
public AppBuilder BeforeStarting(Action<AppBuilder> callback) public AppBuilder BeforeStarting(Action<AppBuilder> callback)
{ {
BeforeStartCallback = callback; BeforeStartCallback = callback;
return this; return this;
} }
/// <summary>
/// Starts the application with an instance of <typeparamref name="TMainWindow"/>.
/// </summary>
/// <typeparam name="TMainWindow">The window type.</typeparam>
public void Start<TMainWindow>() public void Start<TMainWindow>()
where TMainWindow : Window, new() where TMainWindow : Window, new()
{ {
@ -49,25 +83,42 @@ namespace Avalonia.Controls
Instance.Run(window); Instance.Run(window);
} }
/// <summary>
/// Sets up the platform-specific services for the application, but does not run it.
/// </summary>
/// <returns></returns>
public AppBuilder SetupWithoutStarting() public AppBuilder SetupWithoutStarting()
{ {
Setup(); Setup();
return this; return this;
} }
/// <summary>
/// Specifies a windowing subsystem to use.
/// </summary>
/// <param name="initializer">The method to call to initialize the windowing subsystem.</param>
/// <returns>An <see cref="AppBuilder"/> instance.</returns>
public AppBuilder WithWindowingSubsystem(Action initializer) public AppBuilder WithWindowingSubsystem(Action initializer)
{ {
WindowingSubsystem = initializer; WindowingSubsystem = initializer;
return this; return this;
} }
/// <summary>
/// Specifies a rendering subsystem to use.
/// </summary>
/// <param name="initializer">The method to call to initialize the rendering subsystem.</param>
/// <returns>An <see cref="AppBuilder"/> instance.</returns>
public AppBuilder WithRenderingSubsystem(Action initializer) public AppBuilder WithRenderingSubsystem(Action initializer)
{ {
RenderingSubsystem = initializer; RenderingSubsystem = initializer;
return this; return this;
} }
public void Setup() /// <summary>
/// Sets up the platform-speciic services for the <see cref="Application"/>.
/// </summary>
private void Setup()
{ {
if (Instance == null) if (Instance == null)
{ {
@ -83,6 +134,7 @@ namespace Avalonia.Controls
{ {
throw new InvalidOperationException("No rendering system configured."); throw new InvalidOperationException("No rendering system configured.");
} }
Instance.RegisterServices(); Instance.RegisterServices();
WindowingSubsystem(); WindowingSubsystem();
RenderingSubsystem(); RenderingSubsystem();

2
src/Avalonia.DesignerSupport/DesignerAssist.cs

@ -62,7 +62,7 @@ namespace Avalonia.DesignerSupport
AppBuilder.Configure(app == null ? new DesignerApp() : (Application) Activator.CreateInstance(app.AsType())) AppBuilder.Configure(app == null ? new DesignerApp() : (Application) Activator.CreateInstance(app.AsType()))
.WithWindowingSubsystem(Application.InitializeWin32Subsystem) .WithWindowingSubsystem(Application.InitializeWin32Subsystem)
.WithRenderingSubsystem(() => { }) .WithRenderingSubsystem(() => { })
.Setup(); .SetupWithoutStarting();
} }
private static void SetScalingFactor(double factor) private static void SetScalingFactor(double factor)

Loading…
Cancel
Save