From 6e01dd272f7f4e619367917a899de7e58f86a061 Mon Sep 17 00:00:00 2001 From: Bi11 Date: Tue, 10 Jan 2017 08:34:25 +0800 Subject: [PATCH] Use outlets instead of iterating through subviews --- Sparkle/SUAutomaticUpdateAlert.m | 24 ++++++------------- Sparkle/SUUpdatePermissionPrompt.m | 21 +++++----------- Sparkle/en.lproj/SUAutomaticUpdateAlert.xib | 2 ++ Sparkle/en.lproj/SUUpdatePermissionPrompt.xib | 2 ++ 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index 6bcd1ff3..aae589c4 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -19,6 +19,8 @@ @property (strong) SUHost *host; @property (weak) IBOutlet NSButton *skipButton; +@property (weak) IBOutlet NSButton *laterButton; +@property (weak) IBOutlet NSButton *installButton; @property (strong) SUTouchBarProvider *touchBarProvider; @end @@ -27,6 +29,8 @@ @synthesize updateItem; @synthesize completionBlock; @synthesize skipButton; +@synthesize laterButton; +@synthesize installButton; @synthesize touchBarProvider; - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block @@ -105,25 +109,11 @@ - (NSTouchBar *)makeTouchBar { - NSButton *installButton, *laterButton, *cancelButton; - for (NSView *control in self.window.contentView.subviews) { - if ([control isKindOfClass:[NSButton class]]) { - NSButton *button = (NSButton *)control; - if (button.action == @selector(installNow:)) { - installButton = button; - } else if (button.action == @selector(installLater:)) { - laterButton = button; - } else if (button.action == @selector(doNotInstall:)) { - cancelButton = button; - } - } - } - self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:cancelButton]; + [self.touchBarProvider addButtonWithButton:self.skipButton]; [self.touchBarProvider addSpace]; - [self.touchBarProvider addButtonWithButton:laterButton]; - [self.touchBarProvider addButtonWithButton:installButton]; + [self.touchBarProvider addButtonWithButton:self.laterButton]; + [self.touchBarProvider addButtonWithButton:self.installButton]; [self.touchBarProvider addSpace]; [self.touchBarProvider addSpace]; return self.touchBarProvider.touchBar; diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 62a221e7..7e3ab730 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -26,6 +26,8 @@ @property (weak) IBOutlet NSView *moreInfoView; @property (weak) IBOutlet NSButton *moreInfoButton; @property (weak) IBOutlet NSTableView *profileTableView; +@property (weak) IBOutlet NSButton *cancelButton; +@property (weak) IBOutlet NSButton *checkButton; @property (strong) SUTouchBarProvider *touchBarProvider; @property (nonatomic, readonly) void (^reply)(SUUpdatePermissionResponse *); @@ -43,6 +45,8 @@ @synthesize moreInfoView; @synthesize moreInfoButton; @synthesize profileTableView; +@synthesize cancelButton; +@synthesize checkButton; @synthesize touchBarProvider; - (BOOL)shouldAskAboutProfile @@ -165,22 +169,9 @@ - (NSTouchBar *)makeTouchBar { - NSButton *checkButton, *cancelButton; - for (NSView *control in self.window.contentView.subviews) { - if ([control isKindOfClass:[NSButton class]]) { - NSButton *button = (NSButton *)control; - if (button.action == @selector(finishPrompt:)) { - if (button.tag == 1) { - checkButton = button; - } else if (button.tag == 0) { - cancelButton = button; - } - } - } - } self.touchBarProvider = [[SUTouchBarProvider alloc] initWithIdentifier:self.className]; - [self.touchBarProvider addButtonWithButton:cancelButton]; - [self.touchBarProvider addButtonWithButton:checkButton]; + [self.touchBarProvider addButtonWithButton:self.cancelButton]; + [self.touchBarProvider addButtonWithButton:self.checkButton]; return self.touchBarProvider.touchBar; } diff --git a/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib b/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib index 8c96fb03..213f7b57 100644 --- a/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib +++ b/Sparkle/en.lproj/SUAutomaticUpdateAlert.xib @@ -6,6 +6,8 @@ + + diff --git a/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib b/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib index 3ad4bd24..4a007572 100644 --- a/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib +++ b/Sparkle/en.lproj/SUUpdatePermissionPrompt.xib @@ -7,6 +7,8 @@ + +