Annotation of chimera/ExtendedOutlineView.mm, revision 1.1

1.1     ! hyatt       1: //
        !             2: //  ExtendedOutlineView.mm
        !             3: //  Chimera
        !             4: //
        !             5: //  Created by David Hyatt on Fri Apr 19 2002.
        !             6: //  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
        !             7: //
        !             8: 
        !             9: #import "ExtendedOutlineView.h"
        !            10: 
        !            11: 
        !            12: @implementation ExtendedOutlineView
        !            13: 
        !            14: - (id)initWithFrame:(NSRect)frame {
        !            15:   self = [super initWithFrame:frame];
        !            16:   if (self) {
        !            17:     mDeleteAction = 0;
        !            18:   }
        !            19:   return self;
        !            20: }
        !            21: 
        !            22: -(void)setDeleteAction: (SEL)aDeleteAction
        !            23: {
        !            24:   mDeleteAction = aDeleteAction;
        !            25: }
        !            26: 
        !            27: -(SEL)deleteAction
        !            28: {
        !            29:   return mDeleteAction;
        !            30: }
        !            31: 
        !            32: int kReturnKeyCode = 0x24;
        !            33: int kDeleteKeyCode = 0x33;
        !            34: int kLeftArrowKeyCode = 0x7B;
        !            35: int kRightArrowKeyCode = 0x7C;
        !            36: 
        !            37: -(void)keyDown:(NSEvent*)aEvent
        !            38: {
        !            39:   // Check for a certain set of special keys.
        !            40:   
        !            41:   //NSDeleteFunctionKey
        !            42:   if ([aEvent keyCode] == kDeleteKeyCode) {
        !            43:     if (mDeleteAction)
        !            44:       [NSApp sendAction: mDeleteAction to: [self target] from: self];
        !            45:     return;
        !            46:   }
        !            47:   else if ([aEvent keyCode] == kReturnKeyCode) {
        !            48:     // Override return to keep the goofy inline editing
        !            49:     // from happening.
        !            50:     if ([self numberOfSelectedRows] == 1)
        !            51:       [NSApp sendAction: [self doubleAction] to: [self target] from: self];
        !            52:     return;
        !            53:   }
        !            54:   else if ([aEvent keyCode] == kLeftArrowKeyCode ||
        !            55:            [aEvent keyCode] == kRightArrowKeyCode)
        !            56:   {
        !            57:     BOOL expand = ([aEvent keyCode] == kRightArrowKeyCode);
        !            58:     if ([self numberOfSelectedRows] == 1) {
        !            59:       int index = [self selectedRow];
        !            60:       if (index == -1)
        !            61:         return;
        !            62: 
        !            63:       id item = [self itemAtRow: index];
        !            64:       if (!item)
        !            65:         return;
        !            66: 
        !            67:       if (![self isExpandable: item])
        !            68:         return;
        !            69:       
        !            70:       if (![self isItemExpanded: item] && expand)
        !            71:         [self expandItem: item];
        !            72:       else if ([self isItemExpanded: item] && !expand)
        !            73:         [self collapseItem: item];
        !            74:     }
        !            75:   }
        !            76:   
        !            77:   return [super keyDown: aEvent];
        !            78: }
        !            79: 
        !            80: @end

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