Unified detail views, model

This commit is contained in:
Christoph Hagen
2024-12-16 09:54:21 +01:00
parent 1e67a99866
commit 31d1ecb8bd
57 changed files with 853 additions and 954 deletions

View File

@@ -11,131 +11,66 @@ struct PathSettingsView: View {
@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)
DetailTitle(
title: "Folder Settings",
text: "Select the folders for the app to work.")
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)
FolderOnDiskPropertyView(
title: "Content Folder",
folder: $contentPath,
footer: "The folder where the raw content of the website is stored") { url in
guard content.storage.save(folderUrl: url, in: .contentPath) else {
return
}
contentPath = url.path()
}
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)
FolderOnDiskPropertyView(
title: "Output Folder",
folder: $content.settings.paths.outputDirectoryPath,
footer: "The folder where the generated website is stored") { url in
guard content.storage.save(folderUrl: url, in: .outputPath) else {
return
}
content.settings.paths.outputDirectoryPath = url.path()
}
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)
StringPropertyView(
title: "Pages output folder",
text: $content.settings.paths.pagesOutputFolderPath,
footer: "The path in the output folder where the generated pages are stored")
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)
StringPropertyView(
title: "Tags output folder",
text: $content.settings.paths.tagsOutputFolderPath,
footer: "The path in the output folder where the generated tag pages are stored")
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)
StringPropertyView(
title: "Files output folder",
text: $content.settings.paths.filesOutputFolderPath,
footer: "The path in the output folder where the copied files are stored")
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)
StringPropertyView(
title: "Images output folder",
text: $content.settings.paths.imagesOutputFolderPath,
footer: "The path in the output folder where the generated images are stored")
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)
StringPropertyView(
title: "Videos output folder",
text: $content.settings.paths.videosOutputFolderPath,
footer: "The path in the output folder where the generated videos are stored")
Text("Assets output folder")
.font(.headline)
TextField("", text: $content.settings.paths.assetsOutputFolderPath)
.textFieldStyle(.roundedBorder)
Text("The path in the output folder where assets are stored")
.foregroundStyle(.secondary)
.padding(.bottom)
StringPropertyView(
title: "Assets output folder",
text: $content.settings.paths.assetsOutputFolderPath,
footer: "The path in the output folder where assets are stored")
}
.padding()
}
}
// 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 {