// // UIViewController+FilePathTitle.swift // Freetime // // Created by Ryan Nystrom on 1/13/18. // Copyright © 2018 Ryan Nystrom. All rights reserved. // import UIKit extension UIViewController { func configureTitle(filePath: FilePath, target: Any, action: Selector) { let accessibilityLabel: String? switch (filePath.current, filePath.basePath) { case (.some(let current), .some(let basePath)): let isCurrentAFile = filePath.fileExtension != nil let currentType = isCurrentAFile ? "File" : "Folder" accessibilityLabel = .localizedStringWithFormat("%@: %@, file path: %@", currentType, current, basePath) case (.some(let current), .none): // NOTE: This is currently unused, as we early-exit // and set the navigationItem's title, but not it's titleView - // and thus we can't set an accessibility label. let isFile = filePath.fileExtension != nil let type = isFile ? "File" : "File path" accessibilityLabel = .localizedStringWithFormat("%@: %@", type, current) case (.none, .some(let basePath)): assert(false, "We should never have just a base path; this should always be accompanied by a current path!") accessibilityLabel = .localizedStringWithFormat("File path: %@", basePath) case (.none, .none): accessibilityLabel = nil } let navigationTitle = NavigationTitleDropdownView() navigationTitle.configure(title: filePath.current, subtitle: filePath.basePath, accessibilityLabel: accessibilityLabel) navigationTitle.addTarget(target, action: action, for: .touchUpInside) navigationItem.titleView = navigationTitle } private func popFileViewControllers(count: Int) { guard let children = navigationController?.viewControllers, count < children.count else { return } navigationController?.setViewControllers(Array(children[0..