From f2ca019cb0c4d16df2bdab33ccf222b28738c89c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Mon, 7 Jul 2014 00:22:14 +0100 Subject: [PATCH] Rely on autolayout --- Sparkle/SUConstants.h | 2 +- Sparkle/SUUpdateAlert.m | 126 +++------------------ Sparkle/en.lproj/SUUpdateAlert.xib | 172 +++++++++++++++-------------- 3 files changed, 110 insertions(+), 190 deletions(-) diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index 5b208707..2dbbd7ea 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -53,9 +53,9 @@ extern NSString *const SUEnableSystemProfilingKey; extern NSString *const SUSendProfileInfoKey; extern NSString *const SULastProfileSubmitDateKey; extern NSString *const SUPromptUserOnFirstLaunchKey; -extern NSString *const SUFixedHTMLDisplaySizeKey; extern NSString *const SUKeepDownloadOnFailedInstallKey; extern NSString *const SUDefaultsDomainKey; +extern NSString *const SUFixedHTMLDisplaySizeKey __attribute__((deprecated("This key is obsolete and has no effect."))); // ----------------------------------------------------------------------------- // Errors: diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index b79e5d7e..93d5b129 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -17,13 +17,6 @@ #import "SUConstants.h" - -@interface WebView () - --(void) setDrawsBackground: (BOOL)state; - -@end - @interface SUUpdateAlert () @property (strong) SUAppcastItem *updateItem; @@ -33,6 +26,7 @@ @property (assign) BOOL webViewFinishedLoading; @property (weak) IBOutlet WebView *releaseNotesView; +@property (weak) IBOutlet NSView *releaseNotesContainerView; @property (weak) IBOutlet NSTextField *descriptionField; @property (weak) IBOutlet NSButton *installButton; @property (weak) IBOutlet NSButton *skipButton; @@ -52,6 +46,7 @@ @synthesize webViewFinishedLoading; @synthesize releaseNotesView; +@synthesize releaseNotesContainerView; @synthesize descriptionField; @synthesize installButton; @synthesize skipButton; @@ -178,115 +173,28 @@ - (void)awakeFromNib { - NSString* sizeStr = [self.host objectForInfoDictionaryKey:SUFixedHTMLDisplaySizeKey]; + if ([self.host isBackgroundApplication]) { + [self.window setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! + } - if ([self.host isBackgroundApplication]) { - [[self window] setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! UK 2007-09-04 - } - [[self window] setFrameAutosaveName: sizeStr ? @"" : @"SUUpdateAlertFrame"]; + if ([self.updateItem fileURL] == nil) { + [self.installButton setTitle:SULocalizedString(@"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed.")]; + [self.installButton setAction:@selector(openInfoURL:)]; + } - // We're gonna do some frame magic to match the window's size to the description field and the presence of the release notes view. - NSRect frame = [[self window] frame]; - BOOL showReleaseNotes = [self showsReleaseNotes]; - if (!showReleaseNotes) { - // Resize the window to be appropriate for not having a huge release notes view. - frame.size.height -= [self.releaseNotesView frame].size.height + 40; // Extra 40 is for the release notes label and margin. + BOOL showReleaseNotes = [self showsReleaseNotes]; + + if (showReleaseNotes) { + [self displayReleaseNotes]; + } - if ([self allowsAutomaticUpdates]) { - frame.size.height += 10; // Make room for the check box. - } + [self.releaseNotesContainerView setHidden:!showReleaseNotes]; - // Hiding the resize handles is not enough on 10.5, you can still click - // where they would be, so we set the min/max sizes to be equal to - // inhibit resizing completely: - [[self window] setShowsResizeIndicator: NO]; - [[self window] setMinSize: frame.size]; - [[self window] setMaxSize: frame.size]; - } - else if (![self allowsAutomaticUpdates]) - { - NSRect boxFrame = [[[self.releaseNotesView superview] superview] frame]; - boxFrame.origin.y -= 20; - boxFrame.size.height += 20; - [[[self.releaseNotesView superview] superview] setFrame:boxFrame]; - } - - if( [self.updateItem fileURL] == nil ) { - [self.installButton setTitle: SULocalizedString( @"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed." )]; - [self.installButton setAction: @selector(openInfoURL:)]; - } - - // Make sure button widths are OK: - #define DISTANCE_BETWEEN_BUTTONS 3 - #define DISTANCE_BETWEEN_BUTTON_GROUPS 12 - - CGFloat minimumWindowWidth = [[self window] frame].size.width -NSMaxX([self.self.installButton frame]) +NSMinX([self.skipButton frame]); // Distance between contents and left/right edge. - NSDictionary* attrs = @{NSFontAttributeName: [self.installButton font]}; - NSSize titleSize = [[self.installButton title] sizeWithAttributes: attrs]; - titleSize.width += (16 + 8) * 2; // 16 px for the end caps plus 8 px padding at each end or it'll look as ugly as calling -sizeToFit. - NSRect installBtnBox = [self.installButton frame]; - installBtnBox.origin.x += installBtnBox.size.width -titleSize.width; - installBtnBox.size.width = titleSize.width; - [self.installButton setFrame: installBtnBox]; - minimumWindowWidth += titleSize.width; - - titleSize = [[self.laterButton title] sizeWithAttributes: attrs]; - titleSize.width += (16 + 8) * 2; // 16 px for the end caps plus 8 px padding at each end or it'll look as ugly as calling -sizeToFit. - NSRect laterBtnBox = [self.installButton frame]; - laterBtnBox.origin.x = installBtnBox.origin.x -DISTANCE_BETWEEN_BUTTONS -titleSize.width; - laterBtnBox.size.width = titleSize.width; - [self.laterButton setFrame: laterBtnBox]; - minimumWindowWidth += DISTANCE_BETWEEN_BUTTONS +titleSize.width; - - titleSize = [[self.skipButton title] sizeWithAttributes: attrs]; - titleSize.width += (16 + 8) * 2; // 16 px for the end caps plus 8 px padding at each end or it'll look as ugly as calling -sizeToFit. - NSRect skipBtnBox = [self.skipButton frame]; - skipBtnBox.size.width = titleSize.width; - [self.skipButton setFrame: skipBtnBox]; - minimumWindowWidth += DISTANCE_BETWEEN_BUTTON_GROUPS +titleSize.width; - - if( showReleaseNotes ) { - if( sizeStr ) { - NSSize desiredSize = NSSizeFromString( sizeStr ); - NSSize sizeDiff = NSZeroSize; - // NSBox* boxView = (NSBox*)[[releaseNotesView superview] superview]; - - //[boxView setBorderType: NSNoBorder]; - [self.releaseNotesView setDrawsBackground: NO]; - - sizeDiff.width = desiredSize.width -[self.releaseNotesView frame].size.width; - sizeDiff.height = desiredSize.height -[self.releaseNotesView frame].size.height; - frame.size.width += sizeDiff.width; - frame.size.height += sizeDiff.height; - - // No resizing: - [[self window] setShowsResizeIndicator:NO]; - [[self window] setMinSize:frame.size]; - [[self window] setMaxSize:frame.size]; - } - } - - if (frame.size.width < minimumWindowWidth) { - frame.size.width = minimumWindowWidth; - } - - [[self window] setFrame: frame display: NO]; - [[self window] center]; - - if (showReleaseNotes) { - [self displayReleaseNotes]; - } - - [[[self.releaseNotesView superview] superview] setHidden: !showReleaseNotes]; + [self.window.contentView setNeedsLayout:YES]; // Prod autolayout to place everything + [self.window center]; } --(BOOL)showsReleaseNotesText -{ - return( [self.host objectForInfoDictionaryKey:SUFixedHTMLDisplaySizeKey] == nil ); -} - - - (BOOL)windowShouldClose:(NSNotification *) __unused note { [self endWithSelection:SURemindMeLaterChoice]; diff --git a/Sparkle/en.lproj/SUUpdateAlert.xib b/Sparkle/en.lproj/SUUpdateAlert.xib index 358fa8d2..c1178be9 100644 --- a/Sparkle/en.lproj/SUUpdateAlert.xib +++ b/Sparkle/en.lproj/SUUpdateAlert.xib @@ -1,6 +1,7 @@ - + + @@ -13,6 +14,7 @@ + @@ -31,7 +33,7 @@ - + @@ -43,7 +45,7 @@ - + @@ -57,24 +59,91 @@ - - + + - + + - - + + - - - NSNegateBoolean - - + + + + + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + - - - - - - - - - - - - - - - NSNegateBoolean - - - - - - - - - - - - - - - - - - - - NSNegateBoolean - - - - - - - - - - - - - - - - - - - - + - - - + + - - - - + + - - - + + + - + - +