From 6a7554b9d8ab67489b2d80427932d5fe1f3fe0ba Mon Sep 17 00:00:00 2001 From: Guillaume Algis Date: Mon, 28 Sep 2015 22:12:59 +0200 Subject: [PATCH] Keep the packages table view content offset unchanged after reloading the packages --- .../Controllers/ATZPackageTableViewDelegate.h | 2 ++ .../Controllers/ATZPackageTableViewDelegate.m | 4 ++++ .../Controllers/ATZPluginWindowController.m | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Alcatraz/Controllers/ATZPackageTableViewDelegate.h b/Alcatraz/Controllers/ATZPackageTableViewDelegate.h index c74b02c..3699a8e 100644 --- a/Alcatraz/Controllers/ATZPackageTableViewDelegate.h +++ b/Alcatraz/Controllers/ATZPackageTableViewDelegate.h @@ -29,6 +29,8 @@ - (instancetype)initWithPackages:(NSArray*)packages tableViewOwner:(id)owner; +- (void)updatePackages:(NSArray*)packages; + - (void)configureTableView:(NSTableView*)tableView; - (void)filterUsingPredicate:(NSPredicate*)predicate; diff --git a/Alcatraz/Controllers/ATZPackageTableViewDelegate.m b/Alcatraz/Controllers/ATZPackageTableViewDelegate.m index 05436bd..b840301 100644 --- a/Alcatraz/Controllers/ATZPackageTableViewDelegate.m +++ b/Alcatraz/Controllers/ATZPackageTableViewDelegate.m @@ -53,6 +53,10 @@ - (instancetype)initWithPackages:(NSArray*)packages tableViewOwner:(id)owner { return self; } +- (void)updatePackages:(NSArray*)packages { + _packages = packages; +} + - (void)configureTableView:(NSTableView *)tableView { NSNib* nib = [[NSNib alloc] initWithNibNamed:NSStringFromClass([ATZPackageListTableCellView class]) bundle:[Alcatraz sharedPlugin].bundle]; [tableView registerNib:nib forIdentifier:packageCellIdentifier]; diff --git a/Alcatraz/Controllers/ATZPluginWindowController.m b/Alcatraz/Controllers/ATZPluginWindowController.m index 9ed0318..0d1c984 100644 --- a/Alcatraz/Controllers/ATZPluginWindowController.m +++ b/Alcatraz/Controllers/ATZPluginWindowController.m @@ -178,13 +178,19 @@ - (IBAction)resetPackageRepoPath:(id)sender { } - (void)reloadTableView { - self.tableViewDelegate = [[ATZPackageTableViewDelegate alloc] initWithPackages:self.packages - tableViewOwner:self]; - self.tableView.delegate = self.tableViewDelegate; - self.tableView.dataSource = self.tableViewDelegate; - [self.tableViewDelegate configureTableView:self.tableView]; + if (!self.tableViewDelegate) { + self.tableViewDelegate = [[ATZPackageTableViewDelegate alloc] initWithPackages:self.packages + tableViewOwner:self]; + self.tableView.delegate = self.tableViewDelegate; + self.tableView.dataSource = self.tableViewDelegate; + + [self.tableViewDelegate configureTableView:self.tableView]; + } + else { + [self.tableViewDelegate updatePackages:self.packages]; + } + [self updatePredicate]; - [self.tableView reloadData]; } #pragma mark - Private