File:  [mozdev] / chimera / ExtendedOutlineView.mm
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Fri Apr 19 08:45:57 2002 UTC (15 years, 6 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
add support for additional keys to the outline view used by bookmarks.  adding delete support, return support, and left/right arrow support.

//
//  ExtendedOutlineView.mm
//  Chimera
//
//  Created by David Hyatt on Fri Apr 19 2002.
//  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
//

#import "ExtendedOutlineView.h"


@implementation ExtendedOutlineView

- (id)initWithFrame:(NSRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    mDeleteAction = 0;
  }
  return self;
}

-(void)setDeleteAction: (SEL)aDeleteAction
{
  mDeleteAction = aDeleteAction;
}

-(SEL)deleteAction
{
  return mDeleteAction;
}

int kReturnKeyCode = 0x24;
int kDeleteKeyCode = 0x33;
int kLeftArrowKeyCode = 0x7B;
int kRightArrowKeyCode = 0x7C;

-(void)keyDown:(NSEvent*)aEvent
{
  // Check for a certain set of special keys.
  
  //NSDeleteFunctionKey
  if ([aEvent keyCode] == kDeleteKeyCode) {
    if (mDeleteAction)
      [NSApp sendAction: mDeleteAction to: [self target] from: self];
    return;
  }
  else if ([aEvent keyCode] == kReturnKeyCode) {
    // Override return to keep the goofy inline editing
    // from happening.
    if ([self numberOfSelectedRows] == 1)
      [NSApp sendAction: [self doubleAction] to: [self target] from: self];
    return;
  }
  else if ([aEvent keyCode] == kLeftArrowKeyCode ||
           [aEvent keyCode] == kRightArrowKeyCode)
  {
    BOOL expand = ([aEvent keyCode] == kRightArrowKeyCode);
    if ([self numberOfSelectedRows] == 1) {
      int index = [self selectedRow];
      if (index == -1)
        return;

      id item = [self itemAtRow: index];
      if (!item)
        return;

      if (![self isExpandable: item])
        return;
      
      if (![self isItemExpanded: item] && expand)
        [self expandItem: item];
      else if ([self isItemExpanded: item] && !expand)
        [self collapseItem: item];
    }
  }
  
  return [super keyDown: aEvent];
}

@end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>