]> git.saurik.com Git - cydia.git/commitdiff
Refactor edit button in SectionsController; use system provided UIBarButtonItems.
authorGrant Paul <chpwn@chpwn.com>
Tue, 1 Feb 2011 19:00:09 +0000 (11:00 -0800)
committerGrant Paul <chpwn@chpwn.com>
Tue, 1 Feb 2011 19:00:09 +0000 (11:00 -0800)
MobileCydia.mm

index 023284a5acabcfaedd0140d7d3a27c61869c5e8c..392c173ac9404bb04ec3cf763a1260ae6b719339 100644 (file)
@@ -6670,15 +6670,26 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [super dealloc];
 }
 
+- (void) updateNavigationItem {
+    [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")];
+    if ([sections_ count] == 0) {
+        [[self navigationItem] setRightBarButtonItem:nil];
+    } else {
+        [[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc]
+            initWithBarButtonSystemItem:(editing_ ? UIBarButtonSystemItemDone : UIBarButtonSystemItemEdit)
+            target:self
+            action:@selector(editButtonClicked)
+        ] animated:([[self navigationItem] rightBarButtonItem] != nil)];
+    }
+}
+
 - (void) setEditing:(BOOL)editing {
     if ((editing_ = editing))
         [list_ reloadData];
     else
         [delegate_ updateData];
 
-    [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")];
-    [[[self navigationItem] rightBarButtonItem] setTitle:[sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT")];
-    [[[self navigationItem] rightBarButtonItem] setStyle:editing_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain];
+    [self updateNavigationItem];
 }
 
 - (void) viewDidAppear:(BOOL)animated {
@@ -6802,13 +6813,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [filtered_ addObject:section];
     }
 
-    [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc]
-        initWithTitle:([sections_ count] == 0 ? nil : UCLocalize("EDIT"))
-        style:UIBarButtonItemStylePlain
-        target:self
-        action:@selector(editButtonClicked)
-    ] autorelease] animated:([[self navigationItem] rightBarButtonItem] != nil)];
-
+    [self updateNavigationItem];
     [list_ reloadData];
     _trace();
 }