92 lines
3.3 KiB
Swift
92 lines
3.3 KiB
Swift
import MusicAssistantCore
|
|
import SwiftUI
|
|
|
|
struct ArabicPronunciationSettingsView: View {
|
|
@Binding var settings: ArabicPronunciationSettings
|
|
|
|
@State private var newPreservedSpelling = ""
|
|
|
|
var body: some View {
|
|
Toggle("Enable Arabic pronunciation processing", isOn: $settings.isEnabled)
|
|
|
|
Picker("Diacritics", selection: $settings.diacritizationPolicy) {
|
|
Text("Unspecified").tag(ArabicDiacritizationPolicy.unspecified)
|
|
Text("Pronunciation targeted").tag(ArabicDiacritizationPolicy.pronunciationTargeted)
|
|
Text("Full tashkeel").tag(ArabicDiacritizationPolicy.fullTashkeel)
|
|
}
|
|
.disabled(!settings.isEnabled)
|
|
|
|
Picker("Tanween", selection: $settings.tanweenPolicy) {
|
|
Text("Unspecified").tag(ArabicTanweenPolicy.unspecified)
|
|
Text("Preserve user input").tag(ArabicTanweenPolicy.preserveUserInput)
|
|
Text("Add when pronunciation needs it").tag(ArabicTanweenPolicy.addWhenPronunciationRequires)
|
|
Text("Remove when unwanted").tag(ArabicTanweenPolicy.removeWhenUnwanted)
|
|
}
|
|
.disabled(!settings.isEnabled)
|
|
|
|
TextField("Pronunciation notes", text: userNotesBinding, axis: .vertical)
|
|
.lineLimit(2...4)
|
|
.disabled(!settings.isEnabled)
|
|
|
|
if settings.preservedSpellings.isEmpty {
|
|
Text("No preserved spellings")
|
|
.foregroundStyle(.secondary)
|
|
} else {
|
|
ForEach(settings.preservedSpellings.indices, id: \.self) { index in
|
|
HStack {
|
|
Text(settings.preservedSpellings[index])
|
|
.lineLimit(1)
|
|
|
|
Spacer()
|
|
|
|
Button {
|
|
settings.preservedSpellings.remove(at: index)
|
|
} label: {
|
|
Label("Remove preserved spelling", systemImage: "minus.circle")
|
|
.labelStyle(.iconOnly)
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.help("Remove preserved spelling")
|
|
}
|
|
}
|
|
}
|
|
|
|
HStack {
|
|
TextField("Preserve spelling", text: $newPreservedSpelling)
|
|
.onSubmit(addPreservedSpelling)
|
|
|
|
Button(action: addPreservedSpelling) {
|
|
Label("Add preserved spelling", systemImage: "plus.circle.fill")
|
|
.labelStyle(.iconOnly)
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.disabled(trimmedNewPreservedSpelling.isEmpty)
|
|
.help("Add preserved spelling")
|
|
}
|
|
.disabled(!settings.isEnabled)
|
|
}
|
|
|
|
private var userNotesBinding: Binding<String> {
|
|
Binding {
|
|
settings.userNotes ?? ""
|
|
} set: { newValue in
|
|
let trimmedValue = newValue.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
settings.userNotes = trimmedValue.isEmpty ? nil : trimmedValue
|
|
}
|
|
}
|
|
|
|
private var trimmedNewPreservedSpelling: String {
|
|
newPreservedSpelling.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
}
|
|
|
|
private func addPreservedSpelling() {
|
|
let spelling = trimmedNewPreservedSpelling
|
|
guard !spelling.isEmpty, !settings.preservedSpellings.contains(spelling) else {
|
|
return
|
|
}
|
|
|
|
settings.preservedSpellings.append(spelling)
|
|
newPreservedSpelling = ""
|
|
}
|
|
}
|