This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)firstAvailableFilename:(NSString *)filename | |
{ | |
while (![self isFilenameAvailable:filename]) | |
{ | |
filename = [filename ks_stringByIncrementingPath]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGImageRef)renderImage:(CIImage *)scaledImage fromSource:(CIImage *)sourceImage; | |
{ | |
// We want sRGB as fallback output colorspace | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); | |
CIContext *context = [CIContext contextWithCGContext:nil | |
options:[NSDictionary dictionaryWithObjectsAndKeys: | |
colorSpace, kCIContextOutputColorSpace, | |
nil]]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)hardResetContext:(NSManagedObjectContext *)context store:(NSPersistentStore *)store; | |
{ | |
NSPersistentStoreCoordinator *storeCoordinator = [context persistentStoreCoordinator]; | |
if (![storeCoordinator removePersistentStore:myStore error:NULL]) | |
{ | |
return NO; | |
} | |
return [storeCoordinator addPersistentStoreWithType:[store type] | |
configuration:nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)restoreDocumentWindowWithIdentifier:(NSString *)identifier state:(NSCoder *)state completionHandler:(void (^)(NSWindow *, NSError *))completionHandler; | |
{ | |
if ([identifier isEqualToString:@"Secondary"]) | |
{ | |
// Rely on main controller to create secondary window | |
if (![[self windowControllers] count]) [self makeWindowControllers]; | |
MyWindowController *mainController = [[self windowControllers] objectAtIndex:0]; | |
completionHandler([[mainController secondaryWindowController] window], nil); | |
} | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation MySecondaryWindowController | |
- (void)windowDidLoad | |
{ | |
[super windowDidLoad]; | |
[[self window] setIdentifier:@"Secondary"]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)clearUndoHistoryOfDoc:(NSDocument *)doc | |
{ | |
NSUndoManager *undoManager = [doc undoManager]; | |
// Post a checkpoint first so any pending registrations | |
// (e.g. from Core Data) are committed | |
[[NSNotificationCenter defaultCenter] | |
postNotificationName:NSUndoManagerCheckpointNotification | |
object:undoManager]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSAlert (Karelia) | |
- (void)ks_setMessageTextWithFormat:(NSString *)format, ...; | |
{ | |
va_list argList; | |
va_start(argList, format); | |
NSString *formatted = [[NSString alloc] initWithFormat:format arguments:argList]; | |
va_end(argList); | |
[self setMessageText:formatted]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSWindow *)windowForSheet; | |
{ | |
NSWindow *result = [super windowForSheet]; | |
NSWindow *sheet; | |
while ((sheet = [result attachedSheet])) | |
{ | |
result = sheet; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)saveAndReturnError:(NSError **)error | |
{ | |
NSManagedObjectContext *context = [self managedObjectContext]; | |
__block BOOL result; | |
[context performBlockAndWait:^{ | |
result = [context save:error]; | |
}]; | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)saveAndReturnError:(NSError **)error | |
{ | |
NSManagedObjectContext *context = [self managedObjectContext]; | |
__block BOOL result; | |
[context performBlockAndWait:^{ | |
result = [context save:error]; | |
if (!result && error) [*error retain]; | |
}]; | |
if (!result && error) [*error autorelease]; |