Question 1:
I’d like to change the default action of a matrix of text fields so that hitting the TAB key will move DOWN and ACROSS as opposed to the standard ACROSS and DOWN action. I found that if I have a 3x3 matrix with each cell having tags set in the order I want I can use the following code to achieve the desired result IF I set each cell to Send Action on Enter Only. With this code pressing TAB results in the default “across then down” action while pressing ENTER results in the “down then across” action I’d like. (I may keep this as it will add flexibility to the interface.)
on matDidEndEditing_(sender)
set theTag to sender's selectedCell()'s |tag|()
set theTag to (theTag + 1) mod 9
mat's selectCellWithTag_(theTag)
end matDidEndEditing_
In my testing I found that using mat’s setTabKeyTraversesCells_(0) in the applicationWillFinishLaunching_ handler had no effect on the matrix at all. (“mat” is an IB Outlet connected to the matrix.) Replacing 0 with false didn’t change the result.
Question 2:
In the application that I am working on (as opposed the test app from Question 1) I have a matrix of text fields with 8 rows and 4 columns. I’d like to attach a date formatter to all the text fields in column 0 and a number formatter to all the text fields in columns 1-3. I could do this in IB but that’d take awhile. How can I accomplish this in code. Say I wanted column 0 to use “M/d” and columns 1-3 to use “0.00” with a max of 70.00 and negatives in red.
Thanks in Advance,
Brad
There may be some way to do this, but I suspect there isn’t and easy way: Apple don’t make generally make it easy to make your app go against their interface guidelines.
After working with it a bit, I actually like that TAB moves ACROSS then DOWN and ENTER (via code) moves DOWN then ACROSS. The downside to this is only the ENTER key will call the action handler I have set up. This is due to the fact that I changed the cells to Send Action on Enter Only.
Therefore the next steps are to determine how to call an action when the TAB key is pressed and set up my formatters. Next step: formatters.
Thanks,
Brad
I should know better than to try to read/learn about ObjC code just before going to bed.:lol: It appears that I should be able to determine whether a TAB key or an ENTER key was pressed to send Edit action. My question is: how?
Also, regarding formatters. I have set up a formatter and associated it with all the appropriate text fields within the matrix. I haven’t been able to figure out how to modify/add to the formatter the ability to display negative numbers in red. It appears to require a dictionary to do this and thus far I’ve been unable to set that up correctly. Any help here will be greatly appreciated as well.
Thanks,
Brad
If you want the default behavior, just set the action back to “Sent on End Editing”. The action will then be called by either tab or enter (or by clicking another text field).
Ric
To get the red color you can do this:
set theDict to current application's NSDictionary's dictionaryWithDictionary_({NSColor:current application's NSColor's redColor()})
numberFormatter's setTextAttributesForNegativeValues_(theDict)
In this example, numberFormatter is the IBOutlet for the number formatter attached to a text field.
Ric