From a5938ea5e2ca223b9e969fe0424f63d7a4b31a4c Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Mon, 4 Oct 2010 10:15:46 -0400 Subject: [PATCH] Fix the custom button problem - applyRightButton was overriding BrowserView's support for custom buttons. We now just expose a default right button that is used in BrowserView's applyRightButton. Minor visual artifact: The 'Install' button flashes for non-commercial packages as it changes between loading/not-loading. Slightly better behaviour than before: AlwaysReload == 1 means the button is called 'Reload'. --- Cydia.mm | 30 +++++++++++++++--------------- UICaboodle/BrowserView.h | 3 ++- UICaboodle/BrowserView.mm | 8 ++++++-- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index f5610784..2638e422 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -5227,9 +5227,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } +// We don't want to allow non-commercial packages to do custom things to the install button, +// so it must call customButtonClicked with a custom commercial_ == 1 fallthrough. - (void) customButtonClicked { - // Wait until it's done loading. - if (![self isLoading]) + if (commercial_) + [super customButtonClicked]; + else [self _customButtonClicked]; } @@ -5240,6 +5243,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) applyLoadingTitle { // Don't show "Loading" as the title. Ever. } + +- (UIBarButtonItem *) rightButton { + int count = [buttons_ count]; + return [[[UIBarButtonItem alloc] + initWithTitle:count == 0 ? nil : count != 1 ? UCLocalize("MODIFY") : [buttons_ objectAtIndex:0] + style:UIBarButtonItemStylePlain + target:self + action:@selector(customButtonClicked) + ] autorelease]; +} #endif - (id) initWithDatabase:(Database *)database { @@ -5307,19 +5320,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } -- (void) applyRightButton { - int count = [buttons_ count]; - UIBarButtonItem *actionItem = [[UIBarButtonItem alloc] - initWithTitle:count == 0 ? nil : count != 1 ? UCLocalize("MODIFY") : [buttons_ objectAtIndex:0] - style:UIBarButtonItemStylePlain - target:self - action:@selector(customButtonClicked) - ]; - if (![self isLoading]) [[self navigationItem] setRightBarButtonItem:actionItem]; - else [super applyRightButton]; - [actionItem release]; -} - - (bool) isLoading { return commercial_ ? [super isLoading] : false; } diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index f2b0db87..23be6317 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -108,9 +108,10 @@ - (bool) allowSensitiveRequests; - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button; +- (void) customButtonClicked; - (void) applyRightButton; - (void) _startLoading; - (void) close; -@end \ No newline at end of file +@end diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index ee8563f0..1615795d 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -1075,6 +1075,10 @@ static Class $UIWebBrowserView; return [customItem autorelease]; } +- (UIBarButtonItem *) rightButton { + return reloaditem_; +} + - (void) applyLoadingTitle { [[self navigationItem] setTitle:UCLocalize("LOADING")]; } @@ -1087,7 +1091,7 @@ static Class $UIWebBrowserView; } else if (button_) { [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES]; } else { - [[self navigationItem] setRightBarButtonItem:reloaditem_ animated:YES]; + [[self navigationItem] setRightBarButtonItem:[self rightButton] animated:YES]; } } @@ -1615,4 +1619,4 @@ static Class $UIWebBrowserView; return 980; } -@end \ No newline at end of file +@end -- 2.45.2