-
Notifications
You must be signed in to change notification settings - Fork 221
/
AfloatWindowIdentifier.m
171 lines (125 loc) · 4.2 KB
/
AfloatWindowIdentifier.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
//
// AfloatWindowIdentifier.m
// Afloat
//
// Created by ∞ on 28/08/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "AfloatWindowIdentifier.h"
@interface AfloatWindowIdentifier ()
@property(setter=_setCategory:, copy) NSString* category;
@property(setter=_setKey:, copy) NSString* key;
@property(setter=_setCanMatchMultipleWindows:, assign) BOOL canMatchMultipleWindows;
+ (NSArray*) identifierSubclasses;
@end
@interface AfloatWindowIdentifier (AfloatAbstractPrivateMethods)
+ (BOOL) canInitWithWindow:(NSWindow*) w;
- (id) initWithWindow:(NSWindow*) w;
@end
// the class that implements kAfloatByWindowCustomSubclassCategory
@interface _AfloatWindowByClassIdentifier : AfloatWindowIdentifier {}
@end
@implementation _AfloatWindowByClassIdentifier
+ (BOOL) canInitWithWindow:(NSWindow*) w {
return ![w isKindOfClass:[NSPanel class]] && ![w isMemberOfClass:[NSWindow class]];
}
- (id) initWithWindow:(NSWindow*) w {
if (self = [super init]) {
self.category = kAfloatByWindowCustomSubclassCategory;
self.key = NSStringFromClass([w class]);
self.canMatchMultipleWindows = YES;
}
return self;
}
- (BOOL) matchesWindow:(NSWindow*) w {
return [(NSStringFromClass([w class])) isEqual:self.key];
}
@end
// the class that implements kAfloatByDelegateCustomSubclassCategory
@interface _AfloatWindowByDelegateClassIdentifier : AfloatWindowIdentifier {}
@end
@implementation _AfloatWindowByDelegateClassIdentifier
+ (BOOL) canInitWithWindow:(NSWindow*) w {
return [w delegate] != nil;
}
- (id) initWithWindow:(NSWindow*) w {
if (self = [super init]) {
self.category = kAfloatByDelegateCustomSubclassCategory;
self.key = NSStringFromClass([[w delegate] class]);
self.canMatchMultipleWindows = YES;
}
return self;
}
- (BOOL) matchesWindow:(NSWindow*) w {
return [w delegate] && [(NSStringFromClass([[w delegate] class])) isEqual:self.key];
}
@end
// the class that implements kAfloatByWindowCustomControllerCategory
@interface _AfloatWindowByControllerClassIdentifier : AfloatWindowIdentifier {}
@end
@implementation _AfloatWindowByControllerClassIdentifier
+ (BOOL) canInitWithWindow:(NSWindow*) w {
return [w windowController] && ![[w windowController] isMemberOfClass:[NSWindowController class]];
}
- (id) initWithWindow:(NSWindow*) w {
if (self = [super init]) {
self.category = kAfloatByWindowCustomControllerCategory;
self.key = NSStringFromClass([[w windowController] class]);
self.canMatchMultipleWindows = YES;
}
return self;
}
- (BOOL) matchesWindow:(NSWindow*) w {
return [w windowController] && [(NSStringFromClass([[w windowController] class])) isEqual:self.key];
}
@end
// the class that implements kAfloatByWindowAutosaveNameCategory
@interface _AfloatWindowByAutosaveNameIdentifier : AfloatWindowIdentifier {}
@end
@implementation _AfloatWindowByAutosaveNameIdentifier
+ (BOOL) canInitWithWindow:(NSWindow*) w {
return [w frameAutosaveName] && ![[w frameAutosaveName] isEqual:@""];
}
- (id) initWithWindow:(NSWindow*) w {
if (self = [super init]) {
self.category = kAfloatByWindowAutosaveNameCategory;
self.key = [w frameAutosaveName];
self.canMatchMultipleWindows = YES;
}
return self;
}
- (BOOL) matchesWindow:(NSWindow*) w {
return [w frameAutosaveName] && [[w frameAutosaveName] isEqual:self.key];
}
@end
// - * - - * - - * - - * - - * - - * - - * -
@implementation AfloatWindowIdentifier
+ (NSArray*) identifierSubclasses {
static id classes = nil; if (!classes) {
classes = [[NSArray alloc] initWithObjects:
[_AfloatWindowByAutosaveNameIdentifier class],
[_AfloatWindowByClassIdentifier class],
[_AfloatWindowByDelegateClassIdentifier class],
[_AfloatWindowByControllerClassIdentifier class],
nil];
}
return classes;
}
- (void) dealloc {
self.category = nil;
self.key = nil;
[super dealloc];
}
@synthesize category = _category, key = _key, canMatchMultipleWindows = _canMatchMultipleWindows;
+ (NSArray*) allIdentifiersForWindow:(NSWindow*) w {
NSMutableArray* results = [NSArray array];
for (Class c in [self identifierSubclasses]) {
if ([c canInitWithWindow:w])
[results addObject:[[[c alloc] initWithWindow:w] autorelease]];
}
return results;
}
- (BOOL) matchesWindow:(NSWindow*) w {
return NO;
}
@end