-
Notifications
You must be signed in to change notification settings - Fork 5
/
ISSourceListDataView.j
396 lines (318 loc) · 13 KB
/
ISSourceListDataView.j
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/*
* ISSourceListDataView.j
* GithubIssues
*
* Created by Randy Luecke on April 14, 2011.
* Copyright 2011, RCLConcepts, LLC All rights reserved.
*/
/*!
This data view is used to display nearly every item in the sidebar
There are four components to the object value
1. Image - Small image that represents the item
this image can be a lock if it's a private repo or a tag/milestone/assignee
2. Text - duh
3. Number - The main number in the badge
4. Special number - displayed in green with the
badge. For now the only reason we have this is to show "assigned repos"
*/
var ISSourceLockImage = nil,
ISSourceLockImageActive = nil;
@implementation ISSourceListDataView : CPView
{
@outlet CPImageView imageview;
ISLabelIcon labelIconView;
@outlet CPTextField textfield;
ISAssignedBadgeView assignedBadgeView;
ISOpenBadgeView openBadgeView;
CPString text;
int number;
int specialNumber;
CPImage image;
CPImage selectedImage;
CPFont cachedFont;
}
- (id)initWithFrame:(CGRect)aRect
{
self = [super initWithFrame:aRect];
cachedFont = [CPFont boldSystemFontOfSize:11];
imageview = [[CPImageView alloc] initWithFrame:CGRectMake(5, 9, 15, 15)];
[imageview setImageScaling:CPScaleNone];
[self addSubview:imageview];
labelIconView = [[ISLabelIcon alloc] initWithFrame:CGRectMake(7, 12, 13, 13)];
[self addSubview:labelIconView];
textfield = [[CPTextField alloc] initWithFrame:CGRectMake(18, 9, 90, 15)];
[textfield setFont:[CPFont boldSystemFontOfSize:11]];
[textfield setLineBreakMode:CPLineBreakByTruncatingTail];
[self addSubview:textfield];
[textfield setValue:[CPColor colorWithRed:75/255 green:83/255 blue:89/255 alpha:1] forThemeAttribute:@"text-color" inState:CPThemeStateNormal];
[textfield setValue:[CPColor colorWithRed:1 green:1 blue:1 alpha:.55] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[textfield setValue:CGSizeMake(0,1) forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
[textfield setValue:[CPColor colorWithRed:1 green:1 blue:1 alpha:1] forThemeAttribute:@"text-color" inState:CPThemeStateSelectedTableDataView];
[textfield setValue:[CPColor colorWithRed:0 green:0 blue:0 alpha:.25] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateSelectedTableDataView];
assignedBadgeView = [[ISAssignedBadgeView alloc] initWithFrame:CGRectMake(0, 0, 0, 17)];
[assignedBadgeView setAutoresizingMask:CPViewMinXMargin];
[self addSubview:assignedBadgeView];
openBadgeView = [[ISOpenBadgeView alloc] initWithFrame:CGRectMake(0, 0, 50, 17)];
[openBadgeView setAutoresizingMask:CPViewMinXMargin];
[self addSubview:openBadgeView];
return self;
}
- (void)layoutSubviews
{
if (!cachedFont)
cachedFont = [CPFont boldSystemFontOfSize:11];
[super layoutSubviews];
if (image || [labelIconView color])
var origin = CGPointMake(18, 9);
else
var origin = CGPointMake(5, 9);
[textfield setFrameOrigin:origin];
// now find the inset of the textfield
// console.log([specialNumber sizeWithFont:cachedFont], [number sizeWithFont:cachedFont]);
var inset = 15,
width = [self frameSize].width,
height = [textfield frameSize].height;
// Size to fit works automatically because the theme insets are correct.
[assignedBadgeView sizeToFit];
[openBadgeView sizeToFit];
var beginingOfBadge = width - [assignedBadgeView bounds].size.width - [openBadgeView bounds].size.width - 3;
[assignedBadgeView setFrame:CGRectMake(beginingOfBadge, 9, [assignedBadgeView bounds].size.width, 17)];
[openBadgeView setFrameOrigin:CGPointMake(CGRectGetMaxX([assignedBadgeView frame]), 9)];
[textfield setFrameSize:CGSizeMake(beginingOfBadge - inset, height)];
}
- (void)setObjectValue:(id)aValue
{
var image = nil,
labelColor = nil;
if ([aValue isKindOfClass:ISRepository])
{
text = [aValue identifier];
number = [aValue numberOfOpenIssues];
specialNumber = [aValue issuesAssignedToCurrentUser];
if ([aValue isPrivate])
{
if (!ISSourceLockImage)
ISSourceLockImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"lock-icon.png"] size:CGSizeMake(8.0, 12.0)];
image = ISSourceLockImage;
if (!ISSourceLockImageActive)
ISSourceLockImageActive = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"lock-icon-active.png"] size:CGSizeMake(8.0, 12.0)];
selectedImage = ISSourceLockImageActive;
}
}
else if ([aValue isKindOfClass:ISLabel])
{
text = [aValue name];
number = nil;
specialNumber = nil;
labelColor = [aValue color];
}
else if (aValue)
{
text = aValue.text;
number = aValue.number;
specialNumber = aValue.specialNumber;
}
[textfield setStringValue:text];
[imageview setImage:image];
[labelIconView setColor:labelColor];
[assignedBadgeView setStringValue:specialNumber];
[assignedBadgeView setHidden:!specialNumber];
[openBadgeView setStringValue:number];
[openBadgeView setIsClosed:!specialNumber];
[openBadgeView setHidden:!number && !specialNumber];
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
[textfield setThemeState:aState];
[imageview setImage:[self hasThemeState:CPThemeStateSelectedDataView] ? selectedImage : image];
[assignedBadgeView setThemeState:aState];
[openBadgeView setThemeState:aState];
}
- (void)unsetThemeState:(CPThemeState)aState
{
[super unsetThemeState:aState];
[textfield unsetThemeState:aState];
[imageview setImage:[self hasThemeState:CPThemeStateSelectedDataView] ? selectedImage : image];
[assignedBadgeView unsetThemeState:aState];
[openBadgeView unsetThemeState:aState];
}
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
imageview = [aCoder decodeObjectForKey:"imageview"];
labelIconView = [aCoder decodeObjectForKey:"labelIconView"];
textfield = [aCoder decodeObjectForKey:"textfield"];
assignedBadgeView = [aCoder decodeObjectForKey:"assignedBadgeView"];
openBadgeView = [aCoder decodeObjectForKey:"openBadgeView"];
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:imageview forKey:"imageview"];
[aCoder encodeObject:labelIconView forKey:"labelIconView"];
[aCoder encodeObject:textfield forKey:"textfield"];
[aCoder encodeObject:assignedBadgeView forKey:"assignedBadgeView"];
[aCoder encodeObject:openBadgeView forKey:"openBadgeView"];
}
@end
@implementation ISBadgeView : CPTextField
- (id)initWithFrame:aFrame
{
if (self = [super initWithFrame:aFrame])
{
[self applyLook];
}
return self;
}
- (void)applyLook
{
[self setBezeled:NO];
[self setTextColor:[CPColor colorWithHexString:"F5F5F5"]];
[self setTextShadowColor:[CPColor colorWithCSSString:@"rgba(0, 0, 0, 0.5)"]];
[self setTextShadowOffset:CGSizeMake(0.0, 1.0)];
[self setFont:[CPFont systemFontOfSize:11.0]];
[self setVerticalAlignment:CPCenterVerticalTextAlignment];
[self setAlignment:CPCenterTextAlignment];
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
[self updateBackground];
}
- (void)unsetThemeState:(CPThemeState)aState
{
[super unsetThemeState:aState];
[self updateBackground];
}
- (void)updateBackground
{
}
@end
// Reuse these for optimal speed - we don't want one colour instance per row.
var ISAssignedBadgeViewBackgroundColor = nil,
ISOpenBadgeViewBackgroundColor = nil,
ISOpenBadgeViewClosedBackgroundColor = nil,
ISAssignedBadgeActiveViewBackgroundColor = nil,
ISOpenBadgeViewActiveBackgroundColor = nil,
ISOpenBadgeViewActiveClosedBackgroundColor = nil;
@implementation ISAssignedBadgeView : ISBadgeView
- (void)applyLook
{
[super applyLook];
[self setValue:CGInsetMake(3.0, 5.0, 2.0, 7.0) forThemeAttribute:"content-inset"];
if (!ISAssignedBadgeViewBackgroundColor)
{
ISAssignedBadgeViewBackgroundColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
resourcesImage("assigned-badge-left.png", 7, 17),
resourcesImage("assigned-badge-middle.png", 1, 17),
resourcesImage("assigned-badge-right.png", 1, 17)
] isVertical:NO]];
ISAssignedBadgeActiveViewBackgroundColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
resourcesImage("assigned-badge-active-left.png", 7, 17),
resourcesImage("assigned-badge-active-middle.png", 1, 17),
resourcesImage("assigned-badge-active-right.png", 1, 17)
] isVertical:NO]];
}
[self setBackgroundColor:ISAssignedBadgeViewBackgroundColor];
}
- (void)updateBackground
{
[self setBackgroundColor:[self hasThemeState:CPThemeStateSelectedDataView] ? ISAssignedBadgeActiveViewBackgroundColor : ISAssignedBadgeViewBackgroundColor];
}
@end
@implementation ISOpenBadgeView : ISBadgeView
{
BOOL isClosed @accessors;
}
- (void)applyLook
{
[super applyLook];
[self setValue:CGInsetMake(3.0, 6.0, 2.0, 6.0) forThemeAttribute:"content-inset"];
if (!ISOpenBadgeViewBackgroundColor)
{
ISOpenBadgeViewBackgroundColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
resourcesImage("open-badge-left.png", 1, 17),
resourcesImage("open-badge-middle.png", 1, 17),
resourcesImage("open-badge-right.png", 7, 17)
] isVertical:NO]];
ISOpenBadgeViewClosedBackgroundColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
resourcesImage("open-badge-closed-left.png", 7, 17),
resourcesImage("open-badge-middle.png", 1, 17),
resourcesImage("open-badge-right.png", 7, 17)
] isVertical:NO]];
ISOpenBadgeActiveViewBackgroundColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
resourcesImage("open-badge-active-left.png", 1, 17),
resourcesImage("open-badge-active-middle.png", 1, 17),
resourcesImage("open-badge-active-right.png", 7, 17)
] isVertical:NO]];
ISOpenBadgeActiveViewClosedBackgroundColor = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
resourcesImage("open-badge-closed-active-left.png", 7, 17),
resourcesImage("open-badge-active-middle.png", 1, 17),
resourcesImage("open-badge-active-right.png", 7, 17)
] isVertical:NO]];
}
[self setIsClosed:YES];
}
- (void)setIsClosed:(BOOL)aFlag
{
isClosed = aFlag;
[self updateBackground];
}
- (void)updateBackground
{
[self setBackgroundColor:
[self hasThemeState:CPThemeStateSelectedDataView] ?
isClosed ? ISOpenBadgeActiveViewClosedBackgroundColor : ISOpenBadgeActiveViewBackgroundColor :
isClosed ? ISOpenBadgeViewClosedBackgroundColor : ISOpenBadgeViewBackgroundColor];
}
@end
@implementation ISLabelIcon : CPView
{
CPColor color @accessors;
}
- (void)setColor:(CPColor)aColor
{
if (color == aColor)
return;
color = aColor;
[self setNeedsDisplay:YES];
}
- (void)drawRect:(CGRect)aRect
{
[super drawRect:aRect];
if (!color)
return;
var context = [[CPGraphicsContext currentContext] graphicsPort],
bounds = [self bounds];
CGContextSetFillColor(context, color);
CGContextSetShadowWithColor(context, CGSizeMake(0, 1), 0, [CPColor colorWithCalibratedWhite:0 alpha:.4]);
CGContextBeginPath(context);
/*
M 10.07,0 H 6.568 L 0,6.488 L 4.543,11 L 11,4.588 V 0.924 L 10.07,0 z
M 9.814,2.493
C 9.449,2.856 8.855,2.856 8.488,2.493
C 8.122,2.129 8.122,1.54 8.488,1.176
C 8.854,0.812 9.449,0.812 9.814,1.176
C 10.182,1.54 10.182,2.129 9.814,2.493 z
*/
// Coordinates below are all based on an 11x11 size label.
CGContextScaleCTM(context, (bounds.size.width -2) / 11.0, (bounds.size.height- 2) / 11.0);
CGContextMoveToPoint(context, 10.07, 0);
CGContextAddLineToPoint(context, 6.568, 0);
CGContextAddLineToPoint(context, 0, 6.488);
CGContextAddLineToPoint(context, 4.543, 11);
CGContextAddLineToPoint(context, 11, 4.588);
CGContextAddLineToPoint(context, 11, 0.924);
CGContextAddLineToPoint(context, 10.07, 0);
CGContextClosePath(context);
CGContextMoveToPoint(context, 9.814, 2.493);
CGContextAddCurveToPoint(context, 9.449, 2.856, 8.855, 2.856, 8.488, 2.493);
CGContextAddCurveToPoint(context, 8.122, 2.129, 8.122, 1.54, 8.488, 1.176);
CGContextAddCurveToPoint(context, 8.854, 0.812, 9.449, 0.812, 9.814, 1.176);
CGContextAddCurveToPoint(context, 10.182, 1.54, 10.182, 2.129, 9.814, 2.493);
CGContextClosePath(context);
CGContextFillPath(context);
}
@end