forked from phildow/Journler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportReviewController.m
724 lines (572 loc) · 19.8 KB
/
ImportReviewController.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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/*
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the
distribution.
* Neither the name of the author nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Basically, you can use the code in your free, commercial, private and public projects
// as long as you include the above notice and attribute the code to Philip Dow / Sprouted
// If you use this code in an app send me a note. I'd love to know how the code is used.
// Please also note that this copyright does not supersede any other copyrights applicable to
// open source code used herein. While explicit credit has been given in the Journler about box,
// it may be lacking in some instances in the source code. I will remedy this in future commits,
// and if you notice any please point them out.
#import "ImportReviewController.h"
#import "JournlerApplicationDelegate.h"
#import <SproutedUtilities/SproutedUtilities.h>
#import "JournlerEntry.h"
#import "JournlerCollection.h"
#import "JournlerJournal.h"
#import "JournlerSearchManager.h"
#import "ImportReviewTable.h"
#import "ImportReviewSourceList.h"
#import "BrowseTableFieldEditor.h"
#import "Definitions.h"
#define kSourceListSmallHeight 20.0
#define kSourceListSeparatorHeight 10.0
@implementation ImportReviewController
- (id) init
{
return [self initWithJournal:nil folders:nil entries:nil];
}
- (id) initWithJournal:(JournlerJournal*)aJournal folders:(NSArray*)theFolders entries:(NSArray*)theEntries
{
// designated initializer
if ( self = [self initWithWindowNibName:@"BulkImportReview"] )
{
_importHasBegun = NO;
_continuing = YES;
_finishedImport = NO;
_entries = [theEntries retain];
folders = [theFolders retain];
journal = [aJournal retain];
[[NSApp delegate] prepareLabelMenu:&labelMenu];
[self retain];
}
return self;
}
- (void) windowDidLoad
{
[foldersOutline setIntercellSpacing:NSMakeSize(0.0,0.0)];
[foldersController setSelectionIndexPath:[NSIndexPath indexPathWithIndex:0]];
// the custom field editor
[browseTableFieldEditor retain];
[browseTableFieldEditor setFieldEditor:YES];
NSInteger borders[4] = {0,0,0,0};
[gradient setBorders:borders];
[gradient setBordered:NO];
// tags token field cell
PDTokenFieldCell *tokenCell = [[[PDTokenFieldCell alloc] init] autorelease];
[tokenCell setFont:[NSFont controlContentFontOfSize:11]];
[tokenCell setControlSize:NSSmallControlSize];
[tokenCell setDelegate:self];
[tokenCell setBezeled:NO];
[tokenCell setBordered:NO];
[[entriesTable tableColumnWithIdentifier:@"tags"] setDataCell:tokenCell];
[foldersOutline bind:@"font" toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.FoldersTableFont" options:[NSDictionary dictionaryWithObjectsAndKeys:
@"NSUnarchiveFromData", NSValueTransformerNameBindingOption,
[NSFont controlContentFontOfSize:11], NSNullPlaceholderBindingOption, nil]];
[foldersOutline bind:@"backgroundColor" toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.FolderBackgroundColor" options:[NSDictionary dictionaryWithObjectsAndKeys:
@"NSUnarchiveFromData", NSValueTransformerNameBindingOption,
[NSColor colorWithCalibratedHue:234.0/400.0 saturation:1.0/100.0 brightness:97.0/100.0 alpha:1.0], NSNullPlaceholderBindingOption, nil]];
[foldersOutline sizeToFit];
//import review note
//import review target folder
NSMutableString *tip = [NSMutableString string];
[tip appendString:NSLocalizedString(@"import review note",@"")];
[tipField setStringValue:tip];
}
- (void) dealloc
{
#ifdef __DEBUG__
NSLog(@"%s",__PRETTY_FUNCTION__);
#endif
[_entries release];
[journal release];
[folders release];
[browseTableFieldEditor release];
[super dealloc];
}
- (void)windowWillClose:(NSNotification *)aNotification
{
#ifdef __DEBUG__
NSLog(@"%s",__PRETTY_FUNCTION__);
#endif
if ( [aNotification object] == [self window] )
{
//[entriesController unbind:@"contentArray"];
//[entriesController unbind:@"contentArrayForMultipleSelection"];
//[entriesController setContent:nil];
//[foldersController unbind:@"contentArray"];
//[foldersController setContent:nil];
[foldersOutline setDelegate:nil];
[objectController unbind:@"contentObject"];
[objectController setContent:nil];
}
[self autorelease];
}
#pragma mark -
- (JournlerJournal*) journal
{
return journal;
}
- (void) setJournal:(JournlerJournal*)aJournal
{
if ( journal != aJournal )
{
[journal release];
journal = [aJournal retain];
}
}
- (NSArray*) entries
{
return _entries;
}
- (void) setEntries:(NSArray*)entryContent
{
if ( _entries != entryContent )
{
[_entries release];
_entries = [entryContent retain];
}
}
- (NSArray*) folders
{
return folders;
}
- (void) setFolders:(NSArray*)theFolders
{
if ( folders != theFolders )
{
[folders release];
folders = [theFolders retain];
}
}
- (BOOL) userInteraction
{
return _userInteraction;
}
- (void) setUserInteraction:(BOOL)visual
{
_userInteraction = visual;
}
- (BOOL) preserveModificationDate
{
return _preserveModificationDate;
}
- (void) setPreserveModificationDate:(BOOL)preserve
{
_preserveModificationDate = preserve;
}
#pragma mark -
- (NSInteger) runAsSheetForWindow:(NSWindow*)window attached:(BOOL)sheet targetCollection:(JournlerCollection*)aFolder
{
NSInteger result = NSRunStoppedResponse;
_targetFolder = aFolder;
if ( _userInteraction )
{
if ( sheet )
[NSApp beginSheet: [self window] modalForWindow: window modalDelegate: nil
didEndSelector: nil contextInfo: nil];
NSModalSession session = [NSApp beginModalSessionForWindow:[self window]];
// change the tip
NSMutableString *tip = [NSMutableString string];
[tip appendString:NSLocalizedString(@"import review note",@"")];
if ( aFolder == nil || [aFolder isLibrary] )
[tipField setStringValue:tip];
else
{
NSString *targetString = [NSString stringWithFormat:NSLocalizedString(@"import review target folder",@""), [aFolder title]];
[tip appendFormat:@" %@", targetString];
[tipField setStringValue:tip];
}
for (;;)
{
result = [NSApp runModalSession:session];
if ( result != NSRunContinuesResponse || _continuing == NO || _finishedImport == YES )
break;
[[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
[NSApp endModalSession:session];
if ( sheet )
[NSApp endSheet: [self window]];
/*
result = [NSApp runModalForWindow:[self window]];
if ( result == NSRunStoppedResponse )
{
[self _performImport:nil];
}
*/
[self close];
//[[self window] orderOut:self];
//[[self window] close];
return result;
}
else
{
[self performImport:NO];
return NSRunStoppedResponse;
}
}
#pragma mark -
- (IBAction)cancel:(id)sender
{
_continuing = NO;
//[NSApp abortModal];
}
- (IBAction)okay:(id)sender
{
if ( _importHasBegun )
NSBeep();
else
{
if ( ![objectController commitEditing] )
NSLog(@"%s - unable to commit editing", __PRETTY_FUNCTION__);
_importHasBegun = YES;
[tipField setHidden:YES];
//[self performImport:YES];
[self performImport:NO];
//[NSApp stopModal];
}
}
- (IBAction)help:(id)sender
{
[[NSHelpManager sharedHelpManager] openHelpAnchor:@"JournlerImporting" inBook:@"JournlerHelp"];
}
- (IBAction)log:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:@"/tmp/jrlrbulkimportlog.txt"]];
}
#pragma mark -
- (BOOL)windowShouldClose:(id)sender
{
//if ( sender == previewWin )
// [NSApp stopModal];
return YES;
}
- (IBAction)preview:(id)sender
{
if ( [[entriesController selectedObjects] count] != 1 )
{
NSBeep(); return;
}
NSAttributedString *attr = [[[entriesController selectedObjects] objectAtIndex:0] attributedContent];
if ( !attr )
return;
[[previewText textStorage] beginEditing];
[[previewText textStorage] setAttributedString:attr];
[[previewText textStorage] endEditing];
[previewWin makeKeyAndOrderFront:self];
//[NSApp runModalForWindow:previewWin];
//[previewWin orderOut:self];
}
- (IBAction) editEntryLabel:(id)sender
{
NSArray *theEntries;
// grab the available entries from the controller
theEntries = [entriesController selectedObjects];
if ( theEntries == nil || [theEntries count] == 0 ) {
NSBeep(); return;
}
[theEntries setValue:[NSNumber numberWithInteger:[sender tag]] forKey:@"label"];
}
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
{
BOOL enabled = NO;
if ( [menuItem tag] == 841 && [[entriesController selectedObjects] count] == 1)
enabled = YES;
return enabled;
}
#pragma mark -
#pragma mark Performing the Import
- (void) performImport:(BOOL)threaded {
if ( threaded )
[NSThread detachNewThreadSelector:@selector(_performImport:) toTarget:self withObject:nil];
else
[self _performImport:nil];
}
- (void) _performImport:(id)anObject {
NSInteger i;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if ( _userInteraction ) {
[progress setHidden:NO];
[progress setMaxValue:[_entries count]];
[okayButton setEnabled:NO];
[[self window] display];
}
NSInteger entryImportOptions = 0;
NSInteger kMaxWidth = ( [[NSUserDefaults standardUserDefaults] boolForKey:@"EmbeddedImageUseFullSize"] ? 0
: [[NSUserDefaults standardUserDefaults] integerForKey:@"EmbeddedImageMaxWidth"] );
NSSize maxPreviewSize = NSMakeSize(kMaxWidth,kMaxWidth);
if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"NewMediaLinkIncludeIcon"] )
entryImportOptions |= kEntryImportIncludeIcon;
if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"EntryImportSetDefaultResource"] )
entryImportOptions |= kEntryImportSetDefaultResource;
if ( _preserveModificationDate )
entryImportOptions |= kEntryImportPreserveDateModified;
NSArray *theEntries = [self entries];
NSArray *theFolders = [self folders];
// disabled threaded indexing during the import
BOOL wasThreaded = [[[self journal] searchManager] indexesOnSeparateThread];
[[[self journal] searchManager] setIndexesOnSeparateThread:NO];
// iterate through the entries, adding them to the journal
for ( i = 0; i < [theEntries count]; i++ )
{
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
BOOL err = NO, addToTargetFolder = NO;
JournlerEntry *anEntry = [theEntries objectAtIndex:i];
if ( !_continuing )
{
[innerPool release];
break;
}
// if the entry is not already in any of the preserved folders, add it to the target folder
if ( _targetFolder != nil && ( [anEntry collections] == nil || [[anEntry collections] count] == 0 ) )
addToTargetFolder = YES;
// temporarily disable searching and indexing
[[self journal] setSaveEntryOptions:kEntrySaveDoNotIndex|kEntrySaveDoNotCollect];
// add the import to the journal
[[self journal] addEntry:anEntry];
// save the entry to guarantee a file location
if ( ![[self journal] saveEntry:anEntry] )
{
// error
err = YES;
}
else
{
// complete the import
if ( ![anEntry completeImport:entryImportOptions operation:kNewResourceForceCopy maxPreviewSize:maxPreviewSize] )
{
// error
err = YES;
}
else
{
// save the entry once more, indexing and collecting
[[self journal] setSaveEntryOptions:kEntrySaveIndexAndCollect];
if ( ![[self journal] saveEntry:anEntry] )
{
// error
err = YES;
}
// mark the entry's resources as no longer dirty
[[anEntry valueForKey:@"resources"] setValue:[NSNumber numberWithBool:NO] forKey:@"dirty"];
// add the entry to the target folder
if ( addToTargetFolder )
{
if ( [_targetFolder isRegularFolder] )
[_targetFolder addEntry:anEntry];
else if ( [_targetFolder isSmartFolder] )
[_targetFolder autotagEntry:anEntry add:YES];
}
}
}
// handle the folders
/*
if ( _targetFolder ) {
if ( [[_targetFolder valueForKey:@"tagID"] integerValue] == PDCollectionTypeIDTrash )
[[self journal] markEntryForTrash:anEntry];
else
[_targetFolder addEntry:anEntry];
}
*/
if ( _userInteraction )
{
// updateh the progres indicator if user interaction
[progress incrementBy:1];
[progress performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:YES];
}
// let go of the autoreleased objects
[innerPool release];
}
if ( _continuing )
{
// iterate through the folders, adding them to the journal (only regular folders)
JournlerCollection *folderParent = ( _targetFolder == nil ? [[self journal] rootCollection] : _targetFolder );
for ( i = 0; i < [theFolders count]; i++ )
{
if ( [[theFolders objectAtIndex:i] isRegularFolder] )
{
[self addFolderToJournal:[theFolders objectAtIndex:i]];
[folderParent addChild:[theFolders objectAtIndex:i]];
}
}
// reload root list
[[self journal] setRootFolders:nil];
}
// double check to ensure the journal is indexing and collecting
[[self journal] setSaveEntryOptions:kEntrySaveIndexAndCollect];
// reset threaded indexing state
[[[self journal] searchManager] setIndexesOnSeparateThread:wasThreaded];
_finishedImport = YES;
[pool release];
}
- (void) addFolderToJournal:(JournlerCollection*)aFolder
{
if ( ![aFolder isRegularFolder] )
return;
// add this folder to the journal and save it
[[self journal] addCollection:aFolder];
[[self journal] saveCollection:aFolder];
// do the same for the folder's children
NSInteger i;
NSArray *kids = [aFolder children];
for ( i = 0; i < [kids count]; i++ )
[self addFolderToJournal:[kids objectAtIndex:i]];
}
#pragma mark -
#pragma mark Window Delegation
- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
{
if ( [self window] != sender )
return nil;
if ( [anObject isKindOfClass:[ImportReviewTable class]] && [(ImportReviewTable*)anObject editingCategory] )
{
[browseTableFieldEditor setCompletions:[[NSUserDefaults standardUserDefaults] arrayForKey:@"Journler Categories List"]];
[browseTableFieldEditor setCompletes:YES];
return browseTableFieldEditor;
}
else
{
return nil;
}
}
#pragma mark -
#pragma mark OutlineView Delegation
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
JournlerCollection *actualItem;
// necessary hack to get around NSTreeController proxy object, 10.5 compatible
if ( [item respondsToSelector:@selector(representedObject)] )
actualItem = [item representedObject];
else if ( [item respondsToSelector:@selector(observedObject)] )
actualItem = [item observedObject];
else
actualItem = item;
return ![actualItem isSeparatorFolder];
}
- (float)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
{
JournlerCollection *actualItem;
// necessary hack to get around NSTreeController proxy object, 10.5 compatible
if ( [item respondsToSelector:@selector(representedObject)] )
actualItem = [item representedObject];
else if ( [item respondsToSelector:@selector(observedObject)] )
actualItem = [item observedObject];
else
actualItem = item;
if ( [actualItem isSeparatorFolder] )
return kSourceListSeparatorHeight;
else
return kSourceListSmallHeight;
}
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
if ([[tableColumn identifier] isEqualToString: @"title"])
{
// Set the image here since the value returned from
// outlineView:objectValueForTableColumn:... didn't specify the image part...
JournlerCollection *actualItem;
// necessary hack to get around NSTreeController proxy object, 10.5 compatile
if ( [item respondsToSelector:@selector(representedObject)] )
actualItem = [item representedObject];
else if ( [item respondsToSelector:@selector(observedObject)] )
actualItem = [item observedObject];
else
actualItem = item;
// separator?
[(ImageAndTextCell*)cell setIsSeparatorCell:[actualItem isSeparatorFolder]];
// set the image
[(ImageAndTextCell*)cell setImage:[actualItem valueForKey:@"icon"]];
// let the cell know what size of image to use
[(ImageAndTextCell*)cell setImageSize:NSMakeSize(kSourceListSmallHeight,kSourceListSmallHeight)];
// show the count
[(ImageAndTextCell*)cell setContentCount:[[actualItem entries] count]];
// set selected
[(ImageAndTextCell*)cell setSelected:( [[outlineView selectedRowIndexes] containsIndex:[outlineView rowForItem:item]] )];
}
}
- (void) importReviewSourceList:(ImportReviewSourceList*)aSourceList deleteFolders:(NSNotification*)aNotification
{
// #warning doesn't work, causes crash
for ( id anObject in [foldersController selectedObjects] )
{
JournlerCollection *aFolder;
// necessary hack, 10.5 compatible
if ( [anObject respondsToSelector:@selector(representedObject)] )
aFolder = [anObject representedObject];
else if ( [anObject respondsToSelector:@selector(observedObject)] )
aFolder = [anObject observedObject];
else
aFolder = anObject;
if ( [aFolder isLibrary] )
NSBeep();
else
[self deleteFolder:aFolder];
}
}
#pragma mark -
#pragma mark TableView Delegation
- (void) importReviewTable:(ImportReviewTable*)aTable deleteEntries:(NSNotification*)aNotification
{
NSArray *theEntries = [entriesController selectedObjects];
[self deleteEntries:theEntries];
}
#pragma mark -
#pragma mark NSTokenFieldCell Delegation
- (NSArray *)tokenFieldCell:(NSTokenFieldCell *)tokenFieldCell completionsForSubstring:(NSString *)substring
indexOfToken:(NSInteger )tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex
{
//NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self beginswith[cd] %@", substring];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self beginswith %@", substring];
NSArray *completions = [[[[self journal] entryTags] allObjects] filteredArrayUsingPredicate:predicate];
return completions;
}
#pragma mark -
#pragma mark Deleting Entries and Folders
- (void) deleteEntries:(NSArray*)theEntries
{
for ( JournlerCollection *aFolder in [self folders] )
{
for ( JournlerEntry *anEntry in theEntries )
[aFolder removeEntry:anEntry];
}
// remove the entries from the main entries list
NSMutableArray *myEntries = [[[self entries] mutableCopyWithZone:[self zone]] autorelease];
[myEntries removeObjectsInArray:theEntries];
[self setEntries:myEntries];
}
- (void) deleteFolder:(JournlerCollection*)aFolder
{
// delete all the entries contained in the folder
NSArray *entries = [aFolder entries];
[self deleteEntries:entries];
// remove the folder from its parent, or from the main array if the parent is nil
if ( [aFolder parent] == nil )
{
NSMutableArray *myFolders = [[[self folders] mutableCopyWithZone:[self zone]] autorelease];
[myFolders removeObject:aFolder];
[self setFolders:myFolders];
}
else
{
[[aFolder parent] removeChild:aFolder recursively:YES];
}
}
@end