-
Notifications
You must be signed in to change notification settings - Fork 56
/
FilesTableView.m
637 lines (581 loc) · 23.8 KB
/
FilesTableView.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
//
// MyTableView.m
// MetaZ
//
// Created by Brian Olsen on 02/09/09.
// Copyright 2009 Maven-Group. All rights reserved.
//
#import <MetaZKit/MetaZKit.h>
#import "FilesTableView.h"
#import "MZMetaLoader.h"
#define MZFilesTableRows @"MZFilesTableRows"
@interface FilesTableView ()
- (BOOL)writeSelectionUncheckedToPasteboard:(NSPasteboard *)pboard
types:(NSArray *)types;
- (void)registerUndoName:(NSUndoManager *)manager;
@end
@implementation FilesTableView
@synthesize undoController;
@synthesize filesController;
+ (void)initialize
{
if(self != [FilesTableView class])
return;
NSArray* sendTypes = [NSArray arrayWithObjects:NSFilenamesPboardType,
NSStringPboardType, nil];
NSArray* returnTypes = [NSArray arrayWithObjects:NSFilenamesPboardType,
NSStringPboardType, nil];
[NSApp registerServicesMenuSendTypes:sendTypes
returnTypes:returnTypes];
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
[self registerForDraggedTypes:
[NSArray arrayWithObjects:MZFilesTableRows,
MZMetaEditsDataType, iTunesMetadataPboardType,
TVAppMetadataPboardType, iTunesPboardType,
NSFilenamesPboardType, NSStringPboardType, nil] ];
}
return self;
}
- (id)initWithCoder:(NSCoder*)decoder
{
self = [super initWithCoder:decoder];
if(self)
{
[self registerForDraggedTypes:
[NSArray arrayWithObjects:MZFilesTableRows,
MZMetaEditsDataType, iTunesMetadataPboardType,
TVAppMetadataPboardType, iTunesPboardType,
NSFilenamesPboardType, NSStringPboardType, nil] ];
}
return self;
}
-(void)dealloc {
[undoController release];
[filesController release];
[super dealloc];
}
#pragma mark - actions
-(IBAction)delete:(id)sender
{
if([self selectedRow] >= 0)
{
NSRect rowRect = [self rectOfRow:[self selectedRow]];
NSRect prect;
prect.origin = NSMakePoint(
rowRect.origin.x + rowRect.size.width/2,
rowRect.origin.y + rowRect.size.height/2);
prect.size = NSZeroSize;
prect = [self.window convertRectToScreen:[self convertRect:prect toView:nil]];
NSPoint point = prect.origin;
/*
NSPoint point = NSMakePoint(
rowRect.origin.x + rowRect.size.width/2,
rowRect.origin.y + rowRect.size.height/2);
point = [[self window] convertBaseToScreen:[self convertPointToBase:point]];
*/
NSShowAnimationEffect(NSAnimationEffectDisappearingItemDefault,point,NSZeroSize,nil,Nil,NULL);
}
[filesController remove:sender];
}
-(IBAction)copy:(id)sender
{
NSPasteboard *pb = [NSPasteboard generalPasteboard];
if([self numberOfSelectedRows] == 0)
return;
NSMutableArray* types = [NSMutableArray array];
if([self numberOfSelectedRows] == 1)
{
[types addObject:MZMetaEditsDataType];
[types addObject:NSStringPboardType];
}
[types addObject:NSFilenamesPboardType];
[self writeSelectionUncheckedToPasteboard:pb types:types];
}
-(IBAction)paste:(id)sender
{
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSLog(@"Pasteboard Types %@", pb.types);
NSArray *types = [NSArray arrayWithObjects:MZMetaEditsDataType,
iTunesMetadataPboardType, TVAppMetadataPboardType,
iTunesPboardType, NSFilenamesPboardType,
NSStringPboardType, nil];
NSString *bestType = [pb availableTypeFromArray:types];
if (bestType != nil)
{
if([bestType isEqualToString:MZMetaEditsDataType])
{
NSData* data = [pb dataForType:MZMetaEditsDataType];
MetaEdits* pasted = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSArray* edits = [filesController selectedObjects];
NSInteger count = [edits count];
for(MetaEdits* edit in edits)
[self registerUndoName:edit.undoManager];
for(MetaEdits* edit in edits)
{
for(MZTag* tag in [pasted providedTags])
{
if([tag isKindOfClass:[MZReadOnlyTag class]])
continue;
id value = [pasted pure];
value = [value valueForKey:[tag identifier]];
if( count == 1 || ![edit getterChangedForKey:[tag identifier]])
{
[edit setValue:value forKey:[tag identifier]];
}
}
}
for(MetaEdits* edit in edits)
[self registerUndoName:edit.undoManager];
}
if([bestType isEqualToString:iTunesMetadataPboardType] ||
[bestType isEqualToString:TVAppMetadataPboardType] ||
[bestType isEqualToString:iTunesPboardType])
{
NSDictionary* prop = [pb propertyListForType:iTunesMetadataPboardType];
BOOL tv = NO;
if(!prop) {
prop = [pb propertyListForType:TVAppMetadataPboardType];
tv = YES;
}
if(!prop)
prop = [pb propertyListForType:iTunesPboardType];
if(prop)
{
NSMutableArray* names = [NSMutableArray array];
NSMutableArray* dataDicts = [NSMutableArray array];
NSDictionary* tracks = [prop objectForKey:@"Tracks"];
for(id track in [tracks allValues])
{
NSURL* location = [NSURL URLWithString:[track objectForKey:@"Location"]];
[names addObject:[location path]];
NSString* persistentId = [track objectForKey:@"Persistent ID"];
NSDictionary* data;
if (tv) {
data = [NSDictionary dictionaryWithObject:persistentId
forKey:MZTVAppPersistentIDTagIdent];
} else {
data = [NSDictionary dictionaryWithObject:persistentId
forKey:MZiTunesPersistentIDTagIdent];
}
[dataDicts addObject:data];
}
[[MZMetaLoader sharedLoader] loadFromFiles:names withMetaData:dataDicts];
}
}
if([bestType isEqualToString:NSFilenamesPboardType])
{
NSArray* filenames = [pb propertyListForType:NSFilenamesPboardType];
[[MZMetaLoader sharedLoader] loadFromFiles:filenames];
}
if([bestType isEqualToString:NSStringPboardType])
{
NSString* filename = [pb stringForType:NSStringPboardType];
NSFileManager* mgr = [NSFileManager manager];
BOOL dir = NO;
if([mgr fileExistsAtPath:[filename stringByExpandingTildeInPath]
isDirectory:&dir] && !dir)
[[MZMetaLoader sharedLoader] loadFromFile:filename];
}
}
}
- (BOOL)pasteboardHasTypes {
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSLog(@"Pasteboard Types %@", pb.types);
NSArray *types = [NSArray arrayWithObjects:MZMetaEditsDataType,
iTunesMetadataPboardType, TVAppMetadataPboardType,
iTunesPboardType, NSFilenamesPboardType,
NSStringPboardType, nil];
NSString *bestType = [pb availableTypeFromArray:types];
if(bestType != nil && [bestType isEqualToString:MZMetaEditsDataType])
return [self numberOfSelectedRows] > 0;
if(bestType != nil && [bestType isEqualToString:NSStringPboardType])
{
NSString* str = [pb stringForType:NSStringPboardType];
NSFileManager* mgr = [NSFileManager manager];
BOOL dir = NO;
str = [str stringByExpandingTildeInPath];
return [mgr fileExistsAtPath:str isDirectory:&dir] && !dir &&
[[MZPluginController sharedInstance] dataProviderForPath:str] != nil;
}
if(bestType != nil && [bestType isEqualToString:NSFilenamesPboardType])
{
NSArray* filenames = [pb propertyListForType:NSFilenamesPboardType];
for(NSString* str in filenames)
{
if(![[MZPluginController sharedInstance] dataProviderForPath:str])
return NO;
}
}
if(bestType != nil &&
([bestType isEqualToString:iTunesMetadataPboardType] ||
[bestType isEqualToString:TVAppMetadataPboardType] ||
[bestType isEqualToString:iTunesPboardType]))
{
NSDictionary* prop = [pb propertyListForType:iTunesMetadataPboardType];
if(!prop)
prop = [pb propertyListForType:TVAppMetadataPboardType];
if(!prop)
prop = [pb propertyListForType:iTunesPboardType];
if(prop)
{
NSDictionary* tracks = [prop objectForKey:@"Tracks"];
for(id track in [tracks allValues])
{
NSURL* location = [NSURL URLWithString:[track objectForKey:@"Location"]];
if(![[MZPluginController sharedInstance] dataProviderForPath:[location path]])
return NO;
}
return YES;
}
return NO;
}
return bestType != nil;
}
- (IBAction)revertChanges:(id)sender {
NSNumber* num = [filesController valueForKeyPath:@"selection.fileNameChanged"];
num = [NSNumber numberWithBool:![num boolValue]];
[filesController setValue:num forKeyPath:@"selection.fileNameChanged"];
}
#pragma mark - user interface validation
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem {
SEL action = [anItem action];
if(action == @selector(delete:))
return [self numberOfSelectedRows] > 0;
if(action == @selector(copy:))
return [self numberOfSelectedRows] == 1;
if(action == @selector(paste:))
return [self pasteboardHasTypes];
if(action == @selector(revertChanges:))
{
if([[filesController selectedObjects] count] >= 1)
{
BOOL changed = [[filesController valueForKeyPath:@"selection.fileNameChanged"] boolValue];
NSMenuItem* item = (NSMenuItem*)anItem;
if(changed)
[item setTitle:NSLocalizedString(@"Revert Changes", @"Revert changes menu item")];
else
[item setTitle:NSLocalizedString(@"Apply Changes", @"Apply changes menu item")];
return YES;
}
else
return NO;
}
return [super validateUserInterfaceItem:anItem];
}
#pragma mark - services support
- (id)validRequestorForSendType:(NSString *)sendType
returnType:(NSString *)returnType
{
if((sendType && [self selectedRow] >= 0) &&
([sendType isEqual:NSStringPboardType] ||
[sendType isEqual:NSFilenamesPboardType]) &&
(!returnType || [returnType length] == 0))
{
return self;
}
return [super validRequestorForSendType:sendType
returnType:returnType];
}
- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard
types:(NSArray *)types
{
if(![types containsObject:NSStringPboardType] &&
![types containsObject:NSFilenamesPboardType] &&
![types containsObject:MZMetaEditsDataType])
{
return NO;
}
if([self selectedRow] < 0)
return NO;
NSMutableArray* returnTypes = [NSMutableArray array];
if([types containsObject:MZMetaEditsDataType])
[returnTypes addObject:MZMetaEditsDataType];
if([types containsObject:NSFilenamesPboardType])
[returnTypes addObject:NSFilenamesPboardType];
if([types containsObject:NSStringPboardType])
[returnTypes addObject:NSStringPboardType];
return [self writeSelectionUncheckedToPasteboard:pboard types:returnTypes];
}
#pragma mark - drag'n'drop support
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{
[super draggedImage:anImage endedAt:aPoint operation:operation];
}
- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes
toPasteboard:(NSPasteboard*)pboard
{
[pboard declareTypes:[NSArray arrayWithObjects:MZFilesTableRows,
MZMetaEditsDataType, NSFilenamesPboardType,
NSStringPboardType,nil] owner:nil];
NSData *rowdata = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
if(![pboard setData:rowdata forType:MZFilesTableRows])
return NO;
NSArray* edits = [[filesController arrangedObjects] objectsAtIndexes:rowIndexes];
NSData *editsdata = [NSKeyedArchiver archivedDataWithRootObject:edits];
if(![pboard setData:editsdata forType:MZMetaEditsDataType])
return NO;
NSArray* filenames = [edits arrayByPerformingSelector:@selector(loadedFileName)];
if(![pboard setPropertyList:filenames forType:NSFilenamesPboardType])
return NO;
if(![pboard setString:[filenames objectAtIndex:0] forType:NSStringPboardType])
return NO;
return YES;
}
- (NSDragOperation)tableView:(NSTableView*)tv
validateDrop:(id <NSDraggingInfo>)info
proposedRow:(NSInteger)row
proposedDropOperation:(NSTableViewDropOperation)op
{
if(op==NSTableViewDropOn)
[self setDropRow:row dropOperation:NSTableViewDropAbove];
NSPasteboard* pboard = [info draggingPasteboard];
NSArray *types = [NSArray arrayWithObjects:MZFilesTableRows,
MZMetaEditsDataType, iTunesMetadataPboardType,
TVAppMetadataPboardType, iTunesPboardType,
NSFilenamesPboardType, NSStringPboardType, nil];
//NSDragOperation operation = [info draggingSourceOperationMask];
NSString *bestType = [pboard availableTypeFromArray:types];
if(bestType != nil)
{
if([bestType isEqualToString:NSStringPboardType])
{
NSString* str = [pboard stringForType:NSStringPboardType];
NSFileManager* mgr = [NSFileManager manager];
BOOL dir = NO;
str = [str stringByExpandingTildeInPath];
if([mgr fileExistsAtPath:str isDirectory:&dir] && !dir &&
[[MZPluginController sharedInstance] dataProviderForPath:str])
{
return NSDragOperationGeneric;
}
return NSDragOperationNone;
}
if([bestType isEqualToString:NSFilenamesPboardType])
{
NSArray* filenames = [pboard propertyListForType:NSFilenamesPboardType];
for(NSString* str in filenames)
{
if(![[MZPluginController sharedInstance] dataProviderForPath:str])
return NSDragOperationNone;
}
return NSDragOperationGeneric;
}
if([bestType isEqualToString:iTunesMetadataPboardType] ||
[bestType isEqualToString:TVAppMetadataPboardType] ||
[bestType isEqualToString:iTunesPboardType])
{
return NSDragOperationGeneric;
}
return NSDragOperationMove;
}
return NSDragOperationNone;
}
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
NSPasteboard* pboard = [info draggingPasteboard];
NSArray *types = [NSArray arrayWithObjects:MZFilesTableRows,
MZMetaEditsDataType, iTunesMetadataPboardType,
TVAppMetadataPboardType, iTunesPboardType,
NSFilenamesPboardType, NSStringPboardType, nil];
NSString *bestType = [pboard availableTypeFromArray:types];
if (bestType != nil)
{
if([bestType isEqualToString:MZFilesTableRows])
{
NSData* data = [pboard dataForType:MZFilesTableRows];
NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSArray* edits = [[filesController arrangedObjects] objectsAtIndexes:rowIndexes];
[filesController setSortDescriptors:nil];
[[MZMetaLoader sharedLoader] moveObjects:edits toIndex:row];
return YES;
}
if([bestType isEqualToString:iTunesMetadataPboardType] ||
[bestType isEqualToString:TVAppMetadataPboardType] ||
[bestType isEqualToString:iTunesPboardType])
{
NSDictionary* prop = [pboard propertyListForType:iTunesMetadataPboardType];
BOOL tv = NO;
if(!prop) {
prop = [pboard propertyListForType:TVAppMetadataPboardType];
tv = YES;
}
if(!prop)
prop = [pboard propertyListForType:iTunesPboardType];
if(prop)
{
NSDictionary* tracks = [prop objectForKey:@"Tracks"];
for(id track in [tracks allValues])
{
NSURL* location = [NSURL URLWithString:[track objectForKey:@"Location"]];
if(![[MZPluginController sharedInstance] dataProviderForPath:[location path]])
return NO;
}
if(![filesController commitEditing])
return NO;
NSArray* params = [NSArray arrayWithObjects:prop,
[NSNumber numberWithInteger:row],
[NSNumber numberWithBool:tv], nil];
[self performSelector:@selector(loadFiles:) withObject:params afterDelay:1];
return YES;
}
return NO;
}
if([bestType isEqualToString:NSFilenamesPboardType])
{
NSArray* filenames = [pboard propertyListForType:NSFilenamesPboardType];
for(NSString* file in filenames)
{
if(![[MZPluginController sharedInstance] dataProviderForPath:file])
return NO;
}
if(![filesController commitEditing])
return NO;
NSArray* params = [NSArray arrayWithObjects:filenames, [NSNumber numberWithInteger:row], nil];
[self performSelector:@selector(loadFiles:) withObject:params afterDelay:1];
return YES;
}
if([bestType isEqualToString:NSStringPboardType])
{
NSString* filename = [pboard stringForType:NSStringPboardType];
NSFileManager* mgr = [NSFileManager manager];
BOOL dir = NO;
filename = [filename stringByExpandingTildeInPath];
if([mgr fileExistsAtPath:filename isDirectory:&dir] && !dir &&
[[MZPluginController sharedInstance] dataProviderForPath:filename])
{
if(![filesController commitEditing])
return NO;
NSArray* params = [NSArray arrayWithObjects:filename, [NSNumber numberWithInteger:row], nil];
[self performSelector:@selector(loadFiles:) withObject:params afterDelay:1];
return YES;
}
}
}
return NO;
}
- (void)loadFiles:(NSArray *)params
{
id first = [params objectAtIndex:0];
NSInteger row = [[params objectAtIndex:1] integerValue];
BOOL tv = NO;
if ([params count] == 3) {
tv = [[params objectAtIndex:2] boolValue];
}
if([first isKindOfClass:[NSDictionary class]])
{
NSMutableArray* names = [NSMutableArray array];
NSMutableArray* dataDicts = [NSMutableArray array];
NSDictionary* tracks = [first objectForKey:@"Tracks"];
for(id track in [tracks allValues])
{
NSURL* location = [NSURL URLWithString:[track objectForKey:@"Location"]];
[names addObject:[location path]];
NSString* persistentId = [track objectForKey:@"Persistent ID"];
NSDictionary* data;
if (tv) {
data = [NSDictionary dictionaryWithObject:persistentId
forKey:MZTVAppPersistentIDTagIdent];
} else {
data = [NSDictionary dictionaryWithObject:persistentId
forKey:MZiTunesPersistentIDTagIdent];
}
[dataDicts addObject:data];
}
[[MZMetaLoader sharedLoader] loadFromFiles:names toIndex:row withMetaData:dataDicts];
}
else if([first isKindOfClass:[NSArray class]])
[[MZMetaLoader sharedLoader] loadFromFiles:first toIndex:row];
else
[[MZMetaLoader sharedLoader] loadFromFile:first toIndex:row];
}
#pragma mark - private
- (BOOL)writeSelectionUncheckedToPasteboard:(NSPasteboard *)pboard
types:(NSArray *)types
{
[pboard declareTypes:types owner:nil];
if([types containsObject:MZMetaEditsDataType])
{
MetaEdits* selection = [[filesController arrangedObjects] objectAtIndex:[self selectedRow]];
NSData* data = [NSKeyedArchiver archivedDataWithRootObject:selection];
if(![pboard setData:data forType:MZMetaEditsDataType])
return NO;
}
if([types containsObject:NSFilenamesPboardType])
{
NSArray* selection = [[filesController arrangedObjects] objectsAtIndexes:[self selectedRowIndexes]];
selection = [selection arrayByPerformingSelector:@selector(loadedFileName)];
if(![pboard setPropertyList:selection forType:NSFilenamesPboardType])
return NO;
}
if([types containsObject:NSStringPboardType])
{
MetaEdits* selection = [[filesController arrangedObjects] objectAtIndex:[self selectedRow]];
if(![pboard setString:[selection loadedFileName] forType:NSStringPboardType])
return NO;
}
return YES;
}
- (void)registerUndoName:(NSUndoManager *)manager
{
[manager setActionName:NSLocalizedString(@"Paste Tags", @"Paste tags undo name")];
[manager registerUndoWithTarget:self
selector:@selector(registerUndoName:)
object:manager];
}
- (NSCell *)preparedCellAtColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex
{
NSCell* aCell = [super preparedCellAtColumn:columnIndex row:rowIndex];
NSTableColumn* column = [[self tableColumns] objectAtIndex:columnIndex];
if([[column identifier] isEqualToString:@"status"])
{
NSButtonCell* cell = (NSButtonCell*)aCell;
if([self isRowSelected:rowIndex])
{
[cell setAlternateImage:[NSImage imageNamed:@"modified_selected"]];
} else {
[cell setAlternateImage:[NSImage imageNamed:@"modified"]];
}
}
return aCell;
}
#pragma mark - general
- (void)awakeFromNib
{
NSTableColumn* status = [self tableColumnWithIdentifier:@"status"];
NSImage *image = [NSImage imageNamed:@"modified_header"];
[[status headerCell] setImage:image];
[self setDataSource:self];
NSSortDescriptor* sort = [NSSortDescriptor sortDescriptorWithKey:@"fileName" ascending:YES selector:@selector(numericCompare:)];
[self setSortDescriptors:[NSArray arrayWithObject:sort]];
}
- (void)keyDown:(NSEvent *)theEvent {
NSString* ns = [theEvent charactersIgnoringModifiers];
NSUInteger modifierFlags = [theEvent modifierFlags];
if([ns length] == 1)
{
unichar ch = [ns characterAtIndex:0];
switch(ch) {
case NSBackspaceCharacter:
case NSDeleteCharacter:
if([self numberOfSelectedRows] > 0 && (modifierFlags & NSEventModifierFlagCommand) == NSEventModifierFlagCommand )
{
[self delete:self];
return;
}
}
}
[super keyDown:theEvent];
}
-(NSUndoManager *)undoManager {
NSUndoManager* man = [undoController undoManager];
if(man != nil)
return man;
return [super undoManager];
}
@end