From 45c6f93f8fffbf829cf60d1e3bddc0f0ba34a969 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Mon, 29 Apr 2024 22:08:31 -0400 Subject: [PATCH] new file and reload --- src/config/quickphrase.swift | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/config/quickphrase.swift b/src/config/quickphrase.swift index 55682d7..62471a3 100644 --- a/src/config/quickphrase.swift +++ b/src/config/quickphrase.swift @@ -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() @ObservedObject private var quickphraseVM = QuickPhraseVM() @@ -122,6 +124,18 @@ struct QuickPhraseView: View { } } VStack { + Button { + reloadQuickPhrase() + } label: { + Text("Reload") + } + + Button { + showNewFile = true + } label: { + Text("New file") + } + Button { mkdirP(localQuickphrasePath) writeUTF8( @@ -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) }