-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGBArrayController.m
114 lines (90 loc) · 4.14 KB
/
GBArrayController.m
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// This file is part of hdhomerunner.
// hdhomerunner is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// hdhomerunner is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// GBArrayController.m
// hdhomerunner
//
// Created by Gregory Barchard on 7/29/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "GBArrayController.h"
#define GBTableViewDataType @"GBPasteBoardType"
@implementation GBArrayController
- (void)selectNext:(id)sender{
//NSLog(@"before indexes = %@", [tableView selectedRowIndexes]);
//[super selectNext:sender];
//NSLog(@"int = %i", [[tableView selectedRowIndexes] firstIndex] + 1);
//NSLog(@"next selected row %@", [tableView selectedRowIndexes]);
[self setSelectionIndexes:[NSIndexSet indexSetWithIndex:([[tableView selectedRowIndexes] firstIndex] + 1)]];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
//[nc postNotificationName:NSTableViewSelectionDidChangeNotification object:nil];
//[super setSelectionIndexes:[tableView selectedRowIndexes]];
[nc postNotificationName:@"GBTunerWillChangeChannel" object:nil];
//NSLog(@"int2 = %@", [tableView selectedRowIndexes]);
//NSLog(@"after indexes = %@", [self selectionIndexes]);
}
- (void)selectPrevious:(id)sender{
//[super selectPrevious:sender];
//NSLog(@"previous selected row %@", [tableView selectedRowIndexes]);
//[self setSelectionIndexes:[tableView selectedRowIndexes]];
[self setSelectionIndexes:[NSIndexSet indexSetWithIndex:([[tableView selectedRowIndexes] firstIndex] - 1)]];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
//[nc postNotificationName:NSTableViewSelectionDidChangeNotification object:nil];
[nc postNotificationName:@"GBTunerWillChangeChannel" object:nil];
}
- (BOOL)tableView:(NSTableView *)tv
writeRowsWithIndexes:(NSIndexSet *)rowIndexes
toPasteboard:(NSPasteboard*)pboard{
NSLog(@"should drag");
BOOL result = NO;
if([[[self arrangedObjects] objectAtIndex:[rowIndexes firstIndex]] isKindOfClass:[GBChannel class]]){
// Copy the row numbers to the pasteboard.
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:[[self arrangedObjects] objectAtIndex:[rowIndexes firstIndex]]];
[pboard declareTypes:[NSArray arrayWithObject:@"channel"] owner:self];
[pboard setData:data forType:GBTableViewDataType];
result = YES;
}
return result;
}
- (NSDragOperation)tableView:(NSTableView*)tv
validateDrop:(id <NSDraggingInfo>)info
proposedRow:(int)row
proposedDropOperation:(NSTableViewDropOperation)op{
if ([info draggingSource] == tableView){
return NSDragOperationNone;
}
[tv setDropRow:row dropOperation:NSTableViewDropOn];
//NSLog(@"validate Drop");
//return NSDragOperationEvery;
return NSDragOperationGeneric;
//return NSDragOperationLink;
}
- (BOOL)tableView:(NSTableView*)tv
acceptDrop:(id <NSDraggingInfo>)info
row:(int)row
dropOperation:(NSTableViewDropOperation)op{
//NSLog(@"accept drop");
NSPasteboard* pboard = [info draggingPasteboard];
NSData* rowData = [pboard dataForType:GBTableViewDataType];
//NSLog(@"tv = %@", [[[[tv dataSource] arrangedObjects] objectAtIndex:row] setChannel:[NSKeyedUnarchiver unarchiveObjectWithData:rowData]]);
[[[self arrangedObjects] objectAtIndex:row] setChannel:[NSKeyedUnarchiver unarchiveObjectWithData:rowData]];
NSLog(@"data %@", [NSKeyedUnarchiver unarchiveObjectWithData:rowData]);
//NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
//int dragRow = [rowIndexes firstIndex];
return YES;
}
- (void)awakeFromNib
{
[super awakeFromNib];
[tableView registerForDraggedTypes:[NSArray arrayWithObject:GBTableViewDataType]];
}
@end