forked from phildow/Journler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewEntryController.m
742 lines (571 loc) · 21.9 KB
/
NewEntryController.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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
/*
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 "NewEntryController.h"
#import "Definitions.h"
#import "JournlerCollection.h"
#import "JournlerJournal.h"
#import "JournlerEntry.h"
#import "JournlerCondition.h"
#import "DropBoxFoldersController.h"
#import "DropBoxSourceList.h"
#import <SproutedUtilities/SproutedUtilities.h>
#import <SproutedInterface/SproutedInterface.h>
/*
#import "LabelPicker.h"
#import "PDGradientView.h"
#import "NSOutlineView_Extensions.h"
#import "NSOutlineView_ProxyAdditions.h"
#import "NSString+PDStringAdditions.h"
*/
@implementation NewEntryController
static NSSortDescriptor *FoldersByIndexSortPrototype()
{
static NSSortDescriptor *descriptor = nil;
if ( descriptor == nil )
{
descriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES selector:@selector(compare:)];
}
return descriptor;
}
#pragma mark -
- (id) init
{
return [self initWithJournal:nil];
}
- (id)initWithJournal:(JournlerJournal*)aJournal
{
if ( self = [self initWithWindowNibName:@"NewEntry"] )
{
journal = aJournal;
title = [NSLocalizedString(@"untitled title", @"") retain];
category = [[NSString alloc] init];
tags = [[NSArray alloc] init];
date = [[NSDate date] retain];
dateDue = [[NSDate date] retain];
marking = [NSNumber numberWithInteger:0];
alreadyEditedCategory = NO;
[self window];
}
return self;
}
- (void) windowDidLoad
{
[[self window] setAutorecalculatesKeyViewLoop:YES];
[containerView setBordered:NO];
// prepare the collections
/*
NSMenu *collectionsMenu = [[[NSMenu alloc] init] autorelease];
[[self valueForKeyPath:@"journal.rootCollection"] flatMenuRepresentation:&collectionsMenu
target:self action:@selector(selectFolder:) smallImages:YES inset:0];
[collectionsMenu setAutoenablesItems:NO];
// go through the menu and disable anything that isn't a folder
NSInteger i;
for ( i = [collectionsMenu numberOfItems]-1; i >= 0; i-- )
{
if ( [[collectionsMenu itemAtIndex:i] representedObject] == nil )
[[collectionsMenu itemAtIndex:i] setEnabled:NO];
//else if ( [[[[collectionsMenu itemAtIndex:i] representedObject] valueForKey:@"typeID"] integerValue] != PDCollectionTypeIDFolder )
// [[collectionsMenu itemAtIndex:i] setEnabled:NO];
if ( [[[collectionsMenu itemAtIndex:i] representedObject] isSmartFolder] && ![[[collectionsMenu itemAtIndex:i] representedObject] canAutotag:nil] )
[[collectionsMenu itemAtIndex:i] setEnabled:NO];
if ( [[[[collectionsMenu itemAtIndex:i] representedObject] valueForKey:@"typeID"] integerValue] == PDCollectionTypeIDLibrary )
[collectionsMenu removeItemAtIndex:i];
else if ( [[[[collectionsMenu itemAtIndex:i] representedObject] valueForKey:@"typeID"] integerValue] == PDCollectionTypeIDTrash )
[collectionsMenu removeItemAtIndex:i];
}
[collectionsMenu insertItem:[NSMenuItem separatorItem] atIndex:0];
[collectionsMenu insertItemWithTitle:NSLocalizedString(@"no selection",@"") action:nil keyEquivalent:@"" atIndex:0];
[collectionField setMenu:collectionsMenu];
*/
// prepare the categories and select the default
NSArray *categoriesList = [[NSUserDefaults standardUserDefaults] arrayForKey:@"Journler Categories List"];
[categoryField addItemsWithObjectValues:
[categoriesList sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] ];
[self setCategory:[JournlerEntry defaultCategory]];
if ( [categoryField numberOfVisibleItems] > [categoryField numberOfItems] )
[categoryField setNumberOfVisibleItems:[categoryField numberOfItems]];
// disclose if last selection asked for it
[disclose setState:[[NSUserDefaults standardUserDefaults] integerForKey:@"NewEntryDiscloseState"]];
[self disclose:disclose];
[self bind:@"includeDateDue" toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.NewEntryWithDueDate" options:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], NSNullPlaceholderBindingOption, nil]];
// the folders controller must know the actual root (vs. the roots children)
[sourceController setRootCollection:[[self journal] valueForKey:@"rootCollection"]];
// populate the list with regular and smart folders
NSPredicate *folderFilter = [NSPredicate predicateWithFormat:@"isRegularFolder == YES OR isSmartFolder == YES"];
NSArray *filteredFolders = [[[self journal] rootFolders] filteredArrayUsingPredicate:folderFilter];
[sourceController setContent:filteredFolders];
// set the sort descriptors on the source list
[sourceController setSortDescriptors:[NSArray arrayWithObject:FoldersByIndexSortPrototype()]];
// appearance bindings
/*
[sourceList bind:@"font" toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.FoldersTableFont" options:[NSDictionary dictionaryWithObjectsAndKeys:
@"NSUnarchiveFromData", NSValueTransformerNameBindingOption,
[NSFont controlContentFontOfSize:11], NSNullPlaceholderBindingOption, nil]];
*/
[sourceList 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]];
// source list state
NSArray *sourceListState;
NSData *sourceListStateData;
if ( ( sourceListStateData = [[NSUserDefaults standardUserDefaults] dataForKey:@"NewEntrySourceListState"] ) != nil
&& ( sourceListState = [NSKeyedUnarchiver unarchiveObjectWithData:sourceListStateData] ) != nil )
[sourceList restoreStateFromArray:sourceListState];
}
- (void) dealloc
{
#ifdef __DEBUG__
NSLog(@"%s",__PRETTY_FUNCTION__);
#endif
[category release];
[title release];
[tags release];
[date release];
[marking release];
[tagCompletions release];
[super dealloc];
}
- (void)windowWillClose:(NSNotification *)aNotification {
NSArray *sourceListState = [sourceList stateArray];
NSData *sourceListStateData = [NSKeyedArchiver archivedDataWithRootObject:sourceListState];
[[NSUserDefaults standardUserDefaults] setObject:sourceListStateData forKey:@"EntryEntrySourceListState"];
[sourceList setDelegate:nil];
[self unbind:@"includeDateDue"];
[objectController unbind:@"contentObject"];
[objectController setContent:nil];
}
#pragma mark -
- (JournlerJournal*) journal
{
return journal;
}
- (void) setJournal:(JournlerJournal*)aJournal
{
journal = aJournal;
}
- (NSString*) title
{
return title;
}
- (void) setTitle:(NSString*)aString
{
if ( title != aString )
{
[title release];
title = [aString copyWithZone:[self zone]];
}
}
- (NSDate*) date
{
return date;
}
- (void) setDate:(NSDate*)aDate
{
if ( date != aDate )
{
[date release];
date = [aDate copyWithZone:[self zone]];
}
}
- (NSDate*) dateDue
{
return dateDue;
}
- (void) setDateDue:(NSDate*)aDate
{
if ( dateDue != aDate )
{
[dateDue release];
dateDue = [aDate copyWithZone:[self zone]];
}
}
- (BOOL) includeDateDue
{
return includeDateDue;
}
- (void) setIncludeDateDue:(BOOL)include
{
includeDateDue = include;
}
- (NSArray*) tags
{
return tags;
}
- (void) setTags:(NSArray*)anArray
{
if ( tags != anArray )
{
[tags release];
tags = [anArray copyWithZone:[self zone]];
}
}
- (NSString*) category
{
return category;
}
- (void) setCategory:(NSString*)aString
{
if ( category != aString )
{
[category release];
category = [aString copyWithZone:[self zone]];
}
}
- (NSNumber*) marking
{
return marking;
}
- (void) setMarking:(NSNumber*)aNumber
{
if ( marking != aNumber )
{
[marking release];
marking = [aNumber copyWithZone:[self zone]];
}
}
- (NSNumber*) labelValue
{
return [NSNumber numberWithInteger:[labelPicker labelSelection]];
}
- (void) setLabelValue:(NSNumber*)aNumber
{
[labelPicker setLabelSelection:[aNumber integerValue]];
[labelPicker setNeedsDisplay:YES];
}
- (NSArray*) tagCompletions
{
return tagCompletions;
}
- (void) setTagCompletions:(NSArray*)anArray
{
if ( tagCompletions != anArray )
{
[tagCompletions release];
tagCompletions = [anArray copyWithZone:[self zone]];
}
}
#pragma mark -
// DEPRECATED
- (JournlerCollection*) selectedCollection
{
return [[collectionField selectedItem] representedObject];
}
// DEPRECATED
- (void) setSelectedCollection:(JournlerCollection*)aCollection
{
// go through the menu looking at the represented items, select the appropriate one
if ( ![self isWindowLoaded] ) [self window];
if ( aCollection )
{
[collectionField selectItemWithTag:[[aCollection valueForKey:@"tagID"] integerValue]];
[self selectFolder:[collectionField selectedItem]];
}
}
- (NSArray*) selectedFolders
{
return [sourceController selectedObjects];
}
- (void) setSelectedFolders:(NSArray*)anArray
{
if ( anArray == nil ) return;
if ( ![self isWindowLoaded] ) [self window];
BOOL firstSelection = YES;
for ( JournlerCollection *aFolder in anArray )
{
if ( [aFolder isRegularFolder] || ( [aFolder isSmartFolder] && [aFolder canAutotag:nil] ) )
{
[sourceController selectCollection:aFolder byExtendingSelection:YES];
if ( firstSelection == YES )
{
[sourceList scrollRowToVisible:[sourceList rowForOriginalItem:aFolder]];
firstSelection = NO;
}
}
}
}
#pragma mark -
// DEPRECATED
- (IBAction) selectFolder:(id)sender
{
// gives me a chance to update our visual cues based on the folders conditions
// support or conditioning so that the list number of conditions are set
if ( YES )
{
return;
}
JournlerCollection *theFolder = [sender representedObject];
if ( theFolder == nil )
{
NSBeep(); return;
}
// attempt to autotag the entry based on my conditions and the conditions of my parents
// this should be a category on ns predicate
BOOL added = YES;
NSArray *allConditions = [theFolder allConditions:YES];
#ifdef __DEBUG __
NSLog([allConditions description]);
#endif
// clear the category field if this folder edits the category
if ( alreadyEditedCategory == NO && [theFolder autotagsKey:@"category"] )
{
alreadyEditedCategory = YES;
[self setCategory:[NSString string]];
}
// supported conditions:
// 1. title 2. category 3. keywords 4. label 5. mark
for ( NSDictionary *aDictionary in allConditions )
{
NSArray *localConditions = [aDictionary objectForKey:@"conditions"];
NSNumber *localCombination = [aDictionary objectForKey:@"combinationStyle"];
BOOL alreadyAddedLocal = NO;
for ( NSString *aCondition in localConditions )
{
NSDictionary *conditionOp = [JournlerCondition operationForCondition:aCondition entry:nil];
#ifdef __DEBUG_
NSLog([conditionOp description]);
#endif
if ( conditionOp == nil )
{
// don't worry about it, a later condition will suffice (we already checked for canAutotag, so it should be there)
if ( [localCombination integerValue] == 0 )
continue;
// otherwise, we're finished
else if ( [localCombination integerValue] == 1 )
{
added = NO;
goto bail;
}
}
// we're finished if one of the conditions from this set has already been added and the op is any
else if ( alreadyAddedLocal == YES && [localCombination integerValue] == 0 )
continue;
id theOriginalValue;
id theValue = [conditionOp objectForKey:kOperationDictionaryKeyValue];
NSString *theKey = [conditionOp objectForKey:kOperationDictionaryKeyKey];
NSInteger theOperation = [[conditionOp objectForKey:kOperationDictionaryKeyOperation] integerValue];
// make some modifications to the key to support our keys
//if ( [theKey isEqualToString:@"keywords"] )
// theKey = @"tags";
if ( [theKey isEqualToString:@"marked"] )
theKey = @"marking";
else if ( [theKey isEqualToString:@"label"] )
theKey = @"labelValue";
switch ( theOperation )
{
case kKeyOperationNilOut:
// the simplest operation, for use with tags right now
[self setValue:nil forKey:theKey];
break;
case kKeyOperationAddObjects:
theOriginalValue = (NSMutableArray*)[[[self valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
[(NSMutableArray*)theOriginalValue addObjectsFromArray:theValue];
[self setValue:theOriginalValue forKey:theKey];
break;
case kKeyOperationRemoveObjects:
theOriginalValue = (NSMutableArray*)[[[self valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
[(NSMutableArray*)theOriginalValue removeObjectsInArray:theValue];
[self setValue:theOriginalValue forKey:theKey];
break;
case kKeyOperationSetString:
theOriginalValue = (NSMutableString*)[[[self valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
[(NSMutableString*)theOriginalValue setString:theValue];
[self setValue:theOriginalValue forKey:theKey];
break;
case kKeyOperationSetNumber:
// easy
[self setValue:theValue forKey:theKey];
break;
case kKeyOperationSetAttributedString:
//theOriginalValue = [[[NSAttributedString alloc] initWithString:theValue attributes:[JournlerEntry defaultTextAttributes]] autorelease];
//[self setValue:theOriginalValue forKey:theKey];
break;
case kKeyOperationAppendString:
theOriginalValue = (NSMutableString*)[[[self valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
if ( [theOriginalValue length] == 0 )
[(NSMutableString*)theOriginalValue setString:theValue];
else if ( [theOriginalValue rangeOfString:theValue options:NSCaseInsensitiveSearch range:NSMakeRange(0,[theOriginalValue length])].location == NSNotFound )
[(NSMutableString*)theOriginalValue appendFormat:@" %@", theValue];
[self setValue:theOriginalValue forKey:theKey];
break;
case kKeyOperationRemoveString:
theOriginalValue = (NSMutableString*)[[[self valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
[(NSMutableString*)theOriginalValue replaceOccurrencesOfString:theValue
withString:[NSString string] options:NSCaseInsensitiveSearch range:NSMakeRange(0,[theOriginalValue length])];
[self setValue:theOriginalValue forKey:theKey];
break;
case kKeyOperationPrependString:
theOriginalValue = (NSMutableString*)[[[self valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
if ( [theOriginalValue length] == 0 )
[(NSMutableString*)theOriginalValue setString:theValue];
else if ( [theOriginalValue rangeOfString:theValue options:NSCaseInsensitiveSearch range:NSMakeRange(0,[theOriginalValue length])].location != 0 )
[(NSMutableString*)theOriginalValue insertString:[NSString stringWithFormat:@"%@ ", theValue] atIndex:0];
[self setValue:theOriginalValue forKey:theKey];
break;
case kKeyOperationAppendAttributedString:
/*
theOriginalValue = (NSMutableAttributedString*)[[[anEntry valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
if ( [theOriginalValue length] == 0 )
[(NSMutableAttributedString*)theOriginalValue setAttributedString:
[[[NSAttributedString alloc] initWithString:theValue attributes:[JournlerEntry defaultTextAttributes]] autorelease]];
else
[(NSMutableAttributedString*)theOriginalValue replaceCharactersInRange:NSMakeRange([theOriginalValue length],0) withString:[NSString stringWithFormat:@" %@", theValue]];
[anEntry setValue:theOriginalValue forKey:theKey];
*/
break;
case kKeyOperationRemoveAttributedString:
/*
theOriginalValue = (NSMutableAttributedString*)[[[anEntry valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
//else if ( [[(NSMutableAttributedString*) theOriginalValue string] rangeOfString:theValue options:NSCaseInsensitiveSearch range:NSMakeRange(0,[theOriginalValue length])].location != 0 )
// [(NSMutableAttributedString*)theOriginalValue
#warning get the else here working
[anEntry setValue:theOriginalValue forKey:theKey];
*/
break;
case kKeyOperationPrependAttributedString:
/*
theOriginalValue = (NSMutableAttributedString*)[[[anEntry valueForKey:theKey] mutableCopyWithZone:[self zone]] autorelease];
if ( [theOriginalValue length] == 0 )
[(NSMutableAttributedString*)theOriginalValue setAttributedString:
[[[NSAttributedString alloc] initWithString:theValue attributes:[JournlerEntry defaultTextAttributes]] autorelease]];
else
[(NSMutableAttributedString*)theOriginalValue replaceCharactersInRange:NSMakeRange(0,0) withString:[NSString stringWithFormat:@"%@ ", theValue]];
[anEntry setValue:theOriginalValue forKey:theKey];
*/
break;
}
alreadyAddedLocal = YES;
}
}
bail:
return;
}
- (IBAction) didChangeCategory:(id)sender
{
alreadyEditedCategory = YES;
}
- (void)comboBoxSelectionDidChange:(NSNotification *)aNotification
{
if ( [aNotification object] == categoryField )
[self didChangeCategory:categoryField];
}
- (void)controlTextDidChange:(NSNotification *)aNotification
{
if ( [aNotification object] == categoryField )
[self didChangeCategory:categoryField];
}
#pragma mark -
- (NSInteger) runAsSheetForWindow:(NSWindow*)window attached:(BOOL)sheet
{
NSInteger result;
if ( sheet )
[NSApp beginSheet: [self window] modalForWindow: window modalDelegate: nil
didEndSelector: nil contextInfo: nil];
result = [NSApp runModalForWindow: [self window]];
if ( ![objectController commitEditing] )
NSLog(@"%s - unable to commit editing", __PRETTY_FUNCTION__);
if ( sheet )
[NSApp endSheet: [self window]];
[self close];
return result;
}
#pragma mark -
- (IBAction)cancel:(id)sender
{
[NSApp abortModal];
}
- (IBAction)okay:(id)sender
{
[NSApp stopModal];
}
- (IBAction)disclose:(id)sender
{
NSRect newFrame;
NSRect contentRect;
// expand the window
switch ( [sender state] )
{
case NSOnState:
//height = 288 resize the window
contentRect = [[self window] contentRectForFrameRect:[[self window] frame]];
contentRect.origin.y = contentRect.origin.y + contentRect.size.height - 412;
contentRect.size.height = 412;
newFrame = [[self window] frameRectForContentRect:contentRect];
[[self window] setFrame:newFrame display:YES animate:YES];
[advancedView setFrame:NSMakeRect(0,45,390,250)];
[containerView addSubview:advancedView];
break;
case NSOffState:
//height = 172 resize the window
[advancedView removeFromSuperview];
contentRect = [[self window] contentRectForFrameRect:[[self window] frame]];
contentRect.origin.y = contentRect.origin.y + contentRect.size.height - 172;
contentRect.size.height = 172;
newFrame = [[self window] frameRectForContentRect:contentRect];
[[self window] setFrame:newFrame display:YES animate:YES];
break;
}
[[self window] recalculateKeyViewLoop];
[[NSUserDefaults standardUserDefaults] setInteger:[sender state] forKey:@"NewEntryDiscloseState"];
}
- (IBAction)help:(id)sender
{
[[NSHelpManager sharedHelpManager] openHelpAnchor:@"EntryCreation" inBook:@"JournlerHelp"];
}
#pragma mark -
#pragma mark NSTokenFieldCell Delegation
- (BOOL)tokenField:(NSTokenField *)tokenField hasMenuForRepresentedObject:(id)representedObject
{
return NO;
}
- (NSMenu *)tokenField:(NSTokenField *)tokenField menuForRepresentedObject:(id)representedObject
{
return nil;
}
- (NSArray *)tokenField:(NSTokenField *)tokenField 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 tagCompletions] filteredArrayUsingPredicate:predicate];
return completions;
}
- (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index
{
NSMutableArray *modifiedArray = [NSMutableArray array];
for ( NSString *aString in tokens )
{
if ( ![aString isOnlyWhitespace] )
//[modifiedArray addObject:[aString lowercaseString]];
[modifiedArray addObject:aString];
}
return modifiedArray;
}
@end