62 lines
2.3 KiB
Swift
62 lines
2.3 KiB
Swift
|
|
import SwiftUI
|
||
|
|
|
||
|
|
struct NewFileSheet: View {
|
||
|
|
let parentPath: String
|
||
|
|
var onConfirm: (String, String) -> Void
|
||
|
|
@Environment(\.dismiss) var dismiss
|
||
|
|
@State private var fileName = "NewFile.swift"
|
||
|
|
@FocusState private var focused: Bool
|
||
|
|
|
||
|
|
var body: some View {
|
||
|
|
NavigationStack {
|
||
|
|
Form {
|
||
|
|
Section("File Name") {
|
||
|
|
TextField("FileName.swift", text: $fileName)
|
||
|
|
.autocorrectionDisabled().autocapitalization(.none).focused($focused)
|
||
|
|
}
|
||
|
|
Section("Location") {
|
||
|
|
Text(parentPath).font(.caption).foregroundStyle(.secondary).lineLimit(2).truncationMode(.middle)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
.navigationTitle("New File").navigationBarTitleDisplayMode(.inline)
|
||
|
|
.onAppear { focused = true }
|
||
|
|
.toolbar {
|
||
|
|
ToolbarItem(placement: .cancellationAction) { Button("Cancel") { dismiss() } }
|
||
|
|
ToolbarItem(placement: .confirmationAction) {
|
||
|
|
Button("Create") { onConfirm(parentPath, fileName); dismiss() }
|
||
|
|
.disabled(fileName.isEmpty)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
.presentationDetents([.medium])
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
struct RenameSheet: View {
|
||
|
|
let node: FileNode
|
||
|
|
var onConfirm: (FileNode, String) -> Void
|
||
|
|
@Environment(\.dismiss) var dismiss
|
||
|
|
@State private var newName = ""
|
||
|
|
@FocusState private var focused: Bool
|
||
|
|
|
||
|
|
var body: some View {
|
||
|
|
NavigationStack {
|
||
|
|
Form {
|
||
|
|
Section(node.isDirectory ? "Folder Name" : "File Name") {
|
||
|
|
TextField(node.name, text: $newName).autocorrectionDisabled().autocapitalization(.none).focused($focused)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
.navigationTitle("Rename").navigationBarTitleDisplayMode(.inline)
|
||
|
|
.onAppear { newName = node.name; focused = true }
|
||
|
|
.toolbar {
|
||
|
|
ToolbarItem(placement: .cancellationAction) { Button("Cancel") { dismiss() } }
|
||
|
|
ToolbarItem(placement: .confirmationAction) {
|
||
|
|
Button("Rename") { onConfirm(node, newName); dismiss() }
|
||
|
|
.disabled(newName.isEmpty || newName == node.name)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
.presentationDetents([.height(200)])
|
||
|
|
}
|
||
|
|
}
|