Merge pull request #40 from jwilling/master

Add support for a block-based sheet handler
This commit is contained in:
Danny Greg 2012-10-25 16:00:27 -07:00
Родитель 7391dc0c44 19c76a3f53
Коммит 5ed7ec3bd9
4 изменённых файлов: 55 добавлений и 0 удалений

Просмотреть файл

@ -16,6 +16,8 @@
306A81EB1601EAE700BF45F3 /* CAAnimation+RBLBlockAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 306A81EA1601EAE700BF45F3 /* CAAnimation+RBLBlockAdditionsSpec.m */; };
AB61F63616373FE000DD5D2C /* RBLTableCellView.h in Headers */ = {isa = PBXBuildFile; fileRef = AB61F63416373FE000DD5D2C /* RBLTableCellView.h */; settings = {ATTRIBUTES = (Public, ); }; };
AB61F63716373FE000DD5D2C /* RBLTableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = AB61F63516373FE000DD5D2C /* RBLTableCellView.m */; };
AB61F6D41638370900DD5D2C /* NSApplication+RBLBlockAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = AB61F6D21638370900DD5D2C /* NSApplication+RBLBlockAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
AB61F6D51638370900DD5D2C /* NSApplication+RBLBlockAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = AB61F6D31638370900DD5D2C /* NSApplication+RBLBlockAdditions.m */; };
D011FD5E16239A8600A27946 /* NSImage+RBLResizableImageAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = D011FD5C16239A8600A27946 /* NSImage+RBLResizableImageAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
D011FD5F16239A8600A27946 /* NSImage+RBLResizableImageAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = D011FD5D16239A8600A27946 /* NSImage+RBLResizableImageAdditions.m */; };
D01A4A28162C81EE0092D61F /* libExpecta.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D01A4A0C162C81CC0092D61F /* libExpecta.a */; };
@ -135,6 +137,8 @@
306A81EC1601F44200BF45F3 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
AB61F63416373FE000DD5D2C /* RBLTableCellView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RBLTableCellView.h; sourceTree = "<group>"; };
AB61F63516373FE000DD5D2C /* RBLTableCellView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RBLTableCellView.m; sourceTree = "<group>"; };
AB61F6D21638370900DD5D2C /* NSApplication+RBLBlockAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSApplication+RBLBlockAdditions.h"; sourceTree = "<group>"; };
AB61F6D31638370900DD5D2C /* NSApplication+RBLBlockAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSApplication+RBLBlockAdditions.m"; sourceTree = "<group>"; };
D011FD5C16239A8600A27946 /* NSImage+RBLResizableImageAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+RBLResizableImageAdditions.h"; sourceTree = "<group>"; };
D011FD5D16239A8600A27946 /* NSImage+RBLResizableImageAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+RBLResizableImageAdditions.m"; sourceTree = "<group>"; };
D0410EA915C61895003A3203 /* NSTextView+RBLAntialiasingAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTextView+RBLAntialiasingAdditions.h"; sourceTree = "<group>"; };
@ -274,6 +278,8 @@
D04CBFC715F6D87B004A5BCC /* NSView+RBLAnimationAdditions.m */,
306A81E61601E92000BF45F3 /* CAAnimation+RBLBlockAdditions.h */,
306A81E71601E92000BF45F3 /* CAAnimation+RBLBlockAdditions.m */,
AB61F6D21638370900DD5D2C /* NSApplication+RBLBlockAdditions.h */,
AB61F6D31638370900DD5D2C /* NSApplication+RBLBlockAdditions.m */,
);
name = Extensions;
sourceTree = "<group>";
@ -456,6 +462,7 @@
D0E91C581603CC7600D23E93 /* RBLClipView.h in Headers */,
D011FD5E16239A8600A27946 /* NSImage+RBLResizableImageAdditions.h in Headers */,
AB61F63616373FE000DD5D2C /* RBLTableCellView.h in Headers */,
AB61F6D41638370900DD5D2C /* NSApplication+RBLBlockAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -648,6 +655,7 @@
D0E91C591603CC7600D23E93 /* RBLClipView.m in Sources */,
D011FD5F16239A8600A27946 /* NSImage+RBLResizableImageAdditions.m in Sources */,
AB61F63716373FE000DD5D2C /* RBLTableCellView.m in Sources */,
AB61F6D51638370900DD5D2C /* NSApplication+RBLBlockAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

Просмотреть файл

@ -0,0 +1,18 @@
//
// NSApplication+RBLBlockAdditions.h
// Rebel
//
// Created by Jonathan Willing on 10/24/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import <Cocoa/Cocoa.h>
// Adds support for block handlers on a standard sheet.
@interface NSApplication (RBLBlockAdditions)
// Adds onto the standard `beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:`
// with support for a block completion handler.
- (void)rbl_beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)modalWindow completionHandler:(void (^)(NSInteger returnCode))handler;
@end

Просмотреть файл

@ -0,0 +1,28 @@
//
// NSApplication+RBLBlockAdditions.m
// Rebel
//
// Created by Jonathan Willing on 10/24/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import "NSApplication+RBLBlockAdditions.h"
#import <objc/runtime.h>
static void *RBLNSApplicationSheetBlockAssociatedObjectKey = &RBLNSApplicationSheetBlockAssociatedObjectKey;
@implementation NSApplication (RBLBlockAdditions)
- (void)rbl_beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)modalWindow completionHandler:(void (^)(NSInteger returnCode))handler {
[self beginSheet:sheet modalForWindow:modalWindow modalDelegate:self didEndSelector:@selector(rbl_sheetDidEnd:returnCode:contextInfo:) contextInfo:NULL];
objc_setAssociatedObject(sheet, RBLNSApplicationSheetBlockAssociatedObjectKey, handler, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (void)rbl_sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
void (^handler)(NSInteger returnCode) = objc_getAssociatedObject(sheet, RBLNSApplicationSheetBlockAssociatedObjectKey);
[sheet orderOut:self];
handler(returnCode);
objc_setAssociatedObject(sheet, RBLNSApplicationSheetBlockAssociatedObjectKey, nil, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
@end

Просмотреть файл

@ -6,6 +6,7 @@
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import <Rebel/NSApplication+RBLBlockAdditions.h>
#import <Rebel/NSColor+RBLCGColorAdditions.h>
#import <Rebel/NSImage+RBLResizableImageAdditions.h>
#import <Rebel/NSView+RBLAnimationAdditions.h>