diff --git a/DPSetupWindow.h b/DPSetupWindow.h index f32bcfa..1b5abb6 100644 --- a/DPSetupWindow.h +++ b/DPSetupWindow.h @@ -71,6 +71,7 @@ @property (retain) NSImage *backgroundImage; @property (assign) BOOL animates; @property (retain) NSArray *viewControllers; +@property (assign) BOOL funnelsRepresentedObjects; - (id)initWithViewControllers:(NSArray *)viewControllers completionHandler:(void (^)(BOOL completed))completionHandler; diff --git a/DPSetupWindow.m b/DPSetupWindow.m index e1bb130..dde9e70 100644 --- a/DPSetupWindow.m +++ b/DPSetupWindow.m @@ -35,6 +35,7 @@ - (id)initWithViewControllers:(NSArray *)viewControllers completionHandler:(void currentStage = -1; _animates = YES; + _funnelsRepresentedObjects = NO; [self setViewControllers:viewControllers]; [self setCompletionHandler:completionHandler]; [[self viewControllers] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { @@ -171,6 +172,20 @@ - (void)shift:(DPSetupWindowDirection)direction { [nextViewController performSelectorIfExists:@selector(willRevertToStage)]; } + void (^finished)() = ^{ + if (direction == DPSetupWindowNextDirection) { + [previousViewController performSelectorIfExists:@selector(didProgressToNextStage)]; + [nextViewController performSelectorIfExists:@selector(didProgressToStage)]; + } else if (direction == DPSetupWindowBackDirection) { + [previousViewController performSelectorIfExists:@selector(didRevertToPreviousStage)]; + [nextViewController performSelectorIfExists:@selector(didRevertToStage)]; + } + }; + + if ([self funnelsRepresentedObjects]) { + [nextViewController setRepresentedObject:[previousViewController representedObject]]; + } + if ([self animates] && previousViewController) { [NSAnimationContext beginGrouping]; @@ -179,13 +194,7 @@ - (void)shift:(DPSetupWindowDirection)direction { } [[NSAnimationContext currentContext] setCompletionHandler:^{ [[previousViewController view] removeFromSuperviewWithoutNeedingDisplay]; - if (direction == DPSetupWindowNextDirection) { - [previousViewController performSelectorIfExists:@selector(didProgressToNextStage)]; - [nextViewController performSelectorIfExists:@selector(didProgressToStage)]; - } else if (direction == DPSetupWindowBackDirection) { - [previousViewController performSelectorIfExists:@selector(didRevertToPreviousStage)]; - [nextViewController performSelectorIfExists:@selector(didRevertToStage)]; - } + finished(); }]; [view setFrame:NSMakeRect((400 * direction), 0, 400, 330)]; @@ -200,6 +209,7 @@ - (void)shift:(DPSetupWindowDirection)direction { [[previousViewController view] removeFromSuperviewWithoutNeedingDisplay]; } [[self contentBox] addSubview:view]; + finished(); } currentStage = nextStage; diff --git a/Readme.md b/Readme.md index d835ee0..77add7c 100644 --- a/Readme.md +++ b/Readme.md @@ -53,6 +53,11 @@ application's icon. [setupFlow setBackgroundImage:[NSImage imageNamed:@"NSUserAccounts"]]; ``` +The setup process can also be set to funnel the `representedObject` property of +each view controller along to the next as a way of moving state between stages. +This is not enabled by default and can be set by calling +`setFunnelsRepresentedObjects:` on the setup process window. + Each view controller in the setup process must implement the optional `DPSetupWindowStageViewController` protocol.