mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-22 18:31:27 +00:00
The beginnings of bundle-loading support Scary, but it seems to work!
This commit is contained in:
parent
61382f4967
commit
9c92717c15
18 changed files with 516 additions and 75 deletions
68
tools/Forge/BundleController.h
Normal file
68
tools/Forge/BundleController.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
BundleController.h
|
||||
|
||||
Bundle manager class and protocol
|
||||
|
||||
Copyright (C) 2001 Dusk to Dawn Computing, Inc.
|
||||
Additional copyrights here
|
||||
|
||||
Author: Jeff Teunissen <deek@d2dc.net>
|
||||
Date: 20 Nov 2001
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "Config.h"
|
||||
#endif
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
/*
|
||||
Bundle Delegate protocol
|
||||
|
||||
App controllers need to adopt this protocol to receive notifications
|
||||
*/
|
||||
@class BundleController; // forward reference so the compiler doesn't get confused
|
||||
@protocol BundleDelegate <NSObject>
|
||||
|
||||
// Notification, sent when a bundle is loaded.
|
||||
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle;
|
||||
|
||||
@end
|
||||
|
||||
@interface BundleController: NSObject <BundleDelegate>
|
||||
{
|
||||
id delegate;
|
||||
NSMutableArray *loadedBundles;
|
||||
}
|
||||
|
||||
- (id) init;
|
||||
- (void) dealloc;
|
||||
|
||||
- (id) delegate;
|
||||
- (void) setDelegate: (id) aDelegate;
|
||||
|
||||
- (void) loadBundles;
|
||||
|
||||
- (NSArray *) loadedBundles;
|
||||
|
||||
@end
|
170
tools/Forge/BundleController.m
Normal file
170
tools/Forge/BundleController.m
Normal file
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
BundleController.m
|
||||
|
||||
Bundle manager class
|
||||
|
||||
Copyright (C) 2001 Dusk to Dawn Computing, Inc.
|
||||
Additional copyrights here
|
||||
|
||||
Author: Jeff Teunissen <deek@d2dc.net>
|
||||
Date: 20 Nov 2001
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
*/
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "Config.h"
|
||||
#endif
|
||||
|
||||
#import <Foundation/NSDebug.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
#import <Foundation/NSPathUtilities.h>
|
||||
#import "BundleController.h"
|
||||
|
||||
@interface BundleController (Private)
|
||||
|
||||
- (void) loadBundleInPath: (NSString *) path;
|
||||
- (NSArray *) bundlesWithExtension: (NSString *) extension inPath: (NSString *) path;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BundleController (Private)
|
||||
|
||||
- (void) loadBundleInPath: (NSString *) path
|
||||
{
|
||||
NSBundle *bundle;
|
||||
|
||||
if (!path) {
|
||||
NSLog (@"%@ -loadBundleInPath: No path given!", [[self class] description]);
|
||||
return;
|
||||
}
|
||||
|
||||
NSDebugLog (@"Loading bundle %@...", path);
|
||||
|
||||
if ((bundle = [NSBundle bundleWithPath: path])) {
|
||||
NSDebugLog (@"Bundle %@ successfully loaded.", path);
|
||||
|
||||
/*
|
||||
Fire off the notification if we have a delegate that adopts the
|
||||
BundleDelegate protocol
|
||||
*/
|
||||
if (delegate && [delegate conformsToProtocol: @protocol(BundleDelegate)])
|
||||
[(id <BundleDelegate>) delegate bundleController: self didLoadBundle: bundle];
|
||||
[self bundleController: self didLoadBundle: bundle];
|
||||
} else {
|
||||
NSRunAlertPanel (@"Attention", @"Could not load bundle %@", @"OK", nil, nil, path);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *) bundlesWithExtension: (NSString *) extension inPath: (NSString *) path
|
||||
{
|
||||
NSMutableArray *bundleList = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
NSEnumerator *enumerator;
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *dir;
|
||||
BOOL isDir;
|
||||
|
||||
// ensure path exists, and is a directory
|
||||
if (![fm fileExistsAtPath: path isDirectory: &isDir])
|
||||
return;
|
||||
|
||||
if (!isDir)
|
||||
return;
|
||||
|
||||
// scan for bundles matching the extension in the dir
|
||||
enumerator = [[fm directoryContentsAtPath: path] objectEnumerator];
|
||||
while ((dir = [enumerator nextObject])) {
|
||||
if ([[dir pathExtension] isEqualToString: extension])
|
||||
[bundleList addObject: dir];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation BundleController
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
loadedBundles = [[NSMutableArray alloc] init];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[loadedBundles release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) delegate
|
||||
{
|
||||
return delegate;
|
||||
}
|
||||
|
||||
- (void) setDelegate: (id) aDelegate;
|
||||
{
|
||||
delegate = aDelegate;
|
||||
}
|
||||
|
||||
- (void) loadBundles
|
||||
{
|
||||
NSMutableArray *dirList = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
NSArray *temp;
|
||||
NSMutableArray *modified = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
NSEnumerator *counter;
|
||||
id obj;
|
||||
|
||||
// Start out with our own resource dir
|
||||
[dirList addObject: [[NSBundle mainBundle] resourcePath]];
|
||||
|
||||
// Get the library dirs and add our path to all of its entries
|
||||
temp = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSAllDomainsMask, YES);
|
||||
|
||||
counter = [temp objectEnumerator];
|
||||
while ((obj = [counter nextObject])) {
|
||||
[modified addObject: [obj stringByAppendingPathComponent: @"Forge"]];
|
||||
}
|
||||
[dirList addObjectsFromArray: modified];
|
||||
|
||||
// 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];
|
||||
NSString *str;
|
||||
|
||||
while ((str = [enum2 nextObject])) {
|
||||
[self loadBundleInPath: str];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *) loadedBundles
|
||||
{
|
||||
return loadedBundles;
|
||||
}
|
||||
|
||||
- (void) bundleController: (BundleController *) aController didLoadBundle: (NSBundle *) aBundle
|
||||
{
|
||||
[loadedBundles addObject: aBundle];
|
||||
}
|
||||
|
||||
@end
|
7
tools/Forge/Bundles/MainPrefs/.gitignore
vendored
Normal file
7
tools/Forge/Bundles/MainPrefs/.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
.vimrc
|
||||
shared_debug_obj
|
||||
shared_obj
|
||||
shared_profile_debug_obj
|
||||
shared_profile_obj
|
||||
obj
|
||||
*.forgeb
|
20
tools/Forge/Bundles/MainPrefs/GNUmakefile
Normal file
20
tools/Forge/Bundles/MainPrefs/GNUmakefile
Normal file
|
@ -0,0 +1,20 @@
|
|||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
BUNDLE_NAME= MainPrefs
|
||||
BUNDLE_EXTENSION= .forgeb
|
||||
BUNDLE_INSTALL_DIR= $(GNUSTEP_LOCAL_ROOT)/Library/Forge
|
||||
|
||||
MainPrefs_OBJC_FILES= \
|
||||
MainPrefsView.m
|
||||
|
||||
MainPrefs_HEADERS= \
|
||||
MainPrefsView.h
|
||||
|
||||
MainPrefs_PRINCIPAL_CLASS= \
|
||||
MainPrefsController
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/bundle.make
|
||||
|
||||
-include GNUmakefile.postamble
|
39
tools/Forge/Bundles/MainPrefs/GNUmakefile.preamble
Normal file
39
tools/Forge/Bundles/MainPrefs/GNUmakefile.preamble
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Additional flags to pass to the preprocessor
|
||||
ADDITIONAL_CPPFLAGS +=
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
ADDITIONAL_OBJCFLAGS +=
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
ADDITIONAL_CFLAGS +=
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS += -I ../..
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
ADDITIONAL_LDFLAGS +=
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS +=
|
||||
|
||||
# Additional libraries
|
||||
|
||||
# GNUstepWeb
|
||||
ADDITIONAL_GSW_LIBS +=
|
||||
# GUI apps
|
||||
ADDITIONAL_GUI_LIBS +=
|
||||
# Libraries
|
||||
ADDITIONAL_LIBRARY_LIBS +=
|
||||
# ObjC stuff
|
||||
ADDITIONAL_OBJC_LIBS +=
|
||||
# Tools
|
||||
ADDITIONAL_TOOL_LIBS +=
|
||||
# WebObjects
|
||||
ADDITIONAL_WO_LIBS +=
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
# Additional directories to be created during installation
|
||||
ADDITIONAL_INSTALL_DIRS +=
|
37
tools/Forge/Bundles/MainPrefs/MainPrefsView.h
Normal file
37
tools/Forge/Bundles/MainPrefs/MainPrefsView.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
ForgePrefsView.h
|
||||
|
||||
Forge internal preferences view
|
||||
|
||||
Copyright (C) 2001 Dusk to Dawn Computing, Inc.
|
||||
|
||||
Author: Jeff Teunissen <deek@d2dc.net>
|
||||
Date: 17 Nov 2001
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "Config.h"
|
||||
#endif
|
||||
|
||||
#import "PrefsView.h"
|
||||
|
||||
@interface MainPrefsView: NSView
|
||||
@end
|
46
tools/Forge/Bundles/MainPrefs/MainPrefsView.m
Normal file
46
tools/Forge/Bundles/MainPrefs/MainPrefsView.m
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
MainPrefsView.m
|
||||
|
||||
Forge internal preferences view
|
||||
|
||||
Copyright (C) 2001 Dusk to Dawn Computing, Inc.
|
||||
|
||||
Author: Jeff Teunissen <deek@d2dc.net>
|
||||
Date: 17 Nov 2001
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
*/
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "Config.h"
|
||||
#endif
|
||||
|
||||
#import <AppKit/NSBezierPath.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
|
||||
#import "MainPrefsView.h"
|
||||
|
||||
@implementation MainPrefsView
|
||||
|
||||
- (void) initUI
|
||||
{
|
||||
}
|
||||
@end
|
|
@ -109,13 +109,7 @@ static PrefsController *prefsController = nil;
|
|||
- (void) showPreferencesPanel: (id) sender;
|
||||
{
|
||||
NSDebugLog (@"Showing Preferences panel...");
|
||||
|
||||
if (!prefsController)
|
||||
prefsController = [[PrefsController alloc] init];
|
||||
|
||||
[prefsController orderFrontPreferencesPanel: self];
|
||||
|
||||
return;
|
||||
[[PrefsController sharedPrefsController] orderFrontPreferencesPanel: self];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -152,8 +146,6 @@ static PrefsController *prefsController = nil;
|
|||
[menu addItemWithTitle: _(@"Project") action: NULL keyEquivalent: @""];
|
||||
[menu addItemWithTitle: _(@"File") action: NULL keyEquivalent: @""];
|
||||
[menu addItemWithTitle: _(@"Edit") action: NULL keyEquivalent: @""];
|
||||
[menu addItemWithTitle: _(@"BSP") action: NULL keyEquivalent: @""];
|
||||
[menu addItemWithTitle: _(@"Brush") action: NULL keyEquivalent: @""];
|
||||
[menu addItemWithTitle: _(@"Windows") action: NULL keyEquivalent: @""];
|
||||
[menu addItemWithTitle: _(@"Services") action: NULL keyEquivalent: @""];
|
||||
|
||||
|
@ -254,22 +246,6 @@ static PrefsController *prefsController = nil;
|
|||
action: @selector (selectAll:)
|
||||
keyEquivalent: @"a"];
|
||||
|
||||
/*
|
||||
BSP
|
||||
*/
|
||||
bsp = [[[NSMenu alloc] init] autorelease];
|
||||
[menu setSubmenu: bsp forItem: [menu itemWithTitle: _(@"BSP")]];
|
||||
|
||||
[bsp addItemWithTitle: _(@"None") action: @selector(nothing:) keyEquivalent: @""];
|
||||
|
||||
/*
|
||||
Brush
|
||||
*/
|
||||
brush = [[[NSMenu alloc] init] autorelease];
|
||||
[menu setSubmenu: brush forItem: [menu itemWithTitle: _(@"Brush")]];
|
||||
|
||||
[brush addItemWithTitle: _(@"None") action: @selector(nothing:) keyEquivalent: @""];
|
||||
|
||||
/*
|
||||
Windows
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/* App Name */
|
||||
"Forge" = "Forge";
|
||||
|
||||
/* Controller.m Menus */
|
||||
"Info" = "Info";
|
||||
"Info Panel..." = "Info Panel...";
|
||||
|
@ -42,3 +45,4 @@
|
|||
"OK" = "OK";
|
||||
"Cancel" = "Cancel";
|
||||
"Apply" = "Apply";
|
||||
"Default" = "Default";
|
||||
|
|
|
@ -1,4 +1,13 @@
|
|||
{
|
||||
BundleController = {
|
||||
Actions = (
|
||||
setDelegate:
|
||||
);
|
||||
Outlets = (
|
||||
delegate
|
||||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
Controller = {
|
||||
Actions = (
|
||||
createNew:,
|
||||
|
@ -77,13 +86,6 @@
|
|||
);
|
||||
Super = NSResponder;
|
||||
};
|
||||
NewClass = {
|
||||
Actions = (
|
||||
);
|
||||
Outlets = (
|
||||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
Preferences = {
|
||||
Actions = (
|
||||
ok:,
|
||||
|
|
Binary file not shown.
|
@ -30,6 +30,8 @@ include $(GNUSTEP_MAKEFILES)/common.make
|
|||
#
|
||||
# Subprojects
|
||||
#
|
||||
SUBPROJECTS= \
|
||||
Bundles/MainPrefs
|
||||
|
||||
#
|
||||
# Main application
|
||||
|
@ -49,6 +51,7 @@ ADDITIONAL_GUI_LIBS +=
|
|||
#
|
||||
Forge_MAIN_MODEL_FILE= Forge.gorm
|
||||
Forge_RESOURCE_FILES= \
|
||||
Bundles/MainPrefs/MainPrefs.forgeb \
|
||||
Forge.gorm \
|
||||
Forge.tiff \
|
||||
ForgeInfo.plist
|
||||
|
@ -64,6 +67,7 @@ Forge_LANGUAGES= \
|
|||
# Header files
|
||||
#
|
||||
Forge_HEADERS= \
|
||||
BundleController.h \
|
||||
Controller.h \
|
||||
Preferences.h \
|
||||
PrefsPanel.h \
|
||||
|
@ -73,6 +77,7 @@ Forge_HEADERS= \
|
|||
# Class files
|
||||
#
|
||||
Forge_OBJC_FILES= \
|
||||
BundleController.m \
|
||||
Controller.m \
|
||||
Preferences.m \
|
||||
PrefsPanel.m \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
PrefsWindowController.h
|
||||
PrefsController.h
|
||||
|
||||
Preferences window controller class
|
||||
|
||||
|
@ -33,11 +33,13 @@
|
|||
|
||||
#import <AppKit/NSWindowController.h>
|
||||
|
||||
#import "PrefsView.h"
|
||||
|
||||
@interface PrefsController: NSWindowController
|
||||
{
|
||||
NSMutableArray *prefsViews;
|
||||
}
|
||||
|
||||
+ (PrefsController *) sharedPrefsController;
|
||||
- (id) init;
|
||||
- (void) dealloc;
|
||||
|
||||
|
@ -50,9 +52,12 @@
|
|||
Stuff we do in our subclass
|
||||
***/
|
||||
- (void) orderFrontPreferencesPanel: (id) sender;
|
||||
- (void) addPrefsView: (id) aPrefsView;
|
||||
- (void) addPrefsViewController: (id <PrefsViewController>) aPrefsViewController;
|
||||
|
||||
- (void) savePreferences: (id) sender;
|
||||
- (void) savePreferencesAndCloseWindow: (id) sender;
|
||||
|
||||
- (void) loadPreferences: (id) sender;
|
||||
- (void) resetToDefaults: (id) sender;
|
||||
|
||||
@end
|
||||
|
|
|
@ -37,31 +37,46 @@ static const char rcsid[] =
|
|||
|
||||
#import "PrefsController.h"
|
||||
#import "PrefsPanel.h"
|
||||
#import "PrefsView.h"
|
||||
|
||||
@implementation PrefsController
|
||||
|
||||
static PrefsController *sharedInstance = nil;
|
||||
static NSMutableArray *prefsViews = nil;
|
||||
|
||||
+ (PrefsController *) sharedPrefsController
|
||||
{
|
||||
return (sharedInstance ? sharedInstance : [[self alloc] init]);
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
PrefsPanel *prefsPanel;
|
||||
|
||||
prefsViews = [[NSMutableArray alloc] initWithCapacity: 5];
|
||||
|
||||
prefsPanel = [[PrefsPanel alloc]
|
||||
initWithContentRect: NSMakeRect (250, 250, 516, 386)
|
||||
styleMask: NSTitledWindowMask
|
||||
| NSMiniaturizableWindowMask
|
||||
| NSClosableWindowMask
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO
|
||||
];
|
||||
[prefsPanel setTitle: _(@"Preferences")];
|
||||
if (sharedInstance) {
|
||||
[self dealloc];
|
||||
} else {
|
||||
[super init];
|
||||
sharedInstance = self;
|
||||
|
||||
[super initWithWindow: prefsPanel];
|
||||
[prefsPanel initUI];
|
||||
[prefsPanel setDelegate: self];
|
||||
[prefsPanel release];
|
||||
prefsViews = [[[NSMutableArray alloc] initWithCapacity: 5] retain];
|
||||
|
||||
return self;
|
||||
prefsPanel = [[PrefsPanel alloc]
|
||||
initWithContentRect: NSMakeRect (250, 250, 516, 386)
|
||||
styleMask: NSTitledWindowMask
|
||||
| NSMiniaturizableWindowMask
|
||||
| NSClosableWindowMask
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO
|
||||
];
|
||||
[prefsPanel setTitle: [NSString stringWithFormat: @"%@ %@", _(@"Forge"), _(@"Preferences")]];
|
||||
|
||||
[super initWithWindow: prefsPanel];
|
||||
[prefsPanel initUI];
|
||||
[prefsPanel setDelegate: self];
|
||||
[prefsPanel release];
|
||||
}
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -90,8 +105,8 @@ static const char rcsid[] =
|
|||
|
||||
- (void) savePreferences: (id) sender
|
||||
{
|
||||
NSEnumerator *enumerator = [prefsViews objectEnumerator];
|
||||
id current;
|
||||
NSEnumerator *enumerator = [prefsViews objectEnumerator];
|
||||
id <PrefsViewController> current;
|
||||
|
||||
NSDebugLog (@"Saving all preferences...");
|
||||
while ((current = [enumerator nextObject])) {
|
||||
|
@ -101,19 +116,45 @@ static const char rcsid[] =
|
|||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
- (void) addPrefsView: (id) aPrefsView;
|
||||
- (void) loadPreferences: (id) sender
|
||||
{
|
||||
NSEnumerator *enumerator = [prefsViews objectEnumerator];
|
||||
id <PrefsViewController> current;
|
||||
|
||||
NSDebugLog (@"Loading all preferences from database...");
|
||||
while ((current = [enumerator nextObject])) {
|
||||
[current loadPrefs: self];
|
||||
}
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
- (void) resetToDefaults: (id) sender
|
||||
{
|
||||
NSEnumerator *enumerator = [prefsViews objectEnumerator];
|
||||
id <PrefsViewController> current;
|
||||
|
||||
NSDebugLog (@"Setting all preferences to default values...");
|
||||
while ((current = [enumerator nextObject])) {
|
||||
[current resetPrefsToDefault: self];
|
||||
}
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
- (void) addPrefsViewController: (id <PrefsViewController>) controller;
|
||||
{
|
||||
PrefsPanel *prefsPanel;
|
||||
|
||||
prefsPanel = (PrefsPanel *) [self window];
|
||||
|
||||
if (! [prefsViews containsObject: aPrefsView]) {
|
||||
[prefsViews addObject: aPrefsView];
|
||||
[aPrefsView autorelease];
|
||||
if (! [prefsViews containsObject: controller]) {
|
||||
[prefsViews addObject: controller];
|
||||
[controller autorelease];
|
||||
}
|
||||
|
||||
[[prefsPanel prefsViewBox] setContentView: aPrefsView];
|
||||
[[prefsPanel prefsViewBox] display];
|
||||
[[prefsPanel prefsViewBox] setContentView: [controller view]];
|
||||
[[prefsPanel prefsViewBox] setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -47,8 +47,7 @@
|
|||
|
||||
- (void) initUI;
|
||||
- (void) dealloc;
|
||||
|
||||
- (void) addPrefsViewButtonWithDescription: (NSString *) desc andImage: (NSImage *) img;
|
||||
- (void) addPrefsViewButtonWithTitle: (NSString *) desc andImage: (NSImage *) img;
|
||||
|
||||
- (NSBox *) prefsViewBox;
|
||||
- (NSMatrix *) prefsViewList;
|
||||
|
|
|
@ -34,6 +34,7 @@ static const char rcsid[] =
|
|||
# include "Config.h"
|
||||
#endif
|
||||
|
||||
#import <Foundation/NSGeometry.h>
|
||||
#import <AppKit/NSButton.h>
|
||||
#import <AppKit/NSButtonCell.h>
|
||||
#import <AppKit/NSFont.h>
|
||||
|
@ -46,7 +47,7 @@ static const char rcsid[] =
|
|||
|
||||
- (void) initUI
|
||||
{
|
||||
NSButton *ok, *apply, *cancel;
|
||||
NSButton *ok, *apply, *cancel, *revert;
|
||||
NSButtonCell *prototype;
|
||||
NSScrollView *iconScrollView;
|
||||
|
||||
|
@ -60,10 +61,11 @@ static const char rcsid[] =
|
|||
Scroll area is 86 pixels tall, 500 wide
|
||||
content view size: (520, 414)
|
||||
*/
|
||||
|
||||
|
||||
prefsViewBox = [[NSBox alloc] initWithFrame: NSMakeRect (8, 40, 500, 242)];
|
||||
[prefsViewBox setTitlePosition: NSNoTitle];
|
||||
[prefsViewBox setBorderType: NSGrooveBorder];
|
||||
NSDebugLog (@"prefsViewBox bounds: %@", NSStringFromRect ([[prefsViewBox contentView] bounds]));
|
||||
|
||||
[[self contentView] addSubview: prefsViewBox];
|
||||
|
||||
|
@ -87,10 +89,10 @@ static const char rcsid[] =
|
|||
[iconScrollView setHasVerticalScroller: NO];
|
||||
[iconScrollView setDocumentView: prefsViewList];
|
||||
[[self contentView] addSubview: iconScrollView];
|
||||
|
||||
|
||||
/* Create the buttons */
|
||||
// OK
|
||||
ok = [[NSButton alloc] initWithFrame: NSMakeRect (312, 8, 60, 24)];
|
||||
ok = [[NSButton alloc] initWithFrame: NSMakeRect (244, 8, 60, 24)];
|
||||
[ok autorelease];
|
||||
|
||||
[ok setTitle: _(@"OK")];
|
||||
|
@ -98,8 +100,8 @@ static const char rcsid[] =
|
|||
[ok setAction: @selector(savePreferencesAndCloseWindow:)];
|
||||
[[self contentView] addSubview: ok];
|
||||
|
||||
// cancel
|
||||
cancel = [[NSButton alloc] initWithFrame: NSMakeRect (380, 8, 60, 24)];
|
||||
// Cancel
|
||||
cancel = [[NSButton alloc] initWithFrame: NSMakeRect (312, 8, 60, 24)];
|
||||
[cancel autorelease];
|
||||
|
||||
[cancel setTitle: _(@"Cancel")];
|
||||
|
@ -107,25 +109,34 @@ static const char rcsid[] =
|
|||
[cancel setAction: @selector(close)];
|
||||
[[self contentView] addSubview: cancel];
|
||||
|
||||
// apply
|
||||
apply = [[NSButton alloc] initWithFrame: NSMakeRect (448, 8, 60, 24)];
|
||||
// Apply
|
||||
apply = [[NSButton alloc] initWithFrame: NSMakeRect (380, 8, 60, 24)];
|
||||
[apply autorelease];
|
||||
|
||||
[apply setTitle: _(@"Apply")];
|
||||
[apply setTarget: [self windowController]];
|
||||
[apply setAction: @selector(savePreferences:)];
|
||||
[[self contentView] addSubview: apply];
|
||||
|
||||
// Defaults
|
||||
revert = [[NSButton alloc] initWithFrame: NSMakeRect (448, 8, 60, 24)];
|
||||
[revert autorelease];
|
||||
|
||||
[revert setTitle: _(@"Default")];
|
||||
[revert setTarget: [self windowController]];
|
||||
[revert setAction: @selector(resetToDefaults:)];
|
||||
[[self contentView] addSubview: revert];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDebugLog (@"PrefsWindow -dealloc");
|
||||
NSDebugLog (@"PrefsPanel -dealloc");
|
||||
[prefsViewBox release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) addPrefsViewButtonWithDescription: (NSString *) desc andImage: (NSImage *) img
|
||||
- (void) addPrefsViewButtonWithTitle: (NSString *) desc andImage: (NSImage *) img
|
||||
{
|
||||
NSButtonCell *button = [[NSButtonCell alloc] init];
|
||||
|
||||
|
|
|
@ -33,6 +33,18 @@
|
|||
|
||||
#import <AppKit/NSView.h>
|
||||
|
||||
@interface PrefsView: NSView
|
||||
{
|
||||
}
|
||||
// size of a PrefsView
|
||||
#define PrefsRect NSMakeRect (0, 0, 486, 228)
|
||||
|
||||
@protocol PrefsViewController <NSObject>
|
||||
|
||||
- (void) savePrefs: (id) sender;
|
||||
- (void) loadPrefs: (id) sender;
|
||||
- (void) resetPrefsToDefault: (id) sender;
|
||||
|
||||
- (NSView *) view;
|
||||
|
||||
@end
|
||||
|
||||
@interface PrefsViewController <PrefsViewController>
|
||||
@end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#import <AppKit/NSApplication.h>
|
||||
#import "Controller.h"
|
||||
|
||||
#define APP_NAME @"Forge"
|
||||
|
||||
|
|
Loading…
Reference in a new issue