# HG changeset patch # User Jacob Carlborg # Date 1263741924 -3600 # Node ID ae08a08f44d3540506453b86630d5245ef02641c # Parent b2693af5a569e26739565dc52e03ee9294e412db Added IBOutlet diff -r b2693af5a569 -r ae08a08f44d3 dsss.conf --- a/dsss.conf Fri Jan 15 12:41:07 2010 +0100 +++ b/dsss.conf Sun Jan 17 16:25:24 2010 +0100 @@ -1,4 +1,4 @@ -[main.d] +[dstep] #target=cocoa-d-test version (GNU){ diff -r b2693af5a569 -r ae08a08f44d3 dstep/objc/bridge/Bridge.d --- a/dstep/objc/bridge/Bridge.d Fri Jan 15 12:41:07 2010 +0100 +++ b/dstep/objc/bridge/Bridge.d Sun Jan 17 16:25:24 2010 +0100 @@ -179,6 +179,51 @@ mixin dstep.objc.bridge.ClassInitializer.ObjcSubclassInitializer!(this.stringof, super.stringof);"; /** + * Makes the given field available as an IBOutlet. + * + * Mixes in a method that is called by the Objective-C side to set the value of the + * given field. + * + * Mixes in: $(D_PSYMBOL ObjcBindMethod) + * + * Examples: + * --- + * class AppController : NSObject + * { + * NSButton button; + * mixin IBOutlet!(button); + * } + * --- + * + * Params: + * field = the field make available as an IBOutlet + */ +template IBOutlet (alias field) +{ + static assert (is(typeof(field) : Object), dstep.objc.bridge.Bridge.buildIBOutletErrorMessage!(field)); + + void __setMethod (typeof(field) value) + { + field = value; + } + + mixin dstep.objc.bridge.Bridge.ObjcBindMethod!(__setMethod, "set" ~ dstep.objc.bridge.Bridge.toUpper(field.stringof[0]) ~ field.stringof[1 .. $] ~ ":"); +} + +char toUpper (char c) +{ + if (c >= 'a' && c <= 'z') + return c - 32; + + return c; +} + +template buildIBOutletErrorMessage (alias field) +{ + const buildIBOutletErrorMessage = `The type "` ~ typeof(field).stringof ~ `" of the given field "` ~ field.stringof ~ `" in the class "` ~ typeof(this).stringof ~ `" is not a valid IBOutlet type. IBOutlets can only be of the type Object (or any of its subclasses)`; +} + +/** * Binds a selector to an instance method. * * This will create a receiver function which will forward the call to $(D_PARAM method), @@ -204,8 +249,8 @@ */ template IBAction (alias method) { - static assert (dstep.objc.bridge.Bridge.ParameterTupleOf!(method).length == 1, "dstep.objc.bridge.Bridge.IBAction: an action method is only allowed to have one parameter"); - static assert (is(dstep.objc.bridge.Bridge.ParameterTupleOf!(method)[0] : Object), "dstep.objc.bridge.Bridge.IBAction: an action method can only have a parameter of the type Object (or any of its subclasses)"); + static assert (dstep.objc.bridge.Bridge.ParameterTupleOf!(method).length == 1, "An action method is only allowed to have one parameter"); + static assert (is(dstep.objc.bridge.Bridge.ParameterTupleOf!(method)[0] : Object), "An action method can only have a parameter of the type Object (or any of its subclasses)"); mixin ObjcBindMethod!(method, dstep.objc.bridge.TypeEncoding.buildSelector!(method)); } @@ -263,11 +308,7 @@ */ template ObjcBindMethod (alias method, string selector) { - version (Tango) - mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); - - /*else - mixin ObjcBindMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method));*/ + mixin ObjcBindMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); } /** @@ -405,11 +446,7 @@ */ template ObjcBindClassMethod (alias method, string selector) { - version (Tango) - mixin ObjcBindClassMethod!(method, tango.core.Traits.ReturnTypeOf!(method), selector, tango.core.Traits.ParameterTupleOf!(method)); - - else - mixin ObjcBindClassMethod!(method, std.traits.ReturnType!(method), selector, std.traits.ParameterTypeTuple!(method)); + mixin ObjcBindClassMethod!(method, dstep.objc.bridge.Bridge.ReturnTypeOf!(method), selector, dstep.objc.bridge.Bridge.ParameterTupleOf!(method)); } /** @@ -523,7 +560,7 @@ */ template ObjcBindFunction (alias func) { - mixin ObjcBindFunction!(func, ReturnTypeOf!(func), ParameterTupleOf!(func)); + mixin ObjcBindFunction!(func, dstep.objc.bridge.Bridge.ReturnTypeOf!(func), dstep.objc.bridge.Bridge.ParameterTupleOf!(func)); } /**