Re: If Array Controller is empty, how to populate pop-up list?

2010-01-17 Thread Jenny M
Hi Ken,

Thanks for your tips. We're closer I think. I took off the Selected Index
binding and instead bound the Selected Value to
ArrayController-selection-name. I'm probably binding it wrong though,
because I haven't quite gotten it to work yet.

I think what you say makes sense, about the selection objects and enabled
properties. I have a string in all three bindings' No Selection
Placeholder for the popup bindings (Content, Content Values, and Selected
Value), but instead, when the array controller is empty, the popupbutton is
both disabled and empty. Conditionally Sets Enabled is checked AND Avoid
Empty Selection is checked, but, no dice... You said this is what worked
for you? :/

Jenny



 With some experimentation, I discovered the following:

 I bound the pop-up's content to the array controller's arrangedObjects.  I
 bound its Selected Value or Selected Object (but not Selected Index) to the
 array controller's selection with an appropriate model key path.  For the
 content binding, I set a No Selection Placeholder string.  Then, whenever
 the array controller had no selection, the pop-up showed the placeholder
 string.

 If the Selected Value binding's Conditionally Sets Enabled option is on
 (the default), then the pop-up is disabled when there's no selection in the
 array controller.  This is sort of bad if the controlled array is not empty
 but the array controller has no selection.  In that case, the pop-up shows
 the placeholder but is disabled, so the user can't access the other items in
 the pop-up.  However, the array controller won't have no selection if its
 Avoid Empty Selection property is enabled (again, the default).  With that
 property enabled, the pop-up shows the placeholder and is disabled only if
 there's nothing in the controlled array.  If there are objects in the array,
 then the array controller has a selection and the pop-up shows it and is
 enabled.

 So, Conditionally Sets Enabled on the pop-up's Selected Value or Object
 binding, plus Avoids Empty Selection on the array controller works well.
  Turning both of those off makes for a functional but possibly strange
 interface; when the array is non-empty but the array controller has no
 selection, the pop-up shows the placeholder but is enabled and also contains
 the normal items.

 I hope that helps.

 Cheers,
 Ken


___

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: If Array Controller is empty, how to populate pop-up list?

2010-01-17 Thread Ken Thomases
On Jan 17, 2010, at 4:36 PM, Jenny M wrote:

 Thanks for your tips. We're closer I think. I took off the Selected Index 
 binding and instead bound the Selected Value to 
 ArrayController-selection-name. I'm probably binding it wrong though, because 
 I haven't quite gotten it to work yet.
 
 I think what you say makes sense, about the selection objects and enabled 
 properties. I have a string in all three bindings' No Selection Placeholder 
 for the popup bindings (Content, Content Values, and Selected Value), but 
 instead, when the array controller is empty, the popupbutton is both disabled 
 and empty. Conditionally Sets Enabled is checked AND Avoid Empty 
 Selection is checked, but, no dice... You said this is what worked for you? 
 :/

Yes, that sounds like what I did.  However, on thinking some more about this, I 
think I was on the wrong track.  The selection value or object bindings of the 
pop-up would tend to set the bound-to property to whatever was selected in the 
pop-up.  So, if you bind the selected value to ArrayController.selection.name, 
when the pop-up selection changes, it would attempt to set the name property of 
the object selected in the ArrayController.  That's not what you want.

Although the Selected Index of the pop-up may sensibly be bound to the array 
controller's selection index, which will properly result in the selection 
tracked by the array controller matching the selection in the pop-up, that 
doesn't appear to trigger the No Selection placeholder of the content bindings, 
as you've discovered.  Basically, the array controller doesn't return the 
NSNoSelectionMarker marker for its selectionIndex property, it just returns 
NSNotFound.

So, try this: make a property on your window controller, app controller, or 
other appropriate coordinating controller (not the array controller, which is a 
mediating controller; probably this would be the same controller which provides 
the content for the array controller).  This new property will hold the state 
which the pop-up represents in the GUI.  Bind either the pop-up's selected 
object or selected value, whichever makes most sense for your design, to this 
property.

This property can be set when the array has contents, but when the array is 
empty it can return the NSNoSelectionMarker instead of, for example, nil.  That 
should be sufficient to trigger both the No Selection Placeholder and the 
Conditionally Sets Enabled bindings, leaving the pop-up disabled and showing 
the placeholder.

Alternatively, if the new property is bound to the pop-up's selection value, 
you can have it just directly return the placeholder when the array is empty.  
To disable the pop-up, you can bind its Enabled binding to 
arraycontroller.arrangedobjec...@count.

Since the value of this new property changes depending on whether or not the 
array has contents, you'll want to tell KVO that it's dependent on the array 
property (+keyPathsForValuesAffectingKey).

Regards,
Ken

___

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: If Array Controller is empty, how to populate pop-up list?

2010-01-16 Thread Ken Thomases
On Jan 14, 2010, at 4:09 PM, Jenny M wrote:

 I have an Array Controller whose objects are displayed in an NSPopUpButton.

 However, what can I do if the array controller becomes empty? If I delete all 
 the objects, or if the window starts up with an empty array controller, I'd 
 like for the list to then have a null element that says No objects.  Once 
 an object is added, it should go away.


 But if I choose Insert null placeholder in the pop-up options, the null 
 placeholder is ALWAYS there, which is not good.

Well, this part is as expected.  That's what the null placeholder is for.  It's 
not a way to represent when the array controller has no objects.  It's a way 
for the pop-up to give the user the option of selecting none of the objects 
from the array controller.

 Is there a way to do this in IB, or is this a thing I should code? And if so, 
 how can I make sure the method is called whenever there is a change to the 
 array controller?

With some experimentation, I discovered the following:

I bound the pop-up's content to the array controller's arrangedObjects.  I 
bound its Selected Value or Selected Object (but not Selected Index) to the 
array controller's selection with an appropriate model key path.  For the 
content binding, I set a No Selection Placeholder string.  Then, whenever the 
array controller had no selection, the pop-up showed the placeholder string.

If the Selected Value binding's Conditionally Sets Enabled option is on (the 
default), then the pop-up is disabled when there's no selection in the array 
controller.  This is sort of bad if the controlled array is not empty but the 
array controller has no selection.  In that case, the pop-up shows the 
placeholder but is disabled, so the user can't access the other items in the 
pop-up.  However, the array controller won't have no selection if its Avoid 
Empty Selection property is enabled (again, the default).  With that property 
enabled, the pop-up shows the placeholder and is disabled only if there's 
nothing in the controlled array.  If there are objects in the array, then the 
array controller has a selection and the pop-up shows it and is enabled.

So, Conditionally Sets Enabled on the pop-up's Selected Value or Object 
binding, plus Avoids Empty Selection on the array controller works well.  
Turning both of those off makes for a functional but possibly strange 
interface; when the array is non-empty but the array controller has no 
selection, the pop-up shows the placeholder but is enabled and also contains 
the normal items.

I hope that helps.

Cheers,
Ken

___

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


If Array Controller is empty, how to populate pop-up list?

2010-01-14 Thread Jenny M
Hi all,

I have an Array Controller whose objects are displayed in an NSPopUpButton.
I can add and remove objects, and they refresh automatically in the box as
expected.

However, what can I do if the array controller becomes empty? If I delete
all the objects, or if the window starts up with an empty array controller,
I'd like for the list to then have a null element that says No objects.
Once an object is added, it should go away. But if I choose Insert null
placeholder in the pop-up options, the null placeholder is ALWAYS there,
which is not good.

Is there a way to do this in IB, or is this a thing I should code? And if
so, how can I make sure the method is called whenever there is a change to
the array controller?

Thanks in advanced...
___

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: If Array Controller is empty, how to populate pop-up list?

2010-01-14 Thread Jenny M
Uhh, okay so there's another problem I discovered. Below the popupmenu, I
have two text fields that are supposed to show two of the attributes of the
selected object (in the array controller). But changing the selection in the
popupmenu does NOT change the selected item in the array controller. How do
I wire the two together such that selecting a different value in the
nspopupmenu also changes the selected object in the array controller?

Right now the NSPopUpMenu has the bindings set like so:
- Content: ArrayController.arrangedObjects
- Content Values: ArrayController.arrangedObjects.name

Any ideas what else I need to set??
___

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: If Array Controller is empty, how to populate pop-up list?

2010-01-14 Thread Jenny M
Cancel Message #2 - I figured out how to change the selected object. I added
one more binding - I bound the NSPopUpButton Selected Index to
ArrayController.selectionIndex.

However, message #1 still stands - how do I implement a placeholder object
only when the array is empty??
___

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: If Array Controller is empty, how to populate pop-up list?

2010-01-14 Thread Rob Keniger

On 15/01/2010, at 1:18 PM, Jenny M wrote:

 However, message #1 still stands - how do I implement a placeholder object
 only when the array is empty??


In your content binding for the popup button in Interface Builder, check the 
Inserts Null Placeholder checkbox and enter a value in the Null Placeholder 
field.

--
Rob Keniger



___

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: If Array Controller is empty, how to populate pop-up list?

2010-01-14 Thread Jenny M
Like I mentioned previously - when I do that, it stays there even after an
object has been added, which is not what I'm aiming for. I only want it to
appear when empty.


In your content binding for the popup button in Interface Builder, check the
 Inserts Null Placeholder checkbox and enter a value in the Null
 Placeholder field.

-- 

Rob Keniger

___

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: If Array Controller is empty, how to populate pop-up list?

2010-01-14 Thread Rob Keniger

On 15/01/2010, at 4:24 PM, Jenny M wrote:

 Like I mentioned previously - when I do that, it stays there even after an
 object has been added, which is not what I'm aiming for. I only want it to
 appear when empty.


Ah, sorry, I didn't see that in your original post.

--
Rob Keniger



___

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