From 51324656516c0ac8a93027646c6c9919389d0e65 Mon Sep 17 00:00:00 2001 From: vspader Date: Sun, 22 Jun 2008 19:44:09 +0000 Subject: [PATCH] Save previous height when hidden. --- Application/InvertedToolbarWindow.h | 7 ++- Application/InvertedToolbarWindow.m | 82 +++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 18 deletions(-) diff --git a/Application/InvertedToolbarWindow.h b/Application/InvertedToolbarWindow.h index fb79ca0b2..5fa01ad15 100644 --- a/Application/InvertedToolbarWindow.h +++ b/Application/InvertedToolbarWindow.h @@ -15,9 +15,12 @@ } - (void)hideContent; -- (void)hideContentwithAnimation:(BOOL)animate; - - (void)showContent; +//Only sets the flag, doesn't do anything. +- (void)setContentHidden:(BOOL)hidden; +- (NSString *)contentHiddenDefaultsKey; +- (NSString *)contentHeightDefaultsKey; + @end diff --git a/Application/InvertedToolbarWindow.m b/Application/InvertedToolbarWindow.m index 6a3d5d32e..fcaa8601e 100644 --- a/Application/InvertedToolbarWindow.m +++ b/Application/InvertedToolbarWindow.m @@ -11,21 +11,61 @@ @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 { - contentHidden = [[NSUserDefaults standardUserDefaults] boolForKey:@"WindowContentHidden"]; - if (contentHidden) + NSString *contentHiddenDefaultsKey = [self contentHiddenDefaultsKey]; + 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 -{ - [self hideContentwithAnimation:YES]; -} - -- (void)hideContentwithAnimation:(BOOL)animate { NSRect newFrame = [self frame]; + BOOL animate = YES; 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.size.height -= contentSize.height; @@ -60,8 +105,7 @@ [[self contentView] setAutoresizesSubviews:NO]; [self setFrame:newFrame display:YES animate:animate]; - contentHidden = YES; - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WindowContentHidden"]; + [self setContentHidden:YES]; } - (void)showContent @@ -79,8 +123,7 @@ [self setShowsResizeIndicator:YES]; - contentHidden = NO; - [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WindowContentHidden"]; + [self setContentHidden:NO]; } - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize { @@ -91,4 +134,11 @@ return proposedFrameSize; } + +- (void)setContentHidden:(BOOL)hidden +{ + [[NSUserDefaults standardUserDefaults] setBool:hidden forKey:[self contentHiddenDefaultsKey]]; + contentHidden = hidden; +} + @end