More Forge stuff.

Forge now loads the bundles in its resources first, and then loads the
bundles from the User, Local, Network, and System library directories,
in that order -- if it is told to by the defaults system.

Also, the MainPrefs class has some new options, to control what
directories Forge loads bundles from.
This commit is contained in:
Jeff Teunissen 2002-01-26 22:09:15 +00:00
parent 8ef321e2e8
commit 29c68732c0
8 changed files with 222 additions and 44 deletions

View file

@ -141,10 +141,32 @@ static BundleController * sharedInstance = nil;
NSArray *temp;
NSMutableArray *modified = [[NSMutableArray alloc] initWithCapacity: 10];
NSEnumerator *counter;
unsigned int domainMask = 0;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id obj;
// Start out with our own resource dir
[dirList addObject: [[NSBundle mainBundle] resourcePath]];
/*
First, load and init all bundles in the app resource path
*/
NSDebugLog (@"Loading local bundles...");
counter = [[self bundlesWithExtension: @"forgeb" inPath: [[NSBundle mainBundle] resourcePath]] objectEnumerator];
while ((obj = [counter nextObject])) {
[self loadBundleInPath: obj];
}
/*
Then do the same for external bundles
*/
NSDebugLog (@"Loading foreign bundles...");
// build domain mask, to find out where user wants to load bundles from
if ([defaults boolForKey: @"BundlesFromUser"])
domainMask |= NSUserDomainMask;
if ([defaults boolForKey: @"BundlesFromLocal"])
domainMask |= NSLocalDomainMask;
if ([defaults boolForKey: @"BundlesFromNetwork"])
domainMask |= NSNetworkDomainMask;
if ([defaults boolForKey: @"BundlesFromSystem"])
domainMask |= NSSystemDomainMask;
// Get the library dirs and add our path to all of its entries
temp = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSAllDomainsMask, YES);

View file

@ -12,6 +12,10 @@
};
MainPrefs = {
Actions = (
bundlesFromLocalButtonChanged:,
bundlesFromNetworkButtonChanged:,
bundlesFromSystemButtonChanged:,
bundlesFromUserButtonChanged:,
loadPrefs:,
projectPathChanged:,
projectPathFindButtonClicked:,
@ -19,6 +23,10 @@
savePrefs:
);
Outlets = (
bundlesFromLocalButton,
bundlesFromNetworkButton,
bundlesFromSystemButton,
bundlesFromUserButton,
projectPathField,
projectPathFindButton,
view,

View file

@ -37,10 +37,12 @@
#import "BundleController.h"
#import "PrefsView.h"
#define ProjectPath @"projectPath"
@interface MainPrefs: NSObject <PrefsViewController, ForgeBundle>
{
IBOutlet id bundlesFromLocalButton;
IBOutlet id bundlesFromNetworkButton;
IBOutlet id bundlesFromSystemButton;
IBOutlet id bundlesFromUserButton;
IBOutlet id projectPathField;
IBOutlet id projectPathFindButton;
@ -48,4 +50,11 @@
IBOutlet id view;
}
- (IBAction) bundlesFromLocalButtonChanged: (id) sender;
- (IBAction) bundlesFromNetworkButtonChanged: (id) sender;
- (IBAction) bundlesFromSystemButtonChanged: (id) sender;
- (IBAction) bundlesFromUserButtonChanged: (id) sender;
- (IBAction) projectPathChanged: (id) sender;
- (IBAction) projectPathFindButtonClicked: (id) sender;
@end

View file

@ -35,10 +35,7 @@ static const char rcsid[] =
#endif
#import <AppKit/NSButton.h>
#ifdef USING_NIBS
#import <AppKit/NSNibLoading.h>
#endif
#import <AppKit/NSOpenPanel.h>
#import "PrefsPanel.h"
@ -69,12 +66,31 @@ defaultValues (void) {
if (!dict) {
dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
@"/Local/Forge/Projects", ProjectPath,
@"/Local/Forge/Projects", @"ProjectPath",
[NSNumber numberWithBool: YES], @"BundlesFromUser",
[NSNumber numberWithBool: YES], @"BundlesFromLocal",
[NSNumber numberWithBool: YES], @"BundlesFromNetwork",
[NSNumber numberWithBool: YES], @"BundlesFromSystem",
nil];
}
return dict;
}
static BOOL
getBoolDefault (NSMutableDictionary *dict, NSString *name)
{
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey: name];
NSNumber *num;
if (!str)
str = [[defaultValues() objectForKey: name] stringValue];
num = [NSNumber numberWithBool: [str hasPrefix: @"Y"]];
[dict setObject: num forKey: name];
return [num boolValue];
}
static NSString *
getStringDefault (NSMutableDictionary *dict, NSString *name)
{
@ -92,7 +108,11 @@ getStringDefault (NSMutableDictionary *dict, NSString *name)
{
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity: 5];
getStringDefault (dict, ProjectPath);
getStringDefault (dict, @"ProjectPath");
getBoolDefault (dict, @"BundlesFromLocal");
getBoolDefault (dict, @"BundlesFromNetwork");
getBoolDefault (dict, @"BundlesFromSystem");
getBoolDefault (dict, @"BundlesFromUser");
return dict;
}
@ -102,9 +122,15 @@ getStringDefault (NSMutableDictionary *dict, NSString *name)
#define setStringDefault(name) \
[defaults setObject: [dict objectForKey: (name)] forKey: (name)]
#define setBoolDefault(name) \
[defaults setBool: [[dict objectForKey: (name)] boolValue] forKey: (name)]
NSDebugLog (@"Updating Main Preferences...");
setStringDefault (ProjectPath);
setStringDefault (@"ProjectPath");
setBoolDefault (@"BundlesFromLocal");
setBoolDefault (@"BundlesFromNetwork");
setBoolDefault (@"BundlesFromSystem");
setBoolDefault (@"BundlesFromUser");
[defaults synchronize];
}
@ -125,8 +151,12 @@ getStringDefault (NSMutableDictionary *dict, NSString *name)
- (void) updateUI
{
[projectPathField setStringValue: [displayedValues objectForKey: ProjectPath]];
[projectPathField setNeedsDisplay: YES];
[projectPathField setStringValue: [displayedValues objectForKey: @"ProjectPath"]];
[bundlesFromLocalButton setIntValue: [[displayedValues objectForKey: @"BundlesFromLocal"] intValue]];
[bundlesFromNetworkButton setIntValue: [[displayedValues objectForKey: @"BundlesFromNetwork"] intValue]];
[bundlesFromSystemButton setIntValue: [[displayedValues objectForKey: @"BundlesFromSystem"] intValue]];
[bundlesFromUserButton setIntValue: [[displayedValues objectForKey: @"BundlesFromUser"] intValue]];
[view setNeedsDisplay: YES];
}
@end // MainPrefs (Private)
@ -145,12 +175,17 @@ static id <BundleDelegate> owner = nil;
owner = anOwner;
[owner registerPrefsController: self];
if (![NSBundle loadNibNamed: @"MainPrefs" owner: self]) {
NSLog (@"MainPrefs: Could not load nib \"MainPrefs\", using compiled version");
NSLog (@"MainPrefs: Could not load nib \"MainPrefs\", using compiled-in version");
view = [[MainPrefsView alloc] initWithOwner: self andFrame: PrefsRect];
// hook up to our outlet(s)
projectPathField = [view directoryField];
projectPathField = [view projectPathField];
bundlesFromUserButton = [view bundlesFromUserButton];
bundlesFromLocalButton = [view bundlesFromLocalButton];
bundlesFromNetworkButton = [view bundlesFromNetworkButton];
bundlesFromSystemButton = [view bundlesFromSystemButton];
} else {
// window can be any size, as long as it's 486x228 :)
view = [window contentView];
}
[view retain];
@ -214,10 +249,13 @@ static id <BundleDelegate> owner = nil;
- (id) projectPath
{
return [displayedValues objectForKey: ProjectPath];
return [displayedValues objectForKey: @"ProjectPath"];
}
- (id) projectPathFindButtonClicked: (id) sender
/*
Action methods
*/
- (IBAction) projectPathFindButtonClicked: (id) sender
{
int result;
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
@ -230,15 +268,39 @@ static id <BundleDelegate> owner = nil;
if (result == NSOKButton) { // got a new dir
NSArray *pathArray = [oPanel filenames];
[displayedValues setObject: [pathArray objectAtIndex: 0] forKey: ProjectPath];
[displayedValues setObject: [pathArray objectAtIndex: 0] forKey: @"ProjectPath"];
[self updateUI];
}
}
- (void) projectPathChanged: (id) sender
- (IBAction) bundlesFromLocalButtonChanged: (id) sender
{
[displayedValues setObject: [sender stringValue] forKey: ProjectPath];
[displayedValues setObject: [NSNumber numberWithBool: [sender intValue]] forKey: @"BundlesFromLocal"];
[self updateUI];
}
@end
- (IBAction) bundlesFromNetworkButtonChanged: (id) sender
{
[displayedValues setObject: [NSNumber numberWithBool: [sender intValue]] forKey: @"BundlesFromNetwork"];
[self updateUI];
}
- (IBAction) bundlesFromSystemButtonChanged: (id) sender
{
[displayedValues setObject: [NSNumber numberWithBool: [sender intValue]] forKey: @"BundlesFromSystem"];
[self updateUI];
}
- (IBAction) bundlesFromUserButtonChanged: (id) sender
{
[displayedValues setObject: [NSNumber numberWithBool: [sender intValue]] forKey: @"BundlesFromUser"];
[self updateUI];
}
- (IBAction) projectPathChanged: (id) sender
{
[displayedValues setObject: [sender stringValue] forKey: @"ProjectPath"];
[self updateUI];
}
@end // MainPrefs

View file

@ -35,13 +35,23 @@
@interface MainPrefsView: NSView
{
id directoryField;
id findButton;
// for controllers to connect to
id projectPathField;
id projectPathFindButton;
id bundlesFromUserButton;
id bundlesFromLocalButton;
id bundlesFromNetworkButton;
id bundlesFromSystemButton;
id owner;
}
- (id) initWithOwner: (id) anOwner andFrame: (NSRect) frameRect;
- (id) directoryField;
- (id) projectPathField;
- (id) bundlesFromUserButton;
- (id) bundlesFromLocalButton;
- (id) bundlesFromNetworkButton;
- (id) bundlesFromSystemButton;
@end

View file

@ -42,7 +42,9 @@ static const char rcsid[] =
#import "MainPrefs.h"
@implementation MainPrefsView
/*
This class sucks, and shouldn't be necessary. With working "nibs", it isn't.
*/
- (id) initWithOwner: (id) anOwner andFrame: (NSRect) frameRect
{
id label = nil;
@ -62,30 +64,95 @@ static const char rcsid[] =
[label setStringValue: @"Project load path"];
[self addSubview: [label autorelease]];
directoryField = [[NSTextField alloc] initWithFrame: NSMakeRect (3, 174, 410, 24)];
[directoryField setEditable: YES];
[directoryField setSelectable: YES];
[directoryField setAllowsEditingTextAttributes: NO];
[directoryField setImportsGraphics: NO];
[directoryField setTextColor: [NSColor blackColor]];
[directoryField setBackgroundColor: [NSColor whiteColor]];
[directoryField setBezeled: YES];
[directoryField setTarget: owner];
[directoryField setAction: @selector(projectPathChanged:)];
[self addSubview: [directoryField autorelease]];
projectPathField = [[NSTextField alloc] initWithFrame: NSMakeRect (3, 174, 409, 24)];
[projectPathField setEditable: YES];
[projectPathField setSelectable: YES];
[projectPathField setAllowsEditingTextAttributes: NO];
[projectPathField setImportsGraphics: NO];
[projectPathField setTextColor: [NSColor blackColor]];
[projectPathField setBackgroundColor: [NSColor whiteColor]];
[projectPathField setBezeled: YES];
[projectPathField setTarget: owner];
[projectPathField setAction: @selector(projectPathChanged:)];
[self addSubview: [projectPathField autorelease]];
projectPathFindButton = [[NSButton alloc] initWithFrame: NSMakeRect (419, 174, 64, 24)];
[projectPathFindButton setTitle: @"Find..."];
[projectPathFindButton setButtonType: NSMomentaryPushButton];
[projectPathFindButton setTarget: owner];
[projectPathFindButton setAction: @selector(projectPathFindButtonClicked:)];
[self addSubview: [projectPathFindButton autorelease]];
label = [[NSTextField alloc] initWithFrame: NSMakeRect (3, 85, 130, 20)];
[label setEditable: NO];
[label setSelectable: NO];
[label setAllowsEditingTextAttributes: NO];
[label setImportsGraphics: NO];
[label setTextColor: [NSColor blackColor]];
[label setBackgroundColor: [NSColor controlColor]];
[label setBezeled: NO];
[label setStringValue: @"Load bundles from:"];
[self addSubview: [label autorelease]];
bundlesFromUserButton = [[NSButton alloc] initWithFrame: NSMakeRect (160, 116, 150, 20)];
[bundlesFromUserButton setTitle: @"Personal Library path"];
[bundlesFromUserButton setButtonType: NSSwitchButton];
[bundlesFromUserButton setImagePosition: NSImageRight];
[bundlesFromUserButton setTarget: owner];
[bundlesFromUserButton setAction: @selector(bundlesFromUserButtonChanged:)];
[self addSubview: [bundlesFromUserButton autorelease]];
bundlesFromLocalButton = [[NSButton alloc] initWithFrame: NSMakeRect (160, 93, 150, 20)];
[bundlesFromLocalButton setTitle: @"Local Library path"];
[bundlesFromLocalButton setButtonType: NSSwitchButton];
[bundlesFromLocalButton setImagePosition: NSImageRight];
[bundlesFromLocalButton setTarget: owner];
[bundlesFromLocalButton setAction: @selector(bundlesFromLocalButtonChanged:)];
[self addSubview: [bundlesFromLocalButton autorelease]];
bundlesFromNetworkButton = [[NSButton alloc] initWithFrame: NSMakeRect (160, 70, 150, 20)];
[bundlesFromNetworkButton setTitle: @"Networked Library path"];
[bundlesFromNetworkButton setButtonType: NSSwitchButton];
[bundlesFromNetworkButton setImagePosition: NSImageRight];
[bundlesFromNetworkButton setTarget: owner];
[bundlesFromNetworkButton setAction: @selector(bundlesFromNetworkButtonChanged:)];
[self addSubview: [bundlesFromNetworkButton autorelease]];
bundlesFromSystemButton = [[NSButton alloc] initWithFrame: NSMakeRect (160, 47, 150, 20)];
[bundlesFromSystemButton setTitle: @"System Library path"];
[bundlesFromSystemButton setButtonType: NSSwitchButton];
[bundlesFromSystemButton setImagePosition: NSImageRight];
[bundlesFromSystemButton setTarget: owner];
[bundlesFromSystemButton setAction: @selector(bundlesFromSystemButtonChanged:)];
[self addSubview: [bundlesFromSystemButton autorelease]];
findButton = [[NSButton alloc] initWithFrame: NSMakeRect (419, 174, 64, 24)];
[findButton setTitle: @"Find..."];
[findButton setTarget: owner];
[findButton setAction: @selector(projectPathFindButtonClicked:)];
[self addSubview: [findButton autorelease]];
}
return self;
}
- (id) directoryField
- (id) projectPathField
{
return directoryField;
return projectPathField;
}
- (id) bundlesFromUserButton
{
return bundlesFromUserButton;
}
- (id) bundlesFromLocalButton
{
return bundlesFromLocalButton;
}
- (id) bundlesFromNetworkButton
{
return bundlesFromNetworkButton;
}
- (id) bundlesFromSystemButton
{
return bundlesFromSystemButton;
}
@end

View file

@ -62,7 +62,7 @@ static NSMutableArray *prefsViews = nil;
prefsViews = [[[NSMutableArray alloc] initWithCapacity: 5] retain];
prefsPanel = [[PrefsPanel alloc]
initWithContentRect: NSMakeRect (250, 250, 516, 386)
initWithContentRect: NSMakeRect (250, 250, 516, 385)
styleMask: NSTitledWindowMask
| NSMiniaturizableWindowMask
| NSClosableWindowMask