-
Notifications
You must be signed in to change notification settings - Fork 11
/
TSModeMatrix.m
72 lines (61 loc) · 1.8 KB
/
TSModeMatrix.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
//
// TSModeMatrix.m
// ThisService
//
// Created by Jesper on 2007-08-04.
// Copyright 2007-2012 waffle software. All rights reserved.
// BSD licensed - see license.txt for more information.
//
#import "TSModeMatrix.h"
@implementation TSModeMatrix
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self != nil) {
lastTag = NSNotFound;
}
return self;
}
- (void)finishInitializing {
[self selectCellWithTag:0];
[self reconfigureWithAnimation:NO];
}
- (void)setContentInitialized {
contentHasInitialized = YES;
[self finishInitializing];
}
- (void)awakeFromNib {
if (contentHasInitialized) return;
[self finishInitializing];
}
- (void)goToTag:(int)tag {
[self selectCellWithTag:tag];
[self selectMe:[self cellWithTag:tag]];
}
- (void)selectMe:(id)sender {
id dlx = [self delegate];
//NSLog(@"do we have a delegate? %@; sender: %@", dlx, sender);
if ([dlx respondsToSelector:@selector(modeMatrix:shouldSwitchFromTag:toTag:)]) {
//NSLog(@"yes, and it responds to the selector");
if (![dlx modeMatrix:self shouldSwitchFromTag:lastTag toTag:[self selectedTag]]) {
//NSLog(@"it responded no. last tag: %d", lastTag);
if ([self selectedTag] != lastTag) {
[self selectCellWithTag:lastTag];
[self selectMe:[self cellWithTag:lastTag]];
}
return;
}
}
// NSLog(@"go ahead");
[self reconfigureWithAnimation:YES];
}
- (id<TSModeMatrixDelegate>)delegate {
return (id<TSModeMatrixDelegate>)[super delegate];
}
- (void)reconfigureWithAnimation:(BOOL)anim {
NSInteger previousTag = lastTag;
lastTag = [self selectedTag];
// NSLog(@"lastTag set to %llu; previousTag is %llu", (unsigned long long)lastTag, (unsigned long long)previousTag);
NSInteger newTag = lastTag;
[[self delegate] modeMatrix:self switchFromTag:previousTag toTag:newTag animate:anim];
}
@end