Selector

50 views
Skip to first unread message

puc...@dropbox.com

unread,
May 5, 2014, 6:13:40 PM5/5/14
to jstal...@googlegroups.com
I'm working on a Sketch plugin, where I'm trying to convert the following code from Obj-C to JSTalk. I have an NSButton, and am trying to run the buttonPressed method when the button is pressed. I feel like I'm missing something super simple? Thanks in advance for any help!

//Obj-C, which is working in my test app
[myButton setAction:@selector(buttonPressed)];
-(void)buttonPressed {
    NSLog(@"Button pressed!");
}
//JSTalk, which is not working in my Sketch plugin
myButton.action = 'buttonPressed'
function buttonPressed() {
log("Button pressed!");
}

Gus Mueller

unread,
May 5, 2014, 11:19:31 PM5/5/14
to jstal...@googlegroups.com
On May 5, 2014, at 3:13 PM, puc...@dropbox.com wrote:

I'm working on a Sketch plugin, where I'm trying to convert the following code from Obj-C to JSTalk. I have an NSButton, and am trying to run the buttonPressed method when the button is pressed. I feel like I'm missing something super simple? Thanks in advance for any help!

JSTalk doesn’t support target action stuff like this right now (unless someone else wants to pipe up with something interesting here, which doesn’t rely on JSCocoa internal stuff…).  CocoaScript (JSTalks’ successor) doesn’t yet either, though I’d like to add something like this some day.

-gus

puc...@dropbox.com

unread,
May 5, 2014, 11:26:19 PM5/5/14
to jstal...@googlegroups.com
Thanks for the quick reply, Gus!

Do you know of any other working around here? Basically the desired flow is enable a user to click on something in an NSWindow, and then execute a block of code. Sounds like this may not be possible?

Abhi Beckert

unread,
May 6, 2014, 5:05:40 AM5/6/14
to jstal...@googlegroups.com
With Dux I added a class to CocoaScript/JSTalk called "COTarget" that allows this kind of stuff.

Basically it lets you provide an anonymous javascript function to an object that receives a target/action message from the button. Then you use NSApplicaiton's built in run loop support to wait for the user to click a button.

Here's how it works: https://github.com/abhibeckert/Dux/blob/master/Default-Bundles/Lorem%20Ipsum.coscript

If you have a look through the comments of this issue: https://github.com/ccgus/CocoaScript/issues/2 you can see Gus's dodgy but functional alternative by setting the button target to an NSMutableArray.

That should work for you without needing the COTarget class.
- Abhi

--
You received this message because you are subscribed to the Google Groups "JSTalk Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jstalk-dev+...@googlegroups.com.
To post to this group, send email to jstal...@googlegroups.com.
Visit this group at http://groups.google.com/group/jstalk-dev.
For more options, visit https://groups.google.com/d/optout.

Gus Mueller

unread,
May 7, 2014, 1:48:42 PM5/7/14
to jstal...@googlegroups.com
On May 6, 2014, at 2:05 AM, Abhi Beckert <ab...@abhibeckert.com> wrote:

With Dux I added a class to CocoaScript/JSTalk called "COTarget" that allows this kind of stuff.

I completely forgot about about that! :)

The NSMutableArray trick will work as well, but… yes, it’s super dodgy.

-gus
Reply all
Reply to author
Forward
0 new messages