-
Notifications
You must be signed in to change notification settings - Fork 30
/
EntryTabController.m
1437 lines (1167 loc) · 43.9 KB
/
EntryTabController.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
//
// EntryTabController.m
// Journler
//
// Created by Philip Dow on 11/9/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 "EntryTabController.h"
#import "TabController.h"
#import "Definitions.h"
#import "JournlerApplicationDelegate.h"
#import "NSAlert+JournlerAdditions.h"
#import "JournlerJournal.h"
#import "JournlerEntry.h"
#import "JournlerResource.h"
#import "JournlerWindowController.h"
#import "EntryWindowController.h"
#import "ResourceController.h"
#import "EntryCellController.h"
#import "ResourceCellController.h"
#import "LinksOnlyNSTextView.h"
#import "WebViewController.h"
#import "JournlerMediaViewer.h"
typedef enum {
kResourceRequestAudio = 0,
kResourceRequestPhoto = 1,
kResourceRequestMovie = 2,
kResourceRequestBookmark = 3,
kResourceRequestContact = 4,
kResourceRequestFile = 5,
kResourceRequestEntry = 6
} NewResourceRequest;
static NSSortDescriptor *ResourceByTitleSortPrototype()
{
static NSSortDescriptor *descriptor = nil;
if ( descriptor == nil )
{
descriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
}
return descriptor;
}
static NSSortDescriptor *ResourceByRankSortPrototype()
{
static NSSortDescriptor *descriptor = nil;
if ( descriptor == nil )
{
descriptor = [[NSSortDescriptor alloc] initWithKey:@"relevance" ascending:NO selector:@selector(compare:)];
}
return descriptor;
}
@implementation EntryTabController
- (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
resourceWorktoolPopCell = [[NSPopUpButtonCell alloc] initTextCell:[NSString string] pullsDown:YES];
newResourcePopCell = [[NSPopUpButtonCell alloc] initTextCell:[NSString string] pullsDown:YES];
// load the associated bundle
[NSBundle loadNibNamed:@"EntryTab" 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]];
// header contextual
[resourceTable sizeToFit];
//[resourceInNewTabItem setKeyEquivalent:@"\r"];
//[resourceInNewTabItem setKeyEquivalentModifierMask:NSShiftKeyMask];
//[resourceInNewTabItemB setKeyEquivalent:@"\r"];
//[resourceInNewTabItemB setKeyEquivalentModifierMask:NSShiftKeyMask];
[resourceWorktoolPopCell setMenu:resourceWorktoolMenu];
[resourceWorktoolPopCell selectItemAtIndex:0];
[resourceWorktoolPopCell setPullsDown:YES];
[newResourcePopCell setMenu:newResourceMenu];
[newResourcePopCell selectItemAtIndex:0];
[newResourcePopCell setPullsDown:YES];
// set the sort descriptors for the resource table
//[resourceController setSortDescriptors:[NSArray arrayWithObject:ResourceByTitleSortPrototype()]];
// hook up the resource controller appropriately
[resourceController bind:@"resources"
toObject:self
withKeyPath:@"selectedEntry.resources"
options:nil];
[resourceController bind:@"folders"
toObject:self
withKeyPath:@"selectedEntry.collections"
options:nil];
// bind ourselves to the folder and entry selection
[self bind:@"selectedResources"
toObject:resourceController
withKeyPath:@"selectedResources"
options:nil];
}
- (void) dealloc
{
// local objects
[selectedEntry release];
[entryCellController release];
[resourceCellController release];
// top level nib ojects
[resourceController release];
[referenceMenu release];
[resourceWorktoolMenu release];
[resourceWorktoolPopCell release];
[newResourcePopCell 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 ( ![resourceController commitEditing] )
NSLog(@"%s - problem with committing changes with the folders controller", __PRETTY_FUNCTION__);
[self unbind:@"selectedResources"];
[resourceController unbind:@"resources"];
[resourceController unbind:@"folders"];
[resourceController unbind:@"contentArray"];
[resourceController setContent:nil];
[entryCellController ownerWillClose];
[resourceCellController ownerWillClose];
}
#pragma mark -
- (void) selectDate:(NSDate*)date folders:(NSArray*)folders entries:(NSArray*)entries resources:(NSArray*)resources
{
if ( ( [entries isEqual:[self selectedEntries]] || entries == [self selectedEntries] )
&& ( [resources isEqual:[self selectedResources]] || resources == [self selectedResources]) )
return;
// 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]];
if ( ![entries isEqualToArray:[self selectedEntries]] && !( entries==nil && [self selectedEntries] == nil) )
{
// next adjust the entry to match the selection
[self setSelectedEntries:entries];
}
if ( ![resources isEqualToArray:[self selectedResources]] && !( resources==nil && [self selectedResources]==nil) )
{
// 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];
}
// 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;
}
- (BOOL) selectResources:(NSArray*)anArray
{
[resourceTable deselectAll:self];
for ( JournlerResource *aResource in anArray )
[resourceController selectResource:aResource byExtendingSelection:NO];
return YES;
}
- (BOOL) selectEntries:(NSArray*)anArray
{
[self setSelectedEntries:anArray];
return YES;
}
- (BOOL) selectFolders:(NSArray*)anArray
{
NSBeep();
return NO;
}
#pragma mark -
- (JournlerEntry*)selectedEntry
{
return selectedEntry;
}
- (void) setSelectedEntry:(JournlerEntry*)anEntry
{
if ( selectedEntry != anEntry )
{
[selectedEntry release];
selectedEntry = [anEntry retain];
}
}
- (void) setSelectedEntries:(NSArray*)anArray
{
// autosave - could lead to redundancy, but only dirty objects are saved anyway
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithArray:[self selectedEntries]], @"entries", nil];
NSNotification *aNotification = [NSNotification notificationWithName:@"JournlerAutosaveNotification" object:self userInfo:userInfo];
[self performSelector:@selector(performAutosave:) withObject:aNotification afterDelay:0.1];
// keep track of the single selected entry as well
if ( [anArray count] > 0 )
{
// call super's implementation, forcing it to take only the single entry
[super setSelectedEntries:[NSArray arrayWithObject:[anArray objectAtIndex:0]]];
[self setSelectedEntry:[anArray objectAtIndex:0]];
[entryCellController setSelectedEntries:[NSArray arrayWithObject:[anArray objectAtIndex:0]]];
}
else
{
[super setSelectedEntries:nil];
[self setSelectedEntry:nil];
[entryCellController setSelectedEntries:nil];
}
// make sure the entry cell is the active view
[self setActiveContentView:[entryCellController contentView]];
// restore the resource table state
[resourceController restoreStateFromDictionary:[resourceController stateDictionary]];
}
- (void) setSelectedResources:(NSArray*)anArray
{
#ifdef __DEBUG__
NSLog(@"%s",__PRETTY_FUNCTION__);
#endif
// 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];
}
#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];
}
[aView setFrame:[activeContentView frame]];
[[activeContentView superview] replaceSubview:activeContentView with:aView];
activeContentView = aView;
}
- (NSDictionary*) localStateDictionary
{
NSMutableDictionary *stateDictionary = [NSMutableDictionary dictionary];
// splitview dimension
NSNumber *resourceDimension = [NSNumber numberWithFloat:[[contentResourceSplit subviewAtPosition:1] dimension]];
// is the resource view collapsed
NSNumber *resourceCollapsed = [NSNumber numberWithBool:[[contentResourceSplit subviewAtPosition:1] isHidden]];
[stateDictionary setValue:resourceDimension forKey:@"resourceDimension"];
[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"];
// the resource table state
NSDictionary *resourceTableState = [stateDictionary valueForKey:@"resourceTableState"];
if ( resourceTableState != nil )
[resourceController restoreStateFromDictionary:resourceTableState];
// get on outa here
return stateDictionary;
}
- (void) restoreLocalStateWithDictionary:(NSDictionary*)stateDictionary
{
NSNumber *resourceDimension = [stateDictionary valueForKey:@"resourceDimension"];
if ( resourceDimension != nil )
[[contentResourceSplit subviewAtPosition:1] setDimension:[resourceDimension floatValue]];
// collapse the resources if necesary
if ( [[stateDictionary valueForKey:@"resourceCollapsed"] boolValue] )
[[contentResourceSplit subviewAtPosition:1] setHidden:YES];
// collapse the entry cell's header and footer if necessary
if ( [[stateDictionary valueForKey:@"headerHidden"] boolValue] )
[entryCellController setHeaderHidden:YES];
if ( [[stateDictionary valueForKey:@"footerHidden"] boolValue] )
[entryCellController setFooterHidden:YES];
// visible ruler
if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"EntryTextShowRuler"] && ![[entryCellController textView] isRulerVisible] )
[[entryCellController textView] toggleRuler:self];
// resource toggle image
[self _updateResourceToggleImage];
}
- (void) appropriateFirstResponder:(NSWindow*)aWindow
{
if ( [self activeContentView] == [entryCellController contentView] )
[entryCellController appropriateFirstResponder:aWindow];
else if ( [self activeContentView] == [resourceCellController contentView] )
[resourceCellController appropriateFirstResponder:aWindow];
}
- (void) appropriateFirstResponderForNewEntry:(NSWindow*)aWindow
{
if ( [self activeContentView] == [entryCellController contentView] )
[entryCellController appropriateFirstResponderForNewEntry:aWindow];
else if ( [self activeContentView] == [resourceCellController contentView] )
[resourceCellController appropriateFirstResponder:aWindow];
}
- (BOOL) highlightString:(NSString*)aString
{
if ( [self activeContentView] == [entryCellController contentView] )
return [entryCellController highlightString:aString];
else if ( [self activeContentView] == [resourceCellController contentView] )
return [resourceCellController highlightString:aString];
else
return NO;
}
#pragma mark -
- (BOOL) textViewIsInFullscreenMode:(LinksOnlyNSTextView*)aTextView
{
// pass it up the chain if the chain respects it, otherwise definitely not fullscreen
if ( [[self owner] respondsToSelector:@selector(textViewIsInFullscreenMode:)] )
return [[self owner] textViewIsInFullscreenMode:aTextView];
else
return NO;
}
- (IBAction) exportResource:(id)sender
{
// override if there's a single selection and the resource view is active, otherwise pass to super
if ( [self activeContentView] == [resourceCellController contentView] && [[self selectedResources] count] == 1 )
[resourceCellController exportResource:sender];
else
[super exportResource:sender];
}
- (void) maximizeViewingArea
{
[resourceWorktool setHidden:YES];
[newResourceButton setHidden:YES];
[toggleResourcesButton setHidden:YES];
[resourceWorktool setEnabled:NO];
[newResourceButton setEnabled:NO];
[toggleResourcesButton setEnabled:NO];
NSRect contentFrame = [[self tabContent] frame];
[contentResourceSplit setFrame:contentFrame];
[[self tabContent] setNeedsDisplay:YES];
}
- (void) setFullScreen:(BOOL)inFullScreen
{
[entryCellController setFullScreen:inFullScreen];
}
#pragma mark -
#pragma mark RBSplitView Delegation
- (void)splitView:(RBSplitView*)sender willDrawSubview:(RBSplitSubview*)subview inRect:(NSRect)rect
{
[[NSColor darkGrayColor] set];
NSFrameRect(rect);
}
// This makes it possible to drag the divider around by the dragView.
- (NSUInteger)splitView:(RBSplitView*)sender
dividerForPoint:(NSPoint)point inSubview:(RBSplitSubview*)subview
{
if ( [sender tag] == 2 && subview == [sender subviewAtPosition:1] )
{
if ([resourcesDragView mouse:[resourcesDragView convertPoint:point fromView:sender] inRect:[resourcesDragView bounds]])
return 0;
}
return NSNotFound;
}
// This changes the cursor when it's over the dragView.
- (NSRect)splitView:(RBSplitView*)sender cursorRect:(NSRect)rect forDivider:(NSUInteger)divider
{
if ( [sender tag] == 2 && divider == 0 )
[sender addCursorRect:[resourcesDragView convertRect:[resourcesDragView bounds] toView:sender]
cursor:[RBSplitView cursor:RBSVVerticalCursor]];
return rect;
}
// this prevents a subview from resizing while the others around it do
- (void)splitView:(RBSplitView*)sender wasResizedFrom:(float)oldDimension to:(float)newDimension
{
if ( [sender tag] == 2 )
[sender adjustSubviewsExcepting:[sender subviewAtPosition:1]];
}
- (void)splitView:(RBSplitView*)sender didCollapse:(RBSplitSubview*)subview
{
if ( [sender tag] == 2 && subview == [sender subviewAtPosition:1] )
{
[self _updateResourceToggleImage];
[self performSelector:@selector(_hideResourcesSubview:) withObject:self afterDelay:0.1];
}
}
- (void)splitView:(RBSplitView*)sender didExpand:(RBSplitSubview*)subview
{
if ( [sender tag] == 2 && subview == [sender subviewAtPosition:1] )
[self _updateResourceToggleImage];
}
#pragma mark -
- (void) _hideResourcesSubview:(id)anObject
{
[[contentResourceSplit subviewAtPosition:1] setHidden:YES];
}
- (void) _updateResourceToggleImage
{
//NSLog(@"%s",__PRETTY_FUNCTION__);
if ( [[contentResourceSplit subviewAtPosition:1] isHidden] )
{
[resourceToggle setImage:[NSImage imageNamed:@"HideResourcesEnabled.png"]];
[resourceToggle setAlternateImage:[NSImage imageNamed:@"HideResourcesPressed.png"]];
}
else
{
[resourceToggle setImage:[NSImage imageNamed:@"ShowResourcesEnabled.png"]];
[resourceToggle setAlternateImage:[NSImage imageNamed:@"ShowResourcesPressed.png"]];
}
}
#pragma mark -
#pragma mark Entry Cell Delegation
- (void) entryCellController:(EntryCellController*)aController
clickedOnEntry:(JournlerEntry*)anEntry
modifierFlags:(NSUInteger)flags
highlight:(NSString*)aTerm
{
if ( flags & NSCommandKeyMask )
{
if ( flags & NSAlternateKeyMask )
{
// select the entry in a new window
EntryWindowController *entryWindow = [[[EntryWindowController alloc] initWithJournal:[self journal]] autorelease];
[entryWindow showWindow:self];
// set it's selection to our current selection
[[entryWindow selectedTab] selectDate:nil folders:nil entries:[NSArray arrayWithObject:anEntry] resources:nil];
[[entryWindow selectedTab] appropriateFirstResponder:[entryWindow window]];
[[entryWindow selectedTab] highlightString:aTerm];
}
else
{
// select the entry in a new tab
[[self valueForKey:@"owner"] newTab:self];
TabController *theTab = [[self valueForKeyPath:@"owner.tabControllers"] lastObject];
[theTab selectDate:[anEntry valueForKey:@"calDate"] folders:nil entries:[NSArray arrayWithObject:anEntry] resources:nil];
[theTab highlightString:aTerm];
// select the tab if the shift key is down
if ( flags & NSShiftKeyMask )
[[self valueForKey:@"owner"] selectTabAtIndex:-1 force:NO];
}
}
else
{
// select the entry ourselves
[self setSelectedEntries:[NSArray arrayWithObject:anEntry]];
[self highlightString:aTerm];
}
}
- (void) entryCellController:(EntryCellController*)aController
clickedOnResource:(JournlerResource*)aResource
modifierFlags:(NSUInteger)flags
highlight:(NSString*)aTerm
{
if ( flags & NSCommandKeyMask )
{
if ( flags & NSAlternateKeyMask )
{
EntryWindowController *aWindow = [[[EntryWindowController alloc] initWithJournal:[self journal]] autorelease];
[aWindow showWindow:self];
[[aWindow selectedTab] selectDate:nil
folders:nil
entries:[NSArray arrayWithObject:[aResource valueForKey:@"entry"]]
resources:[NSArray arrayWithObject:aResource]];
[[aWindow selectedTab] appropriateFirstResponder:[aWindow window]];
[[aWindow selectedTab] highlightString:aTerm];
}
else
{
// select the resource in a new tab
[[self valueForKey:@"owner"] newTab:self];
TabController *theTab = [[self valueForKeyPath:@"owner.tabControllers"] lastObject];
[theTab selectDate:[aResource valueForKeyPath:@"entry.calDate"]
folders:nil
entries:[NSArray arrayWithObject:[aResource valueForKey:@"entry"]]
resources:[NSArray arrayWithObject:aResource]];
[theTab highlightString:aTerm];
// select the tab if the shift key is down
if ( flags & NSShiftKeyMask )
[[self valueForKey:@"owner"] selectTabAtIndex:-1 force:NO];
}
}
else if ( flags & NSAlternateKeyMask )
{
// open the link in the default application
[aResource openWithFinder];
}
else
{
if ( [aResource representsFile]
&& ( ( [aResource isAppleScript] || [aResource isApplication] )
&& [[NSUserDefaults standardUserDefaults] boolForKey:@"ExecuteAppAndScriptLinks"] ) )
{
// override default behavior if the resources is an exectuable and the user has specified it
NSString *resourcePath;
if ( [aResource isApplication] )
{
resourcePath = [aResource originalPath];
if ( resourcePath != nil )
[[NSWorkspace sharedWorkspace] openFile:resourcePath];
else
NSBeep();
}
else if ( [aResource isAppleScript] )
{
NSString *scriptPath = [aResource originalPath];
if ( scriptPath == nil )
{
NSBeep();
[[NSAlert resourceNotFound] runModal];
}
else
{
[[NSApp delegate] runAppleScriptAtPath:scriptPath showErrors:YES];
}
}
}
else if ( [aResource representsFile]
&& [aResource isDirectory] && ![aResource isFilePackage]
&& [[NSUserDefaults standardUserDefaults] boolForKey:@"OpenFolderLinksInFinder"] )
{
NSString *folderPath = [aResource originalPath];
if ( folderPath == nil )
{
NSBeep();
[[NSAlert resourceNotFound] runModal];
}
else
{
// reveal the folder
// [[NSWorkspace sharedWorkspace] selectFile:folderPath inFileViewerRootedAtPath:[folderPath stringByDeletingLastPathComponent]];
// open the folder
[[NSWorkspace sharedWorkspace] openFile:folderPath];
}
}
else
{
// locate the resource
// action depends on the user's preferences
NSInteger mediaAction = [[NSUserDefaults standardUserDefaults] integerForKey:@"OpenMediaInto"];
if ( mediaAction == kOpenMediaIntoWindow )
{
EntryWindowController *aWindow = [[[EntryWindowController alloc] initWithJournal:[self journal]] autorelease];
[aWindow showWindow:self];
[[aWindow selectedTab] selectDate:nil
folders:nil
entries:[NSArray arrayWithObject:[aResource valueForKey:@"entry"]]
resources:[NSArray arrayWithObject:aResource]];
[[aWindow selectedTab] appropriateFirstResponder:[aWindow window]];
[[aWindow selectedTab] highlightString:aTerm];
}
else if ( mediaAction == kOpenMediaIntoFinder )
{
// open the resource in its own application
[aResource openWithFinder];
}
else /* if ( mediaAction == kOpenMediaIntoTab ) */
{
// open the resource in the selectd tab
if ( [[resourceController resources] indexOfObjectIdenticalTo:aResource] == NSNotFound )
{
// locate the resource's entry
JournlerEntry *anEntry = [aResource valueForKey:@"entry"];
[self setSelectedEntries:[NSArray arrayWithObject:anEntry]];
}
// select the resource
[resourceController selectResource:aResource byExtendingSelection:YES];
[self highlightString:aTerm];
}
}
}
}
- (void) entryCellController:(EntryCellController*)aController clickedOnFolder:(JournlerCollection*)aFolder modifierFlags:(NSUInteger)flags
{
NSBeep();
return;
}
- (void) entryCellController:(EntryCellController*)aController clickedOnURL:(NSURL*)aURL modifierFlags:(NSUInteger)flags
{
// the url must be located in the list of available resources.
// If it isn't there, it must be added to the selected entry
NSArray *theResources = [resourceController resources];
JournlerResource *theResource = nil;
for ( JournlerResource *aResource in theResources )
{
if ( [aResource representsURL] && [[aResource valueForKey:@"urlString"] isEqualToString:[aURL absoluteString]] )
{
theResource = aResource;
break;
}
}
// create the url resource if no resource was found
if ( theResource == nil )
theResource = [[aController selectedEntry] resourceForURL:[aURL absoluteString] title:nil];
// open the resource according to the available flags
if ( flags & NSCommandKeyMask )
{
// open the resource in a new window if possible
if ( flags & NSAlternateKeyMask )
{
EntryWindowController *aWindow = [[[EntryWindowController alloc] initWithJournal:[self journal]] autorelease];
[aWindow showWindow:self];
[[aWindow selectedTab] selectDate:nil folders:nil entries:[NSArray arrayWithObject:[theResource valueForKey:@"entry"]]
resources:[NSArray arrayWithObject:theResource]];
[[aWindow selectedTab] appropriateFirstResponder:[aWindow window]];
/*
NSURL *mediaURL = aURL;
JournlerMediaViewer *mediaViewer = [[[JournlerMediaViewer alloc] initWithURL:mediaURL uti:(NSString*)kUTTypeURL] autorelease];
if ( mediaViewer == nil )
{
NSLog(@"%s - problem allocating media viewer for url %@", __PRETTY_FUNCTION__, mediaURL);
[[NSWorkspace sharedWorkspace] openURL:mediaURL];
}
else
{
[mediaViewer setRepresentedObject:theResource];
[mediaViewer showWindow:self];
}
*/
}
else
{
// select the resource in a new tab
[[self valueForKey:@"owner"] newTab:self];
TabController *theTab = [[self valueForKeyPath:@"owner.tabControllers"] lastObject];
[theTab selectDate:[theResource valueForKeyPath:@"entry.calDate"] folders:nil
entries:[NSArray arrayWithObject:[theResource valueForKey:@"entry"]] resources:[NSArray arrayWithObject:theResource]];
// select the tab if the shift key is down
if ( flags & NSShiftKeyMask )
[[self valueForKey:@"owner"] selectTabAtIndex:-1 force:NO];
}
}
else if ( flags & NSAlternateKeyMask )
{
// open the link in the default application
[theResource openWithFinder];
}
else
{
// act according to the user's media preference
NSInteger mediaAction = [[NSUserDefaults standardUserDefaults] integerForKey:@"OpenMediaInto"];
if ( mediaAction == kOpenMediaIntoWindow )
{
EntryWindowController *aWindow = [[[EntryWindowController alloc] initWithJournal:[self journal]] autorelease];
[aWindow showWindow:self];
[[aWindow selectedTab] selectDate:nil folders:nil entries:[NSArray arrayWithObject:[theResource valueForKey:@"entry"]]
resources:[NSArray arrayWithObject:theResource]];
[[aWindow selectedTab] appropriateFirstResponder:[aWindow window]];
/*
NSURL *mediaURL = aURL;
JournlerMediaViewer *mediaViewer = [[[JournlerMediaViewer alloc] initWithURL:mediaURL uti:(NSString*)kUTTypeURL] autorelease];
if ( mediaViewer == nil )
{
NSLog(@"%s - problem allocating media viewer for url %@", __PRETTY_FUNCTION__, mediaURL);
[[NSWorkspace sharedWorkspace] openURL:mediaURL];
}
else
{
[mediaViewer setRepresentedObject:theResource];
[mediaViewer showWindow:self];
}
*/
}
else if ( mediaAction == kOpenMediaIntoFinder )
{
// open the resource in its own application
[theResource openWithFinder];
}
else /* if ( mediaAction == kOpenMediaIntoTab ) */
{
// simply select the resource
[resourceController selectResource:theResource byExtendingSelection:NO];
}
}
}
#pragma mark -
#pragma mark Resource Cell Delegation
- (void) resourceCellController:(ResourceCellController*)aController didChangeTitle:(NSString*)newTitle
{
if ( [[self owner] respondsToSelector:@selector(tabController:didChangeTitle:)] )
[[self owner] tabController:self didChangeTitle:newTitle];
}
- (void) resourceCellController:(ResourceCellController*)aController didChangePreviewIcon:(NSImage*)icon forResource:(JournlerResource*)aResource
{
// update the resource pane
[resourceTable setNeedsDisplayInRect:[resourceTable rectOfRow:[resourceTable selectedRow]]];
}
- (void) webViewController:(WebViewController*)aController appendPasteboardLink:(NSPasteboard*)pboard
{
[entryCellController webViewController:aController appendPasteboardLink:pboard];
}
- (void) webViewController:(WebViewController*)aController appendPasteboardContents:(NSPasteboard*)pboard
{
[entryCellController webViewController:aController appendPasteboardContents:pboard];
}
- (void) webViewController:(WebViewController*)aController appendPasetboardWebArchive:(NSPasteboard*)pboard
{
[entryCellController webViewController:aController appendPasetboardWebArchive:pboard];
}
#pragma mark -
#pragma mark Token Menu Actions
- (void) selectEntryFromTokenMenu:(NSMenuItem*)aMenuItem
{
JournlerObject *anObject = [aMenuItem representedObject];
NSInteger eventModifiers = 0;
NSInteger modifiers = GetCurrentKeyModifiers();
if ( modifiers & shiftKey ) eventModifiers |= NSShiftKeyMask;
if ( modifiers & optionKey ) eventModifiers |= NSAlternateKeyMask;
if ( modifiers & cmdKey ) eventModifiers |= NSCommandKeyMask;
if ( modifiers & controlKey ) eventModifiers |= NSControlKeyMask;
if ( [anObject isKindOfClass:[JournlerEntry class]] )
{
JournlerEntry *theEntry = (JournlerEntry*)anObject;
[self entryCellController:entryCellController clickedOnEntry:theEntry modifierFlags:eventModifiers highlight:nil];
//[self highlightString:aTerm];
}
else if ( [anObject isKindOfClass:[JournlerResource class]] )
{
JournlerResource *theResource = (JournlerResource*)anObject;
[self entryCellController:entryCellController clickedOnResource:theResource modifierFlags:eventModifiers highlight:nil];
//[self highlightString:aTerm];
}
else
{
NSBeep();
}
}
#pragma mark -
#pragma mark Audio/Video Recording
- (void) sproutedVideoRecorder:(SproutedRecorder*)recorder insertRecording:(NSString*)path title:(NSString*)title
{
#ifdef __DEBUG__
NSLog(@"%s %@",__PRETTY_FUNCTION__,path);
#endif
NSArray *theEntries = [self selectedEntries];
if ( theEntries == nil || [theEntries count] != 1 )
{
NSBeep(); return;
}
// pass the message to the cell controller
[entryCellController sproutedVideoRecorder:recorder insertRecording:path title:title];
}
- (void) sproutedAudioRecorder:(SproutedRecorder*)recorder insertRecording:(NSString*)path title:(NSString*)title
{
#ifdef __DEBUG__
NSLog(@"%s %@",__PRETTY_FUNCTION__,path);
#endif
NSArray *theEntries = [self selectedEntries];
if ( theEntries == nil || [theEntries count] != 1 )
{
NSBeep(); return;
}
// pass the message to the cell controller
[entryCellController sproutedAudioRecorder:recorder insertRecording:path title:title];
}
- (void) sproutedSnapshot:(SproutedRecorder*)recorder insertRecording:(NSString*)path title:(NSString*)title
{
#ifdef __DEBUG__
NSLog(@"%s %@",__PRETTY_FUNCTION__,path);
#endif
NSArray *theEntries = [self selectedEntries];
if ( theEntries == nil || [theEntries count] != 1 )
{
NSBeep(); return;
}
// pass the message to the cell controller
[entryCellController sproutedSnapshot:recorder insertRecording:path title:title];
}
#pragma mark -
- (IBAction) insertContact:(id)sender
{