-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQSWebSearchPlugIn_Source.m
120 lines (94 loc) · 3.33 KB
/
QSWebSearchPlugIn_Source.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
//
// QSWebSearchPlugIn_Source.m
// QSWebSearchPlugIn
//
// Created by Nicholas Jitkoff on 11/24/04.
// Modified by Patrick Robertson on 30/05/11.
// Copyright __MyCompanyName__ 2004. All rights reserved.
//
#import "QSWebSearchPlugIn_Source.h"
@implementation QSWebSearchSource
- (BOOL)isVisibleSource {
return YES;
}
- (BOOL)indexIsValidFromDate:(NSDate *)indexDate forEntry:(NSDictionary *)theEntry {
NSDate *specDate=[NSDate dateWithTimeIntervalSinceReferenceDate:[[theEntry objectForKey:kItemModificationDate]floatValue]];
//NSLog(@"spec %d",([specDate compare:indexDate]==NSOrderedDescending));
return ([specDate compare:indexDate]==NSOrderedDescending);
return NO;
}
- (NSImage *) iconForEntry:(NSDictionary *)dict {
return [QSResourceManager imageNamed:@"Find"];
}
- (NSString *)identifierForObject:(id <QSObject>)object {
return nil;
}
- (NSArray *) objectsForEntry:(NSDictionary *)theEntry {
NSMutableArray *urlArray=[theEntry objectForKey:@"queryList"];
NSMutableArray *objects=[NSMutableArray arrayWithCapacity:1];
QSObject *newObject;
for (NSDictionary * urlDict in urlArray) {
newObject=[QSObject URLObjectWithURL:[urlDict objectForKey:@"url"] title:[urlDict objectForKey:@"name"]];
NSNumber *encoding=[urlDict objectForKey:@"encoding"];
if (encoding) {
[newObject setObject:encoding forMeta:kQSStringEncoding];
}
if (newObject) {
[objects addObject:newObject];
}
}
return objects;
}
- (NSView *) settingsView {
if (![super settingsView]){
[NSBundle loadNibNamed:NSStringFromClass([self class]) owner:self];
}
return [super settingsView];
}
- (void)populateFields {
[self willChangeValueForKey:@"urlArray"];
[self didChangeValueForKey:@"urlArray"];
[encodingCell setMenu:[self encodingMenu]];
}
static NSMenu *encodingMenu=nil;
- (NSMenu *)encodingMenu {
if (!encodingMenu) {
encodingMenu=[[NSMenu alloc]initWithTitle:@"Encodings"];
//[[encodingMenu addItemWithTitle:@"Default" action:nil keyEquivalent:@""]setTag:0];
//NSMenuItem *separator=[NSMenuItem separatorItem];
//[separator setTag:-1];
//[encodingMenu addItem:separator];
const CFStringEncoding *encodings;
encodings = CFStringGetListOfAvailableEncodings();
int i=0;
for (i=0; encodings[i] != kCFStringEncodingInvalidId;i++) {
NSString *encodingName=(NSString *)CFStringGetNameOfEncoding(encodings[i]);
if (i && encodings[i]-encodings[i-1]>16){
[encodingMenu addItem:[NSMenuItem separatorItem]];
}
//NSLog(@"Enc: %d %@",encodings[i],encodingName);
[[encodingMenu addItemWithTitle:encodingName action:nil keyEquivalent:@""]setTag:encodings[i]];
}
}
return encodingMenu;
}
- (void)objectDidEndEditing:(id)editor {
// NSLog(@"edited %@",editor);
[self updateCurrentEntryModificationDate];
[[NSNotificationCenter defaultCenter] postNotificationName:QSCatalogEntryChangedNotification object:[self currentEntry]];
//[QSLib scanItem:[self currentEntry] force:YES];
}
- (void)setUrlArray:(id)array {
NSMutableDictionary *entry=[self currentEntry];
[entry setObject:array forKey:@"queryList"];
}
- (NSMutableArray *)urlArray {
NSMutableDictionary *entry=[self currentEntry];
NSMutableArray *urlArray=[entry objectForKey:@"queryList"];
if (!urlArray) {
urlArray=[NSMutableArray array];
[entry setObject:urlArray forKey:@"queryList"];
}
return urlArray;
}
@end