Skip to content

Commit

Permalink
remove items
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Apr 30, 2024
1 parent 45c6f93 commit 2010a8a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/config/quickphrase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ private let minKeywordColumnWidth: CGFloat = 100
private let minPhraseColumnWidth: CGFloat = 200

class QuickPhraseVM: ObservableObject {
@Published var current = ""
@Published var selectedRows = Set<UUID>()
@Published var current = "" {
didSet {
selectedRows.removeAll()
}
}
@Published private(set) var userFiles: [String] = []
@Published private(set) var files: [String] = []
@Published var quickPhrases: [String: [QuickPhrase]] = [:]
Expand Down Expand Up @@ -78,7 +83,6 @@ 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()

func refreshFiles() -> some View {
Expand All @@ -99,7 +103,7 @@ struct QuickPhraseView: View {
Text(file)
}
}
List(selection: $selectedRows) {
List(selection: $quickphraseVM.selectedRows) {
HStack {
Text("Keyword").frame(
minWidth: minKeywordColumnWidth, maxWidth: .infinity, alignment: .leading)
Expand Down Expand Up @@ -136,6 +140,15 @@ struct QuickPhraseView: View {
Text("New file")
}

Button {
quickphraseVM.quickPhrases[quickphraseVM.current]?.removeAll {
quickphraseVM.selectedRows.contains($0.id)
}
quickphraseVM.selectedRows.removeAll()
} label: {
Text("Remove items")
}.disabled(quickphraseVM.selectedRows.isEmpty)

Button {
mkdirP(localQuickphrasePath)
writeUTF8(
Expand Down

0 comments on commit 2010a8a

Please sign in to comment.