-
Notifications
You must be signed in to change notification settings - Fork 1
/
QSShelfSource.m
154 lines (120 loc) · 4.64 KB
/
QSShelfSource.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
#import "QSShelfSource.h"
#import "QSShelfController.h"
#define QSShelfPboardType @"qs.shelf"
#define kQSClipboardContentsID @"QSPresetClipboardContents"
#define kQSShelfShowAction @"QSShelfShowAction"
#define kQSPutOnShelfAction @"QSPutOnShelfAction"
@implementation QSShelfSource
- (BOOL)indexIsValidFromDate:(NSDate *)indexDate forEntry:(NSDictionary *)theEntry{
return YES;
}
- (NSImage *) iconForEntry:(NSDictionary *)dict{
return [QSResourceManager imageNamed:@"prefsCatalog"];
}
- (NSArray *) objectsForEntry:(NSDictionary *)theEntry{
if ([[theEntry objectForKey:kItemID] isEqualToString:kQSShelfContentsID]) {
return [QSLib shelfNamed:@"General"];
} else if ([[theEntry objectForKey:kItemID] isEqualToString:kQSClipboardContentsID]) {
return [QSLib shelfNamed:@"QSPasteboardHistory"];
}
NSDictionary *nameDict=[NSDictionary dictionaryWithObjectsAndKeys:
@"Shelf",@"General",
@"Clipboard History",@"QSPasteboardHistory",
nil];
NSMutableArray *objects=[NSMutableArray array];
QSObject *newObject;
NSString *name;
NSString *key;
NSEnumerator *objectEnumerator=[[QSLib shelfArrays]keyEnumerator];
while(key=[objectEnumerator nextObject]){
name=[nameDict objectForKey:key];
newObject=[QSObject objectWithName:name];
[newObject setObject:key forType:QSShelfPboardType];
[newObject setPrimaryType:QSShelfPboardType];
[objects addObject:newObject];
}
return objects;
}
// Object Handler Methods
- (NSString *)identifierForObject:(QSObject*)object{
return [@"[Shelf]:" stringByAppendingString:[object objectForType:QSShelfPboardType]];
}
- (BOOL)loadIconForObject:(QSObject *)object{
NSImage *icon=nil;
if ([[object objectForType:QSShelfPboardType] isEqualToString:@"General"])
icon=[QSResourceManager imageNamed:@"prefsCatalog"];
else if ([[object objectForType:QSShelfPboardType] isEqualToString:@"QSPasteboardHistory"]){
icon=[[QSReg bundleForClassName:@"QSPasteboardController"] imageNamed:@"Clipboard"];
}
if (icon){
[object setIcon:icon];
return YES;
}
return NO;
}
- (BOOL)objectHasChildren:(id <QSObject>)object{
return YES;
}
- (BOOL)objectHasValidChildren:(id <QSObject>)object{
return YES;
}
- (BOOL)loadChildrenForObject:(QSObject *)object{
NSArray *children=[self childrenForObject:object];
if (children){
[object setChildren:children];
return YES;
}
return NO;
}
- (NSArray *)childrenForObject:(QSObject *)object{
return [QSLib shelfNamed:[object objectForType:QSShelfPboardType]];
}
// Action Provider Methods
- (NSArray *) types{
return nil;
}
- (NSArray *) actions{
QSAction *action=[QSAction actionWithIdentifier:kQSShelfShowAction];
[action setIcon:[QSResourceManager imageNamed:@"prefsCatalog"]];
[action setProvider:self];
[action setAction:@selector(show:)];
[action setArgumentCount:1];
QSAction *action2=[QSAction actionWithIdentifier:kQSPutOnShelfAction];
[action2 setIcon:[QSResourceManager imageNamed:@"prefsCatalog"]];
[action2 setProvider:self];
[action2 setAction:@selector(putObjectOnShelf:)];
[action2 setArgumentCount:1];
return [NSArray arrayWithObjects:action,action2,nil];
}
- (NSArray *)validActionsForDirectObject:(QSObject *)dObject indirectObject:(QSObject *)iObject{
if ([dObject objectForType:QSShelfPboardType]){
return [NSArray arrayWithObject:kQSShelfShowAction];
}
// else if (dObject && fBETA){
// return [NSArray arrayWithObjects:kQSPutOnShelfAction,nil];
// }
return nil;
}
- (NSArray *)validIndirectObjectsForAction:(NSString *)action directObject:(QSObject *)dObject{return nil;}
- (NSWindowController *)controllerForShelf:(NSString *)shelfName{
if ([shelfName isEqualToString:@"General"])
return [QSShelfController sharedInstance];
else if ([shelfName isEqualToString:@"QSPasteboardHistory"])
return [QSReg getClassInstance:@"QSPasteboardController"];
// NSLog(@"[QSPasteboardController sharedInstance] FIX ME"); //return [QSPasteboardController sharedInstance];
return nil;
}
- (QSObject *) show:(QSObject *)dObject{
[(QSDockingWindow *)[[self controllerForShelf:[dObject objectForType:QSShelfPboardType]] window] toggle:self];
return nil;
}
- (QSObject *) putObjectOnShelf:(QSObject *)dObject{
if (dObject != nil) {
dObject = (QSObject*)[dObject resolvedObject];
[[QSShelfController sharedInstance] addObject:dObject atIndex:0];
} else {
NSBeep();
}
return nil;
}
@end