summaryrefslogtreecommitdiffstats
path: root/macosx/HBQueueOutlineView.m
blob: 0c7bce87f0e92ea763a5d9c347d609576475f21f (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
87
88
89
90
91
92
93
94
95
96
97
98
99
//
//  HBQueueOutlineView.m
//  HandBrake
//
//  Created by Damiano Galassi on 23/11/14.
//
//

#import "HBQueueOutlineView.h"

@implementation HBQueueOutlineView

- (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];
}

/* This should be for dragging, we take this info from the presets right now */
- (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows
                            tableColumns:(NSArray *)tableColumns
                                   event:(NSEvent *)dragEvent
                                  offset:(NSPointPointer)dragImageOffset
{
    _isDragging = YES;

    // By default, NSTableView only drags an image of the first column. Change this to
    // drag an image of the queue's icon and desc and action columns.
    NSArray *cols = @[[self tableColumnWithIdentifier:@"desc"],
                      [self tableColumnWithIdentifier:@"icon"],
                      [self tableColumnWithIdentifier:@"action"]];

    return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
}

- (void)mouseDown:(NSEvent *)theEvent
{
    [super mouseDown:theEvent];
    _isDragging = NO;
}

- (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;
        }
    }

    [super keyDown:event];
}

/**
 *  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];
}

@end