Add repository file browser
This commit is contained in:
@@ -124,6 +124,66 @@ func configureTextCell(_ cell: UITableViewCell, title: String, detail: String, i
|
||||
cell.backgroundColor = .systemBackground
|
||||
}
|
||||
|
||||
func configureRepositoryContentCell(_ cell: UITableViewCell, row: RepositoryContentRow) {
|
||||
let directory = row.kind == "dir"
|
||||
let detail = directory
|
||||
? "Folder"
|
||||
: ByteCountFormatter.string(fromByteCount: row.size, countStyle: .file)
|
||||
configureTextCell(
|
||||
cell,
|
||||
title: row.name,
|
||||
detail: detail,
|
||||
image: UIImage(systemName: directory ? "folder.fill" : "doc")
|
||||
)
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func showRepositoryContent(
|
||||
_ row: RepositoryContentRow,
|
||||
context: AppContext,
|
||||
owner: String,
|
||||
repository: String,
|
||||
navigationController: UINavigationController?
|
||||
) {
|
||||
let destination: UIViewController = row.kind == "dir"
|
||||
? RepositoryDirectoryViewController(
|
||||
context: context,
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
path: row.path
|
||||
)
|
||||
: RepositoryFileViewController(
|
||||
context: context,
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
path: row.path
|
||||
)
|
||||
navigationController?.pushViewController(destination, animated: true)
|
||||
}
|
||||
|
||||
func sourceLanguage(_ path: String) -> String? {
|
||||
let filename = (path as NSString).lastPathComponent.lowercased()
|
||||
let filenames = [
|
||||
"cmakelists.txt": "cmake", "dockerfile": "dockerfile", "gemfile": "ruby",
|
||||
"makefile": "makefile", "podfile": "ruby",
|
||||
]
|
||||
if let language = filenames[filename] { return language }
|
||||
let languages = [
|
||||
"asm": "x86asm", "c": "c", "cc": "cpp", "clj": "clojure", "cpp": "cpp",
|
||||
"cs": "csharp", "css": "css", "dart": "dart", "ex": "elixir", "exs": "elixir",
|
||||
"fs": "fsharp", "go": "go", "groovy": "groovy", "h": "cpp", "hpp": "cpp",
|
||||
"hs": "haskell", "html": "xml", "java": "java", "jl": "julia", "js": "javascript",
|
||||
"json": "json", "jsx": "javascript", "kt": "kotlin", "kts": "kotlin", "lua": "lua",
|
||||
"m": "objectivec", "md": "markdown", "mm": "objectivec", "php": "php", "pl": "perl",
|
||||
"plist": "xml", "ps1": "powershell", "py": "python", "r": "r", "rb": "ruby",
|
||||
"rs": "rust", "scala": "scala", "scss": "scss", "sh": "bash", "sql": "sql",
|
||||
"swift": "swift", "toml": "ini", "ts": "typescript", "tsx": "typescript",
|
||||
"txt": "plaintext", "xml": "xml", "yaml": "yaml", "yml": "yaml",
|
||||
]
|
||||
return languages[(path as NSString).pathExtension.lowercased()]
|
||||
}
|
||||
|
||||
func symbolText(_ symbol: String, text: String, font: UIFont, color: UIColor) -> NSAttributedString {
|
||||
let output = NSMutableAttributedString()
|
||||
if let image = UIImage(systemName: symbol)?.withTintColor(color, renderingMode: .alwaysOriginal) {
|
||||
|
||||
Reference in New Issue
Block a user