From e6124cb6861825f588b0cf7be198ea35b5b730ba Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 3 Mar 2011 13:09:55 -0800 Subject: [PATCH] Provide -[CyteWebViewController leftButton] API. --- CyteKit/WebViewController.h | 3 +++ CyteKit/WebViewController.mm | 24 ++++++++++++++++++++++++ MobileCydia.mm | 32 +++++++++++++++----------------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/CyteKit/WebViewController.h b/CyteKit/WebViewController.h index db40a1c1..c1ec1eeb 100644 --- a/CyteKit/WebViewController.h +++ b/CyteKit/WebViewController.h @@ -128,6 +128,9 @@ - (UIBarButtonItem *) customButton; - (UIBarButtonItem *) rightButton; +- (void) applyLeftButton; +- (UIBarButtonItem *) leftButton; + - (void) _didStartLoading; - (void) _didFinishLoading; diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm index b59d8302..a7502783 100644 --- a/CyteKit/WebViewController.mm +++ b/CyteKit/WebViewController.mm @@ -611,6 +611,27 @@ float CYScrollViewDecelerationRateNormal; ] autorelease]; } +- (UIBarButtonItem *) leftButton { + UINavigationItem *item([self navigationItem]); + if ([item backBarButtonItem] != nil && ![item hidesBackButton]) + return nil; + + if (UINavigationController *navigation = [self navigationController]) + if ([[navigation parentViewController] modalViewController] == navigation) + return [[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("CLOSE") + style:UIBarButtonItemStylePlain + target:self + action:@selector(close) + ] autorelease]; + + return nil; +} + +- (void) applyLeftButton { + [[self navigationItem] setLeftBarButtonItem:[self leftButton]]; +} + - (UIBarButtonItem *) rightButton { return reloaditem_; } @@ -784,6 +805,8 @@ float CYScrollViewDecelerationRateNormal; UITableView *table([[[UITableView alloc] initWithFrame:bounds style:UITableViewStyleGrouped] autorelease]); [webview_ insertSubview:table atIndex:0]; + [self applyLeftButton]; + [table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; @@ -881,6 +904,7 @@ float CYScrollViewDecelerationRateNormal; - (void) setHidesBackButton:(bool)value { [[self navigationItem] setHidesBackButton:value]; + [self applyLeftButton]; } - (void) setHidesBackButtonByNumber:(NSNumber *)value { diff --git a/MobileCydia.mm b/MobileCydia.mm index 0faac890..9eb57911 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4857,16 +4857,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { nil]; [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/confirm/", UI_]]]; - - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("CANCEL") - style:UIBarButtonItemStylePlain - target:self - action:@selector(cancelButtonClicked) - ] autorelease]]; } return self; } +- (UIBarButtonItem *) leftButton { + return [[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("CANCEL") + style:UIBarButtonItemStylePlain + target:self + action:@selector(cancelButtonClicked) + ] autorelease]; +} + #if !AlwaysReload - (void) applyRightButton { if ([issues_ count] == 0 && ![self isLoading]) @@ -6431,15 +6433,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert show]; } -- (void) viewDidLoad { - [super viewDidLoad]; - - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] +- (UIBarButtonItem *) leftButton { + return [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ABOUT") style:UIBarButtonItemStylePlain target:self action:@selector(aboutButtonClicked) - ] autorelease]]; + ] autorelease]; } - (void) unloadData { @@ -6469,15 +6469,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSURL URLWithString:@"cydia://manage"]; } -- (void) viewDidLoad { - [super viewDidLoad]; - - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] +- (UIBarButtonItem *) leftButton { + return [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("SETTINGS") style:UIBarButtonItemStylePlain target:self action:@selector(settingsButtonClicked) - ] autorelease]]; + ] autorelease]; } - (void) settingsButtonClicked { -- 2.45.2