forked from julius/silverflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSilverFlow.m
311 lines (248 loc) · 8.83 KB
/
SilverFlow.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
//
// SilverFlow.m
// SilverFlow
//
// Created by Julius Eckert on 05.05.08.
// Copyright __MyCompanyName__ 2008. All rights reserved.
//
// QS Interface template by Vacuous Virtuoso
//
#import <QSEffects/QSWindow.h>
#import <QSInterface/QSSearchObjectView.h>
#import <QSInterface/QSObjectCell.h>
#import "SilverFlow.h"
@implementation SilverFlow
- (id)init {
id result = [self initWithWindowNibName:@"SilverFlow"];
[SFResources sharedInstance];
return result;
}
- (void) windowDidLoad {
[super windowDidLoad];
QSWindow *window=(QSWindow *)[self window];
[[self window] setLevel:NSModalPanelWindowLevel];
[[self window] setFrameAutosaveName:@"SilverFlowWindow"];
// If it's off the screen, bring it back in
[[self window]setFrame:constrainRectToRect([[self window]frame],[[[self window]screen]visibleFrame]) display:NO];
[window setHideOffset:NSMakePoint(0,0)];
[window setShowOffset:NSMakePoint(0,0)];
[window setShowEffect:[NSDictionary dictionaryWithObjectsAndKeys:@"QSBingeEffect",@"transformFn",@"show",@"type",[NSNumber numberWithFloat:0.1],@"duration",nil]];
[window setHideEffect:[NSDictionary dictionaryWithObjectsAndKeys:@"QSShrinkEffect",@"transformFn",@"hide",@"type",[NSNumber numberWithFloat:.15],@"duration",nil]];
// setWindowProperty returns an error, unfortunately... ignore it
[window setWindowProperty:[NSDictionary dictionaryWithObjectsAndKeys:@"QSExplodeEffect",@"transformFn",@"hide",@"type",[NSNumber numberWithFloat:0.1],@"duration",nil] forKey:kQSWindowExecEffect];
NSArray *theControls=[NSArray arrayWithObjects:dSelector,aSelector,iSelector,nil];
foreach(theControl,theControls){
[theControl setPreferredEdge:NSMinYEdge];
[theControl setResultsPadding:NSMinY([dSelector frame])];
NSCell *theCell=[theControl cell];
[(QSObjectCell *)theCell setShowDetails:NO];
}
[[cfview coverflow] setSilverFlow:self];
iconIndices = [[NSMutableArray alloc] init];
NSThread* t = [[NSThread alloc] initWithTarget:self selector:@selector(iconLoader) object:nil];
[t start];
}
- (void)selectorIsFirstResponder:(id)sender {
if (sender == dSelector) {
[cfview setSelector:1];
}
if (sender == aSelector) {
[cfview setSelector:2];
}
if (sender == iSelector) {
[cfview setSelector:3];
}
[self sfUpdate];
}
// find current index in resultArray
- (int)positionInRange {
int i;
for (i=0; i<[[dSelector resultArray] count]; i++) {
QSObject* cur = [[dSelector resultArray] objectAtIndex:i];
if (cur == [dSelector objectValue]) return i;
}
return 0;//-1;
}
- (NSImage*)getImageOfSelector:(QSSearchObjectView*)sel {
QSObject* qsobj = [sel objectValue];
if (qsobj) {
@try {
NSImage* img = [[NSImage alloc] initWithSize:NSMakeSize(128,128)];
[img lockFocus];
[[sel cell] drawObjectImage:qsobj inRect:NSMakeRect(0,0,128,128) cellFrame:NSMakeRect(0,0,128,128) controlView:sel flipped:false opacity:1.0];
[img unlockFocus];
return img;
}
@catch (NSException *exception) {
NSLog(@"############ getImageOfSelector: Caught %@: %@", [exception name], [exception reason]);
}
return nil;
} else return nil;
}
- (void)sfUpdate {
bool rd = false;
// ---------- text --------------
if ([dSelector objectValue]) {
QSObject* qsobj = nil;
if ([[self window] firstResponder] == dSelector) qsobj = [dSelector objectValue];
if ([[self window] firstResponder] == aSelector) qsobj = [aSelector objectValue];
if ([[self window] firstResponder] == iSelector) qsobj = [iSelector objectValue];
if (qsobj) {
NSString* text = [NSString stringWithFormat:@"%@", [qsobj displayName]];
NSString* details = [NSString stringWithFormat:@"%@", [qsobj details]];
if ([qsobj details] == nil) details = @"";
[cfview setText:text details:details];
} else { [cfview setText:@"" details:@""]; }
}
if ([aSelector objectValue]) [[cfview soAction] setText:[[aSelector objectValue] displayName]];
else [[cfview soAction] setText:@" - "];
if ([iSelector objectValue]) [[cfview soIndirect] setText:[[iSelector objectValue] displayName]];
else [[cfview soIndirect] setText:@" - "];
// -------- coverflow ------------
@synchronized(iconIndices) {
[iconIndices removeAllObjects];
[[cfview coverflow] setSelection:[self positionInRange]];
//[[dSelector getResultController] resultIconLoader] loadIconsInRange:
// ---------- selectorObjects ------------
@try {
if ([aSelector objectValue] != actionLast) {
actionLast = [aSelector objectValue];
if (actionLast) [[cfview soAction] setImage:[self getImageOfSelector:aSelector]];
else [[cfview soAction] setImage:nil];
rd = true;
}
if ([iSelector objectValue] != indirectLast) {
indirectLast = [iSelector objectValue];
if (indirectLast) [[cfview soIndirect] setImage:[self getImageOfSelector:iSelector]];
else [[cfview soIndirect] setImage:nil];
rd = true;
}
}
@catch (NSException *exception) {
NSLog(@"############ sfUpdate: Caught %@: %@", [exception name], [exception reason]);
}/**/
}
if (rd) [cfview dofRedraw];
}
- (void)resultsUpdated:(id)sender {
if (sender == dSelector) {
[[cfview coverflow] setItemCount:[[dSelector resultArray] count]];
}
[self sfUpdate];
}
- (QSObject*)objectAtIndex:(int)i {
if (![dSelector resultArray]) return nil;
if ((i >= [[dSelector resultArray] count]) || (i<0)) return nil;
return [[dSelector resultArray] objectAtIndex:i];
}
/* ---------------------------------------------------------------
Image Loading
----------------------------------------------------------------- */
- (void)requireImageAtIndex:(int)i {
QSObject* qsobj = [self objectAtIndex:i];
if ([qsobj iconLoaded] == false) [qsobj loadIcon];
[iconIndices addObject:[NSNumber numberWithInt:i]];
}
- (void)loadImageFor:(int)i {
QSObject* qsobj = [self objectAtIndex:i];
NSImage* img = nil;
if (([[qsobj displayName] length] > 13) && ([[[qsobj displayName] substringWithRange:NSMakeRange(0,13)] isEqualToString:@"http://images"])) {
/*
@try {
img = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:[qsobj displayName]]];
}
@catch (NSException *exception) {
NSLog(@"############ loadImageFor: Caught %@: %@", [exception name], [exception reason]);
}/**/
}
if (img == nil) {
img = [[NSImage alloc] initWithSize:NSMakeSize(128,128)];
[img lockFocus];
[[dSelector cell] drawObjectImage:qsobj inRect:NSMakeRect(0,0,128,128) cellFrame:NSMakeRect(0,0,128,128) controlView:dSelector flipped:false opacity:1.0];
[img unlockFocus];
}
[[cfview coverflow] setImage:img atIndex:i];
[cfview dofRedraw];
//[[cfview coverflow] setImage:[QSResourceManager imageNamed:@"defaultAction"] atIndex:i];
}
- (void)iconLoader {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
int dr = 0;
while (true) {
@synchronized(iconIndices) {
if ([iconIndices count] > 0) {
int i = [[iconIndices objectAtIndex:0] intValue];
[iconIndices removeObjectAtIndex:0];
[self loadImageFor:i];
}
}
[NSThread sleepForTimeInterval:0.05];
}
[pool release];
}
- (NSSize)maxIconSize{
return NSMakeSize(128,128);
}
- (void)showMainWindow:(id)sender{
if ([[self window]isVisible])[[self window]pulse:self];
[super showMainWindow:sender];
}
- (void)hideMainWindow:(id)sender{
[[self window] saveFrameUsingName:@"SilverFlowWindow"];
[super hideMainWindow:sender];
}
/*
* If you want an effect such as an animation
* when the indirect selector shows up,
* the next three methods are for you to subclass.
*/
- (void)showIndirectSelector:(id)sender{
[super showIndirectSelector:sender];
}
- (void)expandWindow:(id)sender{
[super expandWindow:sender];
}
- (void)contractWindow:(id)sender{
[super contractWindow:sender];
}
// When something changes, update the command string
- (void)firstResponderChanged:(NSResponder *)aResponder{
[super firstResponderChanged:aResponder];
[self updateDetailsString];
}
- (void)searchObjectChanged:(NSNotification*)notif{
[super searchObjectChanged:notif];
@try {
[self updateDetailsString];
}
@catch (NSException *exception) {
NSLog(@"############ searchObjectChanged: Caught %@: %@", [exception name], [exception reason]);
}
}
// The method to update the command string
// Get rid of it if you're not having a commandView outlet
-(void)updateDetailsString{
//[self sfUpdate];
NSString *command=[[self currentCommand]description];
[commandView setStringValue:command?command:@""];
[self sfUpdate];
}
// Uncomment if you're having a customize button + pref pane
/*- (IBAction)customize:(id)sender{
[[NSClassFromString(@"QSPreferencesController") sharedInstance]showPaneWithIdentifier:@"QSFumoInterfacePrefPane"];
}*/
- (void)actionActivate:(id)sender{
[super actionActivate:sender];
}
- (void)updateViewLocations{
[super updateViewLocations];
}
-(void) editorEnabled:(id)sender {
[commandView setHidden:true];
[cfview setHidden:true];
}
-(void) editorDisabled {
[commandView setHidden:false];
[cfview setHidden:false];
}
@end