Project:
pytivox
Code Location:
http://pytivox.googlecode.com/svn/trunk/trunk
/
PrefController.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
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
// // PrefController.m // pyTivoX // // Created by Yoav Yerushalmi on 4/3/09. // Copyright 2009 home. All rights reserved. // #import "PrefController.h" @implementation PrefController - (id)initWithPanesSearchPath:(NSString*)path bundleExtension:(NSString *)ext controller:(id)controller; { if (self = [super init]) { [self setDebug:YES]; preferencePanes = [[NSMutableDictionary alloc] init]; panesOrder = [[NSMutableArray alloc] init]; [self setToolbarDisplayMode:NSToolbarDisplayModeIconAndLabel]; [self setToolbarSizeMode:NSToolbarSizeModeDefault]; [self setUsesTexturedWindow:NO]; [self setAlwaysShowsToolbar:NO]; [self setAlwaysOpensCentered:YES]; if (!ext || [ext isEqualToString:@""]) { bundleExtension = [[NSString alloc] initWithString:@"preferencePane"]; } else { bundleExtension = [ext retain]; } if (!path || [path isEqualToString:@""]) { searchPath = [[NSString alloc] initWithString:[[NSBundle mainBundle] resourcePath]]; } else { searchPath = [path retain]; } // Read PreferencePanes - this is where we differ from SS_PrefsController if (searchPath) { NSEnumerator* enumerator = [[NSBundle pathsForResourcesOfType:bundleExtension inDirectory:searchPath] objectEnumerator]; NSString* panePath; while ((panePath = [enumerator nextObject])) { [self activatePane:panePath controller:controller]; } } return self; } return nil; } - (void)activatePane:(NSString*)path controller:(id)controller{ NSBundle* paneBundle = [NSBundle bundleWithPath:path]; NSAssert1(paneBundle != nil, @"Could not initialize bundle: %@", paneBundle); NSDictionary* paneDict = [paneBundle infoDictionary]; NSString* paneClassName = [paneDict objectForKey:@"NSPrincipalClass"]; NSAssert1(paneClassName != nil, @"Could not obtain name of Principal Class for bundle: %@", paneBundle); Class paneClass = NSClassFromString(paneClassName); NSAssert2(paneClass != nil, @"Did not load bundle: %@ because its Principal Class %@ was already used in another Preference pane.", paneBundle, paneClassName); paneClass = [paneBundle principalClass]; NSAssert2([paneClass isSubclassOfClass:[PrefPaneController class]], @"Could not load bundle %@ because it Principal Class %@ is not a subclass of PrefPaneController", paneBundle, paneClassName); NSString *nibName = [paneDict objectForKey:@"NSMainNibFile"]; NSAssert1(nibName, @"Could not obtain name of nib for bundle: %@", paneBundle); PrefPaneController *aPane = [[paneClass alloc] initWithNib:nibName dictionary:paneDict controller:controller]; if(aPane != nil){ [panesOrder addObject:[aPane paneName]]; [preferencePanes setObject:aPane forKey:[aPane paneName]]; [aPane release]; } } - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar{ return panesOrder; } // make sure we get a highlighted icon first time around. - (void)showPreferencesWindow{ [super showPreferencesWindow]; [prefsToolbar setSelectedItemIdentifier:[prefsWindow title]]; } // make sure we get a highlighted icon when activating a pane programmatically. - (void)showPreferencePane:(NSString *) paneName{ [self loadPreferencePaneNamed:paneName]; [prefsToolbar setSelectedItemIdentifier:paneName]; } @end
