marmelroy / FileBrowser

Finder-style iOS file browser written in Swift
MIT License
1.52k stars 219 forks source link

Unable to edit/delete files within subdirectories #58

Open Emperor-Koala opened 5 years ago

Emperor-Koala commented 5 years ago

When I import this project, I can use it and everything works (mostly) as expected. My only issue is that I can't delete anything if its in a subdirectory to the initial directory. Is this a bug, or is there some sort of easy fix?

I've been scratching my head for about an hour, and I tried adding fileListViewController.allowEditing = allowEditing to the function tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath), but it doesn't appear to work the way I was hoping.

Emperor-Koala commented 5 years ago

The strange thing here is that I got this to work in the simulator, but it still doesn't work on my actual device.

rlegault33 commented 3 years ago

To fix the delete to propagate down to the subdirectory files you need to add the line fileListViewController.allowEditing = self.allowEditing at line 48 in FileListTableView.swift This will allow it to propagate into the subdirectory.

Here is the full function in that file with the added line

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let selectedFile = fileForIndexPath(indexPath)
    searchController.isActive = false
    if selectedFile.isDirectory {
        let fileListViewController = FileListViewController(initialPath: selectedFile.filePath)
        fileListViewController.didSelectFile = didSelectFile

// Here is the fix ----
        fileListViewController.allowEditing = self.allowEditing

        self.navigationController?.pushViewController(fileListViewController, animated: true)
    }
    else {
        if let didSelectFile = didSelectFile {
            self.dismiss()
            didSelectFile(selectedFile)
        }
        else {
            let filePreview = previewManager.previewViewControllerForFile(selectedFile, fromNavigation: true)
            self.navigationController?.pushViewController(filePreview, animated: true)
        }
    }
    tableView.deselectRow(at: indexPath, animated: true)
}