summaryrefslogtreecommitdiffstats
path: root/macosx/HBTableView.m
blob: ba7ea4733c5b175ec855eb4788bfd328825c74e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*  HBQueueOutlineView.m $

 This file is part of the HandBrake source code.
 Homepage: <http://handbrake.fr/>.
 It may be used under the terms of the GNU General Public License. */

#import "HBTableView.h"

@implementation HBTableView

/**
 *  An index set containing the indexes of the targeted rows.
 *  If the selected row indexes contain the clicked row index, it returns every selected row,
 *  otherwise it returns only the clicked row index.
 */
- (NSIndexSet *)targetedRowIndexes
{
    NSMutableIndexSet *rowIndexes = [NSMutableIndexSet indexSet];
    NSIndexSet *selectedRowIndexes = self.selectedRowIndexes;
    NSInteger clickedRow = self.clickedRow;

    if (clickedRow != -1)
    {
        [rowIndexes addIndex:clickedRow];

        // If we clicked on a selected row, then we want to consider all rows in the selection. Otherwise, we only consider the clicked on row.
        if ([selectedRowIndexes containsIndex:clickedRow])
        {
            [rowIndexes addIndexes:selectedRowIndexes];
        }
    }
    else
    {
        [rowIndexes addIndexes:selectedRowIndexes];
    }

    return [rowIndexes copy];
}

- (void)keyDown:(NSEvent *)event
{
    id delegate = self.delegate;

    NSString *characters = [event charactersIgnoringModifiers];
    if (characters.length)
    {
        unichar key = [characters characterAtIndex:0];
        if ((key == NSDeleteCharacter || key == NSDeleteFunctionKey) &&
            [delegate respondsToSelector:@selector(HB_deleteSelectionFromTableView:)])
        {
            if (self.selectedRow == -1)
            {
                NSBeep();
            }
            else
            {
                [delegate HB_deleteSelectionFromTableView:self];
            }
            return;
        }
        else if (key == NSLeftArrowFunctionKey &&
                 [delegate respondsToSelector:@selector(HB_collapseSelectionFromTableView:)])
        {
            [delegate HB_collapseSelectionFromTableView:self];
            return;
        }
        else if (key == NSRightArrowFunctionKey &&
                 [delegate respondsToSelector:@selector(HB_expandSelectionFromTableView:)])
        {
            [delegate HB_expandSelectionFromTableView:self];
            return;
        }
    }

    [super keyDown:event];
}

- (void)viewDidEndLiveResize
{
    // Since we disabled calculating row heights during a live resize, force them to
    // recalculate now.
    [self noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.numberOfRows)]];
    [super viewDidEndLiveResize];
}

@end