Пример #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        private void AddToplevel(
            string name
            )
        {
            ReturnCode         code;
            Result             result    = null;
            IObject            @object   = null;
            ToplevelDictionary toplevels = null;

            code = interpreter.GetObject(
                CollectionName, LookupFlags.Default,
                ref @object, ref result);

            if (code == ReturnCode.Ok)
            {
                toplevels = @object.Value as ToplevelDictionary;

                if (toplevels == null)
                {
                    toplevels     = new ToplevelDictionary();
                    @object.Value = toplevels;
                }

                toplevels.Add(name, new AnyPair <Thread, Toplevel>(
                                  Thread.CurrentThread, this));
            }
            else
            {
                toplevels = new ToplevelDictionary();

                toplevels.Add(name, new AnyPair <Thread, Toplevel>(
                                  Thread.CurrentThread, this));

                long token = 0;

                code = interpreter.AddObject(
                    CollectionName, null, ObjectFlags.Default,
                    ClientData.Empty, 0,
#if NATIVE && TCL
                    null,
#endif
#if DEBUGGER && DEBUGGER_ARGUMENTS
                    null,
#endif
                    toplevels, ref token, ref result);
            }

            if (code != ReturnCode.Ok)
            {
                throw new ScriptException(code, result);
            }
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        #region IExecute Members
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                if (arguments != null)
                {
                    if (arguments.Count == 2)
                    {
                        IObject @object = null;

                        code = interpreter.GetObject(
                            Toplevel.CollectionName, LookupFlags.Default,
                            ref @object, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            ToplevelDictionary toplevels = @object.Value as ToplevelDictionary;

                            if (toplevels != null)
                            {
                                IAnyPair <Thread, Toplevel> anyPair = null;

                                if (toplevels.TryGetValue(arguments[1], out anyPair))
                                {
                                    if (anyPair != null)
                                    {
                                        Toplevel toplevel = anyPair.Y;

                                        if (toplevel != null)
                                        {
                                            try
                                            {
                                                string name = ".fixme";

                                                if (toplevel.InvokeRequired)
                                                {
                                                    toplevel.BeginInvoke(
                                                        new Toplevel.AddButtonDelegate(toplevel.AddButton),
                                                        new object[] { name, "test", 0, 0, new EventHandler(button_Click) });
                                                }
                                                else
                                                {
                                                    toplevel.AddButton(name, "test", 0, 0, new EventHandler(button_Click));
                                                }

                                                result = name;
                                            }
                                            catch (Exception e)
                                            {
                                                result = e;
                                                code   = ReturnCode.Error;
                                            }
                                        }
                                        else
                                        {
                                            result = String.Format(
                                                "toplevel \"{0}\" window is invalid",
                                                arguments[1]);

                                            code = ReturnCode.Error;
                                        }
                                    }
                                    else
                                    {
                                        result = String.Format(
                                            "toplevel \"{0}\" pair is invalid",
                                            arguments[1]);

                                        code = ReturnCode.Error;
                                    }
                                }
                                else
                                {
                                    result = String.Format(
                                        "toplevel \"{0}\" not found",
                                        arguments[1]);

                                    code = ReturnCode.Error;
                                }
                            }
                            else
                            {
                                result = String.Format(
                                    "object \"{0}\" is not a toplevel collection",
                                    Toplevel.CollectionName);

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = "wrong # args: should be \"button toplevel\"";
                        code   = ReturnCode.Error;
                    }
                }
                else
                {
                    result = "invalid argument list";
                    code   = ReturnCode.Error;
                }
            }
            else
            {
                result = "invalid interpreter";
                code   = ReturnCode.Error;
            }

            return(code);
        }