private void RenderWriteHistory(Dictionary<SolutionFileTextFragment, Color> Lookup, SolutionFile f, IHTMLElement Container)
		{
			Func<SolutionFileTextFragment, Color> LookupOrDefault =
				ff =>
				{
					if (this.Colors.ContainsKey(ff))
						return this.Colors[ff];

					return this.Colors[SolutionFileTextFragment.None];
				};

			var Content = new IHTMLDiv().AttachTo(Container);


			Content.style.position = IStyle.PositionEnum.relative;

			var ViewBackground = new IHTMLDiv().AttachTo(Content);

			ViewBackground.style.position = IStyle.PositionEnum.absolute;
			ViewBackground.style.left = "0px";
			ViewBackground.style.top = "0px";
			ViewBackground.style.width = "4em";
			ViewBackground.style.borderRight = "1px dotted gray";
			ViewBackground.style.paddingRight = "0.5em";

			var ViewTrap = new IHTMLDiv().AttachTo(Content);

			ViewTrap.style.position = IStyle.PositionEnum.absolute;
			ViewTrap.style.left = "0px";
			ViewTrap.style.top = "0px";
			ViewTrap.style.right = "0px";
			ViewTrap.style.bottom = "0px";
			//ViewTrap.style.backgroundColor = Color.White;

			var ViewTrapContainer = new IHTMLDiv().AttachTo(ViewTrap);

			ViewTrapContainer.style.cursor = IStyle.CursorEnum.text;
			ViewTrapContainer.style.position = IStyle.PositionEnum.relative;
			ViewTrapContainer.style.paddingLeft = "5em";

			var View = new IHTMLDiv().AttachTo(ViewTrapContainer);



			var ContentHeightDummy = new IHTMLDiv().AttachTo(Content);

			var RegionStack = new Stack<List<Action<bool>>>();
			var RegionGlobal = new List<Action<bool>>();
			RegionStack.Push(RegionGlobal);

			var Lines = new List<IHTMLDiv>();

			var CurrentLineDirty = false;
			var CurrentLine = default(IHTMLDiv);
			var CurrentLineContent = default(IHTMLDiv);

			Action NextLine = delegate
			{
				CurrentLineDirty = false;

				var c = new IHTMLDiv();
				var cc = new IHTMLDiv();
				var cb = new IHTMLDiv();

				CurrentLine = c.AttachTo(View);
				CurrentLineContent = cc.AttachTo(c);

				var CurrentRegion = RegionStack.Peek();

				RegionStack.WithEach(
					k =>
					{
						k.Add(
							IsActive =>
							{
								// should we react when in a global region
								if (k == RegionGlobal)
									return;

								if (IsActive)
								{
									cc.style.backgroundColor = Color.FromGray(0xf9);
									cb.style.backgroundColor = Color.FromGray(0xf9);
								}
								else
								{
									cc.style.backgroundColor = Color.None;
									cb.style.backgroundColor = Color.None;
								}
							}
						);
					}
				);

				CurrentLine.onmouseover +=
					delegate
					{
						CurrentRegion.Invoke(true);
						cc.style.backgroundColor = Color.FromGray(0xf0);
						cb.style.backgroundColor = Color.FromGray(0xf0);
					};

				CurrentLine.onmouseout +=
					delegate
					{
						CurrentRegion.Invoke(false);
						cc.style.backgroundColor = Color.None;
						cb.style.backgroundColor = Color.None;
					};


				Lines.Add(CurrentLine);
				//CurrentLineContent.style.marginLeft = "5em";

				var BCurrentLine = cb.AttachTo(ViewBackground);

				BCurrentLine.style.textAlign = IStyle.TextAlignEnum.right;

				var span = new IHTMLCode { innerText = "" + Lines.Count };
				span.style.color = Lookup[SolutionFileTextFragment.Type];
				span.AttachTo(BCurrentLine);

				//Content.style.height = Lines.Count + "em";

				new IHTMLDiv { new IHTMLCode { innerText = Environment.NewLine } }.AttachTo(ContentHeightDummy);
			};



			foreach (var item in f.WriteHistory.ToArray())
			{
				if (item is SolutionFileWriteArguments.BeginRegion)
				{
					RegionStack.Push(new List<Action<bool>>());
				}

				if (item is SolutionFileWriteArguments.EndRegion)
				{
					RegionStack.Pop();
				}

				if (CurrentLine == null)
					NextLine();



				var innerText = item.Text;
				innerText = innerText.TakeUntilLastIfAny(Environment.NewLine);

				if (!string.IsNullOrEmpty(innerText))
				{
					var span = new IHTMLCode { innerText = innerText };

					if (item.Fragment == SolutionFileTextFragment.Indent)
					{
						span.style.width = "2em";
						span.style.display = IStyle.DisplayEnum.inline_block;

						if (CurrentLineDirty)
							span.style.borderLeft = "1px dotted #afafaf";
					}


					span.style.color = LookupOrDefault(item.Fragment);

					CurrentLineDirty = true;
					span.AttachTo(CurrentLineContent);

					if (item.Tag != null)
					{
						span.style.cursor = ScriptCoreLib.JavaScript.DOM.IStyle.CursorEnum.pointer;
						span.onmouseover +=
							delegate
							{
								span.style.textDecoration = "underline";
							};

						span.onmouseout +=
							delegate
							{
								span.style.textDecoration = "";
							};



						var Type = item.Tag as SolutionProjectLanguageType;
						if (Type != null)
						{
							span.title = Type.FullName;
						}

						var Method = item.Tag as SolutionProjectLanguageMethod;
						if (Method != null)
						{
							span.title = Method.Name;
						}


						var Uri = item.Tag as Uri;
						if (Uri != null)
						{
							var a = new IHTMLAnchor();
							a.style.color = LookupOrDefault(item.Fragment);

							a.href = Uri.ToString();
							a.target = "_blank";
							a.Add(span);
							a.AttachTo(CurrentLineContent);

							a.onclick +=
								e =>
								{
                                    // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201511/20151103
									e.preventDefault();

									if (LinkCommentClick != null)
										LinkCommentClick(Uri);
								};
						}
					}
				}

				if (item.Text.EndsWith(Environment.NewLine))
				{
					if (!CurrentLineDirty)
					{
						var span = new IHTMLCode { innerText = " " };
						span.AttachTo(CurrentLineContent);
					}

					CurrentLine = null;
				}
			}
		}
        private void AddType(IHTMLDiv parent, CompilationType type, Action<string> UpdateLocation)
        {
            var div = new IHTMLDiv().AttachTo(parent);

            div.style.marginTop = "0.1em";
            div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
            div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


            var i = default(IHTMLImage);

            if (type.IsInterface)
            {
                i = new PublicInterface();
            }
            else
            {
                i = new PublicClass();
            }

            i.AttachTo(div);

            i.style.verticalAlign = "middle";
            i.style.marginRight = "0.5em";

            var s = new IHTMLAnchor { innerText = type.Name, title = "" + type.MetadataToken }.AttachTo(div);

            if (!string.IsNullOrEmpty(type.HTMLElement))
            {
                var c = new IHTMLCode();

                Action<string, JSColor> Write =
                    (Text, Color) =>
                    {
                        var cs = new IHTMLSpan { innerText = Text };

                        cs.style.color = Color;

                        cs.AttachTo(c);
                    };

                Write("<", JSColor.Blue);
                Write(type.HTMLElement, JSColor.FromRGB(0xa0, 0, 0));
                Write("/>", JSColor.Blue);

                //c.style.marginLeft = "1em";
                c.style.Float = ScriptCoreLib.JavaScript.DOM.IStyle.FloatEnum.right;

                c.AttachTo(s);
            }

            s.href = "#";
            s.style.textDecoration = "none";
            s.style.color = JSColor.System.WindowText;

            Action onclick = delegate
            {

            };

            s.onclick +=
                e =>
                {
                    e.PreventDefault();

                    s.focus();

                    if (TouchTypeSelected != null)
                        TouchTypeSelected(type);

                    UpdateLocation(type.FullName + " - " + type.Summary + " - HTML:" + type.HTMLElement);

                    onclick();
                };

            s.onfocus +=
                delegate
                {

                    s.style.backgroundColor = JSColor.System.Highlight;
                    s.style.color = JSColor.System.HighlightText;
                };

            s.onblur +=
                delegate
                {

                    s.style.backgroundColor = JSColor.None;
                    s.style.color = JSColor.System.WindowText;
                };



            onclick =
                delegate
                {

                    var children = new IHTMLDiv().AttachTo(div);

                    children.style.paddingLeft = "1em";

                    Func<IHTMLDiv> Group = () => new IHTMLDiv().AttachTo(children);

                    var Groups = new
                    {
                        Nested = Group(),
                        Constructors = Group(),
                        Methods = Group(),
                        Events = Group(),
                        Fields = Group(),
                        Properties = Group(),
                    };


                    type.GetNestedTypes().ForEach(
                        (Current, Next) =>
                        {
                            AddType(Groups.Nested, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    );

                    type.GetConstructors().ForEach(
                        (Current, Next) =>
                        {
                            AddTypeConstructor(Groups.Constructors, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    );

                    var HiddenMethods = new List<int>();

                    Action<CompilationMethod> AddIfAny =
                        SourceMethod =>
                        {
                            if (SourceMethod == null)
                                return;

                            HiddenMethods.Add(SourceMethod.MetadataToken);
                        };

                    Action AfterEvents = delegate
                    {

                        type.GetMethods().ForEach(
                            (Current, Next) =>
                            {
                                if (!HiddenMethods.Contains(Current.MetadataToken))
                                {
                                    AddTypeMethod(Groups.Methods, Current, UpdateLocation);
                                }

                                ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                    50,
                                    Next
                                );
                            }
                        );

                    };

                    Action AfterProperties = delegate
                    {
                        type.GetEvents().ForEach(
                            (Current, Next) =>
                            {
                                AddIfAny(Current.GetAddMethod());
                                AddIfAny(Current.GetRemoveMethod());

                                AddTypeEvent(Groups.Events, Current, UpdateLocation);

                                ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                    50,
                                    Next
                                );
                            }
                        )(AfterEvents);
                    };

                    type.GetProperties().ForEach(
                        (Current, Next) =>
                        {
                            AddIfAny(Current.GetSetMethod());
                            AddIfAny(Current.GetGetMethod());

                            AddTypeProperty(Groups.Properties, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    )(AfterProperties);






                    type.GetFields().ForEach(
                        (Current, Next) =>
                        {
                            AddTypeField(Groups.Fields, Current, UpdateLocation);

                            ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                                50,
                                Next
                            );
                        }
                    );




                    var NextClickHide = default(Action);
                    var NextClickShow = default(Action);

                    NextClickHide =
                        delegate
                        {
                            children.Hide();

                            onclick = NextClickShow;
                        };

                    NextClickShow =
                        delegate
                        {
                            children.Show();

                            onclick = NextClickHide;
                        };


                    onclick = NextClickHide;
                };
        }