Wednesday, July 30, 2014

#1 2011-01-07 04:35:48 pm

magikseb
Member
From: England, UK
Registered: 2010-02-22
Posts: 211

NSTextField disabled

Hi,

I've got a problem with a NSTextField inside a window. It appears to be disabled when I run the application and I can't enter any text. It's selectable, editable, uses single line mode, undo and draws background. It has a placeholder too. The window it's in is being shown with...

Applescript:

enterWindow's setStyleMask_(0)
       enterWindow's setAlphaValue_(1)
       enterWindow's setMovableByWindowBackground_(true)
       
       tell enterWindow
           setAlphaValue_(0)
           my enterWindow's makeKeyAndOrderFront_(me)
           tell animator() to setAlphaValue_(1)
       end tell

It appears to be disabled when I run the application and I can't enter any text. Why? How can I sort this?

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Rockmelt
Operating System: Mac OS X (10.6)

Last edited by magikseb (2011-01-07 04:37:11 pm)


Filed under: text, window, NSTextField

Offline

 

#2 2011-01-07 06:51:05 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3521

Re: NSTextField disabled

First, a style point: using integers instead of enums saves typing, but it can be a pain when someone else looks at your code -- we have to look them up. And you will too in six months.

What you're seeing is "as designed". The documentation for NSBorderlessWindowMask says "Useful only for display or caching purposes." For better or worse, this is Apple's way of encouraging UI uniformity.

That said, it can be done by subclassing NSWindow and overriding canBecomeKeyWindow so it returns yes. But you may still see some odd behavior, especially if you have other windows showing.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2011-01-08 08:30:11 am

magikseb
Member
From: England, UK
Registered: 2010-02-22
Posts: 211

Re: NSTextField disabled

I didn't know that, thanks! I changed it to a normal window and it works fine now.

I know I can use

Applescript:

textField's setStringValue_("Default value.")

to reset the title of a text field, but how do I set the placeholder?

I also tried

Applescript:

textField's setPlaceholderString_("Default value.")

Last edited by magikseb (2011-01-08 08:35:37 am)

Offline

 

#4 2011-01-08 01:26:40 pm

rdelmar
Member
From: Sonoma County, CA
Registered: 2010-03-05
Posts: 1008

Re: NSTextField disabled

textField's setPlaceholderString_("Default value.")

You have to send that method to the text field's cell: (textField's |cell|()'s setPlaceholderString_("Default value.").
You won't see the placeholder unless you set the textField's string to  an empty string ("").  You also won't see it until the text field is no longer the current responder (by clicking in another responder or tabbing to it if you have set NextKeyView for the text field).

Ric

Offline

 

#5 2011-01-08 07:12:43 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3521

Re: NSTextField disabled

rdelmar wrote:

You have to send that method to the text field's cel

Have you found that empirically? I ask because the docs say:

"All of the methods declared by this class [NSTextFieldCell] are also declared by the NSTextField class, which uses NSTextFieldCell objects to draw and edit text. These NSTextField cover methods call the corresponding NSTextFieldCell methods."


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#6 2011-01-08 08:25:48 pm

rdelmar
Member
From: Sonoma County, CA
Registered: 2010-03-05
Posts: 1008

Re: NSTextField disabled

Have you found that empirically? I ask because the docs say:

Yeah, I saw that too, but I did test it, and you get an unrecognized selector error message if you send it to the text field.  I wonder if that was an oversight.

Ric

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.023 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)