/////////////////////////////////////////////////////////////////////////////////////////////// #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); }