Re: How do I delete NSCollectionView item on right click?

2009-08-01 Thread Graham Cox


On 01/08/2009, at 1:11 PM, Austin Grigg wrote:

I've got an NSCollectionView with the prototype view subclassed and  
I'm overriding menuForEvent.  I'm creating a menu that has Edit/ 
Delete and when the user clicks Delete I want to remove that  
collection view item.  Where would you put the selector for the  
Delete menu item, and how would you know when it gets called what  
collection view item to delete?



By selector I assume you mean e.g. a -delete: IBAction method. That  
would go in the controller that is handling the view. To ensure it  
gets called, you simply ctrl-drag a connection from the menu item to  
the controller and choose this method. Verify it gets called using  
NSLog or the debugger.


To actually implement the delete, you'd use the view's - 
selectionIndexes to find out what items to delete, remove them from  
your data model and call the view's -setContent: with the modified  
array from your model, and also remove the selection using - 
setSelectionIndexes: with an empty set. You might need to call - 
setNeedsdisplay:YES on the view to make it show the change.


--Graham


___

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: How do I delete NSCollectionView item on right click?

2009-08-01 Thread Graham Cox


On 01/08/2009, at 4:12 PM, Graham Cox wrote:

I've got an NSCollectionView with the prototype view subclassed and  
I'm overriding menuForEvent.  I'm creating a menu that has Edit/ 
Delete and when the user clicks Delete I want to remove that  
collection view item.  Where would you put the selector for the  
Delete menu item, and how would you know when it gets called what  
collection view item to delete?



By selector I assume you mean e.g. a -delete: IBAction method.  
That would go in the controller that is handling the view. To ensure  
it gets called, you simply ctrl-drag a connection from the menu item  
to the controller and choose this method. Verify it gets called  
using NSLog or the debugger.



Forgot to mention - if you are setting up the menu programmatically,  
you need to set the target of the menu item to the controller and the  
action method selector to the -delete: IBAction (it doesn't strictly  
need to be an IBAction in this case, but personally I find that  
declaring it as such is useful for managing the code and converting it  
to an IB-based solution later).


If your menu is simple and not dynamic - i.e. it never changes  
according to the state of the item it's attached to - you might find  
it easier to set it up in IB rather than overriding -menuForEvent: -  
just create a menu object and connect it to the 'menu' outlet of the  
view.


--Graham


___

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


How do I delete NSCollectionView item on right click?

2009-07-31 Thread Austin Grigg
I've got an NSCollectionView with the prototype view subclassed and  
I'm overriding menuForEvent.  I'm creating a menu that has Edit/Delete  
and when the user clicks Delete I want to remove that collection view  
item.  Where would you put the selector for the Delete menu item, and  
how would you know when it gets called what collection view item to  
delete?


Thanks,
Austin
___

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