ok… same for checking it all before posting.
Still seeing an issue where removing an item from the array, (with a button bound to the array controllers remove action), stops the array from being updated.
ok… same for checking it all before posting.
Still seeing an issue where removing an item from the array, (with a button bound to the array controllers remove action), stops the array from being updated.
I am now removing using the following, this updates theData & the plist…
on deletePKG_(sender)
tell theArrayController to set my selectedRow to selectionIndex()
log selectedRow
tell theArrayController to removeObjectAtArrangedObjectIndex:selectedRow
log "done"
log theData
tell standardUserDefaults() of current application's NSUserDefaults
setObject_forKey_(theData, "theData") --as list
end tell
log "updated plist"
end deletePKG_
But i still cannot add new items to the array… The below doesn’t seem to be adding the newly selected items to the array.
set my theData to theData & selectedPKGPath
In fact, it seems to be replacing theData with the value of selectedPKGPath
So i’ve changed back to a single selection, then am appending to the array using the below:
tell theArrayController to addObject:selectedPKGPath
(oh & if you’re looking theData has been changed to additionalPKGs)
on selectPKG_(sender)
try
choose file of type {"com.apple.installer-package-archive"} with prompt "Select a .pkg to add:" default location (path to desktop folder)
set my selectedPKGPath to POSIX path of result
log selectedPKGPath
tell theArrayController to addObject:selectedPKGPath
log "done"
log additionalPKGs
tell standardUserDefaults() of current application's NSUserDefaults
setObject_forKey_(additionalPKGs, "additionalPKGs")
end tell
log "updated plist"
end try
end selectPKG_
The problem is that, after you delete an item, what gets saved back to theData is a mutable array, not a list, so “theData & selectedPKGPath” makes no sense. You could probably use:
set my theData to (theData as list) & selectedPKGPath
But using addObject: on the array controller is probably a better way to go anyway.
Thanks Shane, your replies… book & site have been a great help!
Hi Guys,
Thanks so much for the help so far with creating TableViews.
But, i’m stumped again…
Basically, i want to run the below to check if a file exists… If it doesn’t then display a dialog advising such (<< this is working) then change the text colour of the row/object which has the path of the missing item.
My attempt below, changes the colour of the whole table… Please enlighten me.
on testButton_(sender)
repeat with theItem in additionalPKGs
try
-- Check for file
do shell script "ls " & quoted form of theItem
log "Found " & theItem
on error
log theItem & " is missing"
display dialog "Cannot Find: " & additionalPKGs & ". Do you wish to proceed?" with icon 2 buttons {"No", "Yes"}
-- Set missing items text to red.
set my selectedPKGsColor to current application's NSColor's redColor()
end try
end repeat
end testButton_
For more context, the whole of this POC script is below:
property parent : class "NSObject"
property additionalPKGs : {} -- the main property; array controller binds its content array to this
-- IBOutlets
property |window| : missing value
property theArrayController : missing value
property selectedPKGPath : missing value
property defaults : missing value
property testValue : missing value
property certsAdded : 0
property certsValue : missing value
property selectedRow : missing value
property selectedObjects : missing value
property textColor : missing value
--property NSColor : class "NSColor" of current application
property selectedPKGsColor : missing value
on applicationWillFinishLaunching:aNotification
-- populate plist file with defaults (will not overwrite non-default settings))
regDefaults_(me)
-- retrieve plist values
retrieveDefaults_(me)
end applicationWillFinishLaunching:
on regDefaults_(sender)
tell current application's NSUserDefaults to set defaults to standardUserDefaults()
tell defaults to registerDefaults_({additionalPKGs:additionalPKGs}) as list
end regDefaults_
-- Get values from plist
on retrieveDefaults_(sender)
tell defaults to set my additionalPKGs to objectForKey_("additionalPKGs") as list
end retrieveDefaults_
on selectPKG_(sender)
try
choose file of type {"com.apple.installer-package-archive"} with prompt "Select a .pkg to add:" default location (path to desktop folder)
set my selectedPKGPath to POSIX path of result
log selectedPKGPath
tell theArrayController to addObject:selectedPKGPath
log "done"
log additionalPKGs
tell standardUserDefaults() of current application's NSUserDefaults
setObject_forKey_(additionalPKGs, "additionalPKGs")
end tell
log "updated plist"
end try
end selectPKG_
on deletePKG_(sender)
tell theArrayController to set my selectedObjects to selectedObjects()
log selectedObjects
tell theArrayController to removeObjects:selectedObjects
log "done"
log additionalPKGs
tell standardUserDefaults() of current application's NSUserDefaults
setObject_forKey_(additionalPKGs, "additionalPKGs")
end tell
log "updated plist"
end deletePKG_
on testButton_(sender)
repeat with theItem in additionalPKGs
try
-- Check for file
do shell script "ls " & quoted form of theItem
log "Found " & theItem
on error
log theItem & " is missing"
display dialog "Cannot Find: " & additionalPKGs & ". Do you wish to proceed?" with icon 2 buttons {"No", "Yes"}
-- Set missing items text to red.
set my selectedPKGsColor to current application's NSColor's redColor()
end try
end repeat
end testButton_
on applicationShouldTerminate:sender
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate:
If you want to do anything other than a simple single-column table with no frills, you have to provide a list of records rather than a simple list of strings. That’s what all the multi-column examples in my book use. Then you can have a value in the records that contains a color, and bind the text color property of the column to it.
So your records might be something like:
{thePath:“/blah/blah/blah”, theColor:textColor}
Once you get the bindings set up, you would change an entry’s color by changing the the value of its theColor property.
Thanks Shane, but if I change the colour of a column. That will change all the text across all rows right?
The below is bound to the table views text color:
set my selectedPKGsColor to current application's NSColor's redColor()
Can changing the color as you mentioned target a single row?
No. It’s like binding a column’s value – it uses the value for a particular row.
Sorry Shane, I don’t follow.
If I have the text color of the table view or textfield & set to red, it changes for the whole table.
What’s the method to change only a wanted rows color?
(Not via the GUI, but programmatically).
Still struggling.
Shane… i guess you mean something like (which you had posted earlier):
But, when I bind “theColor” to Text Color of the Text Field Cell in the Table View, i either get uncaught exception errors… or weirdly, the Table Views contents change to sections of my screen.
As an alternative, perhaps I could add a column with icons. Green for ok, Red for not.
Would that be easier than trying to change the texts colour? (which seems to be more of a PITA than it should be).
This looks promising:
theItem's cell's setTextColor_(NSColor's redColor)
setTextColor should be able to be used for theItem’s text field cell, but i can’t seem to get it to work.
Does textColor always contain an NSColor? It soundd like it doesn’t.
As an alternative, perhaps I could add a column with icons. Green for ok, Red for not.
Would that be easier than trying to change the texts colour? (which seems to be more of a PITA than it should be).
That’s what I’d do. How many tables do you see that change the color of an entry? I can’t think of any off-hand. It’s not standard UI, and you will often find it’s harder to do non-standard things.
Does textColor always contain an NSColor? It soundd like it doesn’t.
The property was being declared as missing value, so I guess I need to figure out how to declare it as black.
When trying: property selectedPKGsColour :
"NSCalibratedRGBColorSpace 1 0 0 1"
i get the error:
Cannot create NSColor from object NSCalibratedRGBColorSpace 1 0 0 1 of class __NSCFString
This works:
property selectedPKGsColour : missing value
on applicationWillFinishLaunching:aNotification
set my selectedPKGsColour to current application's NSColor's blackColor()
log selectedPKGsColour
-- populate plist file with defaults (will not overwrite non-default settings))
regDefaults_(me)
-- retrieve plist values
retrieveDefaults_(me)
end applicationWillFinishLaunching:
But when changing the colour later using the below, all text in the tableview changes to red. How do i target a row?
set my selectedPKGsColour to current application's NSColor's redColor()
How do i target a row?
You change the value in the record/dictionary that represents that row.
You are binding the color to the array controller’s arrangedObjects, aren’t you?
That’s what I’d do. How many tables do you see that change the color of an entry? I can’t think of any off-hand. It’s not standard UI, and you will often find it’s harder to do non-standard things.
Just to add, this behaviour seems common in some Mac admin tools such as Apple Remote Desktop & Casper Remote.
You are binding the color to the array controller’s arrangedObjects, aren’t you?
Yes
So you set the theColor property (or whatever you call it) of every item to current application’s NSColor’s blackColor() (or a property containing same. Then when you want one to appear in red, you set it’s theColor property to current application’s NSColor’s redColor().
Thanks Shane, still unclear how to isolate a row.
My binding for text colour of the text field cell in the table view is set to "selectedPKGsColour.’
If i change this to red, it changes the value for all text field cells.
So how do you tell it to only change the wanted rows colour?
Something like the below fails:
set my theItem's selectedPKGsColour to current application's NSColor's redColor()