Skip to content

Commit

Permalink
Funnel represented objects between stages, fixed bug with non-animate…
Browse files Browse the repository at this point in the history
…d window calling didDoSomething methods.
  • Loading branch information
danpalmer committed Oct 6, 2012
1 parent e0e5f48 commit 23e9b2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions DPSetupWindow.h
Expand Up @@ -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;

Expand Down
24 changes: 17 additions & 7 deletions DPSetupWindow.m
Expand Up @@ -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) {
Expand Down Expand Up @@ -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];

Expand All @@ -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)];
Expand All @@ -200,6 +209,7 @@ - (void)shift:(DPSetupWindowDirection)direction {
[[previousViewController view] removeFromSuperviewWithoutNeedingDisplay];
}
[[self contentBox] addSubview:view];
finished();
}

currentStage = nextStage;
Expand Down
5 changes: 5 additions & 0 deletions Readme.md
Expand Up @@ -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.

Expand Down

0 comments on commit 23e9b2f

Please sign in to comment.