FileBrowser.swift
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// FileBrowser.swift
// FileBrowser
//
// Created by Roy Marmelstein on 14/02/2016.
// Copyright © 2016 Roy Marmelstein. All rights reserved.
//
import UIKit
/// File browser containing navigation controller.
open class FileBrowser: UINavigationController {
let parser = FileParser.sharedInstance
var fileList: FileListViewController?
/// File types to exclude from the file browser.
open var excludesFileExtensions: [String]? {
didSet {
parser.excludesFileExtensions = excludesFileExtensions
}
}
/// File paths to exclude from the file browser.
open var excludesFilepaths: [URL]? {
didSet {
parser.excludesFilepaths = excludesFilepaths
}
}
/// Override default preview and actionsheet behaviour in favour of custom file handling.
open var didSelectFile: ((FBFile) -> ())? {
didSet {
fileList?.didSelectFile = didSelectFile
}
}
public convenience init() {
let parser = FileParser.sharedInstance
let path = parser.documentsURL()
self.init(initialPath: path, allowEditing: true)
}
/// Initialise file browser.
///
/// - Parameters:
/// - initialPath: NSURL filepath to containing directory.
/// - allowEditing: Whether to allow editing.
/// - showCancelButton: Whether to show the cancel button.
public convenience init(initialPath: URL? = nil, allowEditing: Bool = false, showCancelButton: Bool = true) {
let validInitialPath = initialPath ?? FileParser.sharedInstance.documentsURL()
let fileListViewController = FileListViewController(initialPath: validInitialPath, showCancelButton: showCancelButton)
fileListViewController.allowEditing = allowEditing
self.init(rootViewController: fileListViewController)
self.view.backgroundColor = UIColor.white
self.fileList = fileListViewController
}
}