Skip to content

Commit

Permalink
new file and reload
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Apr 30, 2024
1 parent d1385b0 commit 45c6f93
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/config/quickphrase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private func quickPhrasesToString(_ quickPhrases: [QuickPhrase]) -> String {
}

struct QuickPhraseView: View {
@State private var showNewFile = false
@State private var newFileName = ""
@State private var selectedRows = Set<UUID>()
@ObservedObject private var quickphraseVM = QuickPhraseVM()

Expand Down Expand Up @@ -122,6 +124,18 @@ struct QuickPhraseView: View {
}
}
VStack {
Button {
reloadQuickPhrase()
} label: {
Text("Reload")
}

Button {
showNewFile = true
} label: {
Text("New file")
}

Button {
mkdirP(localQuickphrasePath)
writeUTF8(
Expand Down Expand Up @@ -174,6 +188,27 @@ struct QuickPhraseView: View {
Text("Open directory")
}
}
.sheet(isPresented: $showNewFile) {
VStack {
HStack {
Text("Name")
TextField("", text: $newFileName)
}
Button {
if !newFileName.isEmpty && !quickphraseVM.userFiles.contains(newFileName) {
let localURL = localQuickphraseDir.appendingPathComponent(newFileName + ".mb")
writeUTF8(localURL, "")
showNewFile = false
refreshFiles()
quickphraseVM.current = newFileName
newFileName = ""
}
} label: {
Text("Create")
}
}.padding()
.frame(minWidth: 200)
}
}.padding()
.frame(minWidth: 500, minHeight: 300)
}
Expand Down

0 comments on commit 45c6f93

Please sign in to comment.