92 lines
2.5 KiB
Swift
92 lines
2.5 KiB
Swift
import SwiftUI
|
|
|
|
struct FolderSettingsView: View {
|
|
|
|
@Environment(\.language)
|
|
private var language
|
|
|
|
@AppStorage("contentPath")
|
|
private var contentPath: String = ""
|
|
|
|
@EnvironmentObject
|
|
private var content: Content
|
|
|
|
@State
|
|
private var folderSelection: SecurityScopeBookmark = .contentPath
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
VStack(alignment: .leading) {
|
|
Text("Folder Settings")
|
|
.font(.largeTitle)
|
|
.bold()
|
|
Text("Select the folders for the app to work.")
|
|
.padding(.bottom, 30)
|
|
Text("Content Folder")
|
|
.font(.headline)
|
|
.padding(.bottom, 1)
|
|
Text(contentPath)
|
|
Button(action: selectContentFolder) {
|
|
Text("Select folder")
|
|
}
|
|
.padding(.bottom)
|
|
Text("Output Folder")
|
|
.font(.headline)
|
|
.padding(.bottom, 1)
|
|
Text(content.settings.outputDirectoryPath)
|
|
Button(action: selectOutputFolder) {
|
|
Text("Select folder")
|
|
}
|
|
.padding(.bottom)
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: Folder selection
|
|
|
|
private func selectContentFolder() {
|
|
folderSelection = .contentPath
|
|
guard let url = savePanelUsingOpenPanel() else {
|
|
return
|
|
}
|
|
self.contentPath = url.path()
|
|
}
|
|
|
|
private func selectOutputFolder() {
|
|
folderSelection = .outputPath
|
|
guard let url = savePanelUsingOpenPanel() else {
|
|
return
|
|
}
|
|
content.settings.outputDirectoryPath = url.path()
|
|
}
|
|
|
|
private func savePanelUsingOpenPanel() -> URL? {
|
|
let panel = NSOpenPanel()
|
|
// Sets up so user can only select a single directory
|
|
panel.canChooseFiles = false
|
|
panel.canChooseDirectories = true
|
|
panel.allowsMultipleSelection = false
|
|
panel.showsHiddenFiles = false
|
|
panel.title = "Select Save Directory"
|
|
panel.prompt = "Select Save Directory"
|
|
|
|
let response = panel.runModal()
|
|
guard response == .OK else {
|
|
|
|
return nil
|
|
}
|
|
guard let url = panel.url else {
|
|
return nil
|
|
}
|
|
content.storage.save(folderUrl: url, in: folderSelection)
|
|
return url
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
FolderSettingsView()
|
|
.environmentObject(Content.mock)
|
|
.padding()
|
|
}
|