Merge pull request #46 from Machx/master

RBLViewController
This commit is contained in:
Josh Abernathy 2013-01-18 10:16:55 -08:00
Родитель 18c541a794 1cded0e477
Коммит ae14d73ed7
8 изменённых файлов: 367 добавлений и 0 удалений

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

@ -21,6 +21,12 @@
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 */; };
B85EE8DE163ECA8C00265870 /* RBLViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = B85EE8DC163ECA8C00265870 /* RBLViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
B85EE8DF163ECA8C00265870 /* RBLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B85EE8DD163ECA8C00265870 /* RBLViewController.m */; };
B85EE8E9163ECF4C00265870 /* NSView+RBLViewControllerAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = B85EE8E7163ECF4B00265870 /* NSView+RBLViewControllerAdditions.h */; };
B85EE8EA163ECF4C00265870 /* NSView+RBLViewControllerAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = B85EE8E8163ECF4C00265870 /* NSView+RBLViewControllerAdditions.m */; };
B85EE8ED163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = B85EE8EB163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.h */; };
B85EE8EE163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = B85EE8EC163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.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 */; };
@ -151,6 +157,12 @@
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>"; };
B85EE8DC163ECA8C00265870 /* RBLViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RBLViewController.h; sourceTree = "<group>"; };
B85EE8DD163ECA8C00265870 /* RBLViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RBLViewController.m; sourceTree = "<group>"; };
B85EE8E7163ECF4B00265870 /* NSView+RBLViewControllerAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSView+RBLViewControllerAdditions.h"; sourceTree = "<group>"; };
B85EE8E8163ECF4C00265870 /* NSView+RBLViewControllerAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSView+RBLViewControllerAdditions.m"; sourceTree = "<group>"; };
B85EE8EB163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+RBObjectSizzlingAdditions.h"; sourceTree = "<group>"; };
B85EE8EC163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+RBObjectSizzlingAdditions.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>"; };
D03D67161677E13F0041DDF2 /* NSAttributedString+RBLHTMLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAttributedString+RBLHTMLAdditions.h"; sourceTree = "<group>"; };
@ -279,6 +291,8 @@
306A81DA1601C7A300BF45F3 /* RBLPopover.m */,
AB61F63416373FE000DD5D2C /* RBLTableCellView.h */,
AB61F63516373FE000DD5D2C /* RBLTableCellView.m */,
B85EE8DC163ECA8C00265870 /* RBLViewController.h */,
B85EE8DD163ECA8C00265870 /* RBLViewController.m */,
AB10DB4B166EA9CA00AB7AB1 /* RBLScrollView.h */,
AB10DB4C166EA9CA00AB7AB1 /* RBLScrollView.m */,
);
@ -304,6 +318,10 @@
D0410EAA15C61895003A3203 /* NSTextView+RBLAntialiasingAdditions.m */,
D04CBFC615F6D87B004A5BCC /* NSView+RBLAnimationAdditions.h */,
D04CBFC715F6D87B004A5BCC /* NSView+RBLAnimationAdditions.m */,
B85EE8E7163ECF4B00265870 /* NSView+RBLViewControllerAdditions.h */,
B85EE8E8163ECF4C00265870 /* NSView+RBLViewControllerAdditions.m */,
B85EE8EB163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.h */,
B85EE8EC163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.m */,
);
name = Extensions;
sourceTree = "<group>";
@ -489,6 +507,9 @@
D0E91C581603CC7600D23E93 /* RBLClipView.h in Headers */,
D011FD5E16239A8600A27946 /* NSImage+RBLResizableImageAdditions.h in Headers */,
AB61F63616373FE000DD5D2C /* RBLTableCellView.h in Headers */,
B85EE8DE163ECA8C00265870 /* RBLViewController.h in Headers */,
B85EE8E9163ECF4C00265870 /* NSView+RBLViewControllerAdditions.h in Headers */,
B85EE8ED163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.h in Headers */,
AB61F6D41638370900DD5D2C /* NSApplication+RBLBlockAdditions.h in Headers */,
AB10DB4D166EA9CA00AB7AB1 /* RBLScrollView.h in Headers */,
D088BEF916747D8F004B2665 /* NSFont+RBLFallbackAdditions.h in Headers */,
@ -685,6 +706,9 @@
D0E91C591603CC7600D23E93 /* RBLClipView.m in Sources */,
D011FD5F16239A8600A27946 /* NSImage+RBLResizableImageAdditions.m in Sources */,
AB61F63716373FE000DD5D2C /* RBLTableCellView.m in Sources */,
B85EE8DF163ECA8C00265870 /* RBLViewController.m in Sources */,
B85EE8EA163ECF4C00265870 /* NSView+RBLViewControllerAdditions.m in Sources */,
B85EE8EE163EE15800265870 /* NSObject+RBObjectSizzlingAdditions.m in Sources */,
AB61F6D51638370900DD5D2C /* NSApplication+RBLBlockAdditions.m in Sources */,
AB10DB4E166EA9CA00AB7AB1 /* RBLScrollView.m in Sources */,
D088BEFA16747D8F004B2665 /* NSFont+RBLFallbackAdditions.m in Sources */,

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

@ -0,0 +1,15 @@
//
// NSObject+NSObjectSizzlingAdditions.h
// Rebel
//
// Created by Colin Wheeler on 10/29/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSObject (NSObjectSizzlingAdditions)
+ (void)rbl_swapMethod:(SEL)originalSelector with:(SEL)newSelector;
@end

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

@ -0,0 +1,30 @@
//
// NSObject+NSObjectSizzlingAdditions.m
// Rebel
//
// Created by Colin Wheeler on 10/29/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import "NSObject+RBObjectSizzlingAdditions.h"
#import <objc/runtime.h>
@implementation NSObject (NSObjectSizzlingAdditions)
// Shamelessly taken from JAViewController since mine is a bit longer & ties into my other framework methods
+ (void)rbl_swapMethod:(SEL)originalSelector with:(SEL)newSelector
{
Method originalMethod = class_getInstanceMethod(self, originalSelector);
Method newMethod = class_getInstanceMethod(self, newSelector);
const char *originalTypeEncoding = method_getTypeEncoding(originalMethod);
const char *newTypeEncoding = method_getTypeEncoding(newMethod);
NSAssert2(!strcmp(originalTypeEncoding, newTypeEncoding), @"Method type encodings must be the same: %s vs. %s", originalTypeEncoding, newTypeEncoding);
if(class_addMethod(self, originalSelector, method_getImplementation(newMethod), newTypeEncoding)) {
class_replaceMethod(self, newSelector, method_getImplementation(originalMethod), originalTypeEncoding);
} else {
method_exchangeImplementations(originalMethod, newMethod);
}
}
@end

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

@ -0,0 +1,15 @@
//
// NSView+NSView_RBLViewControllerAdditions.h
// Rebel
//
// Created by Colin Wheeler on 10/29/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface NSView (NSView_RBLViewControllerAdditions)
@property (nonatomic, assign) IBOutlet NSViewController *rbl_viewController;
@end

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

@ -0,0 +1,147 @@
//
// NSView+NSView_RBLViewControllerAdditions.m
// Rebel
//
// Created by Colin Wheeler on 10/29/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import "NSView+RBLViewControllerAdditions.h"
#import "RBLViewController.h"
#import "NSObject+RBObjectSizzlingAdditions.h"
#import <objc/runtime.h>
void *kRBLViewControllerKey = &kRBLViewControllerKey;
@implementation NSView (NSView_RBLViewControllerAdditions)
#pragma mark - ViewController
-(id)rbl_viewController {
return objc_getAssociatedObject(self, kRBLViewControllerKey);
}
-(void)setRbl_viewController:(id)newViewController {
[[self class] loadSupportForRBLViewControllers];
if (self.rbl_viewController) {
NSResponder *controllerNextResponder = [self.rbl_viewController nextResponder];
[self setNextResponder:controllerNextResponder];
[self.rbl_viewController setNextResponder:nil];
}
objc_setAssociatedObject(self, kRBLViewControllerKey, newViewController, OBJC_ASSOCIATION_ASSIGN);
if (newViewController) {
NSResponder *ownResponder = [self nextResponder];
[self setNextResponder:self.rbl_viewController];
[self.rbl_viewController setNextResponder:ownResponder];
}
}
#pragma mark - View Controller Methods
+(void)loadSupportForRBLViewControllers {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
//swizzle swizzle...
[self rbl_swapMethod:@selector(viewWillMoveToSuperview:) with:@selector(custom_viewWillMoveToSuperview:)];
[self rbl_swapMethod:@selector(viewDidMoveToSuperview) with:@selector(custom_viewDidMoveToSuperview)];
[self rbl_swapMethod:@selector(viewWillMoveToWindow:) with:@selector(custom_viewWillMoveToWindow:)];
[self rbl_swapMethod:@selector(viewDidMoveToWindow) with:@selector(custom_viewDidMoveToWindow)];
[self rbl_swapMethod:@selector(setNextResponder:) with:@selector(custom_setNextResponder:)];
});
}
- (void)custom_viewWillMoveToSuperview:(NSView *)newSuperview {
[self custom_viewWillMoveToSuperview:newSuperview];
if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (newSuperview == nil) {
[(RBLViewController *)self.rbl_viewController viewWillBeRemovedFromSuperview];
if ((self.superview != nil) && (self.window != nil)) {
[(RBLViewController *)self.rbl_viewController viewWillDisappear];
}
} else {
[(RBLViewController *)self.rbl_viewController viewWillMoveToSuperview:newSuperview];
if (self.window != nil) {
[(RBLViewController *)self.rbl_viewController viewWillAppear];
}
}
}
}
- (void)custom_viewDidMoveToSuperview {
[self custom_viewDidMoveToSuperview];
if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (self.superview == nil) {
[(RBLViewController *)self.rbl_viewController viewWasRemovedFromSuperview];
if (self.window == nil) {
[(RBLViewController *)self.rbl_viewController viewDidDisappear];
}
} else {
[(RBLViewController *)self.rbl_viewController viewDidMoveToSuperview];
if (self.window != nil) {
[(RBLViewController *)self.rbl_viewController viewDidAppear];
}
}
}
}
- (void)custom_viewWillMoveToWindow:(NSWindow *)newWindow {
[self custom_viewWillMoveToWindow:newWindow];
if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (newWindow == nil) {
[(RBLViewController *)self.rbl_viewController viewWillBeRemovedFromWindow];
if ((self.superview != nil) && (self.window != nil)) {
[(RBLViewController *)self.rbl_viewController viewWillDisappear];
}
} else {
[(RBLViewController *)self.rbl_viewController viewWillMoveToWindow:newWindow];
if (self.superview != nil) {
[(RBLViewController *)self.rbl_viewController viewWillAppear];
}
}
}
}
- (void)custom_viewDidMoveToWindow {
[self custom_viewDidMoveToWindow];
if ([self.rbl_viewController isKindOfClass:[RBLViewController class]]) {
if (self.window == nil) {
[(RBLViewController *)self.rbl_viewController viewWasRemovedFromWindow];
if (self.superview == nil) {
[(RBLViewController *)self.rbl_viewController viewDidDisappear];
}
} else {
[(RBLViewController *)self.rbl_viewController viewDidMoveToWindow];
if (self.superview != nil) {
[(RBLViewController *)self.rbl_viewController viewDidAppear];
}
}
}
}
- (void)custom_setNextResponder:(NSResponder *)newNextResponder {
if (self.rbl_viewController != nil) {
[self.rbl_viewController setNextResponder:newNextResponder];
return;
}
[self custom_setNextResponder:newNextResponder];
}
@end

35
Rebel/RBLViewController.h Normal file
Просмотреть файл

@ -0,0 +1,35 @@
//
// RBLViewController.h
// Rebel
//
// Created by Colin Wheeler on 10/29/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface RBLViewController : NSViewController
+ (id)viewController;
- (void)viewDidLoad;
// Called when the view has a superview and window. This does not necessarily mean the view is visible.
- (void)viewWillAppear;
- (void)viewDidAppear;
// Called when the view no longer has a superview or no longer has a window.
- (void)viewWillDisappear;
- (void)viewDidDisappear;
- (void)viewWillMoveToSuperview:(NSView *)newSuperview;
- (void)viewDidMoveToSuperview;
- (void)viewWillBeRemovedFromSuperview;
- (void)viewWasRemovedFromSuperview;
- (void)viewWillMoveToWindow:(NSWindow *)newWindow;
- (void)viewDidMoveToWindow;
- (void)viewWillBeRemovedFromWindow;
- (void)viewWasRemovedFromWindow;
@end

100
Rebel/RBLViewController.m Normal file
Просмотреть файл

@ -0,0 +1,100 @@
//
// RBLViewController.m
// Rebel
//
// Created by Colin Wheeler on 10/29/12.
// Copyright (c) 2012 GitHub. All rights reserved.
//
#import "RBLViewController.h"
#import "NSView+RBLViewControllerAdditions.h"
@interface RBLViewController ()
@end
@implementation RBLViewController
+(id)viewController
{
return [[self alloc] initWithNibName:NSStringFromClass([self class]) bundle:nil];
}
-(void)loadView
{
[super loadView];
[self viewDidLoad];
}
-(void)setView:(NSView *)view
{
super.view = view;
self.view.rbl_viewController = self;
}
- (void)viewDidLoad
{
}
- (void)viewWillAppear
{
}
- (void)viewDidAppear
{
}
- (void)viewWillDisappear
{
}
- (void)viewDidDisappear
{
}
- (void)viewWillMoveToSuperview:(NSView *)newSuperview
{
}
- (void)viewDidMoveToSuperview
{
}
- (void)viewWillBeRemovedFromSuperview
{
}
- (void)viewWasRemovedFromSuperview
{
}
- (void)viewWillMoveToWindow:(NSWindow *)newWindow
{
}
- (void)viewDidMoveToWindow
{
}
- (void)viewWillBeRemovedFromWindow
{
}
- (void)viewWasRemovedFromWindow
{
}
@end

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

@ -17,5 +17,6 @@
#import <Rebel/RBLView.h>
#import <Rebel/CAAnimation+RBLBlockAdditions.h>
#import <Rebel/RBLPopover.h>
#import <Rebel/RBLViewController.h>
#import <Rebel/RBLTableCellView.h>
#import <Rebel/RBLScrollView.h>