mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-29 20:20:43 +00:00
Preferences.m: function scoping fixes (static is your friend).
rest: bundle loading. It's alive! Alive, I tell you! Mwahahahaha! ... uhh... * Deek hides the bodies
This commit is contained in:
parent
bd0ac4a38a
commit
83a778467c
6 changed files with 86 additions and 25 deletions
|
@ -36,6 +36,8 @@
|
|||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
#import "PrefsView.h"
|
||||
|
||||
/*
|
||||
Bundle Delegate protocol
|
||||
|
||||
|
@ -47,9 +49,20 @@
|
|||
// Notification, sent when a bundle is loaded.
|
||||
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle;
|
||||
|
||||
/*
|
||||
Methods for bundles to call
|
||||
*/
|
||||
- (BOOL) registerPrefsController: (id <PrefsViewController>) aPrefsController;
|
||||
#if 0
|
||||
- (BOOL) registerFileSubmenu: (NSMenu *) aMenu;
|
||||
- (BOOL) registerToolsSubmenu: (NSMenu *) aMenu;
|
||||
- (BOOL) registerCompiler: (id <Compiler>) aCompiler forType: (NSString *) type;
|
||||
- (BOOL) registerEditor: (id <Editor>) anEditor forType: (NSString *) type;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@interface BundleController: NSObject <BundleDelegate>
|
||||
@interface BundleController: NSObject
|
||||
{
|
||||
id delegate;
|
||||
NSMutableArray *loadedBundles;
|
||||
|
|
|
@ -60,7 +60,7 @@ static const char rcsid[] =
|
|||
}
|
||||
|
||||
NSDebugLog (@"Loading bundle %@...", path);
|
||||
|
||||
|
||||
if ((bundle = [NSBundle bundleWithPath: path])) {
|
||||
NSDebugLog (@"Bundle %@ successfully loaded.", path);
|
||||
|
||||
|
@ -70,7 +70,7 @@ static const char rcsid[] =
|
|||
*/
|
||||
if (delegate && [delegate conformsToProtocol: @protocol(BundleDelegate)])
|
||||
[(id <BundleDelegate>) delegate bundleController: self didLoadBundle: bundle];
|
||||
[self bundleController: self didLoadBundle: bundle];
|
||||
[loadedBundles addObject: bundle];
|
||||
} else {
|
||||
NSRunAlertPanel (@"Attention", @"Could not load bundle %@", @"OK", nil, nil, path);
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ static const char rcsid[] =
|
|||
enumerator = [[fm directoryContentsAtPath: path] objectEnumerator];
|
||||
while ((dir = [enumerator nextObject])) {
|
||||
if ([[dir pathExtension] isEqualToString: extension])
|
||||
[bundleList addObject: dir];
|
||||
[bundleList addObject: [path stringByAppendingPathComponent: dir]];
|
||||
}
|
||||
return bundleList;
|
||||
}
|
||||
|
@ -104,17 +104,24 @@ static const char rcsid[] =
|
|||
|
||||
@implementation BundleController
|
||||
|
||||
static BundleController * sharedInstance = nil;
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
if (sharedInstance) {
|
||||
[self dealloc];
|
||||
} else {
|
||||
self = [super init];
|
||||
loadedBundles = [[NSMutableArray alloc] init];
|
||||
return self;
|
||||
sharedInstance = self;
|
||||
}
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[loadedBundles release];
|
||||
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -151,7 +158,7 @@ static const char rcsid[] =
|
|||
// Okay, now go through dirList loading all of the bundles in each dir
|
||||
counter = [dirList objectEnumerator];
|
||||
while ((obj = [counter nextObject])) {
|
||||
NSEnumerator *enum2 = [[self bundlesWithExtension: @"Forge" inPath: obj] objectEnumerator];
|
||||
NSEnumerator *enum2 = [[self bundlesWithExtension: @"forgeb" inPath: obj] objectEnumerator];
|
||||
NSString *str;
|
||||
|
||||
while ((str = [enum2 nextObject])) {
|
||||
|
@ -165,9 +172,4 @@ static const char rcsid[] =
|
|||
return loadedBundles;
|
||||
}
|
||||
|
||||
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle
|
||||
{
|
||||
[loadedBundles addObject: aBundle];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -36,7 +36,9 @@
|
|||
#import <Foundation/NSString.h>
|
||||
#import <AppKit/NSApplication.h>
|
||||
|
||||
@interface Controller: NSObject
|
||||
#import "BundleController.h"
|
||||
|
||||
@interface Controller: NSObject <BundleDelegate>
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ static const char rcsid[] =
|
|||
#import <AppKit/NSApplication.h>
|
||||
#import <AppKit/NSMenu.h>
|
||||
#import "Controller.h"
|
||||
#import "Preferences.h"
|
||||
#import "PrefsController.h"
|
||||
|
||||
@implementation Controller
|
||||
|
@ -261,6 +260,13 @@ static const char rcsid[] =
|
|||
[menu setSubmenu: services forItem: [menu itemWithTitle: _(@"Services")]];
|
||||
|
||||
[NSApp setMainMenu: menu];
|
||||
|
||||
{ // yeah, yeah, shaddap
|
||||
id controller = [[BundleController alloc] init];
|
||||
|
||||
[controller setDelegate: self];
|
||||
[controller loadBundles];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -271,3 +277,39 @@ static const char rcsid[] =
|
|||
- (void) applicationWillTerminate: (NSNotification *) not;
|
||||
{
|
||||
}
|
||||
|
||||
/******
|
||||
Bundle Controller delegate methods
|
||||
******/
|
||||
|
||||
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle
|
||||
{
|
||||
if (!aBundle) {
|
||||
NSLog (@"Controller -bundleController: sent nil bundle");
|
||||
return;
|
||||
}
|
||||
|
||||
if (![aBundle principalClass]) {
|
||||
NSDictionary *info = [aBundle infoDictionary];
|
||||
|
||||
if (!(info || [info objectForKey: @"NSExecutable"])) {
|
||||
NSLog (@"%@ has no principal class and no info dictionary", aBundle);
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog (@"Bundle `%@' has no principal class!", [info objectForKey: @"NSExecutable"]);
|
||||
return;
|
||||
}
|
||||
[[[aBundle principalClass] alloc] init];
|
||||
}
|
||||
|
||||
- (BOOL) registerPrefsController: (id <PrefsViewController>) aPrefsController
|
||||
{
|
||||
if (!aPrefsController)
|
||||
return NO;
|
||||
|
||||
[[PrefsController sharedPrefsController] addPrefsViewController: aPrefsController];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Binary file not shown.
|
@ -44,7 +44,7 @@ static const char rcsid[] =
|
|||
|
||||
#import "Preferences.h"
|
||||
|
||||
NSMutableDictionary *
|
||||
static NSMutableDictionary *
|
||||
defaultValues (void) {
|
||||
static NSMutableDictionary *dict = nil;
|
||||
|
||||
|
@ -66,7 +66,7 @@ defaultValues (void) {
|
|||
/***
|
||||
Code to deal with defaults
|
||||
***/
|
||||
BOOL
|
||||
static BOOL
|
||||
getBoolDefault (NSMutableDictionary *dict, NSString *name)
|
||||
{
|
||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||
|
@ -81,7 +81,7 @@ getBoolDefault (NSMutableDictionary *dict, NSString *name)
|
|||
return [num boolValue];
|
||||
}
|
||||
|
||||
float
|
||||
static float
|
||||
getFloatDefault (NSMutableDictionary *dict, NSString *name)
|
||||
{
|
||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||
|
@ -96,7 +96,8 @@ getFloatDefault (NSMutableDictionary *dict, NSString *name)
|
|||
return [num floatValue];
|
||||
}
|
||||
|
||||
int
|
||||
#if 0 // unneeded
|
||||
static int
|
||||
getIntDefault (NSMutableDictionary *dict, NSString *name)
|
||||
{
|
||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||
|
@ -110,8 +111,9 @@ getIntDefault (NSMutableDictionary *dict, NSString *name)
|
|||
|
||||
return [num intValue];
|
||||
}
|
||||
#endif
|
||||
|
||||
NSString *
|
||||
static NSString *
|
||||
getStringDefault (NSMutableDictionary *dict, NSString *name)
|
||||
{
|
||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||
|
@ -322,11 +324,11 @@ static NSMutableDictionary *displayedValues = nil;
|
|||
setStringDefault(ProjectPath);
|
||||
setStringDefault(BspSoundPath);
|
||||
setStringDefault(StartWad);
|
||||
setFloatDefault(XLight);
|
||||
setFloatDefault(YLight);
|
||||
setFloatDefault(ZLight);
|
||||
setBoolDefault(ShowBSPOutput);
|
||||
setBoolDefault(OffsetBrushCopy);
|
||||
setFloatDefault (XLight);
|
||||
setFloatDefault (YLight);
|
||||
setFloatDefault (ZLight);
|
||||
setBoolDefault (ShowBSPOutput);
|
||||
setBoolDefault (OffsetBrushCopy);
|
||||
[defaults synchronize];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue