Re: "intelligent" flexible popup
On Jul 20, 2009, at 22:16, Daniel Child wrote: I seem to have fallen into the pitfall you described below. I can get the table view to display values in a combo box from a data source, which takes those values from an array in the model. I also have autocomplete working. But I can't seem to get the values I choose to "stick" (remain displayed) in the table. Since the tableview is reusing the combo box cell, I don't see how you specify a different value for each row (I only have one column). (The choice values do appear when you click the arrow, but selecting them does not store a value.) Also, I'm not clear on when you "capture" a selection to get the value transferred to the model. Are you supposed to use some notification to know that the field has been edited, and then capture that value and transfer it to the model. Sorry if this seems basic, but I've looked over the documentation and some sample code and just don't get it. Here's what I'd try: -- I'd give each data model object a string property "stateName", and bind the table column to this property. -- I'd write a "validateStateName:" method to check that the entered name was one of the names in my list of names. That'd probably a case- insensitive test, so I'd also use this method to replace the user's entry with a copy of the actual string from the list. (Make sure you turn on "validates immediately" for the binding. That means that the validation is done on Enter or Tab, not on every character typed as the name of the option might suggest.) Refer to the KVC documentation for information about how to write a validate: method. If the user is allowed to enter names not in the list, then this method would validate non-list names for correctness (and do things like apply proper capitalization and replace the user entry with a prettified string) as desired. -- I'd write a "setStateName:" setter to store the entered name in the instance variable backing the "stateName" property. Since this method could potentially be called for other reasons, I'd also re-apply the prettification here, so that the resulting value 'isEqualToString:' the matching string from your master list, if it's in your master list. That's the general idea. The specifics would depend on whether: -- the user was *only* allowed to enter things from your master list -- the user was allowed to enter things not in the master list, which then get added to the master list -- the user was allowed to enter arbitrary names, which are *not* added to the master list if unknown If you need the model objects to store a property that's the numeric index into the master list, that can be done in the setter too. One of the properties would be made dependent on the other, but again the details depend on what behavior you specifically need to allow. Note that this implementation (which is part of the data model) doesn't know that a NSComboxBox is being used to get the name -- a regular text field could be used just as easily (for you, though not for the user). That's as it should be. HTH ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: "intelligent" flexible popup
I seem to have fallen into the pitfall you described below. I can get the table view to display values in a combo box from a data source, which takes those values from an array in the model. I also have autocomplete working. But I can't seem to get the values I choose to "stick" (remain displayed) in the table. Since the tableview is reusing the combo box cell, I don't see how you specify a different value for each row (I only have one column). (The choice values do appear when you click the arrow, but selecting them does not store a value.) Also, I'm not clear on when you "capture" a selection to get the value transferred to the model. Are you supposed to use some notification to know that the field has been edited, and then capture that value and transfer it to the model. Sorry if this seems basic, but I've looked over the documentation and some sample code and just don't get it. Thanks . On Jul 20, 2009, at 4:38 AM, cocoa-dev-requ...@lists.apple.com wrote: On Jul 19, 2009, at 7:58 PM, Quincey Morris wrote: ... and you'd *still* have to prevent the table view from treating [NSComboBoxCell] like a text field. In what way? Are you referring to the fact that a menu can represent an object, whereas a combo box is just a (possibly-pre-baked-chosen-from-the- menu) string? In both cases it's not the NSTableView but your custom data source that would make these decisions (ie, what that new "object" that was set really means in that context). I meant, if you used the NSComboBox methods that told you which item of the popup list was chosen (e.g. indexOfSelectedItem), you'd know what was chosen -- if something *was* chosen from the list -- as a selection index, but the table view would nevertheless set the underlying string as the value of the property bound to the column. Storing or using such combo box selection indexes is tricky to do with a table view, because they don't fit into the bindings *or* the data source patterns. Even knowing where you might usefully call these selected item methods is puzzling. So yes, if you understand that the value corresponding to the column is a string which *may* match (isEqualToString:, not ==) a list of strings you separately maintain, then there's no problem. The easy-to-fall-into pitfall is having the data model property be an index into an array of (say) state names, but returning the string name of the state in place of the index when supplying data to the table view. In that case, changing the string for one row changes that string everywhere it's used, which is usually not what's intended. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: "intelligent" flexible popup
Daniel Child wrote: As a follow-up to the previous question on popups in a table, I am wondering what APIs you can use to implement the kind of "intelligent" popups one finds, for example, when filling out the State field in forms needing an address. You start typing "Ma" and Maine or Maryland come up. But you also have the choice to type something not in the list of choices. This seems to be a combination text field / popup menu. Again, either an API hint or link to a tutorial would be very helpful. Thanks. If I understand what you're asking for, it's just an NSComboBox(Cell). Look at either of those classes, depending on your need, and look at the setCompletes: method (and then NSComboBoxCell's completedString:). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: "intelligent" flexible popup
On Jul 19, 2009, at 17:05, I. Savant wrote: On Jul 19, 2009, at 7:58 PM, Quincey Morris wrote: ... and you'd *still* have to prevent the table view from treating [NSComboBoxCell] like a text field. In what way? Are you referring to the fact that a menu can represent an object, whereas a combo box is just a (possibly-pre-baked-chosen-from-the- menu) string? In both cases it's not the NSTableView but your custom data source that would make these decisions (ie, what that new "object" that was set really means in that context). I meant, if you used the NSComboBox methods that told you which item of the popup list was chosen (e.g. indexOfSelectedItem), you'd know what was chosen -- if something *was* chosen from the list -- as a selection index, but the table view would nevertheless set the underlying string as the value of the property bound to the column. Storing or using such combo box selection indexes is tricky to do with a table view, because they don't fit into the bindings *or* the data source patterns. Even knowing where you might usefully call these selected item methods is puzzling. So yes, if you understand that the value corresponding to the column is a string which *may* match (isEqualToString:, not ==) a list of strings you separately maintain, then there's no problem. The easy-to-fall-into pitfall is having the data model property be an index into an array of (say) state names, but returning the string name of the state in place of the index when supplying data to the table view. In that case, changing the string for one row changes that string everywhere it's used, which is usually not what's intended. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: "intelligent" flexible popup
On Jul 19, 2009, at 7:58 PM, Quincey Morris wrote: ... and you'd *still* have to prevent the table view from treating [NSComboBoxCell] like a text field. In what way? Are you referring to the fact that a menu can represent an object, whereas a combo box is just a (possibly-pre-baked-chosen-from-the- menu) string? In both cases it's not the NSTableView but your custom data source that would make these decisions (ie, what that new "object" that was set really means in that context). -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: "intelligent" flexible popup
On Jul 19, 2009, at 16:43, Daniel Child wrote: As a follow-up to the previous question on popups in a table, I am wondering what APIs you can use to implement the kind of "intelligent" popups one finds, for example, when filling out the State field in forms needing an address. You start typing "Ma" and Maine or Maryland come up. But you also have the choice to type something not in the list of choices. This seems to be a combination text field / popup menu. Again, either an API hint or link to a tutorial would be very helpful. Thanks. You're possibly looking for NSComboBox. But keep in mind that there's an essential difference between NSPopUpButton and NSComboBox. A popup button is a kind of *menu*, which a combo box is a kind of *text field*. The popup button tells you which of the menu choices is in effect (a selection index). The combo box gives you arbitrary text, typing- assisted by the popup list and (optionally) autocompletion. There isn't a standard control that allows you to make a menu choice by typing a partial name. (NSComboBox has some support for finding out this information, but I doubt it's feasible in the context of a table view, and you'd *still* have to prevent the table view from treating it like a text field.) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: "intelligent" flexible popup
On Jul 19, 2009, at 7:43 PM, Daniel Child wrote: As a follow-up to the previous question on popups in a table, I am wondering what APIs you can use to implement the kind of "intelligent" popups one finds, for example, when filling out the State field in forms needing an address. You start typing "Ma" and Maine or Maryland come up. But you also have the choice to type something not in the list of choices. This seems to be a combination text field / popup menu. Again, either an API hint or link to a tutorial would be very helpful. Thanks. ... also known as an "NSComboBox". -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
"intelligent" flexible popup
As a follow-up to the previous question on popups in a table, I am wondering what APIs you can use to implement the kind of "intelligent" popups one finds, for example, when filling out the State field in forms needing an address. You start typing "Ma" and Maine or Maryland come up. But you also have the choice to type something not in the list of choices. This seems to be a combination text field / popup menu. Again, either an API hint or link to a tutorial would be very helpful. Thanks. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com