From 79dc4994714c4a32bcc5ad24c1fba0b6bfe75474 Mon Sep 17 00:00:00 2001 From: Luc Vauvillier Date: Mon, 5 Mar 2012 14:25:53 +0100 Subject: [PATCH 1/6] [TNTableViewDataSource] Expose selected objects --- TNTableViewDataSource.j | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/TNTableViewDataSource.j b/TNTableViewDataSource.j index c567eb1..2ae0a75 100644 --- a/TNTableViewDataSource.j +++ b/TNTableViewDataSource.j @@ -294,6 +294,16 @@ return [_filteredContent count]; } +#pragma mark - +#pragma mark Helpers + +/*! expose selected objects + @return array of selected objects +*/ +- (CPArray)selectedObjects +{ + return [_filteredContent objectsAtIndexes:[_table selectedRowIndexes]]; +} #pragma mark - #pragma mark Datasource implementation From e3d0e532522e98ff3fcd95a21c4a9dfbe3cf8634 Mon Sep 17 00:00:00 2001 From: Luc Vauvillier Date: Mon, 5 Mar 2012 18:27:44 +0100 Subject: [PATCH 2/6] [TNTableViewDataSource] check if _table is not nil --- TNTableViewDataSource.j | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/TNTableViewDataSource.j b/TNTableViewDataSource.j index 2ae0a75..b4ec028 100644 --- a/TNTableViewDataSource.j +++ b/TNTableViewDataSource.j @@ -298,11 +298,16 @@ #pragma mark Helpers /*! expose selected objects - @return array of selected objects + @return array of selected objects or nil if _table is not setted */ - (CPArray)selectedObjects { - return [_filteredContent objectsAtIndexes:[_table selectedRowIndexes]]; + if (_table) + { + return [_filteredContent objectsAtIndexes:[_table selectedRowIndexes]]; + } + + return nil; } #pragma mark - From 0abb154c45d6485cfcf8ebd16e18a169a85e088e Mon Sep 17 00:00:00 2001 From: Luc Vauvillier Date: Mon, 5 Mar 2012 22:40:35 +0100 Subject: [PATCH 3/6] [TNTableViewDataSource] Coding style --- TNTableViewDataSource.j | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/TNTableViewDataSource.j b/TNTableViewDataSource.j index b4ec028..026ebf5 100644 --- a/TNTableViewDataSource.j +++ b/TNTableViewDataSource.j @@ -302,12 +302,9 @@ */ - (CPArray)selectedObjects { - if (_table) - { - return [_filteredContent objectsAtIndexes:[_table selectedRowIndexes]]; - } - - return nil; + if (!_table) + return nil; + return [_filteredContent objectsAtIndexes:[_table selectedRowIndexes]]; } #pragma mark - From ec5ffd43307da0fac89dbef57478bda584366ccc Mon Sep 17 00:00:00 2001 From: Luc Vauvillier Date: Tue, 6 Mar 2012 14:06:39 +0100 Subject: [PATCH 4/6] [TNTableViewDataSource] expose filteredContent --- TNTableViewDataSource.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TNTableViewDataSource.j b/TNTableViewDataSource.j index 026ebf5..aab234e 100644 --- a/TNTableViewDataSource.j +++ b/TNTableViewDataSource.j @@ -65,7 +65,7 @@ CPTableView _table @accessors(property=table); CPPredicate _displayFilter @accessors(property=displayFilter); - CPArray _filteredContent; + CPArray _filteredContent @accessors(property=filteredContent, readonly); CPSearchField _searchField; CPString _filter; BOOL _needsFilter; From db5fdfb8f856b98abca142fced204a24329b76e2 Mon Sep 17 00:00:00 2001 From: Luc Vauvillier Date: Sat, 10 Mar 2012 02:19:12 +0100 Subject: [PATCH 5/6] Add TNMultiDatasource : Display a collection of items with grid mode/ list mode switch possibility --- TNKit.j | 1 + TNMultiViewDataSource.j | 107 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 TNMultiViewDataSource.j diff --git a/TNKit.j b/TNKit.j index 07d527d..c531ae5 100644 --- a/TNKit.j +++ b/TNKit.j @@ -25,6 +25,7 @@ @import "TNLocalizationCenter.j"; @import "TNMessageBoard.j" @import "TNMessageView.j" +@import "TNMultiViewDataSource.j" @import "TNOutlineViewDataSource.j" @import "TNStackView.j" @import "TNSwipeView.j" diff --git a/TNMultiViewDataSource.j b/TNMultiViewDataSource.j new file mode 100644 index 0000000..82a7282 --- /dev/null +++ b/TNMultiViewDataSource.j @@ -0,0 +1,107 @@ +/* + * TNMultiViewDataSource.j + * + * Copyright (C) 2012 Luc Vauvillier + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +@import +@import + +@import "TNTableViewDataSource.j" + +/*! @ingroup tnkit + Synchronize and share datasource between a table view and a collection view + Designed to display a collection of items with grid mode / list mode switch possibility +*/ +@implementation TNMultiViewDataSource: TNTableViewDataSource +{ + CPCollectionView _collectionView @accessors(property=collectionView); +} + +#pragma mark - +#pragma mark Setters and getters + +/*! used to set the collection view + @param aCollectionView the collection view +*/ +- (void)setCollectionView:(CPCollectionView)aCollectionView +{ + if (_collectionView == aCollectionView) + return; + + _collectionView = aCollectionView; + [_collectionView setContent:[self filteredContent]]; + [self synchronizeSelectionFromView:[self table]]; +} + +/*! used to set the table view + @param aTableView the table view +*/ +- (void)setTableView:(CPTableView)aTableView +{ + [super setTable:aTableView]; + [self synchronizeSelectionFromView:_collectionView]; +} + +#pragma mark - +#pragma mark data synchronization + +/*! this action should be bound to a CPSearchField + it will filter the content of the datasource according to the sender value + @param sender the sender of the action +*/ +- (IBAction)filterObjects:(id)sender +{ + [super filterObjects:sender]; + [_collectionView setContent:[self filteredContent]]; +} + +/*! set the given array of object as the content of the datasource + @param aContent CPArray containing the datas of the datasource +*/ +- (void)setContent:(CPArray)aContent +{ + [super setContent:aContent]; + [_collectionView setContent:[self filteredContent]]; +} + +- (void)tableView:(CPTableView)aTableView sortDescriptorsDidChange:(CPArray)oldDescriptors +{ + [super tableView:aTableView sortDescriptorsDidChange:oldDescriptors]; + [_collectionView reloadContent]; +} + +#pragma mark - +#pragma mark selection synchronization + +/*! synchronize selection between the two components + @param aView The master view +*/ +- (void)synchronizeSelectionFromView:(CPView)aView +{ + if(!aView) + return; + + if (aView == _collectionView) + { + [[self table] selectRowIndexes:[_collectionView selectionIndexes] byExtendingSelection:NO]; + } + else if (aView == [self table]) + { + [_collectionView setSelectionIndexes:[[self table] selectedRowIndexes]]; + } +} + +@end \ No newline at end of file From 850cdc47a881754f510760c40f61ef51ae6d4b6f Mon Sep 17 00:00:00 2001 From: Luc Vauvillier Date: Sat, 10 Mar 2012 02:22:37 +0100 Subject: [PATCH 6/6] capp_lint --- TNMultiViewDataSource.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TNMultiViewDataSource.j b/TNMultiViewDataSource.j index 82a7282..8c958d5 100644 --- a/TNMultiViewDataSource.j +++ b/TNMultiViewDataSource.j @@ -91,7 +91,7 @@ */ - (void)synchronizeSelectionFromView:(CPView)aView { - if(!aView) + if (!aView) return; if (aView == _collectionView)