mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-06 15:51:25 +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/NSBundle.h>
|
||||||
#import <Foundation/NSObject.h>
|
#import <Foundation/NSObject.h>
|
||||||
|
|
||||||
|
#import "PrefsView.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Bundle Delegate protocol
|
Bundle Delegate protocol
|
||||||
|
|
||||||
|
@ -47,9 +49,20 @@
|
||||||
// Notification, sent when a bundle is loaded.
|
// Notification, sent when a bundle is loaded.
|
||||||
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle;
|
- (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
|
@end
|
||||||
|
|
||||||
@interface BundleController: NSObject <BundleDelegate>
|
@interface BundleController: NSObject
|
||||||
{
|
{
|
||||||
id delegate;
|
id delegate;
|
||||||
NSMutableArray *loadedBundles;
|
NSMutableArray *loadedBundles;
|
||||||
|
|
|
@ -60,7 +60,7 @@ static const char rcsid[] =
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDebugLog (@"Loading bundle %@...", path);
|
NSDebugLog (@"Loading bundle %@...", path);
|
||||||
|
|
||||||
if ((bundle = [NSBundle bundleWithPath: path])) {
|
if ((bundle = [NSBundle bundleWithPath: path])) {
|
||||||
NSDebugLog (@"Bundle %@ successfully loaded.", path);
|
NSDebugLog (@"Bundle %@ successfully loaded.", path);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ static const char rcsid[] =
|
||||||
*/
|
*/
|
||||||
if (delegate && [delegate conformsToProtocol: @protocol(BundleDelegate)])
|
if (delegate && [delegate conformsToProtocol: @protocol(BundleDelegate)])
|
||||||
[(id <BundleDelegate>) delegate bundleController: self didLoadBundle: bundle];
|
[(id <BundleDelegate>) delegate bundleController: self didLoadBundle: bundle];
|
||||||
[self bundleController: self didLoadBundle: bundle];
|
[loadedBundles addObject: bundle];
|
||||||
} else {
|
} else {
|
||||||
NSRunAlertPanel (@"Attention", @"Could not load bundle %@", @"OK", nil, nil, path);
|
NSRunAlertPanel (@"Attention", @"Could not load bundle %@", @"OK", nil, nil, path);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ static const char rcsid[] =
|
||||||
enumerator = [[fm directoryContentsAtPath: path] objectEnumerator];
|
enumerator = [[fm directoryContentsAtPath: path] objectEnumerator];
|
||||||
while ((dir = [enumerator nextObject])) {
|
while ((dir = [enumerator nextObject])) {
|
||||||
if ([[dir pathExtension] isEqualToString: extension])
|
if ([[dir pathExtension] isEqualToString: extension])
|
||||||
[bundleList addObject: dir];
|
[bundleList addObject: [path stringByAppendingPathComponent: dir]];
|
||||||
}
|
}
|
||||||
return bundleList;
|
return bundleList;
|
||||||
}
|
}
|
||||||
|
@ -104,17 +104,24 @@ static const char rcsid[] =
|
||||||
|
|
||||||
@implementation BundleController
|
@implementation BundleController
|
||||||
|
|
||||||
|
static BundleController * sharedInstance = nil;
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
if ((self = [super init]))
|
if (sharedInstance) {
|
||||||
|
[self dealloc];
|
||||||
|
} else {
|
||||||
|
self = [super init];
|
||||||
loadedBundles = [[NSMutableArray alloc] init];
|
loadedBundles = [[NSMutableArray alloc] init];
|
||||||
return self;
|
sharedInstance = self;
|
||||||
|
}
|
||||||
|
return sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[loadedBundles release];
|
[loadedBundles release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +158,7 @@ static const char rcsid[] =
|
||||||
// Okay, now go through dirList loading all of the bundles in each dir
|
// Okay, now go through dirList loading all of the bundles in each dir
|
||||||
counter = [dirList objectEnumerator];
|
counter = [dirList objectEnumerator];
|
||||||
while ((obj = [counter nextObject])) {
|
while ((obj = [counter nextObject])) {
|
||||||
NSEnumerator *enum2 = [[self bundlesWithExtension: @"Forge" inPath: obj] objectEnumerator];
|
NSEnumerator *enum2 = [[self bundlesWithExtension: @"forgeb" inPath: obj] objectEnumerator];
|
||||||
NSString *str;
|
NSString *str;
|
||||||
|
|
||||||
while ((str = [enum2 nextObject])) {
|
while ((str = [enum2 nextObject])) {
|
||||||
|
@ -165,9 +172,4 @@ static const char rcsid[] =
|
||||||
return loadedBundles;
|
return loadedBundles;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle
|
|
||||||
{
|
|
||||||
[loadedBundles addObject: aBundle];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
#import <Foundation/NSString.h>
|
#import <Foundation/NSString.h>
|
||||||
#import <AppKit/NSApplication.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/NSApplication.h>
|
||||||
#import <AppKit/NSMenu.h>
|
#import <AppKit/NSMenu.h>
|
||||||
#import "Controller.h"
|
#import "Controller.h"
|
||||||
#import "Preferences.h"
|
|
||||||
#import "PrefsController.h"
|
#import "PrefsController.h"
|
||||||
|
|
||||||
@implementation Controller
|
@implementation Controller
|
||||||
|
@ -261,6 +260,13 @@ static const char rcsid[] =
|
||||||
[menu setSubmenu: services forItem: [menu itemWithTitle: _(@"Services")]];
|
[menu setSubmenu: services forItem: [menu itemWithTitle: _(@"Services")]];
|
||||||
|
|
||||||
[NSApp setMainMenu: menu];
|
[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;
|
- (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"
|
#import "Preferences.h"
|
||||||
|
|
||||||
NSMutableDictionary *
|
static NSMutableDictionary *
|
||||||
defaultValues (void) {
|
defaultValues (void) {
|
||||||
static NSMutableDictionary *dict = nil;
|
static NSMutableDictionary *dict = nil;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ defaultValues (void) {
|
||||||
/***
|
/***
|
||||||
Code to deal with defaults
|
Code to deal with defaults
|
||||||
***/
|
***/
|
||||||
BOOL
|
static BOOL
|
||||||
getBoolDefault (NSMutableDictionary *dict, NSString *name)
|
getBoolDefault (NSMutableDictionary *dict, NSString *name)
|
||||||
{
|
{
|
||||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||||
|
@ -81,7 +81,7 @@ getBoolDefault (NSMutableDictionary *dict, NSString *name)
|
||||||
return [num boolValue];
|
return [num boolValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
static float
|
||||||
getFloatDefault (NSMutableDictionary *dict, NSString *name)
|
getFloatDefault (NSMutableDictionary *dict, NSString *name)
|
||||||
{
|
{
|
||||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||||
|
@ -96,7 +96,8 @@ getFloatDefault (NSMutableDictionary *dict, NSString *name)
|
||||||
return [num floatValue];
|
return [num floatValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
#if 0 // unneeded
|
||||||
|
static int
|
||||||
getIntDefault (NSMutableDictionary *dict, NSString *name)
|
getIntDefault (NSMutableDictionary *dict, NSString *name)
|
||||||
{
|
{
|
||||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||||
|
@ -110,8 +111,9 @@ getIntDefault (NSMutableDictionary *dict, NSString *name)
|
||||||
|
|
||||||
return [num intValue];
|
return [num intValue];
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
NSString *
|
static NSString *
|
||||||
getStringDefault (NSMutableDictionary *dict, NSString *name)
|
getStringDefault (NSMutableDictionary *dict, NSString *name)
|
||||||
{
|
{
|
||||||
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
|
||||||
|
@ -322,11 +324,11 @@ static NSMutableDictionary *displayedValues = nil;
|
||||||
setStringDefault(ProjectPath);
|
setStringDefault(ProjectPath);
|
||||||
setStringDefault(BspSoundPath);
|
setStringDefault(BspSoundPath);
|
||||||
setStringDefault(StartWad);
|
setStringDefault(StartWad);
|
||||||
setFloatDefault(XLight);
|
setFloatDefault (XLight);
|
||||||
setFloatDefault(YLight);
|
setFloatDefault (YLight);
|
||||||
setFloatDefault(ZLight);
|
setFloatDefault (ZLight);
|
||||||
setBoolDefault(ShowBSPOutput);
|
setBoolDefault (ShowBSPOutput);
|
||||||
setBoolDefault(OffsetBrushCopy);
|
setBoolDefault (OffsetBrushCopy);
|
||||||
[defaults synchronize];
|
[defaults synchronize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue