• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Deleting a row
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Deleting a row


  • Subject: Re: Deleting a row
  • From: Stéphane Sudre <email@hidden>
  • Date: Sun, 30 May 2004 12:18:51 +0200

On dimanche, mai 30, 2004, at 01:29 AM, Bjvrn Carlstrvm wrote:

I asked before in a different form but didnt get any response.

I want to use the delete command in the edit menu to delete a row in an NSOutlinView. My controller object seems the ideal object to handle this. How do I get the command sent to my controller object?
A. Do I need to sunclass NSOutlineView and add a delete method?
B. Do I make my controller a subclass of NSResponder and insert it into the responder chain?
C Do I let my Document handle it and pass the command on to my controller?
D. Something else?

A solution
----------

Implement:

- (void) deleteSelectedRowsOfOutlineView:(NSOutlineView *) aOutlineView;

and

- (BOOL)validateMenuItem:(NSMenuItem *)aMenuItem;

in your controller

and subclass NSOutlineView:

#import <Cocoa/Cocoa.h>

@interface PBOutlineView : NSOutlineView
{
}

- (IBAction) delete:(id) sender;

@end

#import "PBOutlineView.h"

@implementation PBOutlineView

- (void) keyDown:(NSEvent *) theEvent
{
NSString * tString;
unsigned int stringLength;
unsigned int i;
unichar tChar;

tString= [theEvent characters];

stringLength=[tString length];

for(i=0;i<stringLength;i++)
{
tChar=[tString characterAtIndex:i];

if (tChar==0x7F)
{
NSMenuItem * tMenuItem;

tMenuItem=[[NSMenuItem alloc] initWithTitle:@"" action:@selector(delete:) keyEquivalent:@""];

if ([self validateMenuItem:tMenuItem]==YES)
{
[self delete:nil];
}
else
{
NSBeep();
}

return;
}
}

[super keyDown:theEvent];
}

- (BOOL)validateMenuItem:(NSMenuItem *)aMenuItem
{
if ([aMenuItem action]==@selector(delete:))
{
if ([self numberOfSelectedRows]>0)
{
return [[self dataSource] validateMenuItem:aMenuItem];
}

return NO;
}

return YES;
}

- (IBAction) delete:(id) sender
{
if ([[self dataSource] respondsToSelector:@selector(deleteSelectedRowsOfOutlineView:)]==YES)
{
[[self dataSource] performSelector:@selector(deleteSelectedRowsOfOutlineView:)
withObject:self];
}
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Deleting a row
      • From: Björn Carlström <email@hidden>
References: 
 >Deleting a row (From: Björn Carlström <email@hidden>)

  • Prev by Date: Re: "UseWebKit" in NSAttributedString
  • Next by Date: Re: Deleting a row
  • Previous by thread: Deleting a row
  • Next by thread: Re: Deleting a row
  • Index(es):
    • Date
    • Thread