# HG changeset patch # User Jens Alfke # Date 1207534407 25200 # Node ID 8fad19466c59db99aa2c06d39cce13a5a75fa22a # Parent 3d3dcc3116d58278905c09215c83dc4f17549435 Miscellaneous improvements. diff -r 3d3dcc3116d5 -r 8fad19466c59 DateUtils.h --- a/DateUtils.h Wed Apr 02 14:45:33 2008 -0700 +++ b/DateUtils.h Sun Apr 06 19:13:27 2008 -0700 @@ -8,5 +8,14 @@ #import +#ifdef __cplusplus +extern "C" { +#endif + NSTimeInterval TimeIntervalSinceBoot(void); + + +#ifdef __cplusplus +} +#endif diff -r 3d3dcc3116d5 -r 8fad19466c59 GraphicsUtils.h --- a/GraphicsUtils.h Wed Apr 02 14:45:33 2008 -0700 +++ b/GraphicsUtils.h Sun Apr 06 19:13:27 2008 -0700 @@ -26,3 +26,6 @@ /** Moves/resizes r to fit inside container */ NSRect PinRect( NSRect r, NSRect container ); + +OSStatus LoadFontsFromBundle( NSBundle *bundle ); +OSStatus LoadFontsFromPath( NSString* path ); diff -r 3d3dcc3116d5 -r 8fad19466c59 GraphicsUtils.m --- a/GraphicsUtils.m Wed Apr 02 14:45:33 2008 -0700 +++ b/GraphicsUtils.m Sun Apr 06 19:13:27 2008 -0700 @@ -6,6 +6,8 @@ // #import "GraphicsUtils.h" +#import "FileUtils.h" +#import @implementation NSImage (MYUtilities) @@ -241,3 +243,32 @@ return r; } + + +OSStatus LoadFontsFromBundle( NSBundle *bundle ) +{ + NSString *fontsPath = [[bundle resourcePath] stringByAppendingPathComponent:@"Fonts"]; + if( fontsPath ) + return LoadFontsFromPath(fontsPath); + else + return fnfErr; +} + + +OSStatus LoadFontsFromPath( NSString* path ) +{ + // Tip of the hat to Buddy Kurz! + FSRef fsRef; + OSStatus err = PathToFSRef(path,&fsRef); + if (err==noErr) + err = ATSFontActivateFromFileReference(&fsRef, + kATSFontContextLocal, + kATSFontFormatUnspecified, + NULL, + kATSOptionFlagsDefault, + NULL + ); + if( err ) Warn(@"LoadFontsFromPath: Error %i for %@",err,path); + return err; +} + diff -r 3d3dcc3116d5 -r 8fad19466c59 KVUtils.h --- a/KVUtils.h Wed Apr 02 14:45:33 2008 -0700 +++ b/KVUtils.h Sun Apr 06 19:13:27 2008 -0700 @@ -59,8 +59,9 @@ keyPath: (NSString*)keyPath action: (SEL)action; +/** observed or keyPath may be nil, meaning wildcard */ - (void) stopObserving: (id)observedOrNil keyPath: (NSString*)keyPathOrNil; - +- (void) stopObserving: (id)observed; - (void) stopObserving; @end diff -r 3d3dcc3116d5 -r 8fad19466c59 KVUtils.m --- a/KVUtils.m Wed Apr 02 14:45:33 2008 -0700 +++ b/KVUtils.m Sun Apr 06 19:13:27 2008 -0700 @@ -59,6 +59,7 @@ }@catch( NSException *x ) { Warn(@"Uncaught exception in -[%@<%p> %s] while observing change of key-path %@ in %@<%p>: %@", _target,_target, _action, _keyPath, _observed,_observed, x); + [NSApp reportException: x]; } } @@ -148,6 +149,12 @@ } +- (void) stopObserving: (id)observed +{ + [self stopObserving: observed keyPath: nil]; +} + + - (void) stopObserving: (id)observed keyPath: (NSString*)keyPath { // observed or keyPath may be nil diff -r 3d3dcc3116d5 -r 8fad19466c59 UniqueWindowController.h --- a/UniqueWindowController.h Wed Apr 02 14:45:33 2008 -0700 +++ b/UniqueWindowController.h Sun Apr 06 19:13:27 2008 -0700 @@ -14,6 +14,8 @@ + (UniqueWindowController*) instanceWith: (id)model; + (UniqueWindowController*) openWith: (id)model; ++ (BOOL) isModel: (id)model1 equalToModel: (id)model2; + @end diff -r 3d3dcc3116d5 -r 8fad19466c59 UniqueWindowController.m --- a/UniqueWindowController.m Wed Apr 02 14:45:33 2008 -0700 +++ b/UniqueWindowController.m Sun Apr 06 19:13:27 2008 -0700 @@ -13,11 +13,17 @@ @implementation UniqueWindowController ++ (BOOL) isModel: (id)model1 equalToModel: (id)model2 +{ + return model1==model2; +} + + + (UniqueWindowController*) instanceWith: (id)model { for( NSWindow *window in OpenWindowsWithDelegateClass(self) ) { UniqueWindowController *c = window.delegate; - if( c.model == model ) + if( [self isModel: c.model equalToModel: model] ) return c; } return nil;