Skip to content

Commit

Permalink
Progress on fixing failing tests in GH.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilus committed Aug 22, 2016
1 parent 34c5209 commit b9e8f07
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 17 deletions.
28 changes: 28 additions & 0 deletions GH.Menu.UnitTests/Containers/Line/LineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ public void LineGetPreferredWidthTestWithNull()
Assert.AreEqual(null, width);
}

[TestMethod]
public void LineGetPreferredWidthTestWithOneObject()
{
// Setup
var profiles = new List<LineProfile>();
var dimensionsMapping = new Dictionary<ObjectAlign, double?>()
{
{ ObjectAlign.r, 40 },
};

var menuHandlerMock = SetUpMenuHandlerMock(profiles, ((lineProfile, mock) =>
{
mock.Setup(e => e.GetPreferredWidth()).Returns(dimensionsMapping[lineProfile.Single().align]);
}));

var profile = new LineProfile()
{
GenerateObjectProfile(ObjectAlign.r),
};
this.lineUnderTest.Prepare(profile, menuHandlerMock.Object);

// Act
var width = this.lineUnderTest.GetPreferredWidth();

// Assert
Assert.AreEqual(40, width);
}

[TestMethod]
public void LineGetPreferredHeightTestWithNoNull()
{
Expand Down
5 changes: 2 additions & 3 deletions GH.Menu/BaseElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public abstract class BaseElement : IElement

public IFrame Frame { get; }

public NativeLuaTable NativeFrame { get; }

public BaseElement(string typeName, IWrapper wrapper) : this(typeName, FrameType.Frame, null, wrapper)
{
}
Expand All @@ -27,7 +25,6 @@ public BaseElement(string typeName, FrameType frameType, string inherits, IWrapp
{
this.wrapper = wrapper;
this.Frame = (IFrame)Global.FrameProvider.CreateFrame(frameType, UniqueName(typeName), null, inherits);
this.NativeFrame = this.wrapper.Unwrap(this.Frame);
}


Expand All @@ -52,6 +49,8 @@ public virtual void Recycle()
this.handler.RecyclePool.Store(this);
}

public bool IsPrepared => this.prepared;

public abstract void Clear();

private static string UniqueName(string type)
Expand Down
17 changes: 15 additions & 2 deletions GH.Menu/Containers/BaseContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@

public abstract class BaseContainer<T, TProfile> : BaseElement, IContainer<T> where T : IMenuRegion
{
protected LayoutSettings Layout;
private LayoutSettings layout;

protected LayoutSettings Layout
{
get
{
if (!this.IsPrepared)
{
throw new MenuException("Cannot get layout when container object is not prepared.");
}
return this.layout;
}

}
protected List<T> Content;

public BaseContainer(string typeName, IWrapper wrapper) : base(typeName, wrapper)
Expand Down Expand Up @@ -75,7 +88,7 @@ public override void Prepare(IElementProfile profile, IMenuHandler handler)
{
base.Prepare(profile, handler);
this.Content = new List<T>();
this.Layout = handler.Layout;
this.layout = handler.Layout;

var containerProfile = profile as IContainerProfile<TProfile>;
if (containerProfile == null)
Expand Down
7 changes: 5 additions & 2 deletions GH.Menu/Containers/Line/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public override void Prepare(IElementProfile profile, IMenuHandler handler)
this.leftBlock = GenerateAndPrepareBlock(lineProfile, ObjectAlign.l, handler);
this.centerBlock = GenerateAndPrepareBlock(lineProfile, ObjectAlign.c, handler);
this.rightBlock = GenerateAndPrepareBlock(lineProfile, ObjectAlign.r, handler);
this.Content = new List<IAlignedBlock>() { this.leftBlock, this.centerBlock, this.rightBlock };
this.Content = new List<IAlignedBlock>();
this.Content.AddRange(new[] { this.leftBlock, this.centerBlock, this.rightBlock }.Where(b => b != null));
}

/// <summary>
Expand Down Expand Up @@ -133,7 +134,9 @@ private static IAlignedBlock GenerateAndPrepareBlock(LineProfile profile, Object
return null;
}

return (IAlignedBlock)handler.CreateRegion(blockProfile, false, typeof(AlignedBlock));
var block = (IAlignedBlock)handler.CreateRegion(blockProfile, false, typeof(AlignedBlock));
block.Prepare(blockProfile, handler);
return block;
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions GH.Menu/Containers/Menus/TabMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private IButton CreateButtonFrame(int index)
private void CreateTabButtons()
{
this.tabButtons = new Dictionary<int, IButton>();
var setTabFunc = (Action<NativeLuaTable, int>)Global.Api.GetGlobal("PanelTemplates_SetTab");
var setTabFunc = (Action<IFrame, int>)Global.Api.GetGlobal("PanelTemplates_SetTab");

for (var i = 0; i < this.Content.Count; i++)
{
Expand All @@ -83,7 +83,7 @@ private void CreateTabButtons()

button.SetScript(ButtonHandler.OnClick, (self) =>
{
setTabFunc(this.NativeFrame, button.GetID());
setTabFunc(this.Frame, button.GetID());
if (this.currentPage != null)
{
this.currentPage.Hide();
Expand All @@ -93,7 +93,7 @@ private void CreateTabButtons()
page.Show();
});
}
((Action<NativeLuaTable, int>)Global.Api.GetGlobal("PanelTemplates_SetNumTabs"))(this.NativeFrame, this.Content.Count);
((Action<IFrame, int>)Global.Api.GetGlobal("PanelTemplates_SetNumTabs"))(this.Frame, this.Content.Count);
}

private static void InvokeClick(IButton button)
Expand Down
9 changes: 5 additions & 4 deletions GH.Menu/MenuHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using System;
using System.Collections.Generic;
using Containers.Line;

using CsLuaFramework.Wrapping;

using GH.Menu.Containers.AlignedBlock;
using GH.Menu.Containers.Menus;
using GH.Menu.Containers.Page;
Expand All @@ -24,7 +27,7 @@ public class MenuHandler : SingletonModule, IMenuHandler
{
public MenuHandler()
{
this.RecyclePool = new RecyclePool();
this.RecyclePool = new RecyclePool(new Wrapper());
this.Layout = new LayoutSettings()
{lineSpacing = 5, objectSpacing = 5};
this.Theme = new MenuTheme()
Expand Down Expand Up @@ -118,9 +121,7 @@ public IMenuRegion CreateRegion(IMenuRegionProfile profile, bool skipWrappingObj

public IMenuRegion CreateRegion(IMenuRegionProfile profile, bool skipWrappingObject, Type specificType)
{
var region = (IMenuRegion)this.RecyclePool.Retrieve(specificType);
region.Prepare(profile, this);
return region;
return (IMenuRegion)this.RecyclePool.Retrieve(specificType);
}
}
}
1 change: 1 addition & 0 deletions GH.Menu/Objects/Panel/PanelObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public override void Prepare(IElementProfile profile, IMenuHandler handler)
var innerPageProfile = new PageProfile();
panelProfile.ForEach(innerPageProfile.Add);
this.innerPage = (IPage)handler.CreateRegion(innerPageProfile);
this.innerPage.Prepare(innerPageProfile, handler);
this.name = panelProfile.name;
}

Expand Down
14 changes: 12 additions & 2 deletions GH.Menu/RecyclePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@
using System.Collections.Generic;
using System.Linq;

using CsLuaFramework.Wrapping;

public class RecyclePool : IRecyclePool
{
private List<IElement> list = new List<IElement>();
private readonly List<IElement> list;

private readonly IWrapper wrapper;

public RecyclePool(IWrapper wrapper)
{
this.wrapper = wrapper;
this.list = new List<IElement>();
}

public IElement Retrieve(Type type)
{
return this.list.FirstOrDefault(e => e.GetType() == type) ?? (IElement)Activator.CreateInstance(type);
return this.list.FirstOrDefault(e => e.GetType() == type) ?? (IElement)Activator.CreateInstance(type, this.wrapper);
}

public void Store(IElement element)
Expand Down
2 changes: 1 addition & 1 deletion GH.Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void LoadSettings()

foreach (var loadedModule in loadedModules)
{
this.SetDefaultSettingsFromModule(loadedModule);
this.LoadSettingsForModule(loadedModule);
}

ModuleFactory.ModuleFactorySingleton.RegisterForModuleLoadEvents(
Expand Down
2 changes: 2 additions & 0 deletions GH/GHAddOn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class GHAddOn : ICsLuaAddOn
{
public void Execute()
{
var settings = ModuleFactory.GetM<Settings.Settings>();

var registry = ModuleFactory.ModuleFactorySingleton.GetModule<AddOnRegistry>();
registry.RegisterAddOn(AddOnReference.GH);

Expand Down

0 comments on commit b9e8f07

Please sign in to comment.