forked from phildow/Journler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJournalTabController.m
4577 lines (3706 loc) · 149 KB
/
JournalTabController.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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// JournalTabController.m
// Journler
//
// Created by Philip Dow on 10/24/06.
// Copyright 2006 Sprouted, Philip Dow. All rights reserved.
//
/*
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 "JournalTabController.h"
#import "JournlerWindowController.h"
#import "Definitions.h"
#import "JournlerApplicationDelegate.h"
#import "JournlerEntry.h"
#import "JournlerCollection.h"
#import "JournlerJournal.h"
#import "JournlerSearchManager.h"
#import "FoldersController.h"
#import "DatesController.h"
#import "EntriesController.h"
#import "ResourceController.h"
#import "Calendar.h"
#import "EntryCellController.h"
#import "ResourceCellController.h"
#import "EntryFilterController.h"
#import <SproutedUtilities/SproutedUtilities.h>
#import "PDBorderedFill.h"
#import "NSAttributedString+JournlerAdditions.h"
#import "NSAlert+JournlerAdditions.h"
#import "EntriesTableView.h"
#import "ResourceTableView.h"
#import "CollectionsSourceList.h"
#import "LinksOnlyNSTextView.h"
#import "CalendarController.h"
#import "EntryWindowController.h"
#import "IntelligentCollectionController.h"
#import "FolderInfoController.h"
#import "NewEntryController.h"
#import "EntryInfoController.h"
#import "MultipleEntryInfoController.h"
#import "ResourceInfoController.h"
#import "JournlerMediaViewer.h"
#import "WebViewController.h"
typedef enum {
kResourceRequestAudio = 0,
kResourceRequestPhoto = 1,
kResourceRequestMovie = 2,
kResourceRequestBookmark = 3,
kResourceRequestContact = 4,
kResourceRequestFile = 5,
kResourceRequestEntry = 6
} NewResourceRequest;
static NSDictionary* StatusBarTextAttributes()
{
static NSDictionary *textAttributes = nil;
if ( textAttributes == nil )
{
NSShadow *textShadow;
NSMutableParagraphStyle *paragraphStyle;
textShadow = [[NSShadow alloc] init];
[textShadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.6]];
[textShadow setShadowOffset:NSMakeSize(0,-1)];
paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setAlignment:NSCenterTextAlignment];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
textAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
textShadow, NSShadowAttributeName,
[NSFont boldSystemFontOfSize:11], NSFontAttributeName,
[NSColor blackColor], NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
[textShadow release];
[paragraphStyle release];
}
return textAttributes;
}
static NSArray* EntrySearchDescriptors()
{
static NSArray *descriptors = nil;
if ( descriptors == nil )
{
NSSortDescriptor *searchSort = [[NSSortDescriptor alloc] initWithKey:@"relevanceNumber"
ascending:NO selector:@selector(compare:)];
descriptors = [[NSArray alloc] initWithObjects:searchSort,nil];
[searchSort release];
}
return descriptors;
}
static NSSortDescriptor *FoldersByIndexSortPrototype()
{
static NSSortDescriptor *descriptor = nil;
if ( descriptor == nil )
{
descriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES selector:@selector(compare:)];
}
return descriptor;
}
#pragma mark -
@implementation JournalTabController
- (id) initWithOwner:(JournlerWindowController*)anObject
{
if ( self = [super initWithOwner:anObject] )
{
// prepare the cell controllers
entryCellController = [[EntryCellController alloc] init];
resourceCellController = [[ResourceCellController alloc] init];
[entryCellController setJournal:[self journal]];
[entryCellController setDelegate:self];
[resourceCellController setDelegate:self];
// prepare a popupbutton cell for the folders and resources worktool
worktoolPopCell = [[NSPopUpButtonCell alloc] initTextCell:[NSString string] pullsDown:YES];
resourceWorktoolPopCell = [[NSPopUpButtonCell alloc] initTextCell:[NSString string] pullsDown:YES];
newResourcePopCell = [[NSPopUpButtonCell alloc] initTextCell:[NSString string] pullsDown:YES];
usesSmallCalendar = NO; // to be explicit about it
// load the associated bundle
[NSBundle loadNibNamed:@"JournalTab" owner:self];
}
return self;
}
- (void) awakeFromNib
{
// set up the temporary content, to be immediately replaced by a selection
activeContentView = contentPlaceholder;
// set the default active content view
[self setActiveContentView:[entryCellController contentView]];
// the folders controller must know the actual root (vs. the roots children)
[sourceListController setRootCollection:[[self journal] valueForKey:@"rootCollection"]];
// set the sort descriptors on the source list
[sourceListController setSortDescriptors:[NSArray arrayWithObject:FoldersByIndexSortPrototype()]];
// set the header menu for the entry table and the reference table
[[entriesTable headerView] setMenu:columnsMenu];
[entriesTable setCornerView:aCornerView];
// size the folder list to fit
[sourceList sizeToFit];
// prepare the label menu's colors
[[NSApp delegate] prepareLabelMenu:&labelMenu];
[[NSApp delegate] prepareLabelMenu:&resourceLabelMenu];
[[NSApp delegate] prepareLabelMenu:&folderLableMenu];
[[NSApp delegate] prepareLabelMenu:&folderWorktoolLabelMenu];
[[NSApp delegate] prepareLabelMenu:&resourceWorktoolLabelMenu];
// prepare the worktool button and associated popup button cell
[folderWorktool sendActionOn:NSLeftMouseDownMask];
[resourceWorktool sendActionOn:NSLeftMouseDownMask];
[newResourceButton sendActionOn:NSLeftMouseDownMask];
[worktoolPopCell setMenu:foldersWorktoolMenu];
[worktoolPopCell selectItemAtIndex:0];
[worktoolPopCell setPullsDown:YES];
[resourceWorktoolPopCell setMenu:resourceWorktoolMenu];
[resourceWorktoolPopCell selectItemAtIndex:0];
[resourceWorktoolPopCell setPullsDown:YES];
[newResourcePopCell setMenu:newResourceMenu];
[newResourcePopCell selectItemAtIndex:0];
[newResourcePopCell setPullsDown:YES];
[emptyTrashItem setKeyEquivalent:[NSString stringWithCharacters:(const unichar[]){NSBackspaceCharacter} length:1]];
[emptyTrashItem setKeyEquivalentModifierMask:(NSCommandKeyMask|NSShiftKeyMask)];
//[entryInNewTabItem setKeyEquivalent:@"\r"];
//[entryInNewTabItem setKeyEquivalentModifierMask:NSShiftKeyMask];
//[resourceInNewTabItem setKeyEquivalent:@"\r"];
//[resourceInNewTabItem setKeyEquivalentModifierMask:NSShiftKeyMask];
//[resourceInNewTabItemB setKeyEquivalent:@"\r"];
//[resourceInNewTabItemB setKeyEquivalentModifierMask:NSShiftKeyMask];
// prepare the calendar and controller
calController = [[CalendarController alloc] init];
calendar = [calController calendar];
[calendar setDelegate:self];
[calendar bind:@"content"
toObject:datesController
withKeyPath:@"arrangedObjects"
options:nil];
[datesController bind:@"selectedDate"
toObject:calendar
withKeyPath:@"selectedDate"
options:nil];
// go ahead and add the calendar to the window
[calendar setFrame:NSMakeRect(0,0,172,170)];
[calContainer addSubview:calendar];
// then set the variable (use a binding)
[self bind:@"usesSmallCalendar"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.CalendarUseButton"
options:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSNullPlaceholderBindingOption, nil]];
// hook up the resource controller appropriately
[resourceController bind:@"resources"
toObject:entriesController
withKeyPath:@"[email protected]"
options:nil];
[resourceController bind:@"folders"
toObject:entriesController
withKeyPath:@"[email protected]"
options:nil];
// hook up the entry table state to the folders selection (already the case with sort descriptors)
//[entriesController bind:@"stateArray" toObject:sourceListController withKeyPath:@"selection.entryTableState" options:nil];
// bind ourselves to the folder and entry selection
[self bind:@"selectedEntries"
toObject:entriesController
withKeyPath:@"selectedObjects"
options:nil];
[self bind:@"selectedFolders"
toObject:sourceListController
withKeyPath:@"selectedObjects"
options:nil];
[self bind:@"selectedResources"
toObject:resourceController
withKeyPath:@"selectedResources"
options:nil];
[self bind:@"selectedDate"
toObject:datesController
withKeyPath:@"selectedDate"
options:nil];
// watch for an entry being trashed to adjust entry selection
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_journalWillChangeEntrysTrashStatus:)
name:JournalWillTrashEntryNotification
object:[self journal]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_journalWillChangeEntrysTrashStatus:)
name:JournalWillUntrashEntryNotification
object:[self journal]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_journalDidChangeEntrysTrashStatus:)
name:JournalDidTrashEntryNotification
object:[self journal]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_journalDidChangeEntrysTrashStatus:)
name:JournalDidUntrashEntryNotification
object:[self journal]];
// watch for completed imports so as to update the calendar
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_journlerDidFinishImport:)
name:JournlerDidFinishImportNotification
object:nil];
}
- (void) dealloc
{
#ifdef __DEBUG__
NSLog(@"%s",__PRETTY_FUNCTION__);
#endif
[entryMenu release];
[foldersMenu release];
[referenceMenu release];
[columnsMenu release];
[worktoolPopCell release];
[newResourcePopCell release];
[resourceWorktoolPopCell release];
[resourceWorktoolMenu release];
[foldersWorktoolMenu release];
[newResourceMenu release];
[calController release];
[resourceCellController release];
[entryCellController release];
[searchString release];
[preSearchDescriptors release];
[sourceListController release];
[datesController release];
[entriesController release];
[resourceController release];
[super dealloc];
}
- (void) ownerWillClose
{
#ifdef __DEBUG__
NSLog(@"%s",__PRETTY_FUNCTION__);
#endif
[super ownerWillClose];
// commit editing
if ( ![entryCellController commitEditing] )
NSLog(@"%s - problem with committing changes with the entries cell controller", __PRETTY_FUNCTION__);
if ( ![entriesController commitEditing] )
NSLog(@"%s - problem with committing changes with the entries controller", __PRETTY_FUNCTION__);
if ( ![sourceListController commitEditing] )
NSLog(@"%s - problem with committing changes with the folders controller", __PRETTY_FUNCTION__);
if ( ![resourceController commitEditing] )
NSLog(@"%s - problem with committing changes with the folders controller", __PRETTY_FUNCTION__);
// if searching, restore the last sort descriptor and hide the rank column
if ( [searchString length] != 0 )
{
NSLog(@"%s - still searching, fixing table", __PRETTY_FUNCTION__);
[entriesTable setColumnWithIdentifier:@"relevanceNumber" hidden:YES];
[entriesController setSortDescriptors:preSearchDescriptors];
if ( preSearchTableState != nil )
{
[entriesTable restoreStateWithArray:preSearchTableState];
[preSearchTableState release];
preSearchTableState = nil;
}
}
// unbind our values
[self unbind:@"selectedEntries"];
[self unbind:@"selectedFolders"];
[self unbind:@"selectedResources"];
[self unbind:@"selectedDate"];
//
// Note that's its necessary to unbind the interface first
// I believe I had a problem where unbindinding the controllers first
// was causing one of my custom delegate methods to be called, which
// rebound the controller
// unbind the interface: calendar
[calendar unbind:@"content"];
// unbind the interface: entries table
[entriesTable unbind:@"stateArray"];
[entriesTable unbind:@"content"];
[entriesTable unbind:@"selectionIndexes"];
[entriesTable unbind:@"sortDescriptors"];
// unbind the interface: source list
[sourceList unbind:@"content"];
[sourceList unbind:@"selectionIndexes"];
[sourceList unbind:@"sortDescriptors"];
// unbind the controllers: dates
[datesController unbind:@"selectedDate"];
[datesController unbind:@"contentArray"];
[datesController setContent:nil];
// unbind the controllers: entries
[entriesController unbind:@"contentArrayForMultipleSelection"];
[entriesController unbind:@"contentArray"];
[entriesController unbind:@"sortDescriptors"];
[entriesController setContent:nil];
// unbind the controllers: folder
[sourceListController unbind:@"contentArray"];
[sourceListController setContent:nil];
// unbind the controllers: resources
[resourceController unbind:@"resources"];
[resourceController unbind:@"folders"];
[resourceController setContent:nil];
// notify objects that we're closing
[entryCellController ownerWillClose];
[resourceCellController ownerWillClose];
[calController ownerWillClose:nil];
[calendar ownerWillClose:nil];
// remove the observers we're responsible for
[[NSNotificationCenter defaultCenter] removeObserver:self
name:JournalWillTrashEntryNotification
object:[self journal]];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:JournalDidTrashEntryNotification
object:[self journal]];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:JournalWillUntrashEntryNotification
object:[self journal]];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:JournalDidUntrashEntryNotification
object:[self journal]];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:JournlerDidFinishImportNotification
object:nil];
#ifdef __DEBUG__
NSLog(@"%s - ending",__PRETTY_FUNCTION__);
#endif
}
#pragma mark -
- (NSString*) searchString
{
return searchString;
}
- (void) setSearchString:(NSString*)aString
{
if ( searchString != aString )
{
[searchString release];
searchString = [aString retain];
}
}
#pragma mark -
- (void) selectDate:(NSDate*)date folders:(NSArray*)folders entries:(NSArray*)entries resources:(NSArray*)resources
{
if ( [date fallsOnSameDay:[self selectedDate]]
&& ( [folders isEqual:[self selectedFolders]] || folders == [self selectedFolders] )
&& ( [entries isEqual:[self selectedEntries]] || entries == [self selectedEntries] )
&& ( [resources isEqual:[self selectedResources]] || resources == [self selectedResources]) )
return;
// #warning check for objects that have been deleted?
/*
NSLog(@"%s - date: %@ ; folders : %@ ; entries: %@ ; resources : %@", __PRETTY_FUNCTION__,
( date ? date : @"none" ),
( folders ? [folders valueForKey:@"title"] : @"none" ),
( entries ? [entries valueForKey:@"title"] : @"none" ),
( resources ? [resources valueForKey:@"title"] : @"none" ) );
*/
// register a single, all encomposing undo call while disabling individual undo calls
recordNavigationEvent = NO;
[[navigationManager prepareWithInvocationTarget:self]
selectDate:[self selectedDate] folders:[self selectedFolders]
entries:[self selectedEntries] resources:[self selectedResources]];
BOOL forced = NO;
// if only one item has been specified, give it priority, working backwards
if ( resources != nil && [resources count] != 0 && entries == nil && folders == nil && date == nil )
{
// try to select the resource
if ( [[resourceController resources] containsObjects:resources] )
{
forced = YES;
[resourceTable deselectAll:self];
for ( JournlerResource *aResource in resources )
[resourceController selectResource:aResource byExtendingSelection:YES];
}
}
else if ( entries != nil && [entries count] != 0 && resources == nil && folders == nil && date == nil )
{
// try to select the entry
if ( [[entriesController arrangedObjects] containsObjects:entries] )
{
forced = YES;
[entriesController setSelectedObjects:entries];
}
}
else if ( folders != nil && [folders count] != 0 && resources == nil && entries == nil && date == nil )
{
// force the folder selection
forced = YES;
[sourceList deselectAll:self];
for ( JournlerCollection *aFolder in folders )
[sourceListController selectCollection:aFolder byExtendingSelection:YES];
}
else if ( date != nil && folders == nil && resources == nil && entries == nil )
{
// force the date selection
forced = YES;
[calendar setSelectedDate:[date dateWithCalendarFormat:nil timeZone:nil]];
}
// bail if we successfully forced
if ( forced ) goto bail;
// note change here: checking for selected folders is not nil
if ( ( folders == nil || [folders count] == 0 ) && ( [self selectedFolders] == nil && !(entries == nil || [entries count] == 0) ) )
{
// checking for a nil or empty folder selection is equivalent to checking for the date
[calendar setSelectedDate:[date dateWithCalendarFormat:nil timeZone:nil]];
}
else if ( ![folders isEqualToArray:[self selectedFolders]] && !( folders==nil && [self selectedFolders] == nil) )
{
// adjust the folders to match the selection but only if no date has been selected
// clear the current selection and force a selection on the new objects
[sourceList deselectAll:self];
for ( JournlerCollection *aFolder in folders )
[sourceListController selectCollection:aFolder byExtendingSelection:YES];
}
if ( ![entries isEqualToArray:[self selectedEntries]] && !( entries==nil && [self selectedEntries] == nil) )
{
// if the folder does not contain the entries, switch to the journal
if ( ![[entriesController arrangedObjects] containsObjects:entries] && entries != nil )
{
[sourceList deselectAll:self];
[sourceListController selectCollection:[self valueForKeyPath:@"journal.libraryCollection"] byExtendingSelection:NO];
}
// next adjust the entry to match the selection
[entriesController setSelectedObjects:entries];
}
if ( ![resources isEqualToArray:[self selectedResources]] && !( resources==nil && [self selectedResources]==nil) )
{
// finally adjust the reference to match the selection
if ( ![[resourceController resources] containsObjects:resources] && resources != nil )
{
// select the library
[sourceList deselectAll:self];
[sourceListController selectCollection:[self valueForKeyPath:@"journal.libraryCollection"] byExtendingSelection:NO];
// select each of the resources's entries
[entriesController setSelectedObjects:[resources valueForKey:@"entry"]];
}
// clear the current selection and force a selection on the new objects
[resourceTable deselectAll:self];
for ( JournlerResource *aResource in resources )
[resourceController selectResource:aResource byExtendingSelection:YES];
}
bail:
// if no reference is selected, force this entry's content to load
if ( (resources == nil || [resources count] == 0) && !( [entries count] == 1 && [[entries objectAtIndex:0] selectedResource] != nil ) )
[self setActiveContentView:[entryCellController contentView]];
recordNavigationEvent = YES;
}
#pragma mark -
- (BOOL) selectResources:(NSArray*)anArray
{
// clear the search and filter if there is one
if ( !( GetCurrentKeyModifiers() & optionKey ) )
[self clearSearchAndFilter:self];
if ( anArray == nil )
[resourceTable deselectAll:self];
else
{
// ensure the appropriate entries are selected
// 1. select the library if necessary
NSArray *resourceEntries = [anArray valueForKey:@"entry"];
if ( ![[entriesController arrangedObjects] containsObjects:resourceEntries] )
[sourceListController selectCollection:[[self journal] libraryCollection] byExtendingSelection:NO];
// 2. select those entries
[self selectEntries:resourceEntries];
// and finally select the resources
[resourceTable deselectAll:self];
for ( JournlerResource *aResource in anArray )
[resourceController selectResource:aResource byExtendingSelection:YES];
}
return YES;
}
- (BOOL) selectFolders:(NSArray*)anArray
{
// clear the search and filter if there is one
if ( !( GetCurrentKeyModifiers() & optionKey ) )
[self clearSearchAndFilter:self];
if ( anArray == nil )
[sourceList deselectAll:self];
else
{
[sourceList deselectAll:self];
for ( JournlerCollection *aFolder in anArray )
[sourceListController selectCollection:aFolder byExtendingSelection:YES];
}
return YES;
}
- (BOOL) selectEntries:(NSArray*)anArray
{
// clear the search and filter if there is one
if ( !( GetCurrentKeyModifiers() & optionKey ) )
[self clearSearchAndFilter:self];
if ( anArray == nil )
[entriesTable deselectAll:self];
else
{
// ensure the entries are available for selection
if ( ![[entriesController arrangedObjects] containsObjects:anArray] )
[sourceListController selectCollection:[[self journal] libraryCollection] byExtendingSelection:NO];
[entriesController setSelectedObjects:anArray];
}
return YES;
}
- (BOOL) selectDate:(NSDate*)aDate
{
// clear the search and filter if there is one
if ( !( GetCurrentKeyModifiers() & optionKey ) )
[self clearSearchAndFilter:self];
[calendar setSelectedDate:[aDate dateWithCalendarFormat:nil timeZone:nil]];
return YES;
}
#pragma mark -
- (void) setSelectedFolders:(NSArray*)anArray
{
// call super's implementation
[super setSelectedFolders:anArray];
// clear the search and filter if there is one
if ( keepSearching == NO && !( GetCurrentKeyModifiers() & optionKey ) )
[self clearSearchAndFilter:self];
}
- (void) setSelectedEntries:(NSArray*)anArray
{
// call super's implementation
[super setSelectedEntries:anArray];
// everything should be deselected in the resource table
recordNavigationEvent = NO;
[resourceTable deselectAll:self];
recordNavigationEvent = YES;
// if a single entry is being selected and it holds a last selected resource property, select the resource instead
if ( [anArray count] == 1 && [[anArray objectAtIndex:0] valueForKey:@"selectedResource"] != nil )
{
[resourceController selectResource:[[anArray objectAtIndex:0] valueForKey:@"selectedResource"] byExtendingSelection:NO];
// pass the entries to the cell controller anyway
[entryCellController setSelectedEntries:anArray];
}
else
{
// make sure the entry cell is the active view
[self setActiveContentView:[entryCellController contentView]];
// pass the entries to the cell controller
[entryCellController setSelectedEntries:anArray];
// set the highlight
if ( [[self searchString] length] > 0 )
[self highlightString:[self searchString]];
}
// restore the resource table state
[resourceController restoreStateFromDictionary:[resourceController stateDictionary]];
}
- (void) setSelectedResources:(NSArray*)anArray
{
// call super's implementation
[super setSelectedResources:anArray];
// make sure the appropriate cell is the active view
if ( anArray != nil && [anArray count] != 0 )
[self setActiveContentView:[resourceCellController contentView]];
else
[self setActiveContentView:[entryCellController contentView]];
// pass the resources to the reference cell
[resourceCellController setSelectedResources:anArray];
// set the highlight
if ( [[self searchString] length] > 0 )
[self highlightString:[self searchString]];
}
- (void) setSelectedDate:(NSDate*)aDate
{
// call super's implementation
[super setSelectedDate:aDate];
// clear the search and filter if there is one
if ( !( GetCurrentKeyModifiers() & optionKey ) )
[self clearSearchAndFilter:self];
// whenever the date is selected, immediately deselect the folders
recordNavigationEvent = NO;
[sourceList selectRowIndexes:nil byExtendingSelection:NO];
recordNavigationEvent = YES;
}
#pragma mark -
- (NSView*) activeContentView
{
return activeContentView;
}
- (void) setActiveContentView:(NSView*)aView
{
if ( activeContentView == aView || aView == nil )
return;
// if the current active view is the resource view, we're switch out, so stop whatever it's doing
if ( activeContentView == [resourceCellController contentView] )
[resourceCellController stopContent];
// if switching to text view, disable custom find panel action, otherwise, update
if ( aView == [entryCellController contentView] )
{
//[[NSApp delegate] performSelector:@selector(setFindPanelPerformsCustomAction:) withObject:[NSNumber numberWithBool:NO]];
//[[NSApp delegate] performSelector:@selector(setTextSizePerformsCustomAction:) withObject:[NSNumber numberWithBool:NO]];
}
else
{
//[resourceCellController checkCustomFindPanelAction];
//[resourceCellController checkCustomTextSizeAction];
}
//[activeContentView retain];
[aView setFrame:[activeContentView frame]];
[[activeContentView superview] replaceSubview:activeContentView with:aView];
// rebuild the keyview loop
/*
if ( [[self owner] searchOutlet] != nil )
{
[sourceList setNextKeyView:[[self owner] searchOutlet]];
[[[self owner] searchOutlet] setNextKeyView:entriesTable];
}
else
{
[sourceList setNextKeyView:entriesTable];
}
if ( [contentResourceSplit isCollapsed] )
{
if ( aView == [resourceCellController contentView] )
[resourceCellController establishKeyViews:entriesTable nextKeyView:sourceList];
else if ( aView == [entryCellController contentView] )
[entryCellController establishKeyViews:entriesTable nextKeyView:sourceList];
}
else
{
[resourceTable setNextKeyView:sourceList];
if ( aView == [resourceCellController contentView] )
[resourceCellController establishKeyViews:entriesTable nextKeyView:resourceTable];
else if ( aView == [entryCellController contentView] )
[entryCellController establishKeyViews:entriesTable nextKeyView:resourceTable];
}
*/
activeContentView = aView;
}
#pragma mark -
- (BOOL) usesSmallCalendar
{
return usesSmallCalendar;
}
- (void) setUsesSmallCalendar:(BOOL)smallCalendar
{
if ( usesSmallCalendar != smallCalendar )
{
usesSmallCalendar = smallCalendar;
[calController setUsesSmallCalendar:usesSmallCalendar];
if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"CalendarUseButton"] )
{
NSView *datePickerView = [calController datePickerContainer];
NSInteger datePickerHeight = [datePickerView frame].size.height;
NSRect calendarContainerFrame = [calContainer frame];
NSRect sourceListContainerFrame = [[sourceList enclosingScrollView] frame];
NSInteger originalHeight = calendarContainerFrame.size.height;
NSInteger originalWidth = calendarContainerFrame.size.width;
calendarContainerFrame.size.height = datePickerHeight;
calendarContainerFrame.origin.y = calendarContainerFrame.origin.y + originalHeight - datePickerHeight;
sourceListContainerFrame.size.height += ( originalHeight - datePickerHeight );
[datePickerView setFrame:NSMakeRect(0,0,originalWidth,datePickerHeight)];
[calContainer setFrame:calendarContainerFrame];
[[sourceList enclosingScrollView] setFrame:sourceListContainerFrame];
[calContainer setFill:[NSColor colorWithCalibratedRed:200.0/255.0 green:205.0/255.0 blue:212.0/255.0 alpha:1.0]];
[calContainer addSubview:datePickerView];
}
else
{
static NSInteger kCalRequiredHeight = 170;
NSRect calendarContainerFrame = [calContainer frame];
NSRect sourceListContainerFrame = [[sourceList enclosingScrollView] frame];
NSInteger originalWidth = calendarContainerFrame.size.width;
NSInteger originalHeight = calendarContainerFrame.size.height;
calendarContainerFrame.size.height = kCalRequiredHeight;
calendarContainerFrame.origin.y = calendarContainerFrame.origin.y + originalHeight - kCalRequiredHeight;
sourceListContainerFrame.size.height -= ( kCalRequiredHeight - originalHeight );
[calContainer setFrame:calendarContainerFrame];
[calendar setFrame:NSMakeRect(0, 0, originalWidth, kCalRequiredHeight )];
[[sourceList enclosingScrollView] setFrame:sourceListContainerFrame];
[calContainer setFill:[NSColor whiteColor]];
[calContainer addSubview:calendar];
}
//[calController finalizeCalendarSizeChange:usesSmallCalendar];
}
}
#pragma mark -
- (NSString*) title
{
NSString *theTitle = nil;
if ( [resourceCellController isWebBrowsing] )
{
theTitle = [resourceCellController documentTitle];
if ( theTitle == nil )
theTitle = [super title];
}
else
{
theTitle = [super title];
}
return theTitle;
}
#pragma mark -
#pragma mark Saving and Restoring the Tab's State
- (NSDictionary*) stateDictionary
{
// grab a mutable copy of super's dictionary, storing selection info
NSMutableDictionary *stateDictionary = [[[super stateDictionary] mutableCopyWithZone:[self zone]] autorelease];
[stateDictionary addEntriesFromDictionary:[self localStateDictionary]];
return stateDictionary;
}
- (void) restoreStateWithDictionary:(NSDictionary*)stateDictionary
{
[self restoreLocalStateWithDictionary:stateDictionary];
// allow super to handle the rest (ie entry, folder selection)
[super restoreStateWithDictionary:stateDictionary];
}
- (NSDictionary*) localStateDictionary
{
NSMutableDictionary *stateDictionary = [NSMutableDictionary dictionary];
// add the state of the entry table
NSArray *entryTableState = [entriesTable stateArray];
if ( entryTableState != nil )
[stateDictionary setValue:entryTableState forKey:@"entryTableState"];
// add the state of the folders table
NSArray *folderTableState = [sourceList stateArray];
if ( folderTableState != nil )
[stateDictionary setValue:folderTableState forKey:@"folderTableState"];
// the resource table state
NSDictionary *resourceTableState = [resourceController stateDictionary];
if ( resourceTableState != nil )
[stateDictionary setValue:resourceTableState forKey:@"resourceTableState"];
// inclue the splitview dimensions
NSNumber *browserDimension = [NSNumber numberWithFloat:[[browserContentSplit subviewAtPosition:0] dimension]];
NSNumber *resourceDimension = [NSNumber numberWithFloat:[[contentResourceSplit subviewAtPosition:1] dimension]];
NSNumber *folderDimension = [NSNumber numberWithFloat:[[foldersEntriesSplit subviewAtPosition:0] dimension]];
// is the resource view collapsed
NSNumber *resourceCollapsed = [NSNumber numberWithBool:[[contentResourceSplit subviewAtPosition:1] isHidden]];
[stateDictionary setValue:browserDimension forKey:@"browserDimension"];
[stateDictionary setValue:resourceDimension forKey:@"resourceDimension"];
[stateDictionary setValue:folderDimension forKey:@"folderDimension"];
[stateDictionary setValue:resourceCollapsed forKey:@"resourceCollapsed"];
// the entry cell's footer and header
[stateDictionary setValue:[NSNumber numberWithBool:[entryCellController headerHidden]] forKey:@"headerHidden"];
[stateDictionary setValue:[NSNumber numberWithBool:[entryCellController footerHidden]] forKey:@"footerHidden"];
// get on outa here
return stateDictionary;
}
- (void) restoreLocalStateWithDictionary:(NSDictionary*)stateDictionary
{
// restore the state of the entry table
NSArray *entryTableState = [stateDictionary valueForKey:@"entryTableState"];