Save previous height when hidden.

This commit is contained in:
vspader 2008-06-22 19:44:09 +00:00
parent ab6f61c591
commit 5132465651
2 changed files with 71 additions and 18 deletions

View file

@ -15,9 +15,12 @@
} }
- (void)hideContent; - (void)hideContent;
- (void)hideContentwithAnimation:(BOOL)animate;
- (void)showContent; - (void)showContent;
//Only sets the flag, doesn't do anything.
- (void)setContentHidden:(BOOL)hidden;
- (NSString *)contentHiddenDefaultsKey;
- (NSString *)contentHeightDefaultsKey;
@end @end

View file

@ -11,21 +11,61 @@
@implementation InvertedToolbarWindow @implementation InvertedToolbarWindow
+ (void)initialize - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
{ {
NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary]; self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
if (self)
{
contentHidden = NO;
}
[userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:@"WindowContentHidden"]; return self;
}
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; - (NSString *)contentHiddenDefaultsKey
{
if ([self frameAutosaveName])
{
return [[self frameAutosaveName] stringByAppendingString:@" Window Content Hidden"];
}
return nil;
}
- (NSString *)contentHeightDefaultsKey
{
if ([self frameAutosaveName])
{
return [[self frameAutosaveName] stringByAppendingString:@" Window Content Height"];
}
return nil;
} }
- (void)awakeFromNib - (void)awakeFromNib
{ {
contentHidden = [[NSUserDefaults standardUserDefaults] boolForKey:@"WindowContentHidden"]; NSString *contentHiddenDefaultsKey = [self contentHiddenDefaultsKey];
if (contentHidden) if (contentHiddenDefaultsKey != nil)
{ {
[self hideContentwithAnimation:YES]; NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary];
[userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:contentHiddenDefaultsKey];
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:contentHiddenDefaultsKey])
{
//Rejigger the height
float contentHeight = [[NSUserDefaults standardUserDefaults] floatForKey:[self contentHeightDefaultsKey]];
contentSize = [[self contentView] bounds].size;
NSRect newFrame = [self frame];
newFrame.size.height -= contentSize.height;
newFrame.size.height += contentHeight;
[self setFrame:newFrame display:NO animate:NO];
[self hideContent];
} }
} }
@ -42,15 +82,20 @@
} }
- (void)hideContent - (void)hideContent
{
[self hideContentwithAnimation:YES];
}
- (void)hideContentwithAnimation:(BOOL)animate
{ {
NSRect newFrame = [self frame]; NSRect newFrame = [self frame];
BOOL animate = YES;
contentSize = [[self contentView] bounds].size; contentSize = [[self contentView] bounds].size;
[[NSUserDefaults standardUserDefaults] setFloat:contentSize.height forKey:[self contentHeightDefaultsKey]];
if (contentHidden)
{
//Content is already set as hidden...so we are pretending we were hidden the whole time.
//Currently, this only happens on init.
animate = NO;
}
newFrame.origin.y += contentSize.height; newFrame.origin.y += contentSize.height;
newFrame.size.height -= contentSize.height; newFrame.size.height -= contentSize.height;
@ -60,8 +105,7 @@
[[self contentView] setAutoresizesSubviews:NO]; [[self contentView] setAutoresizesSubviews:NO];
[self setFrame:newFrame display:YES animate:animate]; [self setFrame:newFrame display:YES animate:animate];
contentHidden = YES; [self setContentHidden:YES];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WindowContentHidden"];
} }
- (void)showContent - (void)showContent
@ -79,8 +123,7 @@
[self setShowsResizeIndicator:YES]; [self setShowsResizeIndicator:YES];
contentHidden = NO; [self setContentHidden:NO];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WindowContentHidden"];
} }
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize { - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize {
@ -91,4 +134,11 @@
return proposedFrameSize; return proposedFrameSize;
} }
- (void)setContentHidden:(BOOL)hidden
{
[[NSUserDefaults standardUserDefaults] setBool:hidden forKey:[self contentHiddenDefaultsKey]];
contentHidden = hidden;
}
@end @end