Browse Source

Added a logging manager...

To try and figure out why stuff is flashing up on the screen when you
open a new tree view node, and then decided to put that off for later ;)
pull/4/head
Steven Kirk 12 years ago
parent
commit
371e381006
  1. 67
      Perspex.Diagnostics/LogManager.cs
  2. 6
      Perspex.Diagnostics/Perspex.Diagnostics.csproj
  3. 1
      Perspex.Diagnostics/packages.config
  4. 2
      Perspex.Layout/ILayoutManager.cs
  5. 36
      Perspex.Layout/LayoutManager.cs
  6. 8
      Perspex.Windows/Window.cs
  7. 9
      TestApplication/Program.cs

67
Perspex.Diagnostics/LogManager.cs

@ -0,0 +1,67 @@
// -----------------------------------------------------------------------
// <copyright file="LogManager.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Diagnostics
{
using System;
using Perspex.Layout;
using Splat;
public class LogManager : ILogManager
{
private static LogManager instance;
public static LogManager Instance
{
get
{
if (instance == null)
{
instance = new LogManager();
}
return instance;
}
}
public ILogger Logger
{
get;
set;
}
public bool LogPropertyMessages
{
get;
set;
}
public bool LogLayoutMessages
{
get;
set;
}
public static void Enable(ILogger logger)
{
Instance.Logger = logger;
Locator.CurrentMutable.Register(() => Instance, typeof(ILogManager));
}
public IFullLogger GetLogger(Type type)
{
if ((type == typeof(PerspexObject) && LogPropertyMessages) ||
(type == typeof(Layoutable) && LogLayoutMessages))
{
return new WrappingFullLogger(this.Logger, type);
}
else
{
return new WrappingFullLogger(new NullLogger(), type);
}
}
}
}

6
Perspex.Diagnostics/Perspex.Diagnostics.csproj

@ -21,7 +21,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
@ -65,11 +65,15 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="LogManager.cs" />
<Compile Include="DevTools.cs" /> <Compile Include="DevTools.cs" />
<Compile Include="Debug.cs" /> <Compile Include="Debug.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.3.3\lib\Portable-net45+win+wpa81+wp80\Splat.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Core"> <Reference Include="System.Reactive.Core">
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Core.dll</HintPath> <HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Portable-Net45+WinRT45+WP8\System.Reactive.Core.dll</HintPath>
</Reference> </Reference>

1
Perspex.Diagnostics/packages.config

@ -5,4 +5,5 @@
<package id="Rx-Linq" version="2.1.30214.0" targetFramework="portable-net45+win" /> <package id="Rx-Linq" version="2.1.30214.0" targetFramework="portable-net45+win" />
<package id="Rx-Main" version="2.1.30214.0" targetFramework="portable-net45+win" /> <package id="Rx-Main" version="2.1.30214.0" targetFramework="portable-net45+win" />
<package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="portable-net45+win" /> <package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="portable-net45+win" />
<package id="Splat" version="1.3.3" targetFramework="portable-net45+win" />
</packages> </packages>

2
Perspex.Layout/ILayoutManager.cs

@ -13,6 +13,8 @@ namespace Perspex.Layout
{ {
IObservable<Unit> LayoutNeeded { get; } IObservable<Unit> LayoutNeeded { get; }
bool LayoutQueued { get; }
void ExecuteLayoutPass(); void ExecuteLayoutPass();
void InvalidateMeasure(ILayoutable item); void InvalidateMeasure(ILayoutable item);

36
Perspex.Layout/LayoutManager.cs

@ -7,7 +7,6 @@
namespace Perspex.Layout namespace Perspex.Layout
{ {
using System; using System;
using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Subjects; using System.Reactive.Subjects;
@ -30,25 +29,42 @@ namespace Perspex.Layout
get { return this.layoutNeeded; } get { return this.layoutNeeded; }
} }
public bool LayoutQueued
{
get;
private set;
}
public void ExecuteLayoutPass() public void ExecuteLayoutPass()
{ {
if (this.root != null) this.root.Measure(this.root.ClientSize);
{ this.root.Arrange(new Rect(this.root.ClientSize));
this.root.Measure(this.root.ClientSize); this.LayoutQueued = false;
this.root.Arrange(new Rect(this.root.ClientSize));
}
} }
public void InvalidateMeasure(ILayoutable item) public void InvalidateMeasure(ILayoutable item)
{ {
IVisual visual = item as IVisual; if (!this.LayoutQueued)
this.layoutNeeded.OnNext(Unit.Default); {
IVisual visual = item as IVisual;
this.layoutNeeded.OnNext(Unit.Default);
this.LayoutQueued = true;
}
} }
public void InvalidateArrange(ILayoutable item) public void InvalidateArrange(ILayoutable item)
{ {
IVisual visual = item as IVisual; if (!this.LayoutQueued)
this.layoutNeeded.OnNext(Unit.Default); {
IVisual visual = item as IVisual;
this.layoutNeeded.OnNext(Unit.Default);
this.LayoutQueued = true;
}
}
public void LayoutFinished()
{
this.LayoutQueued = false;
} }
} }
} }

8
Perspex.Windows/Window.cs

@ -59,14 +59,18 @@ namespace Perspex.Windows
}); });
this.RenderManager.RenderNeeded this.RenderManager.RenderNeeded
.Where(_ => !this.LayoutManager.LayoutQueued)
.Subscribe(x => .Subscribe(x =>
{ {
WindowsDispatcher.CurrentDispatcher.BeginInvoke( WindowsDispatcher.CurrentDispatcher.BeginInvoke(
DispatcherPriority.Render, DispatcherPriority.Render,
() => () =>
{ {
this.renderer.Render(this); if (!this.LayoutManager.LayoutQueued)
this.RenderManager.RenderFinished(); {
this.renderer.Render(this);
this.RenderManager.RenderFinished();
}
}); });
}); });
} }

9
TestApplication/Program.cs

@ -1,12 +1,8 @@
using System.Collections; using Perspex;
using System.Collections.Generic;
using System.Linq;
using Perspex;
using Perspex.Controls; using Perspex.Controls;
using Perspex.Layout; using Perspex.Layout;
using Perspex.Media; using Perspex.Media;
using Perspex.Media.Imaging; using Perspex.Media.Imaging;
using Perspex.Threading;
using Perspex.Windows; using Perspex.Windows;
using Splat; using Splat;
@ -86,7 +82,8 @@ namespace TestApplication
static void Main(string[] args) static void Main(string[] args)
{ {
//Locator.CurrentMutable.Register(() => new TestLogger { Level = LogLevel.Debug } , typeof(ILogger)); //LogManager.Enable(new TestLogger());
//LogManager.Instance.LogLayoutMessages = true;
App application = new App App application = new App
{ {

Loading…
Cancel
Save