|
@@ -16,18 +16,14 @@
|
|
|
@interface FLEXFileBrowserTableViewCell : UITableViewCell
|
|
@interface FLEXFileBrowserTableViewCell : UITableViewCell
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
-@interface FLEXFileBrowserTableViewController () <FLEXFileBrowserFileOperationControllerDelegate>
|
|
|
|
|
|
|
+@interface FLEXFileBrowserTableViewController () <FLEXFileBrowserFileOperationControllerDelegate, FLEXFileBrowserSearchOperationDelegate, UISearchResultsUpdating, UISearchControllerDelegate>
|
|
|
|
|
|
|
|
@property (nonatomic, copy) NSString *path;
|
|
@property (nonatomic, copy) NSString *path;
|
|
|
@property (nonatomic, copy) NSArray *childPaths;
|
|
@property (nonatomic, copy) NSArray *childPaths;
|
|
|
-@property (nonatomic, copy) NSString *searchString;
|
|
|
|
|
@property (nonatomic, strong) NSArray *searchPaths;
|
|
@property (nonatomic, strong) NSArray *searchPaths;
|
|
|
@property (nonatomic, strong) NSNumber *recursiveSize;
|
|
@property (nonatomic, strong) NSNumber *recursiveSize;
|
|
|
@property (nonatomic, strong) NSNumber *searchPathsSize;
|
|
@property (nonatomic, strong) NSNumber *searchPathsSize;
|
|
|
-#pragma clang diagnostic push
|
|
|
|
|
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
|
-@property (nonatomic, strong) UISearchDisplayController *searchController;
|
|
|
|
|
-#pragma clang diagnostic pop
|
|
|
|
|
|
|
+@property (nonatomic, strong) UISearchController *searchController;
|
|
|
@property (nonatomic) NSOperationQueue *operationQueue;
|
|
@property (nonatomic) NSOperationQueue *operationQueue;
|
|
|
@property (nonatomic, strong) UIDocumentInteractionController *documentController;
|
|
@property (nonatomic, strong) UIDocumentInteractionController *documentController;
|
|
|
@property (nonatomic, strong) id<FLEXFileBrowserFileOperationController> fileOperationController;
|
|
@property (nonatomic, strong) id<FLEXFileBrowserFileOperationController> fileOperationController;
|
|
@@ -49,16 +45,10 @@
|
|
|
self.title = [path lastPathComponent];
|
|
self.title = [path lastPathComponent];
|
|
|
self.operationQueue = [NSOperationQueue new];
|
|
self.operationQueue = [NSOperationQueue new];
|
|
|
|
|
|
|
|
- //add search controller
|
|
|
|
|
- UISearchBar *searchBar = [UISearchBar new];
|
|
|
|
|
- [searchBar sizeToFit];
|
|
|
|
|
-#pragma clang diagnostic push
|
|
|
|
|
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
|
- self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
|
|
|
|
|
-#pragma clang diagnostic pop
|
|
|
|
|
|
|
+ self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
|
|
|
|
|
+ self.searchController.searchResultsUpdater = self;
|
|
|
self.searchController.delegate = self;
|
|
self.searchController.delegate = self;
|
|
|
- self.searchController.searchResultsDataSource = self;
|
|
|
|
|
- self.searchController.searchResultsDelegate = self;
|
|
|
|
|
|
|
+ self.searchController.dimsBackgroundDuringPresentation = NO;
|
|
|
self.tableView.tableHeaderView = self.searchController.searchBar;
|
|
self.tableView.tableHeaderView = self.searchController.searchBar;
|
|
|
|
|
|
|
|
//computing path size
|
|
//computing path size
|
|
@@ -107,22 +97,20 @@
|
|
|
{
|
|
{
|
|
|
self.searchPaths = searchResult;
|
|
self.searchPaths = searchResult;
|
|
|
self.searchPathsSize = @(size);
|
|
self.searchPathsSize = @(size);
|
|
|
- [self.searchController.searchResultsTableView reloadData];
|
|
|
|
|
|
|
+ [self.tableView reloadData];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#pragma mark - UISearchDisplayDelegate
|
|
|
|
|
|
|
+#pragma mark - UISearchResultsUpdating
|
|
|
|
|
|
|
|
-- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
|
|
|
|
|
|
|
+- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
|
|
|
{
|
|
{
|
|
|
- self.searchString = searchString;
|
|
|
|
|
- [self reloadSearchPaths];
|
|
|
|
|
-
|
|
|
|
|
- return YES;
|
|
|
|
|
|
|
+ [self reloadDisplayedPaths];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView
|
|
|
|
|
|
|
+#pragma mark - UISearchControllerDelegate
|
|
|
|
|
+
|
|
|
|
|
+- (void)willDismissSearchController:(UISearchController *)searchController
|
|
|
{
|
|
{
|
|
|
- //confirm to clear all operations
|
|
|
|
|
[self.operationQueue cancelAllOperations];
|
|
[self.operationQueue cancelAllOperations];
|
|
|
[self reloadChildPaths];
|
|
[self reloadChildPaths];
|
|
|
[self.tableView reloadData];
|
|
[self.tableView reloadData];
|
|
@@ -138,25 +126,14 @@
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
{
|
|
{
|
|
|
- if (tableView == self.tableView) {
|
|
|
|
|
- return [self.childPaths count];
|
|
|
|
|
- } else {
|
|
|
|
|
- return [self.searchPaths count];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return self.searchController.isActive ? [self.searchPaths count] : [self.childPaths count];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
{
|
|
{
|
|
|
- NSNumber *currentSize = nil;
|
|
|
|
|
- NSArray *currentPaths = nil;
|
|
|
|
|
-
|
|
|
|
|
- if (tableView == self.tableView) {
|
|
|
|
|
- currentSize = self.recursiveSize;
|
|
|
|
|
- currentPaths = self.childPaths;
|
|
|
|
|
- } else {
|
|
|
|
|
- currentSize = self.searchPathsSize;
|
|
|
|
|
- currentPaths = self.searchPaths;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ BOOL isSearchActive = self.searchController.isActive;
|
|
|
|
|
+ NSNumber *currentSize = isSearchActive ? self.searchPathsSize : self.recursiveSize;
|
|
|
|
|
+ NSArray *currentPaths = isSearchActive ? self.searchPaths : self.childPaths;
|
|
|
|
|
|
|
|
NSString *sizeString = nil;
|
|
NSString *sizeString = nil;
|
|
|
if (!currentSize) {
|
|
if (!currentSize) {
|
|
@@ -170,14 +147,7 @@
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
{
|
|
{
|
|
|
- NSString *fullPath = nil;
|
|
|
|
|
- if (tableView == self.tableView) {
|
|
|
|
|
- NSString *subpath = self.childPaths[indexPath.row];
|
|
|
|
|
- fullPath = [self.path stringByAppendingPathComponent:subpath];
|
|
|
|
|
- } else {
|
|
|
|
|
- fullPath = self.searchPaths[indexPath.row];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ NSString *fullPath = [self filePathAtIndexPath:indexPath];
|
|
|
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:fullPath error:NULL];
|
|
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:fullPath error:NULL];
|
|
|
BOOL isDirectory = [[attributes fileType] isEqual:NSFileTypeDirectory];
|
|
BOOL isDirectory = [[attributes fileType] isEqual:NSFileTypeDirectory];
|
|
|
NSString *subtitle = nil;
|
|
NSString *subtitle = nil;
|
|
@@ -218,16 +188,8 @@
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
{
|
|
{
|
|
|
- NSString *subpath = nil;
|
|
|
|
|
- NSString *fullPath = nil;
|
|
|
|
|
-
|
|
|
|
|
- if (tableView == self.tableView) {
|
|
|
|
|
- subpath = self.childPaths[indexPath.row];
|
|
|
|
|
- fullPath = [self.path stringByAppendingPathComponent:subpath];
|
|
|
|
|
- } else {
|
|
|
|
|
- fullPath = self.searchPaths[indexPath.row];
|
|
|
|
|
- subpath = [fullPath lastPathComponent];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ NSString *fullPath = [self filePathAtIndexPath:indexPath];
|
|
|
|
|
+ NSString *subpath = [fullPath lastPathComponent];
|
|
|
|
|
|
|
|
BOOL isDirectory = NO;
|
|
BOOL isDirectory = NO;
|
|
|
BOOL stillExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDirectory];
|
|
BOOL stillExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDirectory];
|
|
@@ -313,16 +275,8 @@
|
|
|
|
|
|
|
|
- (void)fileBrowserRename:(UITableViewCell *)sender
|
|
- (void)fileBrowserRename:(UITableViewCell *)sender
|
|
|
{
|
|
{
|
|
|
- NSString *fullPath = nil;
|
|
|
|
|
-
|
|
|
|
|
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
|
|
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
|
|
|
- if (indexPath) {
|
|
|
|
|
- NSString *subpath = self.childPaths[indexPath.row];
|
|
|
|
|
- fullPath = [self.path stringByAppendingPathComponent:subpath];
|
|
|
|
|
- } else {
|
|
|
|
|
- indexPath = [self.searchController.searchResultsTableView indexPathForCell:sender];
|
|
|
|
|
- fullPath = self.searchPaths[indexPath.row];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ NSString *fullPath = [self filePathAtIndexPath:indexPath];
|
|
|
|
|
|
|
|
self.fileOperationController = [[FLEXFileBrowserFileRenameOperationController alloc] initWithPath:fullPath];
|
|
self.fileOperationController = [[FLEXFileBrowserFileRenameOperationController alloc] initWithPath:fullPath];
|
|
|
self.fileOperationController.delegate = self;
|
|
self.fileOperationController.delegate = self;
|
|
@@ -331,17 +285,9 @@
|
|
|
|
|
|
|
|
- (void)fileBrowserDelete:(UITableViewCell *)sender
|
|
- (void)fileBrowserDelete:(UITableViewCell *)sender
|
|
|
{
|
|
{
|
|
|
- NSString *fullPath = nil;
|
|
|
|
|
-
|
|
|
|
|
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
|
|
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
|
|
|
- if (indexPath) {
|
|
|
|
|
- NSString *subpath = self.childPaths[indexPath.row];
|
|
|
|
|
- fullPath = [self.path stringByAppendingPathComponent:subpath];
|
|
|
|
|
- } else {
|
|
|
|
|
- indexPath = [self.searchController.searchResultsTableView indexPathForCell:sender];
|
|
|
|
|
- fullPath = self.searchPaths[indexPath.row];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ NSString *fullPath = [self filePathAtIndexPath:indexPath];
|
|
|
|
|
+
|
|
|
self.fileOperationController = [[FLEXFileBrowserFileDeleteOperationController alloc] initWithPath:fullPath];
|
|
self.fileOperationController = [[FLEXFileBrowserFileDeleteOperationController alloc] initWithPath:fullPath];
|
|
|
self.fileOperationController.delegate = self;
|
|
self.fileOperationController.delegate = self;
|
|
|
[self.fileOperationController show];
|
|
[self.fileOperationController show];
|
|
@@ -351,16 +297,20 @@
|
|
|
{
|
|
{
|
|
|
if (self.searchController.isActive) {
|
|
if (self.searchController.isActive) {
|
|
|
[self reloadSearchPaths];
|
|
[self reloadSearchPaths];
|
|
|
- [self.searchController.searchResultsTableView reloadData];
|
|
|
|
|
} else {
|
|
} else {
|
|
|
[self reloadChildPaths];
|
|
[self reloadChildPaths];
|
|
|
- [self.tableView reloadData];
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ [self.tableView reloadData];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)reloadChildPaths
|
|
- (void)reloadChildPaths
|
|
|
{
|
|
{
|
|
|
- self.childPaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.path error:NULL];
|
|
|
|
|
|
|
+ NSMutableArray *childPaths = [NSMutableArray array];
|
|
|
|
|
+ NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.path error:NULL];
|
|
|
|
|
+ for (NSString *subpath in subpaths) {
|
|
|
|
|
+ [childPaths addObject:[self.path stringByAppendingPathComponent:subpath]];
|
|
|
|
|
+ }
|
|
|
|
|
+ self.childPaths = childPaths;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)reloadSearchPaths
|
|
- (void)reloadSearchPaths
|
|
@@ -370,11 +320,16 @@
|
|
|
|
|
|
|
|
//clear pre search request and start a new one
|
|
//clear pre search request and start a new one
|
|
|
[self.operationQueue cancelAllOperations];
|
|
[self.operationQueue cancelAllOperations];
|
|
|
- FLEXFileBrowserSearchOperation *newOperation = [[FLEXFileBrowserSearchOperation alloc] initWithPath:self.path searchString:self.searchString];
|
|
|
|
|
|
|
+ FLEXFileBrowserSearchOperation *newOperation = [[FLEXFileBrowserSearchOperation alloc] initWithPath:self.path searchString:self.searchController.searchBar.text];
|
|
|
newOperation.delegate = self;
|
|
newOperation.delegate = self;
|
|
|
[self.operationQueue addOperation:newOperation];
|
|
[self.operationQueue addOperation:newOperation];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+- (NSString *)filePathAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
|
+{
|
|
|
|
|
+ return self.searchController.isActive ? self.searchPaths[indexPath.row] : self.childPaths[indexPath.row];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
|
|
|