Exemple #1
0
        public override void Write(string value)
        {
            var p = new IHTMLCode {
                innerText = value
            }.AttachToDocument();
            var s = p.style;

            // jsc, enum tostring?
            if (Console.ForegroundColor == ConsoleColor.Red)
            {
                s.color = "red";
            }

            if (Console.ForegroundColor == ConsoleColor.Blue)
            {
                s.color = "blue";
            }

            if (Console.ForegroundColor == ConsoleColor.Gray)
            {
                s.color = "gray";
            }

            if (Console.ForegroundColor == ConsoleColor.Yellow)
            {
                s.color = "yellow";
            }

            if (Console.ForegroundColor == ConsoleColor.Magenta)
            {
                s.color = "magneta";
            }
        }
Exemple #2
0
        private static TreeNode ApplyLocalName(TreeNode t, XElement cc)
        {
            t.IsExpanded = true;
            t.Element.TextArea.Clear();
            var c = new IHTMLCode();

            t.Element.TextArea.Add(c);

            t.Element.ButtonArea.Hide();
            t.Element.IconArea.Hide();

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

                cs.style.color = Color;

                cs.AttachTo(c);
            };

            Write("<", JSColor.Blue);
            Write(cc.Name.LocalName, JSColor.FromRGB(0xa0, 0, 0));

            foreach (var item in cc.Attributes().ToArray())
            {
                Write(" ", JSColor.None);

                Write("foo", JSColor.Red);
                Write("='", JSColor.Blue);
                Write(item.Value, JSColor.Blue);
                Write("'", JSColor.Blue);
            }

            if (!cc.Elements().Any())
            {
                Write(">", JSColor.Blue);

                Write(cc.Value, JSColor.None);

                Write("</", JSColor.Blue);
                Write(cc.Name.LocalName, JSColor.FromRGB(0xa0, 0, 0));
                Write(">", JSColor.Blue);
            }
            else
            {
                Write("/>", JSColor.Blue);
            }

            return(t);
        }
        //public const string Alias = "Class1";
        //public const string DefaultData = "Class1Data";

        /// <summary>
        /// Creates a new control
        /// </summary>
        /// <param name="DataElement">The hidden data element</param>
        public GoogleGearsSimple()
        {
            // this ctor creates a new div which has a text and a button element
            // on mouseover over the color text is changed
            // on pressing the button the next message in text element is displayed
            IHTMLDiv Control = new IHTMLDiv();

            Control.AttachToDocument();

            Func <string, string, IHTMLElement> link = (href, text) => new IHTMLDiv(new IHTMLAnchor(href, text));


            Control.appendChild(link("http://gears.google.com/", "Google Gears"));
            Control.appendChild(link("http://code.google.com/apis/gears/samples/hello_world_database.html", "Google Example # 1"));

            Control.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.h3, "This page uses Google Gears to record your entries on the local disk. If you navigate away and revisit this page, all your data will still be here. Try it!"));

            // http://code.google.com/apis/gears/samples/hello_world_database.html

            GoogleGearsFactory.Database db = null;

            try
            {
                db = new GoogleGearsFactory.Database();
            }
            catch (Exception exc)
            {
                var err = new IHTMLCode(exc.Message);

                err.style.color = Color.Red;


                Control.appendChild(err);
            }

            IStyleSheet.Default.AddRule(".odd").style.backgroundColor  = Color.FromGray(0xa0);
            IStyleSheet.Default.AddRule(".even").style.backgroundColor = Color.FromGray(0xef);

            if (db != null)
            {
                db.open("demo1");
                db.execute(@"
    create table if not exists Demo
    (Phrase varchar(255), Timestamp int)
            ");

                var textfield = new IHTMLInput(HTMLInputTypeEnum.text, "text1", "");

                var btnadd     = new IHTMLButton("Add new entry");
                var btnrefresh = new IHTMLButton("Refresh");
                var btnclear   = new IHTMLButton("Clear");

                Control.appendChild(textfield, btnadd, btnclear, btnrefresh,

                                    new IHTMLCode(GoogleGearsFactory.Default.getBuildInfo())

                                    );



                var list = new IHTMLElement(IHTMLElement.HTMLElementEnum.ol);

                Control.appendChild(list);

                var read = default(Action);

                read = delegate
                {
                    //from i in Demo
                    //select new { Phrase, Timestamp }
                    //order by Timestamp desc

                    list.removeChildren();

                    Func <string, IHTMLElement> AddItem =
                        text => new IHTMLElement(IHTMLElement.HTMLElementEnum.li, text).Aggregate(v => list.appendChild(v));



                    // this could be rewritten as an expression once they are supported by jsc

                    int counter = 0;

                    var query = from Data in db.AsEnumerable <DemoDataEntity>(
                        "select * from Demo order by Timestamp desc",
                        typeof(DemoDataEntity)
                        )
                                // let ListItem = AddItem(Data.Timestamp + " - " + Data.Phrase)
                                select new __Type2 {
                        ListItem = AddItem(Data.Timestamp + " - " + Data.Phrase), Data = Data
                    };

                    foreach (var v in query)
                    {
                        counter++;
                        var vx = v;


                        if (counter % 2 == 0)
                        {
                            v.ListItem.className = "odd";
                        }
                        else
                        {
                            v.ListItem.className = "even";
                        }

                        #region -
                        var btndel = new IHTMLButton("-");

                        btndel.style.color = Color.Red;

                        btndel.onclick +=
                            delegate
                        {
                            db.execute("delete from Demo where Timestamp = ?", vx.Data.Timestamp);

                            read();
                        };
                        #endregion

                        #region +
                        var btnclone = new IHTMLButton("+");

                        btnclone.style.color = Color.Blue;

                        btnclone.onclick +=
                            delegate
                        {
                            db.Insert("Demo", vx.Data);


                            read();
                        };
                        #endregion

                        v.ListItem.insertBefore(btnclone, v.ListItem.firstChild);
                        v.ListItem.insertBefore(btndel, v.ListItem.firstChild);
                    }


                    #region raw
                    //var rs = db.execute("select * from Demo order by Timestamp desc");

                    //while (rs.isValidRow())
                    //{
                    //    var xt = typeof(DemoDataEntity);
                    //    var xx = (DemoDataEntity)Activator.CreateInstance(xt);

                    //    for (int i = 0; i < rs.fieldCount(); i++)
                    //    {
                    //        xt.GetField(rs.fieldName(i)).SetValue(xx, rs.field(i));
                    //    }

                    //    AddItem(xx.Timestamp + " - " + xx.Phrase);

                    //    rs.next();
                    //}

                    //rs.close();
                    #endregion
                };

                btnclear.onclick +=
                    delegate
                {
                    db.execute("delete from Demo");

                    read();
                };

                btnadd.onclick +=
                    delegate
                {
                    db.Insert("Demo",
                              new DemoDataEntity
                    {
                        Phrase    = textfield.value,
                        Timestamp = IDate.Now.getTime()
                    }
                              );

                    //db.execute("insert into Demo (Phrase, Timestamp) values (?, ?)", textfield.value, IDate.Now.getTime());

                    textfield.value = "";

                    read();
                };

                btnrefresh.onclick +=
                    delegate
                {
                    read();
                };

                read();
            }


            // not array
            // is object
            // no prototype
        }
Exemple #4
0
        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;
            };
        }
        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;
                }
            }
        }