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; NSArray *temp;
NSMutableArray *modified = [[NSMutableArray alloc] initWithCapacity: 10]; NSMutableArray *modified = [[NSMutableArray alloc] initWithCapacity: 10];
NSEnumerator *counter; NSEnumerator *counter;
unsigned int domainMask = 0;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id obj; 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 // Get the library dirs and add our path to all of its entries
temp = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSAllDomainsMask, YES); temp = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSAllDomainsMask, YES);

View file

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

View file

@ -37,10 +37,12 @@
#import "BundleController.h" #import "BundleController.h"
#import "PrefsView.h" #import "PrefsView.h"
#define ProjectPath @"projectPath"
@interface MainPrefs: NSObject <PrefsViewController, ForgeBundle> @interface MainPrefs: NSObject <PrefsViewController, ForgeBundle>
{ {
IBOutlet id bundlesFromLocalButton;
IBOutlet id bundlesFromNetworkButton;
IBOutlet id bundlesFromSystemButton;
IBOutlet id bundlesFromUserButton;
IBOutlet id projectPathField; IBOutlet id projectPathField;
IBOutlet id projectPathFindButton; IBOutlet id projectPathFindButton;
@ -48,4 +50,11 @@
IBOutlet id view; 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 @end

View file

@ -35,10 +35,7 @@ static const char rcsid[] =
#endif #endif
#import <AppKit/NSButton.h> #import <AppKit/NSButton.h>
#ifdef USING_NIBS #import <AppKit/NSNibLoading.h>
# import <AppKit/NSNibLoading.h>
#endif
#import <AppKit/NSOpenPanel.h> #import <AppKit/NSOpenPanel.h>
#import "PrefsPanel.h" #import "PrefsPanel.h"
@ -69,12 +66,31 @@ defaultValues (void) {
if (!dict) { if (!dict) {
dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: 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]; nil];
} }
return dict; 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 * static NSString *
getStringDefault (NSMutableDictionary *dict, NSString *name) getStringDefault (NSMutableDictionary *dict, NSString *name)
{ {
@ -92,7 +108,11 @@ getStringDefault (NSMutableDictionary *dict, NSString *name)
{ {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity: 5]; 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; return dict;
} }
@ -102,9 +122,15 @@ getStringDefault (NSMutableDictionary *dict, NSString *name)
#define setStringDefault(name) \ #define setStringDefault(name) \
[defaults setObject: [dict objectForKey: (name)] forKey: (name)] [defaults setObject: [dict objectForKey: (name)] forKey: (name)]
#define setBoolDefault(name) \
[defaults setBool: [[dict objectForKey: (name)] boolValue] forKey: (name)]
NSDebugLog (@"Updating Main Preferences..."); NSDebugLog (@"Updating Main Preferences...");
setStringDefault (ProjectPath); setStringDefault (@"ProjectPath");
setBoolDefault (@"BundlesFromLocal");
setBoolDefault (@"BundlesFromNetwork");
setBoolDefault (@"BundlesFromSystem");
setBoolDefault (@"BundlesFromUser");
[defaults synchronize]; [defaults synchronize];
} }
@ -125,8 +151,12 @@ getStringDefault (NSMutableDictionary *dict, NSString *name)
- (void) updateUI - (void) updateUI
{ {
[projectPathField setStringValue: [displayedValues objectForKey: ProjectPath]]; [projectPathField setStringValue: [displayedValues objectForKey: @"ProjectPath"]];
[projectPathField setNeedsDisplay: YES]; [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) @end // MainPrefs (Private)
@ -145,12 +175,17 @@ static id <BundleDelegate> owner = nil;
owner = anOwner; owner = anOwner;
[owner registerPrefsController: self]; [owner registerPrefsController: self];
if (![NSBundle loadNibNamed: @"MainPrefs" owner: 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]; view = [[MainPrefsView alloc] initWithOwner: self andFrame: PrefsRect];
// hook up to our outlet(s) // 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 { } else {
// window can be any size, as long as it's 486x228 :)
view = [window contentView]; view = [window contentView];
} }
[view retain]; [view retain];
@ -214,10 +249,13 @@ static id <BundleDelegate> owner = nil;
- (id) projectPath - (id) projectPath
{ {
return [displayedValues objectForKey: ProjectPath]; return [displayedValues objectForKey: @"ProjectPath"];
} }
- (id) projectPathFindButtonClicked: (id) sender /*
Action methods
*/
- (IBAction) projectPathFindButtonClicked: (id) sender
{ {
int result; int result;
NSOpenPanel *oPanel = [NSOpenPanel openPanel]; NSOpenPanel *oPanel = [NSOpenPanel openPanel];
@ -230,15 +268,39 @@ static id <BundleDelegate> owner = nil;
if (result == NSOKButton) { // got a new dir if (result == NSOKButton) { // got a new dir
NSArray *pathArray = [oPanel filenames]; NSArray *pathArray = [oPanel filenames];
[displayedValues setObject: [pathArray objectAtIndex: 0] forKey: ProjectPath]; [displayedValues setObject: [pathArray objectAtIndex: 0] forKey: @"ProjectPath"];
[self updateUI]; [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]; [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 @interface MainPrefsView: NSView
{ {
id directoryField; // for controllers to connect to
id findButton; id projectPathField;
id projectPathFindButton;
id bundlesFromUserButton;
id bundlesFromLocalButton;
id bundlesFromNetworkButton;
id bundlesFromSystemButton;
id owner; id owner;
} }
- (id) initWithOwner: (id) anOwner andFrame: (NSRect) frameRect; - (id) initWithOwner: (id) anOwner andFrame: (NSRect) frameRect;
- (id) directoryField; - (id) projectPathField;
- (id) bundlesFromUserButton;
- (id) bundlesFromLocalButton;
- (id) bundlesFromNetworkButton;
- (id) bundlesFromSystemButton;
@end @end

View file

@ -42,7 +42,9 @@ static const char rcsid[] =
#import "MainPrefs.h" #import "MainPrefs.h"
@implementation MainPrefsView @implementation MainPrefsView
/*
This class sucks, and shouldn't be necessary. With working "nibs", it isn't.
*/
- (id) initWithOwner: (id) anOwner andFrame: (NSRect) frameRect - (id) initWithOwner: (id) anOwner andFrame: (NSRect) frameRect
{ {
id label = nil; id label = nil;
@ -62,30 +64,95 @@ static const char rcsid[] =
[label setStringValue: @"Project load path"]; [label setStringValue: @"Project load path"];
[self addSubview: [label autorelease]]; [self addSubview: [label autorelease]];
directoryField = [[NSTextField alloc] initWithFrame: NSMakeRect (3, 174, 410, 24)]; projectPathField = [[NSTextField alloc] initWithFrame: NSMakeRect (3, 174, 409, 24)];
[directoryField setEditable: YES]; [projectPathField setEditable: YES];
[directoryField setSelectable: YES]; [projectPathField setSelectable: YES];
[directoryField setAllowsEditingTextAttributes: NO]; [projectPathField setAllowsEditingTextAttributes: NO];
[directoryField setImportsGraphics: NO]; [projectPathField setImportsGraphics: NO];
[directoryField setTextColor: [NSColor blackColor]]; [projectPathField setTextColor: [NSColor blackColor]];
[directoryField setBackgroundColor: [NSColor whiteColor]]; [projectPathField setBackgroundColor: [NSColor whiteColor]];
[directoryField setBezeled: YES]; [projectPathField setBezeled: YES];
[directoryField setTarget: owner]; [projectPathField setTarget: owner];
[directoryField setAction: @selector(projectPathChanged:)]; [projectPathField setAction: @selector(projectPathChanged:)];
[self addSubview: [directoryField autorelease]]; [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; 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 @end

View file

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