On May 23, 2010, at 3:31 PM, Velocityboy wrote: > I'm working on an app that has the concept of allowing the user to create > templates of things which are then instanced into a document. Central to this > is the idea that the user can create a template, then select it as part of > another template or an instance. The relationship between template types is > fixed. (For example, suppose one template is a tire and another is a car; the > car has a link to a tire template; the user can select the 17" tire template > for the car they are working on.) > > I have an NSTableView with NSComboBoxCell's which contain lists of the other > appropriate templates the user has created, which can be linked to the > current template. The problem I'm having is that, if I put the templates the > user can choose from into an array controller and source the combo box from > that, the control wants the template to have implemented NSCopying, and then > makes copies of it to render. A copy of the template is what ends up getting > put back into the base template model object's pointer. So base template ends > up referring to the other template by value, not by reference. This is a > problem for me, as the expectation being set is that editing the template > also affects the instances derived from it (to carry the car analogy forward, > if the user uses the 17" tire template on three cars, then changes the tread > pattern on the tire, that should affect those three cars with no further > action.) > > I've come up with two possible solutions, neither of which I like. One is to > use the template's name as a key; that's ugly, the app currently doesn't have > the restriction that template names have to be unique (though that's not an > entirely unreasonable limitation). The other is to wrap the model class in a > proxy that DOES implement NSCopying, but just contains a single pointer to > the template instance. That's ugly since then I have to code and maintain > another layer of indirection between the controller and the model. > > Is there a standard pattern for dealing with this situation?
First off, it is important to remember that a combobox is basically an NSTextField with a menu option. It is designed to edit a single string value. On top of that, it isn't really meant for deterministic data entry. It sounds like you really need a popup button cell instead. Secondly, it sounds like something is wired wrong. The NSComboBox shouldn't be trying to copy your template object, as it isn't relevant to the combobox--per the first paragraph above it is expecting a string. HTH, Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
