138 lines
4.7 KiB
Swift
138 lines
4.7 KiB
Swift
import SwiftUI
|
|
|
|
struct PathSettingsView: 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.")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom, 30)
|
|
|
|
Text("Content Folder")
|
|
.font(.headline)
|
|
.padding(.bottom, 1)
|
|
Text(contentPath)
|
|
Button(action: selectContentFolder) {
|
|
Text("Select folder")
|
|
}
|
|
Text("The folder where the raw content of the website is stored")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom)
|
|
|
|
Text("Output Folder")
|
|
.font(.headline)
|
|
.padding(.bottom, 1)
|
|
Text(content.settings.paths.outputDirectoryPath)
|
|
Button(action: selectOutputFolder) {
|
|
Text("Select folder")
|
|
}
|
|
Text("The folder where the generated website is stored")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom)
|
|
|
|
Text("Pages output folder")
|
|
.font(.headline)
|
|
TextField("", text: $content.settings.paths.pagesOutputFolderPath)
|
|
.textFieldStyle(.roundedBorder)
|
|
Text("The path in the output folder where the generated pages are stored")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom)
|
|
|
|
Text("Tags output folder")
|
|
.font(.headline)
|
|
TextField("", text: $content.settings.paths.tagsOutputFolderPath)
|
|
.textFieldStyle(.roundedBorder)
|
|
Text("The path in the output folder where the generated tag pages are stored")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom)
|
|
|
|
Text("Files output folder")
|
|
.font(.headline)
|
|
TextField("", text: $content.settings.paths.filesOutputFolderPath)
|
|
.textFieldStyle(.roundedBorder)
|
|
Text("The path in the output folder where the copied files are stored")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom)
|
|
|
|
Text("Images output folder")
|
|
.font(.headline)
|
|
TextField("", text: $content.settings.paths.imagesOutputFolderPath)
|
|
.textFieldStyle(.roundedBorder)
|
|
Text("The path in the output folder where the generated images are stored")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom)
|
|
|
|
Text("Videos output folder")
|
|
.font(.headline)
|
|
TextField("", text: $content.settings.paths.videosOutputFolderPath)
|
|
.textFieldStyle(.roundedBorder)
|
|
Text("The path in the output folder where the generated videos are stored")
|
|
.foregroundStyle(.secondary)
|
|
.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.paths.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 {
|
|
PathSettingsView()
|
|
.environmentObject(Content.mock)
|
|
.padding()
|
|
}
|