public
Description: Quicksilver Interface
Homepage: http://www.julius-eckert.com/project/view/2/2
Clone URL: git://github.com/julius/showcase.git
julius (author)
Sun May 17 03:54:14 -0700 2009
commit  9aaf3570fc85a53d13fbe838afd75d5ec34af533
tree    523fc21034122cec47ff589b1532c7cb11f3c1aa
parent  731b6ca867323da7a65aa433437ff90b84d44c2c
showcase / QSCollectingSearchObjectView.m
100644 136 lines (133 sloc) 3.858 kb
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
//
// QSCollectingSearchObjectView.m
// Quicksilver
//
// Created by Alcor on 3/22/05.
// Copyright 2005 Blacktree. All rights reserved.
//
 
#import "QSCollectingSearchObjectView.h"
 
@implementation QSCollectingSearchObjectView
- (void)awakeFromNib {
[super awakeFromNib];
collection = [[QSCollection alloc] init];
collecting = NO;
collectionEdge = NSMinYEdge;
collectionSpace = 16.0;
}
- (NSSize) cellSize {
NSSize size = [super cellSize];
if (collectionSpace < 0.0001)
size.width += [collection count]*16;
return size;
}
- (void)drawRect:(NSRect)rect {
NSRect frame = [self frame];
int count = [collection count];
if (![self currentEditor] && count) {
float totalSpace = collectionSpace+4;
if (collectionSpace < 0.0001) {
totalSpace = count*16+8;
}
frame.origin = NSZeroPoint;
NSRect mainRect, collectRect;
NSDivideRect(frame, &collectRect, &mainRect, totalSpace, collectionEdge);
[[self cell] drawWithFrame:mainRect inView:self];
[[NSColor colorWithDeviceWhite:1.0 alpha:0.92] set];
if (collectionSpace < 0.0001)
collectRect.origin.x += 8;
int i;
float iconSize = collectionSpace?collectionSpace:16;
float opacity = collecting?1.0:0.5;
QSObject *object;
for (i = 0; i<count; i++) {
object = [collection objectAtIndex:i];
NSImage *icon = [object icon];
[icon setSize:NSMakeSize(16, 16)];
[icon setFlipped:NO];
[icon drawInRect:NSMakeRect(collectRect.origin.x+iconSize*i, collectRect.origin.y+2, iconSize, iconSize) fromRect:rectFromSize([icon size]) operation:NSCompositeSourceOver fraction:opacity];
}
} else {
[super drawRect:rect];
}
}
- (IBAction)collect:(id)sender { //Adds additional objects to a collection
if (!collecting) collecting = YES;
if ([super objectValue]) {
[collection addObject:[super objectValue]];
[self setNeedsDisplay:YES];
}
[self setShouldResetSearchString:YES];
}
- (IBAction)uncollect:(id)sender { //Removes an object to a collection
if ([collection count])
[collection removeObject:[super objectValue]];
if (![collection count]) collecting = NO;
[self setNeedsDisplay:YES];
}
- (IBAction)uncollectLast:(id)sender { //Removes an object to a collection
if ([collection count])
[collection removeLastObject];
if (![collection count])
collecting = NO;
[self setNeedsDisplay:YES];
//if ([[resultController window] isVisible])
// [resultController->resultTable setNeedsDisplay:YES];}
}
- (void)clearObjectValue {
[self emptyCollection:nil];
[super clearObjectValue];
}
- (IBAction)emptyCollection:(id)sender {
collecting = NO;
[collection removeAllObjects];
}
- (IBAction)combine:(id)sender { //Resolve a collection as a single object
[self setObjectValue:[self objectValue]];
[self emptyCollection:sender];
collecting = NO;
}
- (id)objectValue {
if ([collection count])
return [QSObject objectByMergingObjects:(NSArray *)collection withObject:[super objectValue]];
else
return [super objectValue];
}
- (BOOL)objectIsInCollection:(QSObject *)thisObject {
return [collection containsObject:thisObject];
}
- (void)deleteBackward:(id)sender {
if ([collection count] && ![partialString length])
[self uncollectLast:sender];
else
[super deleteBackward:sender];
}
- (void)reset:(id)sender {
collecting = NO;
[super reset:sender];
}
- (void)selectObjectValue:( QSObject *)newObject {
if (!collecting)
[self emptyCollection:nil];
[super selectObjectValue:newObject];
}
- (void)setObjectValue:(QSBasicObject *)newObject {
if (!collecting) [self emptyCollection:self];
[super setObjectValue:newObject];
}
- (NSRectEdge)collectionEdge {
return collectionEdge;
}
- (void)setCollectionEdge:(NSRectEdge)value {
collectionEdge = value;
}
- (float)collectionSpace {
return collectionSpace;
}
- (void)setCollectionSpace:(float)value {
collectionSpace = value;
}
- (void)dealloc {
[collection release];
[super dealloc];
}
@end