help with linking data

There is a way around that, but it’s pretty complex. My fix simply stops “canada” being added to the list.

I thought I would take a crack at solving Rounak’s problem with capitalization and auto complete, so I subclassed NSComboBoxCell to override the completedString_ method, and this produced the desired result. To do this you need to:

  1. add a new class to your project (under File → New File, then choose Applescript class)
  2. change the parent class of the script to “NSComboBoxCell”
  3. in the IB inspector, change the class name of your ComboBoxCells to the name of your new class (NewComboCell in my example). The name should show up in the pull down list if you’ve saved your file.

Here is the code for the new class:

script NewComboCell
	property parent : class "NSComboBoxCell"
	
	on completedString_(subString) --subString is what the user is typing in the ComboBox
		set newString to subString's capitalizedString()
		repeat with anEntry in objectValues() 
			if (anEntry's hasPrefix_(newString)) is true then
				set newString to anEntry
			end if
		end repeat
		return newString
	end completedString_
    
end script

There’s no need to call this method explicitly, the ComboBox calls it every time you type a letter.

Ric

Thanks again.
If I add a river named “river1” in Canada>>Ottawa and then I create US>>Ottawa city, then river1 appears in US>>Ottawa also. There are bound to be cities with same names in different countries. So this needs to be fixed.

That one could be hard to fix, given the data model I used. It seems like you need one dictionary that has 3 levels, maybe a dictionary of dictionaries – I don’t know if that’s possible. Maybe it could be done with an NSTreeController, but I don’t have any experience with those, so I don’t know if that would work either.

Ric

It’s an interesting exercise. Let’s use popups instead of comboboxes for a moment. You can do it with multiple array controllers and bindings using either the “Cocoa way” of making country, city and river classes, or the more AS way of making a list of nested records. They both work much the same. The big advantage of using records is that loading and saving is simpler.

But once you move to comboboxes, I suspect it gets more complicated with a record. I think you’d have to do something like add and maybe placeholders to get it to play nice.