forked from phildow/Journler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexServerPDFView.m
87 lines (68 loc) · 2.57 KB
/
IndexServerPDFView.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
//
// IndexServerPDFView.m
// Journler
//
// Created by Philip Dow on 3/5/07.
// Copyright 2007 Sprouted, Philip Dow. All rights reserved.
//
#import "IndexServerPDFView.h"
@implementation IndexServerPDFView
- (BOOL) insertsLexiconContextSeparator
{
return insertsLexiconContextSeparator;
}
- (void) setInsertsLexiconContextSeparator:(BOOL)withSeparator
{
insertsLexiconContextSeparator = withSeparator;
}
#pragma mark -
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
// the menu we will return
NSMenu *returnMenu = [super menuForEvent:theEvent];
// go ahead and get out of here if this menu is already built
if ( [returnMenu itemWithTag:10746] != nil )
return returnMenu;
PDFSelection *pdfSelection = [self currentSelection];
NSString *stringSelection = [pdfSelection string];
// the lexicon menu, but only if a single term is selected
if ( [stringSelection length] > 0
&& [[self delegate] respondsToSelector:@selector(indexServerPDFView:showLexiconSelection:term:)]
&& [[self delegate] respondsToSelector:@selector(representedObject)] )
{
NSString *selection = stringSelection;
if ( [selection rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].location == NSNotFound )
{
if ( [self insertsLexiconContextSeparator] )
[returnMenu addItem:[NSMenuItem separatorItem]];
NSMenu *lexiconMenu = [[[NSMenu alloc] initWithTitle:NSLocalizedString(@"menuitem lexicon", @"")] autorelease];
[lexiconMenu setDelegate:[self valueForKeyPath:@"delegate.representedObject.journal.indexServer"]];
NSMenuItem *lexiconMenuItem = [[[NSMenuItem alloc]
initWithTitle:NSLocalizedString(@"menuitem lexicon", @"")
action:nil
keyEquivalent:@""] autorelease];
[lexiconMenuItem setTag:10746];
[lexiconMenuItem setTarget:self];
[lexiconMenuItem setAction:@selector(_showObjectFromLexicon:)];
[lexiconMenuItem setRepresentedObject:selection];
[lexiconMenuItem setSubmenu:lexiconMenu];
[returnMenu addItem:lexiconMenuItem];
}
}
return returnMenu;
}
- (IBAction) _showObjectFromLexicon:(id)sender
{
id anObject = [sender representedObject];
// modifiers should support opening the item in windows, tabs, etc
// the item should be opened and the terms highlighted and located
if ( anObject == nil || ![[self delegate] respondsToSelector:@selector(indexServerPDFView:showLexiconSelection:term:)] )
{
NSBeep();
}
else
{
[[self delegate] indexServerPDFView:self showLexiconSelection:anObject term:[self valueForKeyPath:@"delegate.representedObject.journal.indexServer.lexiconMenuRepresentedTerm"]];
}
}
@end